| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/corewm/cursor_manager.h" | 5 #include "ui/views/corewm/cursor_manager.h" |
| 6 | 6 |
| 7 #include "ui/aura/client/cursor_client_observer.h" | 7 #include "ui/aura/client/cursor_client_observer.h" |
| 8 #include "ui/views/corewm/native_cursor_manager.h" | 8 #include "ui/views/corewm/native_cursor_manager.h" |
| 9 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 class TestingCursorManager : public views::corewm::NativeCursorManager { | 13 class TestingCursorManager : public views::corewm::NativeCursorManager { |
| 14 public: | 14 public: |
| 15 gfx::NativeCursor current_cursor() { return cursor_; } | |
| 16 | |
| 17 // Overridden from views::corewm::NativeCursorManager: | 15 // Overridden from views::corewm::NativeCursorManager: |
| 18 virtual void SetDisplay( | 16 virtual void SetDisplay( |
| 19 const gfx::Display& display, | 17 const gfx::Display& display, |
| 20 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {} | 18 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {} |
| 21 | 19 |
| 22 virtual void SetCursor( | 20 virtual void SetCursor( |
| 23 gfx::NativeCursor cursor, | 21 gfx::NativeCursor cursor, |
| 24 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 22 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 25 cursor_ = cursor; | |
| 26 delegate->CommitCursor(cursor); | 23 delegate->CommitCursor(cursor); |
| 27 } | 24 } |
| 28 | 25 |
| 29 virtual void SetVisibility( | 26 virtual void SetVisibility( |
| 30 bool visible, | 27 bool visible, |
| 31 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 28 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 32 delegate->CommitVisibility(visible); | 29 delegate->CommitVisibility(visible); |
| 33 } | 30 } |
| 34 | 31 |
| 35 virtual void SetMouseEventsEnabled( | 32 virtual void SetMouseEventsEnabled( |
| 36 bool enabled, | 33 bool enabled, |
| 37 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 34 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 38 delegate->CommitMouseEventsEnabled(enabled); | 35 delegate->CommitMouseEventsEnabled(enabled); |
| 39 } | 36 } |
| 40 | 37 |
| 41 virtual void SetCursorSet( | 38 virtual void SetCursorSet( |
| 42 ui::CursorSetType cursor_set, | 39 ui::CursorSetType cursor_set, |
| 43 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 40 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 44 delegate->CommitCursorSet(cursor_set); | 41 delegate->CommitCursorSet(cursor_set); |
| 45 } | 42 } |
| 46 | 43 |
| 47 virtual void SetScale( | 44 virtual void SetScale( |
| 48 float scale, | 45 float scale, |
| 49 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 46 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 50 delegate->CommitScale(scale); | 47 delegate->CommitScale(scale); |
| 51 } | 48 } |
| 52 | |
| 53 private: | |
| 54 gfx::NativeCursor cursor_; | |
| 55 }; | 49 }; |
| 56 | 50 |
| 57 } // namespace | 51 } // namespace |
| 58 | 52 |
| 59 class CursorManagerTest : public views::ViewsTestBase { | 53 class CursorManagerTest : public views::ViewsTestBase { |
| 60 protected: | 54 protected: |
| 61 CursorManagerTest() | 55 CursorManagerTest() |
| 62 : delegate_(new TestingCursorManager), | 56 : delegate_(new TestingCursorManager), |
| 63 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( | 57 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( |
| 64 delegate_)) { | 58 delegate_)) { |
| 65 } | 59 } |
| 66 | 60 |
| 67 gfx::NativeCursor current_cursor() { return delegate_->current_cursor(); } | |
| 68 | |
| 69 TestingCursorManager* delegate_; | 61 TestingCursorManager* delegate_; |
| 70 views::corewm::CursorManager cursor_manager_; | 62 views::corewm::CursorManager cursor_manager_; |
| 71 }; | 63 }; |
| 72 | 64 |
| 73 class TestingCursorClientObserver : public aura::client::CursorClientObserver { | 65 class TestingCursorClientObserver : public aura::client::CursorClientObserver { |
| 74 public: | 66 public: |
| 75 TestingCursorClientObserver() | 67 TestingCursorClientObserver() |
| 76 : cursor_visibility_(false), | 68 : cursor_visibility_(false), |
| 77 did_visibility_change_(false) {} | 69 did_visibility_change_(false) {} |
| 78 void reset() { cursor_visibility_ = did_visibility_change_ = false; } | 70 void reset() { cursor_visibility_ = did_visibility_change_ = false; } |
| 79 bool is_cursor_visible() const { return cursor_visibility_; } | 71 bool is_cursor_visible() const { return cursor_visibility_; } |
| 80 bool did_visibility_change() const { return did_visibility_change_; } | 72 bool did_visibility_change() const { return did_visibility_change_; } |
| 81 | 73 |
| 82 // Overridden from aura::client::CursorClientObserver: | 74 // Overridden from aura::client::CursorClientObserver: |
| 83 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { | 75 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { |
| 84 cursor_visibility_ = is_visible; | 76 cursor_visibility_ = is_visible; |
| 85 did_visibility_change_ = true; | 77 did_visibility_change_ = true; |
| 86 } | 78 } |
| 87 | 79 |
| 88 private: | 80 private: |
| 89 bool cursor_visibility_; | 81 bool cursor_visibility_; |
| 90 bool did_visibility_change_; | 82 bool did_visibility_change_; |
| 91 | 83 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); | 84 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); |
| 93 }; | 85 }; |
| 94 | 86 |
| 95 TEST_F(CursorManagerTest, ShowHideCursor) { | 87 TEST_F(CursorManagerTest, ShowHideCursor) { |
| 96 cursor_manager_.SetCursor(ui::kCursorCopy); | 88 cursor_manager_.SetCursor(ui::kCursorCopy); |
| 97 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 89 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 98 | 90 |
| 99 cursor_manager_.ShowCursor(); | 91 cursor_manager_.ShowCursor(); |
| 100 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 92 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 101 cursor_manager_.HideCursor(); | 93 cursor_manager_.HideCursor(); |
| 102 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 94 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 103 // The current cursor does not change even when the cursor is not shown. | 95 // The current cursor does not change even when the cursor is not shown. |
| 104 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 96 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 105 | 97 |
| 106 // Check if cursor visibility is locked. | 98 // Check if cursor visibility is locked. |
| 107 cursor_manager_.LockCursor(); | 99 cursor_manager_.LockCursor(); |
| 108 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 100 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 109 cursor_manager_.ShowCursor(); | 101 cursor_manager_.ShowCursor(); |
| 110 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 102 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 111 cursor_manager_.UnlockCursor(); | 103 cursor_manager_.UnlockCursor(); |
| 112 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 104 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 113 | 105 |
| 114 cursor_manager_.LockCursor(); | 106 cursor_manager_.LockCursor(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 138 cursor_manager_.HideCursor(); | 130 cursor_manager_.HideCursor(); |
| 139 cursor_manager_.LockCursor(); | 131 cursor_manager_.LockCursor(); |
| 140 cursor_manager_.UnlockCursor(); | 132 cursor_manager_.UnlockCursor(); |
| 141 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 133 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 142 } | 134 } |
| 143 | 135 |
| 144 // Verifies that LockCursor/UnlockCursor work correctly with | 136 // Verifies that LockCursor/UnlockCursor work correctly with |
| 145 // EnableMouseEvents and DisableMouseEvents | 137 // EnableMouseEvents and DisableMouseEvents |
| 146 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { | 138 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { |
| 147 cursor_manager_.SetCursor(ui::kCursorCopy); | 139 cursor_manager_.SetCursor(ui::kCursorCopy); |
| 148 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 140 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 149 | 141 |
| 150 cursor_manager_.EnableMouseEvents(); | 142 cursor_manager_.EnableMouseEvents(); |
| 151 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 143 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 152 cursor_manager_.DisableMouseEvents(); | 144 cursor_manager_.DisableMouseEvents(); |
| 153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 145 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 154 // The current cursor does not change even when the cursor is not shown. | 146 // The current cursor does not change even when the cursor is not shown. |
| 155 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 147 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 156 | 148 |
| 157 // Check if cursor enable state is locked. | 149 // Check if cursor enable state is locked. |
| 158 cursor_manager_.LockCursor(); | 150 cursor_manager_.LockCursor(); |
| 159 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 151 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 160 cursor_manager_.EnableMouseEvents(); | 152 cursor_manager_.EnableMouseEvents(); |
| 161 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 162 cursor_manager_.UnlockCursor(); | 154 cursor_manager_.UnlockCursor(); |
| 163 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 155 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 164 | 156 |
| 165 cursor_manager_.LockCursor(); | 157 cursor_manager_.LockCursor(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 cursor_manager_.UnlockCursor(); | 178 cursor_manager_.UnlockCursor(); |
| 187 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 179 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 188 | 180 |
| 189 cursor_manager_.DisableMouseEvents(); | 181 cursor_manager_.DisableMouseEvents(); |
| 190 cursor_manager_.LockCursor(); | 182 cursor_manager_.LockCursor(); |
| 191 cursor_manager_.UnlockCursor(); | 183 cursor_manager_.UnlockCursor(); |
| 192 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 184 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 193 } | 185 } |
| 194 | 186 |
| 195 TEST_F(CursorManagerTest, SetCursorSet) { | 187 TEST_F(CursorManagerTest, SetCursorSet) { |
| 196 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 188 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 197 | 189 |
| 198 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 190 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); |
| 199 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 191 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 200 | 192 |
| 201 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); | 193 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); |
| 202 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCurrentCursorSet()); | 194 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet()); |
| 203 | 195 |
| 204 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 196 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); |
| 205 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 197 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 206 } | 198 } |
| 207 | 199 |
| 208 TEST_F(CursorManagerTest, SetScale) { | 200 TEST_F(CursorManagerTest, SetScale) { |
| 209 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); | 201 EXPECT_EQ(1.f, cursor_manager_.GetScale()); |
| 210 cursor_manager_.SetScale(2.f); | 202 cursor_manager_.SetScale(2.f); |
| 211 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); | 203 EXPECT_EQ(2.f, cursor_manager_.GetScale()); |
| 212 | 204 |
| 213 // Cusror scale does change even while cursor is locked. | 205 // Cusror scale does change even while cursor is locked. |
| 214 cursor_manager_.LockCursor(); | 206 cursor_manager_.LockCursor(); |
| 215 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); | 207 EXPECT_EQ(2.f, cursor_manager_.GetScale()); |
| 216 cursor_manager_.SetScale(2.5f); | 208 cursor_manager_.SetScale(2.5f); |
| 217 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); | 209 EXPECT_EQ(2.5f, cursor_manager_.GetScale()); |
| 218 cursor_manager_.UnlockCursor(); | 210 cursor_manager_.UnlockCursor(); |
| 219 | 211 |
| 220 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); | 212 EXPECT_EQ(2.5f, cursor_manager_.GetScale()); |
| 221 cursor_manager_.SetScale(1.f); | 213 cursor_manager_.SetScale(1.f); |
| 222 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); | 214 EXPECT_EQ(1.f, cursor_manager_.GetScale()); |
| 223 } | 215 } |
| 224 | 216 |
| 225 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { | 217 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { |
| 226 cursor_manager_.EnableMouseEvents(); | 218 cursor_manager_.EnableMouseEvents(); |
| 227 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 219 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 228 cursor_manager_.DisableMouseEvents(); | 220 cursor_manager_.DisableMouseEvents(); |
| 229 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 221 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 230 } | 222 } |
| 231 | 223 |
| 232 // Verifies that the mouse events enable state changes correctly when | 224 // Verifies that the mouse events enable state changes correctly when |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_FALSE(observer_a.is_cursor_visible()); | 344 EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 353 | 345 |
| 354 // Show the cursor using ShowCursor(). | 346 // Show the cursor using ShowCursor(). |
| 355 observer_a.reset(); | 347 observer_a.reset(); |
| 356 observer_b.reset(); | 348 observer_b.reset(); |
| 357 cursor_manager_.ShowCursor(); | 349 cursor_manager_.ShowCursor(); |
| 358 EXPECT_TRUE(observer_a.did_visibility_change()); | 350 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 359 EXPECT_FALSE(observer_b.did_visibility_change()); | 351 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 360 EXPECT_TRUE(observer_a.is_cursor_visible()); | 352 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 361 } | 353 } |
| OLD | NEW |