- add sources.
[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     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());
21 }
22
23 DesktopNativeCursorManager::~DesktopNativeCursorManager() {
24 }
25
26 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) {
27   gfx::NativeCursor cursor(type);
28   cursor_loader_->SetPlatformCursor(&cursor);
29   return cursor;
30 }
31
32 void DesktopNativeCursorManager::SetDisplay(
33     const gfx::Display& display,
34     views::corewm::NativeCursorManagerDelegate* delegate) {
35   cursor_loader_->UnloadAll();
36   cursor_loader_->set_display(display);
37
38   if (cursor_loader_updater_.get())
39     cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get());
40
41   SetCursor(delegate->GetCurrentCursor(), delegate);
42 }
43
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);
50
51   if (delegate->GetCurrentVisibility())
52     root_window_->SetCursor(new_cursor);
53 }
54
55 void DesktopNativeCursorManager::SetVisibility(
56     bool visible,
57     views::corewm::NativeCursorManagerDelegate* delegate) {
58   delegate->CommitVisibility(visible);
59
60   if (visible) {
61     SetCursor(delegate->GetCurrentCursor(), delegate);
62   } else {
63     gfx::NativeCursor invisible_cursor(ui::kCursorNone);
64     cursor_loader_->SetPlatformCursor(&invisible_cursor);
65     root_window_->SetCursor(invisible_cursor);
66   }
67
68   root_window_->OnCursorVisibilityChanged(visible);
69 }
70
71 void DesktopNativeCursorManager::SetCursorSet(
72     ui::CursorSetType cursor_set,
73     views::corewm::NativeCursorManagerDelegate* delegate) {
74   NOTIMPLEMENTED();
75 }
76
77 void DesktopNativeCursorManager::SetScale(
78     float scale,
79     views::corewm::NativeCursorManagerDelegate* delegate) {
80   NOTIMPLEMENTED();
81 }
82
83 void DesktopNativeCursorManager::SetMouseEventsEnabled(
84     bool enabled,
85     views::corewm::NativeCursorManagerDelegate* delegate) {
86   delegate->CommitMouseEventsEnabled(enabled);
87
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.
90
91   SetVisibility(delegate->GetCurrentVisibility(), delegate);
92
93   root_window_->OnMouseEventsEnableStateChanged(enabled);
94 }
95
96 }  // namespace views