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 gfx::NativeCursor new_cursor = cursor; | |
James Cook
2014/04/25 22:48:00
Any particular reason for copying the cursor?
Daniel Erat
2014/04/25 23:23:25
i must sheepishly admit that i did this because As
| |
90 image_cursors_->SetPlatformCursor(&new_cursor); | |
91 new_cursor.set_device_scale_factor(image_cursors_->GetScale()); | |
92 | |
93 delegate->CommitCursor(new_cursor); | |
94 | |
95 if (delegate->IsCursorVisible()) | |
96 ApplyCursor(new_cursor); | |
97 } | |
98 | |
99 virtual void SetVisibility( | |
100 bool visible, | |
101 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { | |
102 delegate->CommitVisibility(visible); | |
103 | |
104 if (visible) { | |
105 SetCursor(delegate->GetCursor(), delegate); | |
106 } else { | |
107 gfx::NativeCursor invisible_cursor(ui::kCursorNone); | |
108 image_cursors_->SetPlatformCursor(&invisible_cursor); | |
109 ApplyCursor(invisible_cursor); | |
110 } | |
111 } | |
112 | |
113 virtual void SetCursorSet( | |
114 ui::CursorSetType cursor_set, | |
115 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { | |
116 image_cursors_->SetCursorSet(cursor_set); | |
117 delegate->CommitCursorSet(cursor_set); | |
118 if (delegate->IsCursorVisible()) | |
119 SetCursor(delegate->GetCursor(), delegate); | |
120 } | |
121 | |
122 virtual void SetMouseEventsEnabled( | |
123 bool enabled, | |
124 wm::NativeCursorManagerDelegate* delegate) OVERRIDE { | |
125 delegate->CommitMouseEventsEnabled(enabled); | |
126 SetVisibility(delegate->IsCursorVisible(), delegate); | |
127 } | |
128 | |
129 private: | |
130 // Sets |cursor| as the active cursor within Aura. | |
131 void ApplyCursor(gfx::NativeCursor cursor) { | |
132 host_->SetCursor(cursor); | |
133 } | |
134 | |
135 aura::WindowTreeHost* host_; // Not owned. | |
136 | |
137 scoped_ptr<ui::ImageCursors> image_cursors_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager); | |
140 }; | |
141 | |
62 ShellDesktopController* g_instance = NULL; | 142 ShellDesktopController* g_instance = NULL; |
63 | 143 |
64 } // namespace | 144 } // namespace |
65 | 145 |
66 ShellDesktopController::ShellDesktopController() { | 146 ShellDesktopController::ShellDesktopController() { |
67 #if defined(OS_CHROMEOS) | 147 #if defined(OS_CHROMEOS) |
68 display_configurator_.reset(new ui::DisplayConfigurator); | 148 display_configurator_.reset(new ui::DisplayConfigurator); |
69 display_configurator_->Init(false); | 149 display_configurator_->Init(false); |
70 display_configurator_->ForceInitialConfigure(0); | 150 display_configurator_->ForceInitialConfigure(0); |
71 display_configurator_->AddObserver(this); | 151 display_configurator_->AddObserver(this); |
72 #endif | 152 #endif |
73 CreateRootWindow(); | 153 CreateRootWindow(); |
74 | 154 |
155 cursor_manager_.reset( | |
156 new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>( | |
157 new ShellNativeCursorManager(GetWindowTreeHost())))); | |
158 cursor_manager_->SetDisplay( | |
159 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()); | |
160 cursor_manager_->SetCursor(ui::kCursorPointer); | |
161 aura::client::SetCursorClient( | |
162 GetWindowTreeHost()->window(), cursor_manager_.get()); | |
163 | |
75 user_activity_detector_.reset(new wm::UserActivityDetector); | 164 user_activity_detector_.reset(new wm::UserActivityDetector); |
76 GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler( | 165 GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler( |
77 user_activity_detector_.get()); | 166 user_activity_detector_.get()); |
78 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
79 user_activity_notifier_.reset( | 168 user_activity_notifier_.reset( |
80 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); | 169 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
81 #endif | 170 #endif |
82 | 171 |
83 g_instance = this; | 172 g_instance = this; |
84 } | 173 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 if (displays.empty()) | 250 if (displays.empty()) |
162 return gfx::Size(); | 251 return gfx::Size(); |
163 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 252 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
164 return mode ? mode->size() : gfx::Size(); | 253 return mode ? mode->size() : gfx::Size(); |
165 #else | 254 #else |
166 return gfx::Size(); | 255 return gfx::Size(); |
167 #endif | 256 #endif |
168 } | 257 } |
169 | 258 |
170 } // namespace apps | 259 } // namespace apps |
OLD | NEW |