test_cursor_client.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
9namespace aura {
10namespace test {
11
12TestCursorClient::TestCursorClient(aura::Window* root_window)
13    : visible_(true),
14      mouse_events_enabled_(true),
15      cursor_lock_count_(0),
16      calls_to_set_cursor_(0),
17      root_window_(root_window) {
18  client::SetCursorClient(root_window, this);
19}
20
21TestCursorClient::~TestCursorClient() {
22  client::SetCursorClient(root_window_, NULL);
23}
24
25void TestCursorClient::SetCursor(gfx::NativeCursor cursor) {
26  calls_to_set_cursor_++;
27}
28
29gfx::NativeCursor TestCursorClient::GetCursor() const {
30  return ui::kCursorNull;
31}
32
33void TestCursorClient::ShowCursor() {
34  visible_ = true;
35  FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
36                    OnCursorVisibilityChanged(true));
37}
38
39void TestCursorClient::HideCursor() {
40  visible_ = false;
41  FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
42                    OnCursorVisibilityChanged(false));
43}
44
45void TestCursorClient::SetCursorSet(ui::CursorSetType cursor_set) {
46}
47
48ui::CursorSetType TestCursorClient::GetCursorSet() const {
49  return ui::CURSOR_SET_NORMAL;
50}
51
52void TestCursorClient::SetScale(float scale) {
53}
54
55float TestCursorClient::GetScale() const {
56  return 1.f;
57}
58
59bool TestCursorClient::IsCursorVisible() const {
60  return visible_;
61}
62
63void TestCursorClient::EnableMouseEvents() {
64  mouse_events_enabled_ = true;
65}
66
67void TestCursorClient::DisableMouseEvents() {
68  mouse_events_enabled_ = false;
69}
70
71bool TestCursorClient::IsMouseEventsEnabled() const {
72  return mouse_events_enabled_;
73}
74
75void TestCursorClient::SetDisplay(const gfx::Display& display) {
76}
77
78void TestCursorClient::LockCursor() {
79  cursor_lock_count_++;
80}
81
82void TestCursorClient::UnlockCursor() {
83  cursor_lock_count_--;
84  if (cursor_lock_count_ < 0)
85    cursor_lock_count_ = 0;
86}
87
88bool TestCursorClient::IsCursorLocked() const {
89  return cursor_lock_count_ > 0;
90}
91
92void TestCursorClient::AddObserver(
93    aura::client::CursorClientObserver* observer) {
94  observers_.AddObserver(observer);
95}
96
97void TestCursorClient::RemoveObserver(
98    aura::client::CursorClientObserver* observer) {
99  observers_.RemoveObserver(observer);
100}
101
102}  // namespace test
103}  // namespace aura
104