| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 5 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
| 6 | 6 |
| 7 #include "ui/aura/root_window.h" | 7 #include "ui/aura/root_window.h" |
| 8 #include "ui/base/cursor/cursor_loader.h" | 8 #include "ui/base/cursor/cursor_loader.h" |
| 9 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 9 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
| 10 | 10 |
| 11 namespace views { | 11 namespace views { |
| 12 | 12 |
| 13 DesktopNativeCursorManager::DesktopNativeCursorManager( | 13 DesktopNativeCursorManager::DesktopNativeCursorManager( |
| 14 aura::RootWindow* window, | |
| 15 scoped_ptr<DesktopCursorLoaderUpdater> cursor_loader_updater) | 14 scoped_ptr<DesktopCursorLoaderUpdater> cursor_loader_updater) |
| 16 : root_window_(window), | 15 : cursor_loader_updater_(cursor_loader_updater.Pass()), |
| 17 cursor_loader_updater_(cursor_loader_updater.Pass()), | |
| 18 cursor_loader_(ui::CursorLoader::Create()) { | 16 cursor_loader_(ui::CursorLoader::Create()) { |
| 19 if (cursor_loader_updater_.get()) | 17 if (cursor_loader_updater_.get()) |
| 20 cursor_loader_updater_->OnCreate(root_window_, cursor_loader_.get()); | 18 cursor_loader_updater_->OnCreate(1.0f, cursor_loader_.get()); |
| 21 } | 19 } |
| 22 | 20 |
| 23 DesktopNativeCursorManager::~DesktopNativeCursorManager() { | 21 DesktopNativeCursorManager::~DesktopNativeCursorManager() { |
| 24 } | 22 } |
| 25 | 23 |
| 26 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) { | 24 gfx::NativeCursor DesktopNativeCursorManager::GetInitializedCursor(int type) { |
| 27 gfx::NativeCursor cursor(type); | 25 gfx::NativeCursor cursor(type); |
| 28 cursor_loader_->SetPlatformCursor(&cursor); | 26 cursor_loader_->SetPlatformCursor(&cursor); |
| 29 return cursor; | 27 return cursor; |
| 30 } | 28 } |
| 31 | 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 |
| 32 void DesktopNativeCursorManager::SetDisplay( | 39 void DesktopNativeCursorManager::SetDisplay( |
| 33 const gfx::Display& display, | 40 const gfx::Display& display, |
| 34 views::corewm::NativeCursorManagerDelegate* delegate) { | 41 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 35 cursor_loader_->UnloadAll(); | 42 cursor_loader_->UnloadAll(); |
| 36 cursor_loader_->set_display(display); | 43 cursor_loader_->set_display(display); |
| 37 | 44 |
| 38 if (cursor_loader_updater_.get()) | 45 if (cursor_loader_updater_.get()) |
| 39 cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get()); | 46 cursor_loader_updater_->OnDisplayUpdated(display, cursor_loader_.get()); |
| 40 | 47 |
| 41 SetCursor(delegate->GetCurrentCursor(), delegate); | 48 SetCursor(delegate->GetCursor(), delegate); |
| 42 } | 49 } |
| 43 | 50 |
| 44 void DesktopNativeCursorManager::SetCursor( | 51 void DesktopNativeCursorManager::SetCursor( |
| 45 gfx::NativeCursor cursor, | 52 gfx::NativeCursor cursor, |
| 46 views::corewm::NativeCursorManagerDelegate* delegate) { | 53 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 47 gfx::NativeCursor new_cursor = cursor; | 54 gfx::NativeCursor new_cursor = cursor; |
| 48 cursor_loader_->SetPlatformCursor(&new_cursor); | 55 cursor_loader_->SetPlatformCursor(&new_cursor); |
| 49 delegate->CommitCursor(new_cursor); | 56 delegate->CommitCursor(new_cursor); |
| 50 | 57 |
| 51 if (delegate->GetCurrentVisibility()) | 58 if (delegate->IsCursorVisible()) { |
| 52 root_window_->SetCursor(new_cursor); | 59 RootWindows root_windows(root_windows_); |
| 60 for (RootWindows::const_iterator i = root_windows.begin(); |
| 61 i != root_windows.end(); |
| 62 ++i) { |
| 63 (*i)->SetCursor(new_cursor); |
| 64 } |
| 65 } |
| 53 } | 66 } |
| 54 | 67 |
| 55 void DesktopNativeCursorManager::SetVisibility( | 68 void DesktopNativeCursorManager::SetVisibility( |
| 56 bool visible, | 69 bool visible, |
| 57 views::corewm::NativeCursorManagerDelegate* delegate) { | 70 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 58 delegate->CommitVisibility(visible); | 71 delegate->CommitVisibility(visible); |
| 59 | 72 |
| 60 if (visible) { | 73 if (visible) { |
| 61 SetCursor(delegate->GetCurrentCursor(), delegate); | 74 SetCursor(delegate->GetCursor(), delegate); |
| 62 } else { | 75 } else { |
| 63 gfx::NativeCursor invisible_cursor(ui::kCursorNone); | 76 gfx::NativeCursor invisible_cursor(ui::kCursorNone); |
| 64 cursor_loader_->SetPlatformCursor(&invisible_cursor); | 77 cursor_loader_->SetPlatformCursor(&invisible_cursor); |
| 65 root_window_->SetCursor(invisible_cursor); | 78 RootWindows root_windows(root_windows_); |
| 79 for (RootWindows::const_iterator i = root_windows.begin(); |
| 80 i != root_windows.end(); |
| 81 ++i) { |
| 82 (*i)->SetCursor(invisible_cursor); |
| 83 } |
| 66 } | 84 } |
| 67 | 85 |
| 68 root_window_->OnCursorVisibilityChanged(visible); | 86 RootWindows root_windows(root_windows_); |
| 87 for (RootWindows::const_iterator i = root_windows.begin(); |
| 88 i != root_windows.end(); |
| 89 ++i) { |
| 90 (*i)->OnCursorVisibilityChanged(visible); |
| 91 } |
| 69 } | 92 } |
| 70 | 93 |
| 71 void DesktopNativeCursorManager::SetCursorSet( | 94 void DesktopNativeCursorManager::SetCursorSet( |
| 72 ui::CursorSetType cursor_set, | 95 ui::CursorSetType cursor_set, |
| 73 views::corewm::NativeCursorManagerDelegate* delegate) { | 96 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 74 NOTIMPLEMENTED(); | 97 NOTIMPLEMENTED(); |
| 75 } | 98 } |
| 76 | 99 |
| 77 void DesktopNativeCursorManager::SetScale( | 100 void DesktopNativeCursorManager::SetScale( |
| 78 float scale, | 101 float scale, |
| 79 views::corewm::NativeCursorManagerDelegate* delegate) { | 102 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 80 NOTIMPLEMENTED(); | 103 NOTIMPLEMENTED(); |
| 81 } | 104 } |
| 82 | 105 |
| 83 void DesktopNativeCursorManager::SetMouseEventsEnabled( | 106 void DesktopNativeCursorManager::SetMouseEventsEnabled( |
| 84 bool enabled, | 107 bool enabled, |
| 85 views::corewm::NativeCursorManagerDelegate* delegate) { | 108 views::corewm::NativeCursorManagerDelegate* delegate) { |
| 86 delegate->CommitMouseEventsEnabled(enabled); | 109 delegate->CommitMouseEventsEnabled(enabled); |
| 87 | 110 |
| 88 // TODO(erg): In the ash version, we set the last mouse location on Env. I'm | 111 // 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. | 112 // not sure this concept makes sense on the desktop. |
| 90 | 113 |
| 91 SetVisibility(delegate->GetCurrentVisibility(), delegate); | 114 SetVisibility(delegate->IsCursorVisible(), delegate); |
| 92 | 115 |
| 93 root_window_->OnMouseEventsEnableStateChanged(enabled); | 116 RootWindows root_windows(root_windows_); |
| 117 for (RootWindows::const_iterator i = root_windows.begin(); |
| 118 i != root_windows.end(); |
| 119 ++i) { |
| 120 (*i)->OnMouseEventsEnableStateChanged(enabled); |
| 121 } |
| 94 } | 122 } |
| 95 | 123 |
| 96 } // namespace views | 124 } // namespace views |
| OLD | NEW |