1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/test/test_cursor_client.h"
6
7 #include "ui/aura/client/cursor_client_observer.h"
8
9 namespace aura {
10 namespace test {
11
TestCursorClient(aura::Window * root_window)12 TestCursorClient::TestCursorClient(aura::Window* root_window)
13 : visible_(true),
14 should_hide_cursor_on_key_event_(true),
15 mouse_events_enabled_(true),
16 cursor_lock_count_(0),
17 calls_to_set_cursor_(0),
18 root_window_(root_window) {
19 client::SetCursorClient(root_window, this);
20 }
21
~TestCursorClient()22 TestCursorClient::~TestCursorClient() {
23 client::SetCursorClient(root_window_, NULL);
24 }
25
SetCursor(gfx::NativeCursor cursor)26 void TestCursorClient::SetCursor(gfx::NativeCursor cursor) {
27 calls_to_set_cursor_++;
28 }
29
GetCursor() const30 gfx::NativeCursor TestCursorClient::GetCursor() const {
31 return ui::kCursorNull;
32 }
33
ShowCursor()34 void TestCursorClient::ShowCursor() {
35 visible_ = true;
36 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
37 OnCursorVisibilityChanged(true));
38 }
39
HideCursor()40 void TestCursorClient::HideCursor() {
41 visible_ = false;
42 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
43 OnCursorVisibilityChanged(false));
44 }
45
SetCursorSet(ui::CursorSetType cursor_set)46 void TestCursorClient::SetCursorSet(ui::CursorSetType cursor_set) {
47 }
48
GetCursorSet() const49 ui::CursorSetType TestCursorClient::GetCursorSet() const {
50 return ui::CURSOR_SET_NORMAL;
51 }
52
IsCursorVisible() const53 bool TestCursorClient::IsCursorVisible() const {
54 return visible_;
55 }
56
EnableMouseEvents()57 void TestCursorClient::EnableMouseEvents() {
58 mouse_events_enabled_ = true;
59 }
60
DisableMouseEvents()61 void TestCursorClient::DisableMouseEvents() {
62 mouse_events_enabled_ = false;
63 }
64
IsMouseEventsEnabled() const65 bool TestCursorClient::IsMouseEventsEnabled() const {
66 return mouse_events_enabled_;
67 }
68
SetDisplay(const gfx::Display & display)69 void TestCursorClient::SetDisplay(const gfx::Display& display) {
70 }
71
LockCursor()72 void TestCursorClient::LockCursor() {
73 cursor_lock_count_++;
74 }
75
UnlockCursor()76 void TestCursorClient::UnlockCursor() {
77 cursor_lock_count_--;
78 if (cursor_lock_count_ < 0)
79 cursor_lock_count_ = 0;
80 }
81
IsCursorLocked() const82 bool TestCursorClient::IsCursorLocked() const {
83 return cursor_lock_count_ > 0;
84 }
85
AddObserver(aura::client::CursorClientObserver * observer)86 void TestCursorClient::AddObserver(
87 aura::client::CursorClientObserver* observer) {
88 observers_.AddObserver(observer);
89 }
90
RemoveObserver(aura::client::CursorClientObserver * observer)91 void TestCursorClient::RemoveObserver(
92 aura::client::CursorClientObserver* observer) {
93 observers_.RemoveObserver(observer);
94 }
95
ShouldHideCursorOnKeyEvent(const ui::KeyEvent & event) const96 bool TestCursorClient::ShouldHideCursorOnKeyEvent(
97 const ui::KeyEvent& event) const {
98 return should_hide_cursor_on_key_event_;
99 }
100
101 } // namespace test
102 } // namespace aura
103