diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 06:37:09 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 06:37:09 +0000 |
commit | 1aad332c7d47b1adc56708130d36dc1f513b67ae (patch) | |
tree | 9103e4927e301881f73e5798d4cac8f2f4986afd /ui/aura | |
parent | 382a064036206876b25fdd9052fe073721bebbb5 (diff) | |
download | chromium_src-1aad332c7d47b1adc56708130d36dc1f513b67ae.zip chromium_src-1aad332c7d47b1adc56708130d36dc1f513b67ae.tar.gz chromium_src-1aad332c7d47b1adc56708130d36dc1f513b67ae.tar.bz2 |
Add EnvEventFilter to filter events before root window process event
Factor out CursorManager from RootWindowEventFilter
Review URL: https://chromiumcodereview.appspot.com/10444107
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140714 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/aura.gyp | 9 | ||||
-rw-r--r-- | ui/aura/cursor_delegate.h | 27 | ||||
-rw-r--r-- | ui/aura/cursor_manager.cc | 58 | ||||
-rw-r--r-- | ui/aura/cursor_manager.h | 59 | ||||
-rw-r--r-- | ui/aura/env.cc | 7 | ||||
-rw-r--r-- | ui/aura/env.h | 12 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 3 | ||||
-rw-r--r-- | ui/aura/root_window.h | 1 | ||||
-rw-r--r-- | ui/aura/shared/compound_event_filter.cc (renamed from ui/aura/shared/root_window_event_filter.cc) | 108 | ||||
-rw-r--r-- | ui/aura/shared/compound_event_filter.h (renamed from ui/aura/shared/root_window_event_filter.h) | 54 | ||||
-rw-r--r-- | ui/aura/shared/compound_event_filter_unittest.cc (renamed from ui/aura/shared/root_window_event_filter_unittest.cc) | 24 | ||||
-rw-r--r-- | ui/aura/shared/input_method_event_filter_unittest.cc | 10 |
12 files changed, 244 insertions, 128 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 1707e0f..f8efe8c 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -54,6 +54,9 @@ 'client/window_move_client.cc', 'client/window_move_client.h', 'client/window_types.h', + 'cursor_delegate.h', + 'cursor_manager.cc', + 'cursor_manager.h', 'desktop/desktop_activation_client.cc', 'desktop/desktop_activation_client.h', 'desktop/desktop_dispatcher_client.cc', @@ -99,10 +102,10 @@ 'root_window_view_mac.mm', 'root_window.cc', 'root_window.h', + 'shared/compound_event_filter.cc', + 'shared/compound_event_filter.h', 'shared/input_method_event_filter.cc', 'shared/input_method_event_filter.h', - 'shared/root_window_event_filter.cc', - 'shared/root_window_event_filter.h', 'single_monitor_manager.cc', 'single_monitor_manager.h', 'ui_controls_win.cc', @@ -275,8 +278,8 @@ 'test/test_suite.cc', 'test/test_suite.h', 'root_window_unittest.cc', + 'shared/compound_event_filter_unittest.cc', 'shared/input_method_event_filter_unittest.cc', - 'shared/root_window_event_filter_unittest.cc', 'event_filter_unittest.cc', 'event_unittest.cc', 'window_unittest.cc', diff --git a/ui/aura/cursor_delegate.h b/ui/aura/cursor_delegate.h new file mode 100644 index 0000000..b21bbe8 --- /dev/null +++ b/ui/aura/cursor_delegate.h @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_AURA_CURSOR_DELEGATE_H_ +#define UI_AURA_CURSOR_DELEGATE_H_ +#pragma once + +#include "ui/aura/aura_export.h" +#include "ui/gfx/native_widget_types.h" + +namespace aura { + +// This interface is implmented by a platform specific object that changes +// the cursor's image and visibility. +class AURA_EXPORT CursorDelegate { + public: + virtual void SetCursor(gfx::NativeCursor cursor) = 0; + virtual void ShowCursor(bool visible) = 0; + + protected: + virtual ~CursorDelegate() {}; +}; + +} // namespace aura + +#endif // UI_AURA_CURSOR_DELEGATE_H_ diff --git a/ui/aura/cursor_manager.cc b/ui/aura/cursor_manager.cc new file mode 100644 index 0000000..30c7af1c --- /dev/null +++ b/ui/aura/cursor_manager.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura/cursor_manager.h" + +#include "base/logging.h" +#include "ui/aura/cursor_delegate.h" +#include "ui/aura/env.h" + +namespace aura { + +CursorManager::CursorManager() + : delegate_(NULL), + cursor_lock_count_(0), + did_cursor_change_(false), + cursor_to_set_on_unlock_(0), + cursor_visible_(true) { +} + +CursorManager::~CursorManager() { +} + +void CursorManager::LockCursor() { + cursor_lock_count_++; +} + +void CursorManager::UnlockCursor() { + cursor_lock_count_--; + DCHECK_GE(cursor_lock_count_, 0); + if (cursor_lock_count_ == 0) { + if (did_cursor_change_) { + did_cursor_change_ = false; + if (delegate_) + delegate_->SetCursor(cursor_to_set_on_unlock_); + } + did_cursor_change_ = false; + cursor_to_set_on_unlock_ = gfx::kNullCursor; + } +} + +void CursorManager::SetCursor(gfx::NativeCursor cursor) { + if (cursor_lock_count_ == 0) { + if (delegate_) + delegate_->SetCursor(cursor); + } else { + cursor_to_set_on_unlock_ = cursor; + did_cursor_change_ = true; + } +} + +void CursorManager::ShowCursor(bool show) { + cursor_visible_ = show; + if (delegate_) + delegate_->ShowCursor(show); +} + +} // namespace aura diff --git a/ui/aura/cursor_manager.h b/ui/aura/cursor_manager.h new file mode 100644 index 0000000..2ca4817 --- /dev/null +++ b/ui/aura/cursor_manager.h @@ -0,0 +1,59 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_AURA_CURSOR_MANAGER_H_ +#define UI_AURA_CURSOR_MANAGER_H_ +#pragma once + +#include "base/basictypes.h" +#include "ui/aura/aura_export.h" +#include "ui/gfx/native_widget_types.h" + +namespace aura { +class CursorDelegate; + +// This class controls the visibility and the type of the cursor. +// The cursor type can be locked so that the type stays the same +// until it's unlocked. +class AURA_EXPORT CursorManager { + public: + CursorManager(); + ~CursorManager(); + + void set_delegate(CursorDelegate* delegate) { delegate_ = delegate; } + + // Locks/Unlocks the cursor change. + void LockCursor(); + void UnlockCursor(); + + void SetCursor(gfx::NativeCursor); + + // Shows or hides the cursor. + void ShowCursor(bool show); + bool cursor_visible() const { return cursor_visible_; } + + private: + CursorDelegate* delegate_; + + // Number of times LockCursor() has been invoked without a corresponding + // UnlockCursor(). + int cursor_lock_count_; + + // Set to true if UpdateCursor() is invoked while |cursor_lock_count_| == 0. + bool did_cursor_change_; + + // Cursor to set once |cursor_lock_count_| is set to 0. Only valid if + // |did_cursor_change_| is true. + gfx::NativeCursor cursor_to_set_on_unlock_; + + // Is cursor visible? + bool cursor_visible_; + + DISALLOW_COPY_AND_ASSIGN(CursorManager); +}; + +} // namespace aura + +#endif // UI_AURA_CURSOR_MANAGER_H_ + diff --git a/ui/aura/env.cc b/ui/aura/env.cc index ef160b0..58eea0a 100644 --- a/ui/aura/env.cc +++ b/ui/aura/env.cc @@ -3,7 +3,10 @@ // found in the LICENSE file. #include "ui/aura/env.h" + +#include "ui/aura/cursor_manager.h" #include "ui/aura/env_observer.h" +#include "ui/aura/event_filter.h" #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window_host.h" #include "ui/aura/window.h" @@ -62,6 +65,10 @@ void Env::SetMonitorManager(MonitorManager* monitor_manager) { #endif } +void Env::SetEventFilter(EventFilter* event_filter) { + event_filter_.reset(event_filter); +} + #if !defined(OS_MACOSX) MessageLoop::Dispatcher* Env::GetDispatcher() { return dispatcher_.get(); diff --git a/ui/aura/env.h b/ui/aura/env.h index d3925c7..e8e787d8 100644 --- a/ui/aura/env.h +++ b/ui/aura/env.h @@ -10,11 +10,13 @@ #include "base/message_loop.h" #include "base/observer_list.h" #include "ui/aura/aura_export.h" +#include "ui/aura/cursor_manager.h" #include "ui/aura/client/stacking_client.h" namespace aura { - +class CursorManager; class EnvObserver; +class EventFilter; class MonitorManager; class Window; @@ -59,6 +61,12 @@ class AURA_EXPORT Env { MonitorManager* monitor_manager() { return monitor_manager_.get(); } void SetMonitorManager(MonitorManager* monitor_manager); + // Env takes ownership of the EventFilter. + EventFilter* event_filter() { return event_filter_.get(); } + void SetEventFilter(EventFilter* event_filter); + + CursorManager* cursor_manager() { return &cursor_manager_; } + // Returns the native event dispatcher. The result should only be passed to // MessageLoopForUI::RunWithDispatcher() or // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch @@ -85,6 +93,8 @@ class AURA_EXPORT Env { bool is_touch_down_; client::StackingClient* stacking_client_; scoped_ptr<MonitorManager> monitor_manager_; + scoped_ptr<EventFilter> event_filter_; + CursorManager cursor_manager_; #if defined(USE_X11) scoped_ptr<internal::MonitorChangeObserverX11> monitor_change_observer_; diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index d5130f8..0538c6f 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -72,6 +72,8 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) { filters->push_back(target->event_filter()); target = target->parent(); } + if (Env::GetInstance()->event_filter()) + filters->push_back(Env::GetInstance()->event_filter()); } float GetDeviceScaleFactorFromMonitor(const aura::Window* window) { @@ -118,7 +120,6 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds) mouse_button_flags_(0), touch_ids_down_(0), last_cursor_(ui::kCursorNull), - cursor_shown_(true), capture_window_(NULL), mouse_pressed_handler_(NULL), mouse_moved_handler_(NULL), diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 32bed2f..b5f02cf 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -92,7 +92,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, ui::Compositor* compositor() { return compositor_.get(); } gfx::Point last_mouse_location() const { return last_mouse_location_; } gfx::NativeCursor last_cursor() const { return last_cursor_; } - bool cursor_shown() const { return cursor_shown_; } Window* mouse_pressed_handler() { return mouse_pressed_handler_; } Window* capture_window() { return capture_window_; } diff --git a/ui/aura/shared/root_window_event_filter.cc b/ui/aura/shared/compound_event_filter.cc index a1454ec..66852d23e 100644 --- a/ui/aura/shared/root_window_event_filter.cc +++ b/ui/aura/shared/compound_event_filter.cc @@ -2,9 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/aura/shared/root_window_event_filter.h" +#include "ui/aura/shared/compound_event_filter.h" #include "ui/aura/client/activation_client.h" +#include "ui/aura/cursor_manager.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" #include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" @@ -22,27 +24,28 @@ aura::Window* FindFocusableWindowFor(aura::Window* window) { return window; } +aura::Window* GetActiveWindow(aura::Window* window) { + DCHECK(window->GetRootWindow()); + return aura::client::GetActivationClient(window->GetRootWindow())-> + GetActiveWindow(); +} + } // namespace //////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, public: +// CompoundEventFilter, public: -RootWindowEventFilter::RootWindowEventFilter(aura::RootWindow* root_window) - : root_window_(root_window), - cursor_lock_count_(0), - did_cursor_change_(false), - cursor_to_set_on_unlock_(0), - update_cursor_visibility_(true) { +CompoundEventFilter::CompoundEventFilter() : update_cursor_visibility_(true) { } -RootWindowEventFilter::~RootWindowEventFilter() { - // Additional filters are not owned by RootWindowEventFilter and they +CompoundEventFilter::~CompoundEventFilter() { + // Additional filters are not owned by CompoundEventFilter and they // should all be removed when running here. |filters_| has // check_empty == true and will DCHECK failure if it is not empty. } // static -gfx::NativeCursor RootWindowEventFilter::CursorForWindowComponent( +gfx::NativeCursor CompoundEventFilter::CursorForWindowComponent( int window_component) { switch (window_component) { case HTBOTTOM: @@ -66,45 +69,28 @@ gfx::NativeCursor RootWindowEventFilter::CursorForWindowComponent( } } -void RootWindowEventFilter::LockCursor() { - cursor_lock_count_++; -} - -void RootWindowEventFilter::UnlockCursor() { - cursor_lock_count_--; - DCHECK_GE(cursor_lock_count_, 0); - if (cursor_lock_count_ == 0) { - if (did_cursor_change_) { - did_cursor_change_ = false; - root_window_->SetCursor(cursor_to_set_on_unlock_); - } - did_cursor_change_ = false; - cursor_to_set_on_unlock_ = 0; - } -} - -void RootWindowEventFilter::AddFilter(aura::EventFilter* filter) { +void CompoundEventFilter::AddFilter(aura::EventFilter* filter) { filters_.AddObserver(filter); } -void RootWindowEventFilter::RemoveFilter(aura::EventFilter* filter) { +void CompoundEventFilter::RemoveFilter(aura::EventFilter* filter) { filters_.RemoveObserver(filter); } -size_t RootWindowEventFilter::GetFilterCount() const { +size_t CompoundEventFilter::GetFilterCount() const { return filters_.size(); } //////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, EventFilter implementation: +// CompoundEventFilter, EventFilter implementation: -bool RootWindowEventFilter::PreHandleKeyEvent(aura::Window* target, +bool CompoundEventFilter::PreHandleKeyEvent(aura::Window* target, aura::KeyEvent* event) { return FilterKeyEvent(target, event); } -bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { +bool CompoundEventFilter::PreHandleMouseEvent(aura::Window* target, + aura::MouseEvent* event) { // We must always update the cursor, otherwise the cursor can get stuck if an // event filter registered with us consumes the event. // It should also update the cursor for clicking and wheels for ChromeOS boot. @@ -113,23 +99,23 @@ bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target, if (event->type() == ui::ET_MOUSE_MOVED || event->type() == ui::ET_MOUSE_PRESSED || event->type() == ui::ET_MOUSEWHEEL) { - if (update_cursor_visibility_) - SetCursorVisible(target, event, true); - + SetVisibilityOnEvent(event, true); UpdateCursor(target, event); } if (FilterMouseEvent(target, event)) return true; - if (event->type() == ui::ET_MOUSE_PRESSED && GetActiveWindow() != target) + if (event->type() == ui::ET_MOUSE_PRESSED + && GetActiveWindow(target) != target) { target->GetFocusManager()->SetFocusedWindow( FindFocusableWindowFor(target), event); + } return false; } -ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( +ui::TouchStatus CompoundEventFilter::PreHandleTouchEvent( aura::Window* target, aura::TouchEvent* event) { ui::TouchStatus status = FilterTouchEvent(target, event); @@ -137,16 +123,15 @@ ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( return status; if (event->type() == ui::ET_TOUCH_PRESSED) { - if (update_cursor_visibility_) - SetCursorVisible(target, event, false); - + SetVisibilityOnEvent(event, false); target->GetFocusManager()->SetFocusedWindow( FindFocusableWindowFor(target), event); } + return ui::TOUCH_STATUS_UNKNOWN; } -ui::GestureStatus RootWindowEventFilter::PreHandleGestureEvent( +ui::GestureStatus CompoundEventFilter::PreHandleGestureEvent( aura::Window* target, aura::GestureEvent* event) { ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; @@ -162,33 +147,21 @@ ui::GestureStatus RootWindowEventFilter::PreHandleGestureEvent( } //////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, private: +// CompoundEventFilter, private: -void RootWindowEventFilter::UpdateCursor(aura::Window* target, - aura::MouseEvent* event) { +void CompoundEventFilter::UpdateCursor(aura::Window* target, + aura::MouseEvent* event) { gfx::NativeCursor cursor = target->GetCursor(event->location()); if (event->flags() & ui::EF_IS_NON_CLIENT) { int window_component = target->delegate()->GetNonClientComponent(event->location()); cursor = CursorForWindowComponent(window_component); } - if (cursor_lock_count_ == 0) { - root_window_->SetCursor(cursor); - } else { - cursor_to_set_on_unlock_ = cursor; - did_cursor_change_ = true; - } -} - -void RootWindowEventFilter::SetCursorVisible(aura::Window* target, - aura::LocatedEvent* event, - bool show) { - if (!(event->flags() & ui::EF_IS_SYNTHESIZED)) - root_window_->ShowCursor(show); + Env::GetInstance()->cursor_manager()->SetCursor(cursor); } -bool RootWindowEventFilter::FilterKeyEvent(aura::Window* target, - aura::KeyEvent* event) { +bool CompoundEventFilter::FilterKeyEvent(aura::Window* target, + aura::KeyEvent* event) { bool handled = false; if (filters_.might_have_observers()) { ObserverListBase<aura::EventFilter>::Iterator it(filters_); @@ -199,7 +172,7 @@ bool RootWindowEventFilter::FilterKeyEvent(aura::Window* target, return handled; } -bool RootWindowEventFilter::FilterMouseEvent(aura::Window* target, +bool CompoundEventFilter::FilterMouseEvent(aura::Window* target, aura::MouseEvent* event) { bool handled = false; if (filters_.might_have_observers()) { @@ -211,7 +184,7 @@ bool RootWindowEventFilter::FilterMouseEvent(aura::Window* target, return handled; } -ui::TouchStatus RootWindowEventFilter::FilterTouchEvent( +ui::TouchStatus CompoundEventFilter::FilterTouchEvent( aura::Window* target, aura::TouchEvent* event) { ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; @@ -226,9 +199,10 @@ ui::TouchStatus RootWindowEventFilter::FilterTouchEvent( return status; } -Window* RootWindowEventFilter::GetActiveWindow() { - return aura::client::GetActivationClient(root_window_)-> - GetActiveWindow(); +void CompoundEventFilter::SetVisibilityOnEvent(aura::LocatedEvent* event, + bool show) { + if (update_cursor_visibility_ && !(event->flags() & ui::EF_IS_SYNTHESIZED)) + Env::GetInstance()->cursor_manager()->ShowCursor(show); } } // namespace shared diff --git a/ui/aura/shared/root_window_event_filter.h b/ui/aura/shared/compound_event_filter.h index b579737..7788d5f 100644 --- a/ui/aura/shared/root_window_event_filter.h +++ b/ui/aura/shared/compound_event_filter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_AURA_SHARED_ROOT_WINDOW_EVENT_FILTER_H_ -#define UI_AURA_SHARED_ROOT_WINDOW_EVENT_FILTER_H_ +#ifndef UI_AURA_SHARED_COMPOUND_EVENT_FILTER_H_ +#define UI_AURA_SHARED_COMPOUND_EVENT_FILTER_H_ #pragma once #include "base/compiler_specific.h" @@ -13,32 +13,27 @@ #include "ui/aura/event_filter.h" namespace aura { +class CursorManager; class RootWindow; namespace shared { -// RootWindowEventFilter gets all root window events first and can provide -// actions to those events. It implements root window features such as click to -// activate a window and cursor change when moving mouse. -// Additional event filters can be added to RootWindowEventFilter. Events will +// CompoundEventFilter gets all events first and can provide actions to those +// events. It implements global features such as click to activate a window and +// cursor change when moving mouse. +// Additional event filters can be added to CompoundEventFilter. Events will // pass through those additional filters in their addition order and could be // consumed by any of those filters. If an event is consumed by a filter, the -// rest of the filter(s) and RootWindowEventFilter will not see the consumed +// rest of the filter(s) and CompoundEventFilter will not see the consumed // event. -class AURA_EXPORT RootWindowEventFilter : public aura::EventFilter { +class AURA_EXPORT CompoundEventFilter : public aura::EventFilter { public: - RootWindowEventFilter(aura::RootWindow* root_window); - virtual ~RootWindowEventFilter(); + CompoundEventFilter(); + virtual ~CompoundEventFilter(); // Returns the cursor for the specified component. static gfx::NativeCursor CursorForWindowComponent(int window_component); - // Freezes updates to the cursor until UnlockCursor() is invoked. - void LockCursor(); - - // Unlocks the cursor. - void UnlockCursor(); - void set_update_cursor_visibility(bool update) { update_cursor_visibility_ = update; } @@ -65,11 +60,6 @@ class AURA_EXPORT RootWindowEventFilter : public aura::EventFilter { // default resize cursors for window edges. void UpdateCursor(aura::Window* target, aura::MouseEvent* event); - // Sets the cursor invisible when the target receives touch press event. - void SetCursorVisible(aura::Window* target, - aura::LocatedEvent* event, - bool show); - // Dispatches event to additional filters. Returns false or // ui::TOUCH_STATUS_UNKNOWN if event is consumed. bool FilterKeyEvent(aura::Window* target, aura::KeyEvent* event); @@ -77,33 +67,21 @@ class AURA_EXPORT RootWindowEventFilter : public aura::EventFilter { ui::TouchStatus FilterTouchEvent(aura::Window* target, aura::TouchEvent* event); - // Gets the active window from the activation client. - aura::Window* GetActiveWindow(); - - aura::RootWindow* root_window_; + // Sets the visibility of the cursor if the event is not synthesized and + // |update_cursor_visibility_| is true. + void SetVisibilityOnEvent(aura::LocatedEvent* event, bool show); // Additional event filters that pre-handles events. ObserverList<aura::EventFilter, true> filters_; - // Number of times LockCursor() has been invoked without a corresponding - // UnlockCursor(). - int cursor_lock_count_; - - // Set to true if UpdateCursor() is invoked while |cursor_lock_count_| == 0. - bool did_cursor_change_; - - // Cursor to set once |cursor_lock_count_| is set to 0. Only valid if - // |did_cursor_change_| is true. - gfx::NativeCursor cursor_to_set_on_unlock_; - // Should we show the mouse cursor when we see mouse movement and hide it when // we see a touch event? bool update_cursor_visibility_; - DISALLOW_COPY_AND_ASSIGN(RootWindowEventFilter); + DISALLOW_COPY_AND_ASSIGN(CompoundEventFilter); }; } // namespace shared } // namespace aura -#endif // UI_AURA_ROOT_WINDOW_EVENT_FILTER_H_ +#endif // UI_AURA_COMPOUND_EVENT_FILTER_H_ diff --git a/ui/aura/shared/root_window_event_filter_unittest.cc b/ui/aura/shared/compound_event_filter_unittest.cc index 08561e5..ef98222 100644 --- a/ui/aura/shared/root_window_event_filter_unittest.cc +++ b/ui/aura/shared/compound_event_filter_unittest.cc @@ -2,9 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/aura/shared/root_window_event_filter.h" +#include "ui/aura/shared/compound_event_filter.h" #include "ui/aura/client/activation_client.h" +#include "ui/aura/cursor_manager.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/test_activation_client.h" @@ -19,13 +21,10 @@ base::TimeDelta GetTime() { namespace aura { namespace test { -typedef AuraTestBase RootWindowEventFilterTest; - -TEST_F(RootWindowEventFilterTest, TouchHidesCursor) { - shared::RootWindowEventFilter* root_filter = - new shared::RootWindowEventFilter(root_window()); - root_window()->SetEventFilter(root_filter); +typedef AuraTestBase CompoundEventFilterTest; +TEST_F(CompoundEventFilterTest, TouchHidesCursor) { + aura::Env::GetInstance()->SetEventFilter(new shared::CompoundEventFilter()); aura::client::SetActivationClient(root_window(), new TestActivationClient(root_window())); TestWindowDelegate delegate; @@ -33,29 +32,30 @@ TEST_F(RootWindowEventFilterTest, TouchHidesCursor) { gfx::Rect(5, 5, 100, 100), NULL)); window->Show(); root_window()->SetCapture(window.get()); + CursorManager* cursor_manager = aura::Env::GetInstance()->cursor_manager(); MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(15, 15), 0); root_window()->DispatchMouseEvent(&mouse); - EXPECT_TRUE(root_window()->cursor_shown()); + EXPECT_TRUE(cursor_manager->cursor_visible()); // This press is required for the GestureRecognizer to associate a target // with kTouchId TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(90, 90), 1, GetTime()); root_window()->DispatchTouchEvent(&press); - EXPECT_FALSE(root_window()->cursor_shown()); + EXPECT_FALSE(cursor_manager->cursor_visible()); TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 1, GetTime()); root_window()->DispatchTouchEvent(&move); - EXPECT_FALSE(root_window()->cursor_shown()); + EXPECT_FALSE(cursor_manager->cursor_visible()); TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(10, 10), 1, GetTime()); root_window()->DispatchTouchEvent(&release); - EXPECT_FALSE(root_window()->cursor_shown()); + EXPECT_FALSE(cursor_manager->cursor_visible()); root_window()->DispatchMouseEvent(&mouse); - EXPECT_TRUE(root_window()->cursor_shown()); + EXPECT_TRUE(cursor_manager->cursor_visible()); } } // namespace test diff --git a/ui/aura/shared/input_method_event_filter_unittest.cc b/ui/aura/shared/input_method_event_filter_unittest.cc index 4b11c98..97fedd7 100644 --- a/ui/aura/shared/input_method_event_filter_unittest.cc +++ b/ui/aura/shared/input_method_event_filter_unittest.cc @@ -8,7 +8,7 @@ #include "ui/aura/client/activation_client.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" -#include "ui/aura/shared/root_window_event_filter.h" +#include "ui/aura/shared/compound_event_filter.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/test/test_activation_client.h" @@ -29,8 +29,8 @@ namespace test { typedef AuraTestBase InputMethodEventFilterTest; TEST_F(InputMethodEventFilterTest, TestInputMethodProperty) { - aura::shared::RootWindowEventFilter* root_filter = - new aura::shared::RootWindowEventFilter(root_window()); + aura::shared::CompoundEventFilter* root_filter = + new aura::shared::CompoundEventFilter; root_window()->SetEventFilter(root_filter); // Add the InputMethodEventFilter before the TestEventFilter. @@ -51,8 +51,8 @@ TEST_F(InputMethodEventFilterTest, TestInputMethodKeyEventPropagation) { aura::client::SetActivationClient(root_window(), new TestActivationClient(root_window())); - aura::shared::RootWindowEventFilter* root_filter = - new shared::RootWindowEventFilter(root_window()); + aura::shared::CompoundEventFilter* root_filter = + new shared::CompoundEventFilter; root_window()->SetEventFilter(root_filter); // Add the InputMethodEventFilter before the TestEventFilter. |