diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 00:41:29 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 00:41:29 +0000 |
commit | c0ff0340954f19263637fb2372c9e919f46a5824 (patch) | |
tree | 976d0ad35ea92b6e253a8468886beac981e0176c /ash | |
parent | 6849597e3208cd7e86e927903caae3686deeddaa (diff) | |
download | chromium_src-c0ff0340954f19263637fb2372c9e919f46a5824.zip chromium_src-c0ff0340954f19263637fb2372c9e919f46a5824.tar.gz chromium_src-c0ff0340954f19263637fb2372c9e919f46a5824.tar.bz2 |
Rework ash::CursorManager into a corewm object, to share code with desktop.
Desktop aura no longer spams the console with enable/disable mouse pointer messages.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/12263050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
25 files changed, 376 insertions, 692 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 5cae6a8..a4c6f7c 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -305,6 +305,8 @@ 'wm/always_on_top_controller.h', 'wm/ash_activation_controller.cc', 'wm/ash_activation_controller.h', + 'wm/ash_native_cursor_manager.cc', + 'wm/ash_native_cursor_manager.h', 'wm/ash_focus_rules.cc', 'wm/ash_focus_rules.h', 'wm/base_layout_manager.cc', @@ -315,8 +317,6 @@ 'wm/capture_controller.h', 'wm/coordinate_conversion.cc', 'wm/coordinate_conversion.h', - 'wm/cursor_manager.cc', - 'wm/cursor_manager.h', 'wm/custom_frame_view_ash.cc', 'wm/custom_frame_view_ash.h', 'wm/default_window_resizer.cc', @@ -622,8 +622,8 @@ 'tooltips/tooltip_controller_unittest.cc', 'wm/activation_controller_unittest.cc', 'wm/ash_activation_controller_unittest.cc', + 'wm/ash_native_cursor_manager_unittest.cc', 'wm/base_layout_manager_unittest.cc', - 'wm/cursor_manager_unittest.cc', 'wm/custom_frame_view_ash_unittest.cc', 'wm/drag_window_resizer_unittest.cc', 'wm/frame_painter_unittest.cc', diff --git a/ash/display/mouse_cursor_event_filter.cc b/ash/display/mouse_cursor_event_filter.cc index eb356ff..7534ea1 100644 --- a/ash/display/mouse_cursor_event_filter.cc +++ b/ash/display/mouse_cursor_event_filter.cc @@ -9,7 +9,6 @@ #include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/wm/coordinate_conversion.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/window_util.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" diff --git a/ash/display/mouse_cursor_event_filter_unittest.cc b/ash/display/mouse_cursor_event_filter_unittest.cc index 00a53f5..1812944 100644 --- a/ash/display/mouse_cursor_event_filter_unittest.cc +++ b/ash/display/mouse_cursor_event_filter_unittest.cc @@ -8,7 +8,6 @@ #include "ash/test/ash_test_base.h" #include "ash/test/cursor_manager_test_api.h" #include "ash/display/display_controller.h" -#include "ash/wm/cursor_manager.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/gfx/display.h" diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc index fbab70f..c13e087 100644 --- a/ash/drag_drop/drag_drop_controller.cc +++ b/ash/drag_drop/drag_drop_controller.cc @@ -8,7 +8,6 @@ #include "ash/drag_drop/drag_image_view.h" #include "ash/shell.h" #include "ash/wm/coordinate_conversion.h" -#include "ash/wm/cursor_manager.h" #include "base/bind.h" #include "base/message_loop.h" #include "base/run_loop.h" diff --git a/ash/shell.cc b/ash/shell.cc index e44c477..1519420 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -40,6 +40,7 @@ #include "ash/wm/app_list_controller.h" #include "ash/wm/ash_activation_controller.h" #include "ash/wm/ash_focus_rules.h" +#include "ash/wm/ash_native_cursor_manager.h" #include "ash/wm/base_layout_manager.h" #include "ash/wm/capture_controller.h" #include "ash/wm/coordinate_conversion.h" @@ -198,6 +199,9 @@ Shell::Shell(ShellDelegate* delegate) #if defined(OS_CHROMEOS) output_configurator_(new chromeos::OutputConfigurator()), #endif // defined(OS_CHROMEOS) + native_cursor_manager_(new AshNativeCursorManager), + cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( + native_cursor_manager_)), browser_context_(NULL), simulate_modal_window_open_for_testing_(false) { DCHECK(delegate_.get()); diff --git a/ash/shell.h b/ash/shell.h index 168854f..c6047ea00 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -11,7 +11,6 @@ #include "ash/ash_export.h" #include "ash/shelf_types.h" #include "ash/system/user/login_status.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/system_modal_container_event_filter_delegate.h" #include "base/basictypes.h" #include "base/compiler_specific.h" @@ -23,6 +22,7 @@ #include "ui/gfx/insets.h" #include "ui/gfx/screen.h" #include "ui/gfx/size.h" +#include "ui/views/corewm/cursor_manager.h" class CommandLine; @@ -71,6 +71,7 @@ class MessageCenter; namespace ash { class AcceleratorController; +class AshNativeCursorManager; class CapsLockDelegate; class DesktopBackgroundController; class DisplayController; @@ -327,7 +328,7 @@ class ASH_EXPORT Shell internal::EventTransformationHandler* event_transformation_handler() { return event_transformation_handler_.get(); } - CursorManager* cursor_manager() { return &cursor_manager_; } + views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; } ShellDelegate* delegate() { return delegate_.get(); } @@ -585,7 +586,10 @@ class ASH_EXPORT Shell scoped_ptr<message_center::MessageCenter> message_center_; - CursorManager cursor_manager_; + // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a + // pointer to vend to test code. + AshNativeCursorManager* native_cursor_manager_; + views::corewm::CursorManager cursor_manager_; ObserverList<ShellObserver> observers_; diff --git a/ash/test/cursor_manager_test_api.cc b/ash/test/cursor_manager_test_api.cc index bd24b0d..d3cf8f1 100644 --- a/ash/test/cursor_manager_test_api.cc +++ b/ash/test/cursor_manager_test_api.cc @@ -4,13 +4,17 @@ #include "ash/test/cursor_manager_test_api.h" -#include "ash/wm/cursor_manager.h" +#include "ash/shell.h" +#include "ash/test/shell_test_api.h" +#include "ash/wm/ash_native_cursor_manager.h" #include "ash/wm/image_cursors.h" +#include "ui/views/corewm/cursor_manager.h" namespace ash { namespace test { -CursorManagerTestApi::CursorManagerTestApi(CursorManager* cursor_manager) +CursorManagerTestApi::CursorManagerTestApi( + views::corewm::CursorManager* cursor_manager) : cursor_manager_(cursor_manager) { } @@ -18,11 +22,13 @@ CursorManagerTestApi::~CursorManagerTestApi() { } gfx::NativeCursor CursorManagerTestApi::GetCurrentCursor() const { - return cursor_manager_->GetCurrentCursor(); + return static_cast<views::corewm::NativeCursorManagerDelegate*>( + cursor_manager_)->GetCurrentCursor(); } float CursorManagerTestApi::GetDeviceScaleFactor() const { - return cursor_manager_->image_cursors_->GetDeviceScaleFactor(); + return ShellTestApi(Shell::GetInstance()).ash_native_cursor_manager()-> + image_cursors_->GetDeviceScaleFactor(); } } // namespace test diff --git a/ash/test/cursor_manager_test_api.h b/ash/test/cursor_manager_test_api.h index 73a6e4c..8299822 100644 --- a/ash/test/cursor_manager_test_api.h +++ b/ash/test/cursor_manager_test_api.h @@ -8,23 +8,26 @@ #include "base/basictypes.h" #include "ui/gfx/native_widget_types.h" -namespace ash { - +namespace views { +namespace corewm { class CursorManager; +} +} +namespace ash { namespace test { // Use the api in this class to test CursorManager. class CursorManagerTestApi { public: - explicit CursorManagerTestApi(CursorManager* cursor_manager); + explicit CursorManagerTestApi(views::corewm::CursorManager* cursor_manager); ~CursorManagerTestApi(); gfx::NativeCursor GetCurrentCursor() const; float GetDeviceScaleFactor() const; private: - CursorManager* cursor_manager_; + views::corewm::CursorManager* cursor_manager_; DISALLOW_COPY_AND_ASSIGN(CursorManagerTestApi); }; diff --git a/ash/test/shell_test_api.cc b/ash/test/shell_test_api.cc index 03dbb3a..f4ba794 100644 --- a/ash/test/shell_test_api.cc +++ b/ash/test/shell_test_api.cc @@ -35,6 +35,10 @@ ShellTestApi::screen_position_controller() { return shell_->screen_position_controller_.get(); } +AshNativeCursorManager* ShellTestApi::ash_native_cursor_manager() { + return shell_->native_cursor_manager_; +} + LauncherModel* ShellTestApi::launcher_model() { return shell_->launcher_model_.get(); } diff --git a/ash/test/shell_test_api.h b/ash/test/shell_test_api.h index 9ff7ef2..8f0ea44 100644 --- a/ash/test/shell_test_api.h +++ b/ash/test/shell_test_api.h @@ -14,6 +14,7 @@ class InputMethodEventFilter; } // namespace views namespace ash { +class AshNativeCursorManager; class Shell; class LauncherModel; @@ -36,6 +37,7 @@ public: internal::SystemGestureEventFilter* system_gesture_event_filter(); internal::WorkspaceController* workspace_controller(); internal::ScreenPositionController* screen_position_controller(); + AshNativeCursorManager* ash_native_cursor_manager(); LauncherModel* launcher_model(); private: diff --git a/ash/tooltips/tooltip_controller_unittest.cc b/ash/tooltips/tooltip_controller_unittest.cc index 85ded1e..4cc07b8 100644 --- a/ash/tooltips/tooltip_controller_unittest.cc +++ b/ash/tooltips/tooltip_controller_unittest.cc @@ -5,7 +5,6 @@ #include "ash/display/display_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" -#include "ash/wm/cursor_manager.h" #include "base/utf_string_conversions.h" #include "ui/aura/client/tooltip_client.h" #include "ui/aura/env.h" diff --git a/ash/wm/ash_native_cursor_manager.cc b/ash/wm/ash_native_cursor_manager.cc new file mode 100644 index 0000000..94a08bf --- /dev/null +++ b/ash/wm/ash_native_cursor_manager.cc @@ -0,0 +1,109 @@ +// 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 "ash/wm/ash_native_cursor_manager.h" + +#include "ash/shell.h" +#include "ash/wm/image_cursors.h" +#include "base/logging.h" +#include "ui/aura/env.h" +#include "ui/aura/root_window.h" +#include "ui/base/cursor/cursor.h" + +namespace { + +// The coordinate of the cursor used when the mouse events are disabled. +const int kDisabledCursorLocationX = -10000; +const int kDisabledCursorLocationY = -10000; + +void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { + ash::Shell::RootWindowList root_windows = + ash::Shell::GetInstance()->GetAllRootWindows(); + for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); + iter != root_windows.end(); ++iter) + (*iter)->SetCursor(cursor); +} + +void NotifyCursorVisibilityChange(bool visible) { + ash::Shell::RootWindowList root_windows = + ash::Shell::GetInstance()->GetAllRootWindows(); + for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); + iter != root_windows.end(); ++iter) + (*iter)->OnCursorVisibilityChanged(visible); +} + +void NotifyMouseEventsEnableStateChange(bool enabled) { + ash::Shell::RootWindowList root_windows = + ash::Shell::GetInstance()->GetAllRootWindows(); + for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); + iter != root_windows.end(); ++iter) + (*iter)->OnMouseEventsEnableStateChanged(enabled); +} + +} // namespace + +namespace ash { + +AshNativeCursorManager::AshNativeCursorManager() + : image_cursors_(new ImageCursors) { +} + +AshNativeCursorManager::~AshNativeCursorManager() { +} + +void AshNativeCursorManager::SetDeviceScaleFactor( + float device_scale_factor, + views::corewm::NativeCursorManagerDelegate* delegate) { + if (image_cursors_->SetDeviceScaleFactor(device_scale_factor)) + SetCursor(delegate->GetCurrentCursor(), delegate); +} + +void AshNativeCursorManager::SetCursor( + gfx::NativeCursor cursor, + views::corewm::NativeCursorManagerDelegate* delegate) { + gfx::NativeCursor new_cursor = cursor; + image_cursors_->SetPlatformCursor(&new_cursor); + new_cursor.set_device_scale_factor(image_cursors_->GetDeviceScaleFactor()); + + delegate->CommitCursor(new_cursor); + + if (delegate->GetCurrentVisibility()) + SetCursorOnAllRootWindows(new_cursor); +} + +void AshNativeCursorManager::SetVisibility( + bool visible, + views::corewm::NativeCursorManagerDelegate* delegate) { + delegate->CommitVisibility(visible); + + if (visible) { + SetCursor(delegate->GetCurrentCursor(), delegate); + } else { + gfx::NativeCursor invisible_cursor(ui::kCursorNone); + image_cursors_->SetPlatformCursor(&invisible_cursor); + SetCursorOnAllRootWindows(invisible_cursor); + } + + NotifyCursorVisibilityChange(visible); +} + +void AshNativeCursorManager::SetMouseEventsEnabled( + bool enabled, + views::corewm::NativeCursorManagerDelegate* delegate) { + delegate->CommitMouseEventsEnabled(enabled); + + if (enabled) { + aura::Env::GetInstance()->set_last_mouse_location( + disabled_cursor_location_); + } else { + disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); + aura::Env::GetInstance()->set_last_mouse_location( + gfx::Point(kDisabledCursorLocationX, kDisabledCursorLocationY)); + } + + SetVisibility(delegate->GetCurrentVisibility(), delegate); + NotifyMouseEventsEnableStateChange(enabled); +} + +} // namespace ash diff --git a/ash/wm/ash_native_cursor_manager.h b/ash/wm/ash_native_cursor_manager.h new file mode 100644 index 0000000..2364c70 --- /dev/null +++ b/ash/wm/ash_native_cursor_manager.h @@ -0,0 +1,62 @@ +// 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 ASH_WM_ASH_NATIVE_CURSOR_MANAGER_H_ +#define ASH_WM_ASH_NATIVE_CURSOR_MANAGER_H_ + +#include "ash/ash_export.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/point.h" +#include "ui/views/corewm/native_cursor_manager.h" +#include "ui/views/corewm/native_cursor_manager_delegate.h" + +namespace ash { + +namespace test { +class CursorManagerTestApi; +} + +class ImageCursors; + +// This does the ash-specific setting of cursor details like cursor +// visibility. It communicates back with the CursorManager through the +// NativeCursorManagerDelegate interface, which receives messages about what +// changes were acted on. +class ASH_EXPORT AshNativeCursorManager + : public views::corewm::NativeCursorManager { + public: + AshNativeCursorManager(); + virtual ~AshNativeCursorManager(); + + private: + friend class test::CursorManagerTestApi; + + // Overridden from views::corewm::NativeCursorManager: + virtual void SetDeviceScaleFactor( + float device_scale_factor, + views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + virtual void SetCursor( + gfx::NativeCursor cursor, + views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + virtual void SetVisibility( + bool visible, + views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + virtual void SetMouseEventsEnabled( + bool enabled, + views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + + // The cursor location where the cursor was disabled. + gfx::Point disabled_cursor_location_; + + scoped_ptr<ImageCursors> image_cursors_; + + DISALLOW_COPY_AND_ASSIGN(AshNativeCursorManager); +}; + +} // namespace ash + +#endif // ASH_WM_ASH_NATIVE_CURSOR_MANAGER_H_ diff --git a/ash/wm/ash_native_cursor_manager_unittest.cc b/ash/wm/ash_native_cursor_manager_unittest.cc new file mode 100644 index 0000000..2312cab --- /dev/null +++ b/ash/wm/ash_native_cursor_manager_unittest.cc @@ -0,0 +1,166 @@ +// 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 "ash/wm/ash_native_cursor_manager.h" + +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "ash/test/cursor_manager_test_api.h" +#include "ash/wm/image_cursors.h" +#include "ui/aura/root_window.h" +#include "ui/aura/test/test_window_delegate.h" +#include "ui/aura/test/test_windows.h" +#include "ui/aura/window.h" + +using views::corewm::CursorManager; + +namespace ash { +namespace test { + +namespace { + +// A delegate for recording a mouse event location. +class MouseEventLocationDelegate : public aura::test::TestWindowDelegate { + public: + MouseEventLocationDelegate() {} + virtual ~MouseEventLocationDelegate() {} + + const gfx::Point& mouse_event_location() const { + return mouse_event_location_; + } + + virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { + mouse_event_location_ = event->location(); + event->SetHandled(); + } + + private: + gfx::Point mouse_event_location_; + + DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); +}; + +} // namespace + +typedef test::AshTestBase AshNativeCursorManagerTest; + +TEST_F(AshNativeCursorManagerTest, LockCursor) { + CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); + CursorManagerTestApi test_api(cursor_manager); + + cursor_manager->SetCursor(ui::kCursorCopy); + EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); + cursor_manager->SetDeviceScaleFactor(2.0f); + EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); + + cursor_manager->LockCursor(); + EXPECT_TRUE(cursor_manager->is_cursor_locked()); + + // Cursor type does not change while cursor is locked. + cursor_manager->SetCursor(ui::kCursorPointer); + EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); + + // Device scale factor does change even while cursor is locked. + cursor_manager->SetDeviceScaleFactor(1.0f); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); + + cursor_manager->UnlockCursor(); + EXPECT_FALSE(cursor_manager->is_cursor_locked()); + + // Cursor type changes to the one specified while cursor is locked. + EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); +} + +TEST_F(AshNativeCursorManagerTest, SetCursor) { + CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); + CursorManagerTestApi test_api(cursor_manager); + + cursor_manager->SetCursor(ui::kCursorCopy); + EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); + cursor_manager->SetCursor(ui::kCursorPointer); + EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); +} + +TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactor) { + CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); + CursorManagerTestApi test_api(cursor_manager); + + cursor_manager->SetDeviceScaleFactor(2.0f); + EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); + cursor_manager->SetDeviceScaleFactor(1.0f); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); +} + +#if defined(OS_WIN) +// Temporarily disabled for windows. See crbug.com/112222. +#define MAYBE_DisabledMouseEventsLocation DISABLED_DisabledMouseEventsLocation +#else +#define MAYBE_DisabledMouseEventsLocation DisabledMouseEventsLocation +#endif // defined(OS_WIN) + +// Verifies that RootWindow generates a mouse event located outside of a window +// when mouse events are disabled. +TEST_F(AshNativeCursorManagerTest, MAYBE_DisabledMouseEventsLocation) { + scoped_ptr<MouseEventLocationDelegate> delegate( + new MouseEventLocationDelegate()); + const int kWindowWidth = 123; + const int kWindowHeight = 45; + gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); + scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( + delegate.get(), 1, bounds, Shell::GetInstance()->GetPrimaryRootWindow())); + + CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); + cursor_manager->EnableMouseEvents(); + // Send a mouse event to window. + gfx::Point point(101, 201); + gfx::Point local_point; + ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); + aura::RootWindow* root_window = window->GetRootWindow(); + root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); + + // Location was in window. + local_point = delegate->mouse_event_location(); + aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); + EXPECT_TRUE(window->bounds().Contains(local_point)); + + // Location is now out of window. + cursor_manager->DisableMouseEvents(); + RunAllPendingInMessageLoop(); + local_point = delegate->mouse_event_location(); + aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); + EXPECT_FALSE(window->bounds().Contains(local_point)); + + // Location is back in window. + cursor_manager->EnableMouseEvents(); + RunAllPendingInMessageLoop(); + local_point = delegate->mouse_event_location(); + aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); + EXPECT_TRUE(window->bounds().Contains(local_point)); +} + +#if defined(OS_WIN) +// Disable on Win because RootWindow::MoveCursorTo is not implemented. +#define MAYBE_DisabledQueryMouseLocation DISABLED_DisabledQueryMouseLocation +#else +#define MAYBE_DisabledQueryMouseLocation DisabledQueryMouseLocation +#endif // defined(OS_WIN) + +TEST_F(AshNativeCursorManagerTest, MAYBE_DisabledQueryMouseLocation) { + aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); + root_window->MoveCursorTo(gfx::Point(10, 10)); + gfx::Point mouse_location; + EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location)); + EXPECT_EQ("10,10", mouse_location.ToString()); + Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); + EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location)); + EXPECT_EQ("0,0", mouse_location.ToString()); +} + +} // namespace test +} // namespace ash diff --git a/ash/wm/cursor_manager.cc b/ash/wm/cursor_manager.cc deleted file mode 100644 index a126ae3..0000000 --- a/ash/wm/cursor_manager.cc +++ /dev/null @@ -1,224 +0,0 @@ -// 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 "ash/wm/cursor_manager.h" - -#include "ash/shell.h" -#include "ash/wm/image_cursors.h" -#include "base/logging.h" -#include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/base/cursor/cursor.h" - -namespace { - -// The coordinate of the cursor used when the mouse events are disabled. -const int kDisabledCursorLocationX = -10000; -const int kDisabledCursorLocationY = -10000; - -void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { - ash::Shell::RootWindowList root_windows = - ash::Shell::GetInstance()->GetAllRootWindows(); - for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); - iter != root_windows.end(); ++iter) - (*iter)->SetCursor(cursor); -} - -void NotifyCursorVisibilityChange(bool visible) { - ash::Shell::RootWindowList root_windows = - ash::Shell::GetInstance()->GetAllRootWindows(); - for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); - iter != root_windows.end(); ++iter) - (*iter)->OnCursorVisibilityChanged(visible); -} - -void NotifyMouseEventsEnableStateChange(bool enabled) { - ash::Shell::RootWindowList root_windows = - ash::Shell::GetInstance()->GetAllRootWindows(); - for (ash::Shell::RootWindowList::iterator iter = root_windows.begin(); - iter != root_windows.end(); ++iter) - (*iter)->OnMouseEventsEnableStateChanged(enabled); -} - -} // namespace - -namespace ash { -namespace internal { - -// Represents the cursor state which is composed of cursor type, visibility, and -// mouse events enable state. When mouse events are disabled, the cursor is -// always invisible. -class CursorState { - public: - CursorState() - : cursor_(ui::kCursorNone), - visible_(true), - mouse_events_enabled_(true), - visible_on_mouse_events_enabled_(true) { - } - - gfx::NativeCursor cursor() const { return cursor_; } - void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } - - bool visible() const { return visible_; } - void SetVisible(bool visible) { - if (mouse_events_enabled_) - visible_ = visible; - // Ignores the call when mouse events disabled. - } - - bool mouse_events_enabled() const { return mouse_events_enabled_; } - void SetMouseEventsEnabled(bool enabled) { - if (mouse_events_enabled_ == enabled) - return; - mouse_events_enabled_ = enabled; - - // Restores the visibility when mouse events are enabled. - if (enabled) { - visible_ = visible_on_mouse_events_enabled_; - } else { - visible_on_mouse_events_enabled_ = visible_; - visible_ = false; - } - } - - private: - gfx::NativeCursor cursor_; - bool visible_; - bool mouse_events_enabled_; - - // The visibility to set when mouse events are enabled. - bool visible_on_mouse_events_enabled_; - - DISALLOW_COPY_AND_ASSIGN(CursorState); -}; - -} // namespace internal - -CursorManager::CursorManager() - : cursor_lock_count_(0), - current_state_(new internal::CursorState), - state_on_unlock_(new internal::CursorState), - image_cursors_(new ImageCursors) { -} - -CursorManager::~CursorManager() { -} - -void CursorManager::SetCursor(gfx::NativeCursor cursor) { - state_on_unlock_->set_cursor(cursor); - if (cursor_lock_count_ == 0 && - GetCurrentCursor() != state_on_unlock_->cursor()) { - SetCursorInternal(state_on_unlock_->cursor()); - } -} - -void CursorManager::ShowCursor() { - state_on_unlock_->SetVisible(true); - if (cursor_lock_count_ == 0 && - IsCursorVisible() != state_on_unlock_->visible()) { - SetCursorVisibility(state_on_unlock_->visible()); - } -} - -void CursorManager::HideCursor() { - state_on_unlock_->SetVisible(false); - if (cursor_lock_count_ == 0 && - IsCursorVisible() != state_on_unlock_->visible()) { - SetCursorVisibility(state_on_unlock_->visible()); - } -} - -bool CursorManager::IsCursorVisible() const { - return current_state_->visible(); -} - -void CursorManager::EnableMouseEvents() { - state_on_unlock_->SetMouseEventsEnabled(true); - if (cursor_lock_count_ == 0 && - IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { - SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled()); - } -} - -void CursorManager::DisableMouseEvents() { - state_on_unlock_->SetMouseEventsEnabled(false); - if (cursor_lock_count_ == 0 && - IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { - SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled()); - } -} - -bool CursorManager::IsMouseEventsEnabled() const { - return current_state_->mouse_events_enabled(); -} - -void CursorManager::SetDeviceScaleFactor(float device_scale_factor) { - if (image_cursors_->SetDeviceScaleFactor(device_scale_factor)) - SetCursorInternal(GetCurrentCursor()); -} - -void CursorManager::LockCursor() { - cursor_lock_count_++; -} - -void CursorManager::UnlockCursor() { - cursor_lock_count_--; - DCHECK_GE(cursor_lock_count_, 0); - if (cursor_lock_count_ > 0) - return; - - if (GetCurrentCursor() != state_on_unlock_->cursor()) - SetCursorInternal(state_on_unlock_->cursor()); - if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) - SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled()); - if (IsCursorVisible() != state_on_unlock_->visible()) - SetCursorVisibility(state_on_unlock_->visible()); -} - -void CursorManager::SetCursorInternal(gfx::NativeCursor cursor) { - gfx::NativeCursor new_cursor = cursor; - image_cursors_->SetPlatformCursor(&new_cursor); - new_cursor.set_device_scale_factor(image_cursors_->GetDeviceScaleFactor()); - current_state_->set_cursor(new_cursor); - - if (IsCursorVisible()) - SetCursorOnAllRootWindows(GetCurrentCursor()); -} - -void CursorManager::SetCursorVisibility(bool visible) { - current_state_->SetVisible(visible); - - if (visible) { - SetCursorInternal(GetCurrentCursor()); - } else { - gfx::NativeCursor invisible_cursor(ui::kCursorNone); - image_cursors_->SetPlatformCursor(&invisible_cursor); - SetCursorOnAllRootWindows(invisible_cursor); - } - - NotifyCursorVisibilityChange(visible); -} - -void CursorManager::SetMouseEventsEnabled(bool enabled) { - current_state_->SetMouseEventsEnabled(enabled); - - if (enabled) { - aura::Env::GetInstance()->set_last_mouse_location( - disabled_cursor_location_); - } else { - disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); - aura::Env::GetInstance()->set_last_mouse_location( - gfx::Point(kDisabledCursorLocationX, kDisabledCursorLocationY)); - } - - SetCursorVisibility(current_state_->visible()); - NotifyMouseEventsEnableStateChange(enabled); -} - -gfx::NativeCursor CursorManager::GetCurrentCursor() const { - return current_state_->cursor(); -} - -} // namespace ash diff --git a/ash/wm/cursor_manager.h b/ash/wm/cursor_manager.h deleted file mode 100644 index 774e450..0000000 --- a/ash/wm/cursor_manager.h +++ /dev/null @@ -1,80 +0,0 @@ -// 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 ASH_WM_CURSOR_MANAGER_H_ -#define ASH_WM_CURSOR_MANAGER_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/client/cursor_client.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/point.h" - -namespace ash { - -namespace internal { -class CursorState; -} - -namespace test { -class CursorManagerTestApi; -} - -class ImageCursors; - -// 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 ASH_EXPORT CursorManager : public aura::client::CursorClient { - public: - CursorManager(); - virtual ~CursorManager(); - - bool is_cursor_locked() const { return cursor_lock_count_ > 0; } - - // Overridden from aura::client::CursorClient: - virtual void SetCursor(gfx::NativeCursor) OVERRIDE; - virtual void ShowCursor() OVERRIDE; - virtual void HideCursor() OVERRIDE; - virtual bool IsCursorVisible() const OVERRIDE; - virtual void EnableMouseEvents() OVERRIDE; - virtual void DisableMouseEvents() OVERRIDE; - virtual bool IsMouseEventsEnabled() const OVERRIDE; - virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE; - virtual void LockCursor() OVERRIDE; - virtual void UnlockCursor() OVERRIDE; - - private: - friend class test::CursorManagerTestApi; - - void SetCursorInternal(gfx::NativeCursor cursor); - void SetCursorVisibility(bool visible); - void SetMouseEventsEnabled(bool enabled); - - // Returns the current cursor. - gfx::NativeCursor GetCurrentCursor() const; - - // Number of times LockCursor() has been invoked without a corresponding - // UnlockCursor(). - int cursor_lock_count_; - - // The cursor location where the cursor was disabled. - gfx::Point disabled_cursor_location_; - - // The current state of the cursor. - scoped_ptr<internal::CursorState> current_state_; - - // The cursor state to restore when the cursor is unlocked. - scoped_ptr<internal::CursorState> state_on_unlock_; - - scoped_ptr<ImageCursors> image_cursors_; - - DISALLOW_COPY_AND_ASSIGN(CursorManager); -}; - -} // namespace ash - -#endif // UI_AURA_CURSOR_MANAGER_H_ diff --git a/ash/wm/cursor_manager_unittest.cc b/ash/wm/cursor_manager_unittest.cc deleted file mode 100644 index a290512..0000000 --- a/ash/wm/cursor_manager_unittest.cc +++ /dev/null @@ -1,360 +0,0 @@ -// 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 "ash/wm/cursor_manager.h" - -#include "ash/shell.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/cursor_manager_test_api.h" -#include "ash/wm/image_cursors.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/test_window_delegate.h" -#include "ui/aura/test/test_windows.h" -#include "ui/aura/window.h" - -namespace ash { -namespace test { - -namespace { - -// A delegate for recording a mouse event location. -class MouseEventLocationDelegate : public aura::test::TestWindowDelegate { - public: - MouseEventLocationDelegate() {} - virtual ~MouseEventLocationDelegate() {} - - const gfx::Point& mouse_event_location() const { - return mouse_event_location_; - } - - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { - mouse_event_location_ = event->location(); - event->SetHandled(); - } - - private: - gfx::Point mouse_event_location_; - - DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); -}; - -} // namespace - -typedef test::AshTestBase CursorManagerTest; - -TEST_F(CursorManagerTest, LockCursor) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - CursorManagerTestApi test_api(cursor_manager); - - cursor_manager->SetCursor(ui::kCursorCopy); - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - cursor_manager->SetDeviceScaleFactor(2.0f); - EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); - EXPECT_TRUE(test_api.GetCurrentCursor().platform()); - - cursor_manager->LockCursor(); - EXPECT_TRUE(cursor_manager->is_cursor_locked()); - - // Cursor type does not change while cursor is locked. - cursor_manager->SetCursor(ui::kCursorPointer); - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - - // Device scale factor does change even while cursor is locked. - cursor_manager->SetDeviceScaleFactor(1.0f); - EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); - - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->is_cursor_locked()); - - // Cursor type changes to the one specified while cursor is locked. - EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); - EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); - EXPECT_TRUE(test_api.GetCurrentCursor().platform()); -} - -TEST_F(CursorManagerTest, SetCursor) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - CursorManagerTestApi test_api(cursor_manager); - - cursor_manager->SetCursor(ui::kCursorCopy); - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - EXPECT_TRUE(test_api.GetCurrentCursor().platform()); - cursor_manager->SetCursor(ui::kCursorPointer); - EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); - EXPECT_TRUE(test_api.GetCurrentCursor().platform()); -} - -TEST_F(CursorManagerTest, ShowHideCursor) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - CursorManagerTestApi test_api(cursor_manager); - - cursor_manager->SetCursor(ui::kCursorCopy); - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - - cursor_manager->ShowCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - cursor_manager->HideCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - // The current cursor does not change even when the cursor is not shown. - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - - // Check if cursor visibility is locked. - cursor_manager->LockCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - cursor_manager->ShowCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - - cursor_manager->LockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - cursor_manager->HideCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - - // Checks setting visiblity while cursor is locked does not affect the - // subsequent uses of UnlockCursor. - cursor_manager->LockCursor(); - cursor_manager->HideCursor(); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - - cursor_manager->ShowCursor(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - - cursor_manager->LockCursor(); - cursor_manager->ShowCursor(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - - cursor_manager->HideCursor(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); -} - -TEST_F(CursorManagerTest, SetDeviceScaleFactor) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - CursorManagerTestApi test_api(cursor_manager); - - cursor_manager->SetDeviceScaleFactor(2.0f); - EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); - cursor_manager->SetDeviceScaleFactor(1.0f); - EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); -} - -// Verifies that LockCursor/UnlockCursor work correctly with -// EnableMouseEvents and DisableMouseEvents -TEST_F(CursorManagerTest, EnableDisableMouseEvents) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - CursorManagerTestApi test_api(cursor_manager); - - cursor_manager->SetCursor(ui::kCursorCopy); - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - - cursor_manager->EnableMouseEvents(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - // The current cursor does not change even when the cursor is not shown. - EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); - - // Check if cursor enable state is locked. - cursor_manager->LockCursor(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->EnableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->LockCursor(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->DisableMouseEvents(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - - // Checks enabling cursor while cursor is locked does not affect the - // subsequent uses of UnlockCursor. - cursor_manager->LockCursor(); - cursor_manager->DisableMouseEvents(); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->EnableMouseEvents(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->LockCursor(); - cursor_manager->EnableMouseEvents(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->DisableMouseEvents(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); -} - -TEST_F(CursorManagerTest, IsMouseEventsEnabled) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - cursor_manager->EnableMouseEvents(); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); -} - -// Verifies that the mouse events enable state changes correctly when -// ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used -// together. -TEST_F(CursorManagerTest, ShowAndEnable) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - - // Changing the visibility of the cursor does not affect the enable state. - cursor_manager->EnableMouseEvents(); - cursor_manager->ShowCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->HideCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->ShowCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - // When mouse events are disabled, it also gets invisible. - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - - // When mouse events are enabled, it restores the visibility state. - cursor_manager->EnableMouseEvents(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->ShowCursor(); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->EnableMouseEvents(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - cursor_manager->HideCursor(); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->EnableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); - - // When mouse events are disabled, ShowCursor is ignored. - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->ShowCursor(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); - cursor_manager->DisableMouseEvents(); - EXPECT_FALSE(cursor_manager->IsCursorVisible()); - EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); -} - -// Verifies that calling DisableMouseEvents multiple times in a row makes no -// difference compared with calling it once. -// This is a regression test for http://crbug.com/169404. -TEST_F(CursorManagerTest, MultipleDisableMouseEvents) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - cursor_manager->DisableMouseEvents(); - cursor_manager->DisableMouseEvents(); - cursor_manager->EnableMouseEvents(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); -} - -// Verifies that calling EnableMouseEvents multiple times in a row makes no -// difference compared with calling it once. -TEST_F(CursorManagerTest, MultipleEnableMouseEvents) { - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - cursor_manager->DisableMouseEvents(); - cursor_manager->EnableMouseEvents(); - cursor_manager->EnableMouseEvents(); - cursor_manager->LockCursor(); - cursor_manager->UnlockCursor(); - EXPECT_TRUE(cursor_manager->IsCursorVisible()); -} - -#if defined(OS_WIN) -// Temporarily disabled for windows. See crbug.com/112222. -#define MAYBE_DisabledMouseEventsLocation DISABLED_DisabledMouseEventsLocation -#else -#define MAYBE_DisabledMouseEventsLocation DisabledMouseEventsLocation -#endif // defined(OS_WIN) - -// Verifies that RootWindow generates a mouse event located outside of a window -// when mouse events are disabled. -TEST_F(CursorManagerTest, MAYBE_DisabledMouseEventsLocation) { - scoped_ptr<MouseEventLocationDelegate> delegate( - new MouseEventLocationDelegate()); - const int kWindowWidth = 123; - const int kWindowHeight = 45; - gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); - scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( - delegate.get(), 1, bounds, Shell::GetInstance()->GetPrimaryRootWindow())); - - CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); - cursor_manager->EnableMouseEvents(); - // Send a mouse event to window. - gfx::Point point(101, 201); - gfx::Point local_point; - ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); - aura::RootWindow* root_window = window->GetRootWindow(); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); - - // Location was in window. - local_point = delegate->mouse_event_location(); - aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); - EXPECT_TRUE(window->bounds().Contains(local_point)); - - // Location is now out of window. - cursor_manager->DisableMouseEvents(); - RunAllPendingInMessageLoop(); - local_point = delegate->mouse_event_location(); - aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); - EXPECT_FALSE(window->bounds().Contains(local_point)); - - // Location is back in window. - cursor_manager->EnableMouseEvents(); - RunAllPendingInMessageLoop(); - local_point = delegate->mouse_event_location(); - aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); - EXPECT_TRUE(window->bounds().Contains(local_point)); -} - -#if defined(OS_WIN) -// Disable on Win because RootWindow::MoveCursorTo is not implemented. -#define MAYBE_DisabledQueryMouseLocation DISABLED_DisabledQueryMouseLocation -#else -#define MAYBE_DisabledQueryMouseLocation DisabledQueryMouseLocation -#endif // defined(OS_WIN) - -TEST_F(CursorManagerTest, MAYBE_DisabledQueryMouseLocation) { - aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); - root_window->MoveCursorTo(gfx::Point(10, 10)); - gfx::Point mouse_location; - EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location)); - EXPECT_EQ("10,10", mouse_location.ToString()); - Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); - EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location)); - EXPECT_EQ("0,0", mouse_location.ToString()); -} - -} // namespace test -} // namespace ash diff --git a/ash/wm/default_window_resizer.cc b/ash/wm/default_window_resizer.cc index 48abacd..26ed47e 100644 --- a/ash/wm/default_window_resizer.cc +++ b/ash/wm/default_window_resizer.cc @@ -5,7 +5,6 @@ #include "ash/wm/default_window_resizer.h" #include "ash/shell.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/property_util.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" diff --git a/ash/wm/drag_window_resizer.cc b/ash/wm/drag_window_resizer.cc index cbba83c..b34e931 100644 --- a/ash/wm/drag_window_resizer.cc +++ b/ash/wm/drag_window_resizer.cc @@ -8,7 +8,6 @@ #include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/wm/coordinate_conversion.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/drag_window_controller.h" #include "ash/wm/property_util.h" #include "ui/aura/client/aura_constants.h" diff --git a/ash/wm/drag_window_resizer_unittest.cc b/ash/wm/drag_window_resizer_unittest.cc index d868868..bef092c 100644 --- a/ash/wm/drag_window_resizer_unittest.cc +++ b/ash/wm/drag_window_resizer_unittest.cc @@ -10,7 +10,6 @@ #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" #include "ash/test/cursor_manager_test_api.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/drag_window_controller.h" #include "ash/wm/shelf_layout_manager.h" #include "base/stringprintf.h" diff --git a/ash/wm/panel_window_resizer.cc b/ash/wm/panel_window_resizer.cc index fee35a5..2eda67a 100644 --- a/ash/wm/panel_window_resizer.cc +++ b/ash/wm/panel_window_resizer.cc @@ -8,7 +8,6 @@ #include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/panel_layout_manager.h" #include "ash/wm/property_util.h" #include "ash/wm/window_properties.h" diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc index a2c6cbc..4ecb17a 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -11,7 +11,6 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/test/test_shell_delegate.h" -#include "ash/wm/cursor_manager.h" #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" diff --git a/ash/wm/session_state_controller_impl2_unittest.cc b/ash/wm/session_state_controller_impl2_unittest.cc index bae1f14..ec2f998 100644 --- a/ash/wm/session_state_controller_impl2_unittest.cc +++ b/ash/wm/session_state_controller_impl2_unittest.cc @@ -9,7 +9,6 @@ #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" #include "ash/test/test_shell_delegate.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/power_button_controller.h" #include "ash/wm/session_state_animator.h" #include "ash/wm/session_state_controller.h" diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index 3430d29..2fd6e67 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -8,7 +8,6 @@ #include "ash/test/shell_test_api.h" #include "ash/test/test_activation_delegate.h" #include "ash/wm/activation_controller.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/window_util.h" #include "ui/aura/client/activation_client.h" #include "ui/aura/client/activation_delegate.h" @@ -643,7 +642,7 @@ TEST_F(WindowManagerTest, AdditionalFilters) { // requested. TEST_F(WindowManagerTest, UpdateCursorVisibility) { aura::test::EventGenerator& generator = GetEventGenerator(); - ash::CursorManager* cursor_manager = + views::corewm::CursorManager* cursor_manager = ash::Shell::GetInstance()->cursor_manager(); generator.MoveMouseTo(gfx::Point(0, 0)); @@ -695,7 +694,7 @@ TEST_F(WindowManagerTest, UpdateCursorVisibility) { TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { aura::test::EventGenerator& generator = GetEventGenerator(); - ash::CursorManager* cursor_manager = + views::corewm::CursorManager* cursor_manager = ash::Shell::GetInstance()->cursor_manager(); // Pressing a key hides the cursor but does not disable mouse events. diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc index 748edf5..1c7609c 100644 --- a/ash/wm/workspace/workspace_window_resizer.cc +++ b/ash/wm/workspace/workspace_window_resizer.cc @@ -14,7 +14,6 @@ #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/wm/coordinate_conversion.h" -#include "ash/wm/cursor_manager.h" #include "ash/wm/default_window_resizer.h" #include "ash/wm/drag_window_resizer.h" #include "ash/wm/panel_window_resizer.h" |