Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / aura / test / test_cursor_client.cc
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
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
22 TestCursorClient::~TestCursorClient() {
23   client::SetCursorClient(root_window_, NULL);
24 }
25
26 void TestCursorClient::SetCursor(gfx::NativeCursor cursor) {
27   calls_to_set_cursor_++;
28 }
29
30 gfx::NativeCursor TestCursorClient::GetCursor() const {
31   return ui::kCursorNull;
32 }
33
34 void TestCursorClient::ShowCursor() {
35   visible_ = true;
36   FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
37                     OnCursorVisibilityChanged(true));
38 }
39
40 void TestCursorClient::HideCursor() {
41   visible_ = false;
42   FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
43                     OnCursorVisibilityChanged(false));
44 }
45
46 void TestCursorClient::SetCursorSet(ui::CursorSetType cursor_set) {
47 }
48
49 ui::CursorSetType TestCursorClient::GetCursorSet() const {
50   return ui::CURSOR_SET_NORMAL;
51 }
52
53 bool TestCursorClient::IsCursorVisible() const {
54   return visible_;
55 }
56
57 void TestCursorClient::EnableMouseEvents() {
58   mouse_events_enabled_ = true;
59 }
60
61 void TestCursorClient::DisableMouseEvents() {
62   mouse_events_enabled_ = false;
63 }
64
65 bool TestCursorClient::IsMouseEventsEnabled() const {
66   return mouse_events_enabled_;
67 }
68
69 void TestCursorClient::SetDisplay(const gfx::Display& display) {
70 }
71
72 void TestCursorClient::LockCursor() {
73   cursor_lock_count_++;
74 }
75
76 void TestCursorClient::UnlockCursor() {
77   cursor_lock_count_--;
78   if (cursor_lock_count_ < 0)
79     cursor_lock_count_ = 0;
80 }
81
82 bool TestCursorClient::IsCursorLocked() const {
83   return cursor_lock_count_ > 0;
84 }
85
86 void TestCursorClient::AddObserver(
87     aura::client::CursorClientObserver* observer) {
88   observers_.AddObserver(observer);
89 }
90
91 void TestCursorClient::RemoveObserver(
92     aura::client::CursorClientObserver* observer) {
93   observers_.RemoveObserver(observer);
94 }
95
96 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