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
3 // found in the LICENSE file.
5 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
7 #include "ui/aura/root_window.h"
8 #include "ui/base/cursor/cursor_loader.h"
9 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
13 DesktopNativeCursorManager::DesktopNativeCursorManager(
14 scoped_ptr<DesktopCursorLoaderUpdater> cursor_loader_updater)
15 : cursor_loader_updater_(cursor_loader_updater.Pass()),
16 cursor_loader_(ui::CursorLoader::Create()) {
17 if (cursor_loader_updater_.get())
18 cursor_loader_updater_->OnCreate(1.0f, cursor_loader_.get());
21 DesktopNativeCursorManager::~DesktopNativeCursorManager() {
24 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) {
25 gfx::NativeCursor cursor(type);
26 cursor_loader_->SetPlatformCursor(&cursor);
30 void DesktopNativeCursorManager::AddRootWindow(aura::RootWindow* root_window) {
31 root_windows_.insert(root_window);
34 void DesktopNativeCursorManager::RemoveRootWindow(
35 aura::RootWindow* root_window) {
36 root_windows_.erase(root_window);
39 void DesktopNativeCursorManager::SetDisplay(
40 const gfx::Display& display,
41 views::corewm::NativeCursorManagerDelegate* delegate) {
42 cursor_loader_->UnloadAll();
43 cursor_loader_->set_display(display);
45 if (cursor_loader_updater_.get())
46 cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get());
48 SetCursor(delegate->GetCursor(), delegate);
51 void DesktopNativeCursorManager::SetCursor(
52 gfx::NativeCursor cursor,
53 views::corewm::NativeCursorManagerDelegate* delegate) {
54 gfx::NativeCursor new_cursor = cursor;
55 cursor_loader_->SetPlatformCursor(&new_cursor);
56 delegate->CommitCursor(new_cursor);
58 if (delegate->IsCursorVisible()) {
59 for (RootWindows::const_iterator i = root_windows_.begin();
60 i != root_windows_.end();
62 (*i)->SetCursor(new_cursor);
67 void DesktopNativeCursorManager::SetVisibility(
69 views::corewm::NativeCursorManagerDelegate* delegate) {
70 delegate->CommitVisibility(visible);
73 SetCursor(delegate->GetCursor(), delegate);
75 gfx::NativeCursor invisible_cursor(ui::kCursorNone);
76 cursor_loader_->SetPlatformCursor(&invisible_cursor);
77 for (RootWindows::const_iterator i = root_windows_.begin();
78 i != root_windows_.end();
80 (*i)->SetCursor(invisible_cursor);
84 for (RootWindows::const_iterator i = root_windows_.begin();
85 i != root_windows_.end();
87 (*i)->OnCursorVisibilityChanged(visible);
91 void DesktopNativeCursorManager::SetCursorSet(
92 ui::CursorSetType cursor_set,
93 views::corewm::NativeCursorManagerDelegate* delegate) {
97 void DesktopNativeCursorManager::SetScale(
99 views::corewm::NativeCursorManagerDelegate* delegate) {
103 void DesktopNativeCursorManager::SetMouseEventsEnabled(
105 views::corewm::NativeCursorManagerDelegate* delegate) {
106 delegate->CommitMouseEventsEnabled(enabled);
108 // TODO(erg): In the ash version, we set the last mouse location on Env. I'm
109 // not sure this concept makes sense on the desktop.
111 SetVisibility(delegate->IsCursorVisible(), delegate);
113 for (RootWindows::const_iterator i = root_windows_.begin();
114 i != root_windows_.end();
116 (*i)->OnMouseEventsEnableStateChanged(enabled);