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 aura::RootWindow* window,
15 scoped_ptr<DesktopCursorLoaderUpdater> cursor_loader_updater)
16 : root_window_(window),
17 cursor_loader_updater_(cursor_loader_updater.Pass()),
18 cursor_loader_(ui::CursorLoader::Create()) {
19 if (cursor_loader_updater_.get())
20 cursor_loader_updater_->OnCreate(root_window_, cursor_loader_.get());
23 DesktopNativeCursorManager::~DesktopNativeCursorManager() {
26 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) {
27 gfx::NativeCursor cursor(type);
28 cursor_loader_->SetPlatformCursor(&cursor);
32 void DesktopNativeCursorManager::SetDisplay(
33 const gfx::Display& display,
34 views::corewm::NativeCursorManagerDelegate* delegate) {
35 cursor_loader_->UnloadAll();
36 cursor_loader_->set_display(display);
38 if (cursor_loader_updater_.get())
39 cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get());
41 SetCursor(delegate->GetCurrentCursor(), delegate);
44 void DesktopNativeCursorManager::SetCursor(
45 gfx::NativeCursor cursor,
46 views::corewm::NativeCursorManagerDelegate* delegate) {
47 gfx::NativeCursor new_cursor = cursor;
48 cursor_loader_->SetPlatformCursor(&new_cursor);
49 delegate->CommitCursor(new_cursor);
51 if (delegate->GetCurrentVisibility())
52 root_window_->SetCursor(new_cursor);
55 void DesktopNativeCursorManager::SetVisibility(
57 views::corewm::NativeCursorManagerDelegate* delegate) {
58 delegate->CommitVisibility(visible);
61 SetCursor(delegate->GetCurrentCursor(), delegate);
63 gfx::NativeCursor invisible_cursor(ui::kCursorNone);
64 cursor_loader_->SetPlatformCursor(&invisible_cursor);
65 root_window_->SetCursor(invisible_cursor);
68 root_window_->OnCursorVisibilityChanged(visible);
71 void DesktopNativeCursorManager::SetCursorSet(
72 ui::CursorSetType cursor_set,
73 views::corewm::NativeCursorManagerDelegate* delegate) {
77 void DesktopNativeCursorManager::SetScale(
79 views::corewm::NativeCursorManagerDelegate* delegate) {
83 void DesktopNativeCursorManager::SetMouseEventsEnabled(
85 views::corewm::NativeCursorManagerDelegate* delegate) {
86 delegate->CommitMouseEventsEnabled(enabled);
88 // TODO(erg): In the ash version, we set the last mouse location on Env. I'm
89 // not sure this concept makes sense on the desktop.
91 SetVisibility(delegate->GetCurrentVisibility(), delegate);
93 root_window_->OnMouseEventsEnableStateChanged(enabled);