OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/widget/desktop_aura/desktop_cursor_client.h" | 5 #include "ui/views/widget/desktop_aura/desktop_cursor_client.h" |
6 | 6 |
7 #include "ui/aura/root_window.h" | 7 #include "ui/aura/root_window.h" |
8 #include "ui/base/cursor/cursor_loader.h" | 8 #include "ui/base/cursor/cursor_loader.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
11 | 11 |
12 DesktopCursorClient::DesktopCursorClient(aura::RootWindow* window) | 12 DesktopCursorClient::DesktopCursorClient(aura::RootWindow* window) |
13 : root_window_(window), | 13 : root_window_(window), |
14 cursor_loader_(ui::CursorLoader::Create()), | 14 cursor_loader_(ui::CursorLoader::Create()) { |
15 current_cursor_(ui::kCursorNone), | |
16 cursor_visible_(true) { | |
17 } | 15 } |
18 | 16 |
19 DesktopCursorClient::~DesktopCursorClient() { | 17 DesktopCursorClient::~DesktopCursorClient() { |
20 } | 18 } |
21 | 19 |
22 void DesktopCursorClient::SetCursor(gfx::NativeCursor cursor) { | |
23 current_cursor_ = cursor; | |
24 cursor_loader_->SetPlatformCursor(¤t_cursor_); | |
25 if (cursor_visible_) | |
26 root_window_->SetCursor(current_cursor_); | |
27 } | |
28 | |
29 void DesktopCursorClient::ShowCursor() { | |
30 SetCursorVisibility(true); | |
31 } | |
32 | |
33 void DesktopCursorClient::HideCursor() { | |
34 SetCursorVisibility(false); | |
35 } | |
36 | |
37 bool DesktopCursorClient::IsCursorVisible() const { | |
38 return cursor_visible_; | |
39 } | |
40 | |
41 void DesktopCursorClient::EnableMouseEvents() { | |
42 // TODO(mazda): Implement this. | |
43 NOTIMPLEMENTED(); | |
44 } | |
45 | |
46 void DesktopCursorClient::DisableMouseEvents() { | |
47 // TODO(mazda): Implement this. | |
48 NOTIMPLEMENTED(); | |
49 } | |
50 | |
51 bool DesktopCursorClient::IsMouseEventsEnabled() const { | |
52 // TODO(mazda): Implement this. | |
53 NOTIMPLEMENTED(); | |
54 return true; | |
55 } | |
56 | |
57 void DesktopCursorClient::SetDeviceScaleFactor(float device_scale_factor) { | 20 void DesktopCursorClient::SetDeviceScaleFactor(float device_scale_factor) { |
58 cursor_loader_->UnloadAll(); | 21 cursor_loader_->UnloadAll(); |
59 cursor_loader_->set_device_scale_factor(device_scale_factor); | 22 cursor_loader_->set_device_scale_factor(device_scale_factor); |
| 23 |
| 24 DLOG(ERROR) << "Make sure the SetDeviceScaleFactor doesn't spin!"; |
| 25 SetCursorInternal(GetCurrentCursor()); |
60 } | 26 } |
61 | 27 |
62 void DesktopCursorClient::LockCursor() { | 28 void DesktopCursorClient::SetCursorInternal(gfx::NativeCursor cursor) { |
63 // TODO(mazda): Implement this. | 29 gfx::NativeCursor new_cursor = cursor; |
64 NOTIMPLEMENTED(); | 30 cursor_loader_->SetPlatformCursor(&new_cursor); |
65 } | 31 CursorController::SetCursorInternal(new_cursor); |
66 | 32 |
67 void DesktopCursorClient::UnlockCursor() { | 33 if (IsCursorVisible()) |
68 // TODO(mazda): Implement this. | 34 root_window_->SetCursor(new_cursor); |
69 NOTIMPLEMENTED(); | |
70 } | 35 } |
71 | 36 |
72 void DesktopCursorClient::SetCursorVisibility(bool visible) { | 37 void DesktopCursorClient::SetCursorVisibility(bool visible) { |
73 if (cursor_visible_ == visible) | 38 CursorController::SetCursorVisibility(visible); |
74 return; | 39 |
75 cursor_visible_ = visible; | 40 if (visible) { |
76 root_window_->SetCursor(current_cursor_); | 41 SetCursorInternal(GetCurrentCursor()); |
| 42 } else { |
| 43 gfx::NativeCursor invisible_cursor(ui::kCursorNone); |
| 44 cursor_loader_->SetPlatformCursor(&invisible_cursor); |
| 45 root_window_->SetCursor(invisible_cursor); |
| 46 } |
| 47 |
77 root_window_->OnCursorVisibilityChanged(visible); | 48 root_window_->OnCursorVisibilityChanged(visible); |
78 } | 49 } |
79 | 50 |
| 51 void DesktopCursorClient::SetMouseEventsEnabled(bool enabled) { |
| 52 CursorController::SetMouseEventsEnabled(enabled); |
| 53 |
| 54 // TODO(erg): In the ash version, we set the last mouse location on Env. I'm |
| 55 // not sure this concept makes sense on the desktop. |
| 56 |
| 57 SetCursorVisibility(IsCursorVisible()); |
| 58 |
| 59 root_window_->OnMouseEventsEnableStateChanged(enabled); |
| 60 } |
| 61 |
80 } // namespace views | 62 } // namespace views |
OLD | NEW |