Only fsync leveldb's directory when the manifest is being updated.
[chromium-blink-merge.git] / ash / wm / ash_native_cursor_manager.cc
bloba52858f78f8bda11dfda8906deec38def9be12a9
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 "ash/wm/ash_native_cursor_manager.h"
7 #include "ash/display/mirror_window_controller.h"
8 #include "ash/shell.h"
9 #include "ash/wm/image_cursors.h"
10 #include "base/logging.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h"
13 #include "ui/base/cursor/cursor.h"
15 namespace ash {
16 namespace {
18 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
19 Shell::RootWindowList root_windows =
20 Shell::GetInstance()->GetAllRootWindows();
21 for (Shell::RootWindowList::iterator iter = root_windows.begin();
22 iter != root_windows.end(); ++iter)
23 (*iter)->SetCursor(cursor);
24 #if defined(OS_CHROMEOS)
25 Shell::GetInstance()->mirror_window_controller()->SetMirroredCursor(cursor);
26 #endif
29 void NotifyCursorVisibilityChange(bool visible) {
30 Shell::RootWindowList root_windows =
31 Shell::GetInstance()->GetAllRootWindows();
32 for (Shell::RootWindowList::iterator iter = root_windows.begin();
33 iter != root_windows.end(); ++iter)
34 (*iter)->OnCursorVisibilityChanged(visible);
35 #if defined(OS_CHROMEOS)
36 Shell::GetInstance()->mirror_window_controller()->
37 SetMirroredCursorVisibility(visible);
38 #endif
41 void NotifyMouseEventsEnableStateChange(bool enabled) {
42 Shell::RootWindowList root_windows =
43 Shell::GetInstance()->GetAllRootWindows();
44 for (Shell::RootWindowList::iterator iter = root_windows.begin();
45 iter != root_windows.end(); ++iter)
46 (*iter)->OnMouseEventsEnableStateChanged(enabled);
47 // Mirror window never process events.
50 } // namespace
52 AshNativeCursorManager::AshNativeCursorManager()
53 : image_cursors_(new ImageCursors) {
56 AshNativeCursorManager::~AshNativeCursorManager() {
59 void AshNativeCursorManager::SetDisplay(
60 const gfx::Display& display,
61 views::corewm::NativeCursorManagerDelegate* delegate) {
62 if (image_cursors_->SetDisplay(display))
63 SetCursor(delegate->GetCurrentCursor(), delegate);
66 void AshNativeCursorManager::SetCursor(
67 gfx::NativeCursor cursor,
68 views::corewm::NativeCursorManagerDelegate* delegate) {
69 gfx::NativeCursor new_cursor = cursor;
70 image_cursors_->SetPlatformCursor(&new_cursor);
71 new_cursor.set_device_scale_factor(
72 image_cursors_->GetDisplay().device_scale_factor());
74 delegate->CommitCursor(new_cursor);
76 if (delegate->GetCurrentVisibility())
77 SetCursorOnAllRootWindows(new_cursor);
80 void AshNativeCursorManager::SetScale(
81 float scale,
82 views::corewm::NativeCursorManagerDelegate* delegate) {
83 image_cursors_->SetScale(scale);
84 delegate->CommitScale(scale);
86 // Sets the cursor to refrect the scale change imidiately.
87 SetCursor(delegate->GetCurrentCursor(), delegate);
90 void AshNativeCursorManager::SetVisibility(
91 bool visible,
92 views::corewm::NativeCursorManagerDelegate* delegate) {
93 delegate->CommitVisibility(visible);
95 if (visible) {
96 SetCursor(delegate->GetCurrentCursor(), delegate);
97 } else {
98 gfx::NativeCursor invisible_cursor(ui::kCursorNone);
99 image_cursors_->SetPlatformCursor(&invisible_cursor);
100 SetCursorOnAllRootWindows(invisible_cursor);
103 NotifyCursorVisibilityChange(visible);
106 void AshNativeCursorManager::SetMouseEventsEnabled(
107 bool enabled,
108 views::corewm::NativeCursorManagerDelegate* delegate) {
109 delegate->CommitMouseEventsEnabled(enabled);
111 if (enabled) {
112 aura::Env::GetInstance()->set_last_mouse_location(
113 disabled_cursor_location_);
114 } else {
115 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location();
118 SetVisibility(delegate->GetCurrentVisibility(), delegate);
119 NotifyMouseEventsEnableStateChange(enabled);
122 void AshNativeCursorManager::SetCursorResourceModule(
123 const base::string16& module_name) {
124 image_cursors_->SetCursorResourceModule(module_name);
128 } // namespace ash