71bfeca0a3cd1250d13894b4d021d6e3b1d4a701
[platform/framework/web/crosswalk.git] / src / ui / views / widget / desktop_aura / desktop_native_cursor_manager.cc
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.
4
5 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
6
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"
10
11 namespace views {
12
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());
19 }
20
21 DesktopNativeCursorManager::~DesktopNativeCursorManager() {
22 }
23
24 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) {
25   gfx::NativeCursor cursor(type);
26   cursor_loader_->SetPlatformCursor(&cursor);
27   return cursor;
28 }
29
30 void DesktopNativeCursorManager::AddRootWindow(aura::RootWindow* root_window) {
31   root_windows_.insert(root_window);
32 }
33
34 void DesktopNativeCursorManager::RemoveRootWindow(
35     aura::RootWindow* root_window) {
36   root_windows_.erase(root_window);
37 }
38
39 void DesktopNativeCursorManager::SetDisplay(
40     const gfx::Display& display,
41     views::corewm::NativeCursorManagerDelegate* delegate) {
42   cursor_loader_->UnloadAll();
43   cursor_loader_->set_display(display);
44
45   if (cursor_loader_updater_.get())
46     cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get());
47
48   SetCursor(delegate->GetCursor(), delegate);
49 }
50
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);
57
58   if (delegate->IsCursorVisible()) {
59     for (RootWindows::const_iterator i = root_windows_.begin();
60          i != root_windows_.end();
61          ++i) {
62       (*i)->SetCursor(new_cursor);
63     }
64   }
65 }
66
67 void DesktopNativeCursorManager::SetVisibility(
68     bool visible,
69     views::corewm::NativeCursorManagerDelegate* delegate) {
70   delegate->CommitVisibility(visible);
71
72   if (visible) {
73     SetCursor(delegate->GetCursor(), delegate);
74   } else {
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();
79          ++i) {
80       (*i)->SetCursor(invisible_cursor);
81     }
82   }
83
84   for (RootWindows::const_iterator i = root_windows_.begin();
85        i != root_windows_.end();
86        ++i) {
87     (*i)->OnCursorVisibilityChanged(visible);
88   }
89 }
90
91 void DesktopNativeCursorManager::SetCursorSet(
92     ui::CursorSetType cursor_set,
93     views::corewm::NativeCursorManagerDelegate* delegate) {
94   NOTIMPLEMENTED();
95 }
96
97 void DesktopNativeCursorManager::SetScale(
98     float scale,
99     views::corewm::NativeCursorManagerDelegate* delegate) {
100   NOTIMPLEMENTED();
101 }
102
103 void DesktopNativeCursorManager::SetMouseEventsEnabled(
104     bool enabled,
105     views::corewm::NativeCursorManagerDelegate* delegate) {
106   delegate->CommitMouseEventsEnabled(enabled);
107
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.
110
111   SetVisibility(delegate->IsCursorVisible(), delegate);
112
113   for (RootWindows::const_iterator i = root_windows_.begin();
114        i != root_windows_.end();
115        ++i) {
116     (*i)->OnMouseEventsEnableStateChanged(enabled);
117   }
118 }
119
120 }  // namespace views