OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "apps/shell/browser/shell_desktop_controller.h" | 5 #include "apps/shell/browser/shell_desktop_controller.h" |
6 | 6 |
7 #include "apps/shell/browser/shell_app_window.h" | 7 #include "apps/shell/browser/shell_app_window.h" |
| 8 #include "ui/aura/client/cursor_client.h" |
8 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
9 #include "ui/aura/layout_manager.h" | 10 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/test/test_screen.h" | 11 #include "ui/aura/test/test_screen.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/aura/window_tree_host.h" | 14 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/base/cursor/cursor.h" |
| 16 #include "ui/base/cursor/image_cursors.h" |
14 #include "ui/base/ime/input_method_initializer.h" | 17 #include "ui/base/ime/input_method_initializer.h" |
| 18 #include "ui/gfx/native_widget_types.h" |
15 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 20 #include "ui/wm/core/cursor_manager.h" |
| 21 #include "ui/wm/core/native_cursor_manager.h" |
| 22 #include "ui/wm/core/native_cursor_manager_delegate.h" |
16 #include "ui/wm/core/user_activity_detector.h" | 23 #include "ui/wm/core/user_activity_detector.h" |
17 #include "ui/wm/test/wm_test_helper.h" | 24 #include "ui/wm/test/wm_test_helper.h" |
18 | 25 |
19 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
20 #include "ui/chromeos/user_activity_power_manager_notifier.h" | 27 #include "ui/chromeos/user_activity_power_manager_notifier.h" |
21 #include "ui/display/types/chromeos/display_mode.h" | 28 #include "ui/display/types/chromeos/display_mode.h" |
22 #include "ui/display/types/chromeos/display_snapshot.h" | 29 #include "ui/display/types/chromeos/display_snapshot.h" |
23 #endif | 30 #endif |
24 | 31 |
25 namespace apps { | 32 namespace apps { |
(...skipping 26 matching lines...) Expand all Loading... |
52 bool visible) OVERRIDE {} | 59 bool visible) OVERRIDE {} |
53 | 60 |
54 virtual void SetChildBounds(aura::Window* child, | 61 virtual void SetChildBounds(aura::Window* child, |
55 const gfx::Rect& requested_bounds) OVERRIDE { | 62 const gfx::Rect& requested_bounds) OVERRIDE { |
56 SetChildBoundsDirect(child, requested_bounds); | 63 SetChildBoundsDirect(child, requested_bounds); |
57 } | 64 } |
58 | 65 |
59 DISALLOW_COPY_AND_ASSIGN(FillLayout); | 66 DISALLOW_COPY_AND_ASSIGN(FillLayout); |
60 }; | 67 }; |
61 | 68 |
| 69 // A class that bridges the gap between CursorManager and Aura. It borrows |
| 70 // heavily from AshNativeCursorManager. |
| 71 class ShellNativeCursorManager : public wm::NativeCursorManager { |
| 72 public: |
| 73 explicit ShellNativeCursorManager(aura::WindowTreeHost* host) |
| 74 : host_(host), |
| 75 image_cursors_(new ui::ImageCursors) {} |
| 76 virtual ~ShellNativeCursorManager() {} |
| 77 |
| 78 // wm::NativeCursorManager overrides. |
| 79 virtual void SetDisplay( |
| 80 const gfx::Display& display, |
| 81 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 82 if (image_cursors_->SetDisplay(display, display.device_scale_factor())) |
| 83 SetCursor(delegate->GetCursor(), delegate); |
| 84 } |
| 85 |
| 86 virtual void SetCursor( |
| 87 gfx::NativeCursor cursor, |
| 88 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 89 image_cursors_->SetPlatformCursor(&cursor); |
| 90 cursor.set_device_scale_factor(image_cursors_->GetScale()); |
| 91 delegate->CommitCursor(cursor); |
| 92 |
| 93 if (delegate->IsCursorVisible()) |
| 94 ApplyCursor(cursor); |
| 95 } |
| 96 |
| 97 virtual void SetVisibility( |
| 98 bool visible, |
| 99 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 100 delegate->CommitVisibility(visible); |
| 101 |
| 102 if (visible) { |
| 103 SetCursor(delegate->GetCursor(), delegate); |
| 104 } else { |
| 105 gfx::NativeCursor invisible_cursor(ui::kCursorNone); |
| 106 image_cursors_->SetPlatformCursor(&invisible_cursor); |
| 107 ApplyCursor(invisible_cursor); |
| 108 } |
| 109 } |
| 110 |
| 111 virtual void SetCursorSet( |
| 112 ui::CursorSetType cursor_set, |
| 113 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 114 image_cursors_->SetCursorSet(cursor_set); |
| 115 delegate->CommitCursorSet(cursor_set); |
| 116 if (delegate->IsCursorVisible()) |
| 117 SetCursor(delegate->GetCursor(), delegate); |
| 118 } |
| 119 |
| 120 virtual void SetMouseEventsEnabled( |
| 121 bool enabled, |
| 122 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 123 delegate->CommitMouseEventsEnabled(enabled); |
| 124 SetVisibility(delegate->IsCursorVisible(), delegate); |
| 125 } |
| 126 |
| 127 private: |
| 128 // Sets |cursor| as the active cursor within Aura. |
| 129 void ApplyCursor(gfx::NativeCursor cursor) { |
| 130 host_->SetCursor(cursor); |
| 131 } |
| 132 |
| 133 aura::WindowTreeHost* host_; // Not owned. |
| 134 |
| 135 scoped_ptr<ui::ImageCursors> image_cursors_; |
| 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager); |
| 138 }; |
| 139 |
62 ShellDesktopController* g_instance = NULL; | 140 ShellDesktopController* g_instance = NULL; |
63 | 141 |
64 } // namespace | 142 } // namespace |
65 | 143 |
66 ShellDesktopController::ShellDesktopController() { | 144 ShellDesktopController::ShellDesktopController() { |
67 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
68 display_configurator_.reset(new ui::DisplayConfigurator); | 146 display_configurator_.reset(new ui::DisplayConfigurator); |
69 display_configurator_->Init(false); | 147 display_configurator_->Init(false); |
70 display_configurator_->ForceInitialConfigure(0); | 148 display_configurator_->ForceInitialConfigure(0); |
71 display_configurator_->AddObserver(this); | 149 display_configurator_->AddObserver(this); |
72 #endif | 150 #endif |
73 CreateRootWindow(); | 151 CreateRootWindow(); |
74 | 152 |
| 153 cursor_manager_.reset( |
| 154 new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>( |
| 155 new ShellNativeCursorManager(GetWindowTreeHost())))); |
| 156 cursor_manager_->SetDisplay( |
| 157 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()); |
| 158 cursor_manager_->SetCursor(ui::kCursorPointer); |
| 159 aura::client::SetCursorClient( |
| 160 GetWindowTreeHost()->window(), cursor_manager_.get()); |
| 161 |
75 user_activity_detector_.reset(new wm::UserActivityDetector); | 162 user_activity_detector_.reset(new wm::UserActivityDetector); |
76 GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler( | 163 GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler( |
77 user_activity_detector_.get()); | 164 user_activity_detector_.get()); |
78 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
79 user_activity_notifier_.reset( | 166 user_activity_notifier_.reset( |
80 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); | 167 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
81 #endif | 168 #endif |
82 | 169 |
83 g_instance = this; | 170 g_instance = this; |
84 } | 171 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if (displays.empty()) | 248 if (displays.empty()) |
162 return gfx::Size(); | 249 return gfx::Size(); |
163 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 250 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
164 return mode ? mode->size() : gfx::Size(); | 251 return mode ? mode->size() : gfx::Size(); |
165 #else | 252 #else |
166 return gfx::Size(); | 253 return gfx::Size(); |
167 #endif | 254 #endif |
168 } | 255 } |
169 | 256 |
170 } // namespace apps | 257 } // namespace apps |
OLD | NEW |