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 "extensions/shell/browser/shell_desktop_controller.h" | 5 #include "extensions/shell/browser/shell_desktop_controller_aura.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "extensions/browser/app_window/app_window.h" | 12 #include "extensions/browser/app_window/app_window.h" |
13 #include "extensions/browser/app_window/native_app_window.h" | 13 #include "extensions/browser/app_window/native_app_window.h" |
14 #include "extensions/shell/browser/shell_app_delegate.h" | 14 #include "extensions/shell/browser/shell_app_delegate.h" |
15 #include "extensions/shell/browser/shell_app_window_client.h" | 15 #include "extensions/shell/browser/shell_app_window_client.h" |
16 #include "extensions/shell/common/switches.h" | 16 #include "extensions/shell/common/switches.h" |
17 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
18 #include "ui/aura/client/default_capture_client.h" | 18 #include "ui/aura/client/default_capture_client.h" |
19 #include "ui/aura/layout_manager.h" | 19 #include "ui/aura/layout_manager.h" |
20 #include "ui/aura/test/test_screen.h" | 20 #include "ui/aura/test/test_screen.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
23 #include "ui/aura/window_tree_host.h" | 23 #include "ui/aura/window_tree_host.h" |
24 #include "ui/base/cursor/cursor.h" | 24 #include "ui/base/cursor/cursor.h" |
25 #include "ui/base/cursor/image_cursors.h" | 25 #include "ui/base/cursor/image_cursors.h" |
26 #include "ui/base/ime/input_method_initializer.h" | 26 #include "ui/base/ime/input_method_initializer.h" |
| 27 #include "ui/gfx/geometry/size.h" |
27 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
28 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
29 #include "ui/wm/core/base_focus_rules.h" | 30 #include "ui/wm/core/base_focus_rules.h" |
30 #include "ui/wm/core/compound_event_filter.h" | 31 #include "ui/wm/core/compound_event_filter.h" |
31 #include "ui/wm/core/cursor_manager.h" | 32 #include "ui/wm/core/cursor_manager.h" |
32 #include "ui/wm/core/focus_controller.h" | 33 #include "ui/wm/core/focus_controller.h" |
33 #include "ui/wm/core/input_method_event_filter.h" | 34 #include "ui/wm/core/input_method_event_filter.h" |
34 #include "ui/wm/core/native_cursor_manager.h" | 35 #include "ui/wm/core/native_cursor_manager.h" |
35 #include "ui/wm/core/native_cursor_manager_delegate.h" | 36 #include "ui/wm/core/native_cursor_manager_delegate.h" |
36 #include "ui/wm/core/user_activity_detector.h" | 37 #include "ui/wm/core/user_activity_detector.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 bool SupportsChildActivation(aura::Window* window) const override { | 152 bool SupportsChildActivation(aura::Window* window) const override { |
152 return true; | 153 return true; |
153 } | 154 } |
154 | 155 |
155 private: | 156 private: |
156 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); | 157 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); |
157 }; | 158 }; |
158 | 159 |
159 } // namespace | 160 } // namespace |
160 | 161 |
161 ShellDesktopController::ShellDesktopController() | 162 ShellDesktopControllerAura::ShellDesktopControllerAura() |
162 : app_window_client_(new ShellAppWindowClient) { | 163 : app_window_client_(new ShellAppWindowClient) { |
163 extensions::AppWindowClient::Set(app_window_client_.get()); | 164 extensions::AppWindowClient::Set(app_window_client_.get()); |
164 | 165 |
165 #if defined(OS_CHROMEOS) | 166 #if defined(OS_CHROMEOS) |
166 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 167 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
167 AddObserver(this); | 168 this); |
168 display_configurator_.reset(new ui::DisplayConfigurator); | 169 display_configurator_.reset(new ui::DisplayConfigurator); |
169 display_configurator_->Init(false); | 170 display_configurator_->Init(false); |
170 display_configurator_->ForceInitialConfigure(0); | 171 display_configurator_->ForceInitialConfigure(0); |
171 display_configurator_->AddObserver(this); | 172 display_configurator_->AddObserver(this); |
172 #endif | 173 #endif |
173 CreateRootWindow(); | 174 CreateRootWindow(); |
174 } | 175 } |
175 | 176 |
176 ShellDesktopController::~ShellDesktopController() { | 177 ShellDesktopControllerAura::~ShellDesktopControllerAura() { |
177 CloseAppWindows(); | 178 CloseAppWindows(); |
178 DestroyRootWindow(); | 179 DestroyRootWindow(); |
179 #if defined(OS_CHROMEOS) | 180 #if defined(OS_CHROMEOS) |
180 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 181 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
181 RemoveObserver(this); | 182 this); |
182 #endif | 183 #endif |
183 extensions::AppWindowClient::Set(NULL); | 184 extensions::AppWindowClient::Set(NULL); |
184 } | 185 } |
185 | 186 |
186 aura::WindowTreeHost* ShellDesktopController::GetHost() { | 187 gfx::Size ShellDesktopControllerAura::GetWindowSize() { |
187 return host_.get(); | 188 return host_->window()->bounds().size(); |
188 } | 189 } |
189 | 190 |
190 AppWindow* ShellDesktopController::CreateAppWindow( | 191 AppWindow* ShellDesktopControllerAura::CreateAppWindow( |
191 content::BrowserContext* context, | 192 content::BrowserContext* context, |
192 const Extension* extension) { | 193 const Extension* extension) { |
193 app_windows_.push_back( | 194 app_windows_.push_back( |
194 new AppWindow(context, new ShellAppDelegate, extension)); | 195 new AppWindow(context, new ShellAppDelegate, extension)); |
195 return app_windows_.back(); | 196 return app_windows_.back(); |
196 } | 197 } |
197 | 198 |
198 void ShellDesktopController::AddAppWindow(aura::Window* window) { | 199 void ShellDesktopControllerAura::AddAppWindow(gfx::NativeWindow window) { |
199 aura::Window* root_window = GetHost()->window(); | 200 aura::Window* root_window = host_->window(); |
200 root_window->AddChild(window); | 201 root_window->AddChild(window); |
201 } | 202 } |
202 | 203 |
203 void ShellDesktopController::RemoveAppWindow(AppWindow* window) { | 204 void ShellDesktopControllerAura::RemoveAppWindow(AppWindow* window) { |
204 auto iter = std::find(app_windows_.begin(), app_windows_.end(), window); | 205 auto iter = std::find(app_windows_.begin(), app_windows_.end(), window); |
205 DCHECK(iter != app_windows_.end()); | 206 DCHECK(iter != app_windows_.end()); |
206 app_windows_.erase(iter); | 207 app_windows_.erase(iter); |
207 } | 208 } |
208 | 209 |
209 void ShellDesktopController::CloseAppWindows() { | 210 void ShellDesktopControllerAura::CloseAppWindows() { |
210 // Create a copy of the window vector, because closing the windows will | 211 // Create a copy of the window vector, because closing the windows will |
211 // trigger RemoveAppWindow, which will invalidate the iterator. | 212 // trigger RemoveAppWindow, which will invalidate the iterator. |
212 // This vector should be small enough that this should not be an issue. | 213 // This vector should be small enough that this should not be an issue. |
213 std::vector<AppWindow*> app_windows(app_windows_); | 214 std::vector<AppWindow*> app_windows(app_windows_); |
214 for (AppWindow* app_window : app_windows) | 215 for (AppWindow* app_window : app_windows) |
215 app_window->GetBaseWindow()->Close(); // Close() deletes |app_window|. | 216 app_window->GetBaseWindow()->Close(); // Close() deletes |app_window|. |
216 app_windows_.clear(); | 217 app_windows_.clear(); |
217 } | 218 } |
218 | 219 |
219 aura::Window* ShellDesktopController::GetDefaultParent( | 220 aura::Window* ShellDesktopControllerAura::GetDefaultParent( |
220 aura::Window* context, | 221 aura::Window* context, |
221 aura::Window* window, | 222 aura::Window* window, |
222 const gfx::Rect& bounds) { | 223 const gfx::Rect& bounds) { |
223 return host_->window(); | 224 return host_->window(); |
224 } | 225 } |
225 | 226 |
226 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
227 void ShellDesktopController::PowerButtonEventReceived( | 228 void ShellDesktopControllerAura::PowerButtonEventReceived( |
228 bool down, | 229 bool down, |
229 const base::TimeTicks& timestamp) { | 230 const base::TimeTicks& timestamp) { |
230 if (down) { | 231 if (down) { |
231 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 232 chromeos::DBusThreadManager::Get() |
232 RequestShutdown(); | 233 ->GetPowerManagerClient() |
| 234 ->RequestShutdown(); |
233 } | 235 } |
234 } | 236 } |
235 | 237 |
236 void ShellDesktopController::OnDisplayModeChanged( | 238 void ShellDesktopControllerAura::OnDisplayModeChanged( |
237 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { | 239 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { |
238 gfx::Size size = GetPrimaryDisplaySize(); | 240 gfx::Size size = GetPrimaryDisplaySize(); |
239 if (!size.IsEmpty()) | 241 if (!size.IsEmpty()) |
240 host_->UpdateRootWindowSize(size); | 242 host_->UpdateRootWindowSize(size); |
241 } | 243 } |
242 #endif | 244 #endif |
243 | 245 |
244 void ShellDesktopController::OnHostCloseRequested( | 246 void ShellDesktopControllerAura::OnHostCloseRequested( |
245 const aura::WindowTreeHost* host) { | 247 const aura::WindowTreeHost* host) { |
246 DCHECK_EQ(host_.get(), host); | 248 DCHECK_EQ(host_.get(), host); |
247 CloseAppWindows(); | 249 CloseAppWindows(); |
248 base::MessageLoop::current()->PostTask(FROM_HERE, | 250 base::MessageLoop::current()->PostTask(FROM_HERE, |
249 base::MessageLoop::QuitClosure()); | 251 base::MessageLoop::QuitClosure()); |
250 } | 252 } |
251 | 253 |
252 void ShellDesktopController::InitWindowManager() { | 254 void ShellDesktopControllerAura::InitWindowManager() { |
253 wm::FocusController* focus_controller = | 255 wm::FocusController* focus_controller = |
254 new wm::FocusController(new AppsFocusRules()); | 256 new wm::FocusController(new AppsFocusRules()); |
255 aura::client::SetFocusClient(host_->window(), focus_controller); | 257 aura::client::SetFocusClient(host_->window(), focus_controller); |
256 host_->window()->AddPreTargetHandler(focus_controller); | 258 host_->window()->AddPreTargetHandler(focus_controller); |
257 aura::client::SetActivationClient(host_->window(), focus_controller); | 259 aura::client::SetActivationClient(host_->window(), focus_controller); |
258 focus_client_.reset(focus_controller); | 260 focus_client_.reset(focus_controller); |
259 | 261 |
260 input_method_filter_.reset( | 262 input_method_filter_.reset( |
261 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); | 263 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); |
262 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window()); | 264 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window()); |
(...skipping 15 matching lines...) Expand all Loading... |
278 | 280 |
279 user_activity_detector_.reset(new wm::UserActivityDetector); | 281 user_activity_detector_.reset(new wm::UserActivityDetector); |
280 host_->event_processor()->GetRootTarget()->AddPreTargetHandler( | 282 host_->event_processor()->GetRootTarget()->AddPreTargetHandler( |
281 user_activity_detector_.get()); | 283 user_activity_detector_.get()); |
282 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
283 user_activity_notifier_.reset( | 285 user_activity_notifier_.reset( |
284 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); | 286 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
285 #endif | 287 #endif |
286 } | 288 } |
287 | 289 |
288 void ShellDesktopController::CreateRootWindow() { | 290 void ShellDesktopControllerAura::CreateRootWindow() { |
289 // Set up basic pieces of ui::wm. | 291 // Set up basic pieces of ui::wm. |
290 gfx::Size size; | 292 gfx::Size size; |
291 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 293 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
292 if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) { | 294 if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) { |
293 const std::string size_str = | 295 const std::string size_str = |
294 command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds); | 296 command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds); |
295 int width, height; | 297 int width, height; |
296 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); | 298 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); |
297 size = gfx::Size(width, height); | 299 size = gfx::Size(width, height); |
298 } else { | 300 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
312 root_window_event_filter_.reset(new wm::CompoundEventFilter); | 314 root_window_event_filter_.reset(new wm::CompoundEventFilter); |
313 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | 315 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); |
314 InitWindowManager(); | 316 InitWindowManager(); |
315 | 317 |
316 host_->AddObserver(this); | 318 host_->AddObserver(this); |
317 | 319 |
318 // Ensure the X window gets mapped. | 320 // Ensure the X window gets mapped. |
319 host_->Show(); | 321 host_->Show(); |
320 } | 322 } |
321 | 323 |
322 void ShellDesktopController::DestroyRootWindow() { | 324 void ShellDesktopControllerAura::DestroyRootWindow() { |
323 host_->RemoveObserver(this); | 325 host_->RemoveObserver(this); |
324 if (input_method_filter_) | 326 if (input_method_filter_) |
325 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); | 327 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); |
326 if (user_activity_detector_) { | 328 if (user_activity_detector_) { |
327 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( | 329 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( |
328 user_activity_detector_.get()); | 330 user_activity_detector_.get()); |
329 } | 331 } |
330 wm::FocusController* focus_controller = | 332 wm::FocusController* focus_controller = |
331 static_cast<wm::FocusController*>(focus_client_.get()); | 333 static_cast<wm::FocusController*>(focus_client_.get()); |
332 if (focus_controller) { | 334 if (focus_controller) { |
333 host_->window()->RemovePreTargetHandler(focus_controller); | 335 host_->window()->RemovePreTargetHandler(focus_controller); |
334 aura::client::SetActivationClient(host_->window(), NULL); | 336 aura::client::SetActivationClient(host_->window(), NULL); |
335 } | 337 } |
336 root_window_event_filter_.reset(); | 338 root_window_event_filter_.reset(); |
337 capture_client_.reset(); | 339 capture_client_.reset(); |
338 input_method_filter_.reset(); | 340 input_method_filter_.reset(); |
339 focus_client_.reset(); | 341 focus_client_.reset(); |
340 cursor_manager_.reset(); | 342 cursor_manager_.reset(); |
341 #if defined(OS_CHROMEOS) | 343 #if defined(OS_CHROMEOS) |
342 user_activity_notifier_.reset(); | 344 user_activity_notifier_.reset(); |
343 #endif | 345 #endif |
344 user_activity_detector_.reset(); | 346 user_activity_detector_.reset(); |
345 host_.reset(); | 347 host_.reset(); |
346 } | 348 } |
347 | 349 |
348 gfx::Size ShellDesktopController::GetPrimaryDisplaySize() { | 350 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { |
349 #if defined(OS_CHROMEOS) | 351 #if defined(OS_CHROMEOS) |
350 const std::vector<ui::DisplayConfigurator::DisplayState>& displays = | 352 const std::vector<ui::DisplayConfigurator::DisplayState>& displays = |
351 display_configurator_->cached_displays(); | 353 display_configurator_->cached_displays(); |
352 if (displays.empty()) | 354 if (displays.empty()) |
353 return gfx::Size(); | 355 return gfx::Size(); |
354 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 356 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
355 return mode ? mode->size() : gfx::Size(); | 357 return mode ? mode->size() : gfx::Size(); |
356 #else | 358 #else |
357 return gfx::Size(); | 359 return gfx::Size(); |
358 #endif | 360 #endif |
359 } | 361 } |
360 | 362 |
361 } // namespace extensions | 363 } // namespace extensions |
OLD | NEW |