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/window_event_dispatcher.h"
8 #include "ui/aura/window_tree_host.h"
9 #include "ui/base/cursor/cursor_loader.h"
10 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
14 DesktopNativeCursorManager::DesktopNativeCursorManager(
15 scoped_ptr
<DesktopCursorLoaderUpdater
> cursor_loader_updater
)
16 : cursor_loader_updater_(cursor_loader_updater
.Pass()),
17 cursor_loader_(ui::CursorLoader::Create()) {
18 if (cursor_loader_updater_
.get())
19 cursor_loader_updater_
->OnCreate(1.0f
, cursor_loader_
.get());
22 DesktopNativeCursorManager::~DesktopNativeCursorManager() {
25 gfx::NativeCursor
DesktopNativeCursorManager::GetInitializedCursor(int type
) {
26 gfx::NativeCursor
cursor(type
);
27 cursor_loader_
->SetPlatformCursor(&cursor
);
31 void DesktopNativeCursorManager::AddHost(aura::WindowTreeHost
* host
) {
35 void DesktopNativeCursorManager::RemoveHost(aura::WindowTreeHost
* host
) {
39 void DesktopNativeCursorManager::SetDisplay(
40 const gfx::Display
& display
,
41 wm::NativeCursorManagerDelegate
* delegate
) {
42 cursor_loader_
->UnloadAll();
43 cursor_loader_
->set_rotation(display
.rotation());
44 cursor_loader_
->set_scale(display
.device_scale_factor());
46 if (cursor_loader_updater_
.get())
47 cursor_loader_updater_
->OnDisplayUpdated(display
, cursor_loader_
.get());
49 SetCursor(delegate
->GetCursor(), delegate
);
52 void DesktopNativeCursorManager::SetCursor(
53 gfx::NativeCursor cursor
,
54 wm::NativeCursorManagerDelegate
* delegate
) {
55 gfx::NativeCursor new_cursor
= cursor
;
56 cursor_loader_
->SetPlatformCursor(&new_cursor
);
57 delegate
->CommitCursor(new_cursor
);
59 if (delegate
->IsCursorVisible()) {
60 for (Hosts::const_iterator i
= hosts_
.begin(); i
!= hosts_
.end(); ++i
)
61 (*i
)->SetCursor(new_cursor
);
65 void DesktopNativeCursorManager::SetVisibility(
67 wm::NativeCursorManagerDelegate
* delegate
) {
68 delegate
->CommitVisibility(visible
);
71 SetCursor(delegate
->GetCursor(), delegate
);
73 gfx::NativeCursor
invisible_cursor(ui::kCursorNone
);
74 cursor_loader_
->SetPlatformCursor(&invisible_cursor
);
75 for (Hosts::const_iterator i
= hosts_
.begin(); i
!= hosts_
.end(); ++i
)
76 (*i
)->SetCursor(invisible_cursor
);
79 for (Hosts::const_iterator i
= hosts_
.begin(); i
!= hosts_
.end(); ++i
)
80 (*i
)->OnCursorVisibilityChanged(visible
);
83 void DesktopNativeCursorManager::SetCursorSet(
84 ui::CursorSetType cursor_set
,
85 wm::NativeCursorManagerDelegate
* delegate
) {
89 void DesktopNativeCursorManager::SetMouseEventsEnabled(
91 wm::NativeCursorManagerDelegate
* delegate
) {
92 delegate
->CommitMouseEventsEnabled(enabled
);
94 // TODO(erg): In the ash version, we set the last mouse location on Env. I'm
95 // not sure this concept makes sense on the desktop.
97 SetVisibility(delegate
->IsCursorVisible(), delegate
);
99 for (Hosts::const_iterator i
= hosts_
.begin(); i
!= hosts_
.end(); ++i
)
100 (*i
)->dispatcher()->OnMouseEventsEnableStateChanged(enabled
);