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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/accelerators/accelerator_controller.h" | 9 #include "ash/accelerators/accelerator_controller.h" |
10 #include "ash/accelerators/accelerator_filter.h" | 10 #include "ash/accelerators/accelerator_filter.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "ui/gfx/compositor/layer_animator.h" | 51 #include "ui/gfx/compositor/layer_animator.h" |
52 #include "ui/gfx/screen.h" | 52 #include "ui/gfx/screen.h" |
53 #include "ui/gfx/size.h" | 53 #include "ui/gfx/size.h" |
54 #include "ui/views/widget/native_widget_aura.h" | 54 #include "ui/views/widget/native_widget_aura.h" |
55 #include "ui/views/widget/widget.h" | 55 #include "ui/views/widget/widget.h" |
56 | 56 |
57 namespace ash { | 57 namespace ash { |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
| 61 using aura::Window; |
61 using views::Widget; | 62 using views::Widget; |
62 | 63 |
63 // Screen width at or below which we automatically start in compact window mode, | 64 // Screen width at or below which we automatically start in compact window mode, |
64 // in pixels. Should be at least 1366 pixels, the resolution of ChromeOS ZGB | 65 // in pixels. Should be at least 1366 pixels, the resolution of ChromeOS ZGB |
65 // device displays, as we traditionally used a single window on those devices. | 66 // device displays, as we traditionally used a single window on those devices. |
66 const int kCompactWindowModeWidthThreshold = 1366; | 67 const int kCompactWindowModeWidthThreshold = 1366; |
67 | 68 |
| 69 // Returns suggested window mode for a given monitor size. |
| 70 Shell::WindowMode SuggestedWindowMode(const gfx::Size& monitor_size) { |
| 71 // Developers often run the Aura shell in small windows on their desktop. |
| 72 // Prefer overlapping mode for them. |
| 73 if (!aura::RootWindow::use_fullscreen_host_window()) |
| 74 return Shell::MODE_OVERLAPPING; |
| 75 |
| 76 // If the screen is narrow we prefer a single compact window display. |
| 77 // We explicitly don't care about height, since users don't generally stack |
| 78 // browser windows vertically. |
| 79 if (monitor_size.width() <= kCompactWindowModeWidthThreshold) |
| 80 return Shell::MODE_COMPACT; |
| 81 |
| 82 return Shell::MODE_OVERLAPPING; |
| 83 } |
| 84 |
68 // Creates each of the special window containers that holds windows of various | 85 // Creates each of the special window containers that holds windows of various |
69 // types in the shell UI. They are added to |containers| from back to front in | 86 // types in the shell UI. They are added to |containers| from back to front in |
70 // the z-index. | 87 // the z-index. |
71 void CreateSpecialContainers(aura::Window::Windows* containers) { | 88 void CreateSpecialContainers(aura::Window::Windows* containers) { |
72 aura::Window* unparented_control_container = new aura::Window(NULL); | 89 aura::Window* unparented_control_container = new aura::Window(NULL); |
73 unparented_control_container->set_id( | 90 unparented_control_container->set_id( |
74 internal::kShellWindowId_UnparentedControlContainer); | 91 internal::kShellWindowId_UnparentedControlContainer); |
75 containers->push_back(unparented_control_container); | 92 containers->push_back(unparented_control_container); |
76 | 93 |
77 aura::Window* background_container = new aura::Window(NULL); | 94 aura::Window* background_container = new aura::Window(NULL); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 std::string mode = | 360 std::string mode = |
344 command_line->GetSwitchValueASCII(switches::kAuraWindowMode); | 361 command_line->GetSwitchValueASCII(switches::kAuraWindowMode); |
345 if (mode == switches::kAuraWindowModeCompact) | 362 if (mode == switches::kAuraWindowModeCompact) |
346 return MODE_COMPACT; | 363 return MODE_COMPACT; |
347 if (mode == switches::kAuraWindowModeManaged) | 364 if (mode == switches::kAuraWindowModeManaged) |
348 return MODE_MANAGED; | 365 return MODE_MANAGED; |
349 if (mode == switches::kAuraWindowModeOverlapping) | 366 if (mode == switches::kAuraWindowModeOverlapping) |
350 return MODE_OVERLAPPING; | 367 return MODE_OVERLAPPING; |
351 } | 368 } |
352 | 369 |
353 // Developers often run the Aura shell in small windows on their desktop. | 370 // Without an explicit command line flag, guess based on the monitor size. |
354 // Prefer overlapping mode for them. | 371 return SuggestedWindowMode(monitor_size); |
355 if (!aura::RootWindow::use_fullscreen_host_window()) | |
356 return MODE_OVERLAPPING; | |
357 | |
358 // If the screen is narrow we prefer a single compact window display. | |
359 // We explicitly don't care about height, since users don't generally stack | |
360 // browser windows vertically. | |
361 if (monitor_size.width() <= kCompactWindowModeWidthThreshold) | |
362 return MODE_COMPACT; | |
363 | |
364 return MODE_OVERLAPPING; | |
365 } | 372 } |
366 | 373 |
367 aura::Window* Shell::GetContainer(int container_id) { | 374 aura::Window* Shell::GetContainer(int container_id) { |
368 return const_cast<aura::Window*>( | 375 return const_cast<aura::Window*>( |
369 const_cast<const Shell*>(this)->GetContainer(container_id)); | 376 const_cast<const Shell*>(this)->GetContainer(container_id)); |
370 } | 377 } |
371 | 378 |
372 const aura::Window* Shell::GetContainer(int container_id) const { | 379 const aura::Window* Shell::GetContainer(int container_id) const { |
373 return aura::RootWindow::GetInstance()->GetChildById(container_id); | 380 return aura::RootWindow::GetInstance()->GetChildById(container_id); |
374 } | 381 } |
(...skipping 27 matching lines...) Expand all Loading... |
402 | 409 |
403 void Shell::ChangeWindowMode(WindowMode mode) { | 410 void Shell::ChangeWindowMode(WindowMode mode) { |
404 if (mode == window_mode_) | 411 if (mode == window_mode_) |
405 return; | 412 return; |
406 // Window mode must be set before we resize/layout the windows. | 413 // Window mode must be set before we resize/layout the windows. |
407 window_mode_ = mode; | 414 window_mode_ = mode; |
408 if (window_mode_ == MODE_COMPACT) | 415 if (window_mode_ == MODE_COMPACT) |
409 SetupCompactWindowMode(); | 416 SetupCompactWindowMode(); |
410 else | 417 else |
411 SetupNonCompactWindowMode(); | 418 SetupNonCompactWindowMode(); |
412 // Force a layout. | 419 } |
413 aura::RootWindow::GetInstance()->layout_manager()->OnWindowResized(); | 420 |
| 421 void Shell::SetWindowModeForMonitorSize(const gfx::Size& monitor_size) { |
| 422 // Don't allow changes if we're locked in compact mode. |
| 423 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 424 if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode)) |
| 425 return; |
| 426 |
| 427 // If we're running on a device, a resolution change means the user plugged in |
| 428 // or unplugged an external monitor. Change window mode to be appropriate for |
| 429 // the new screen resolution. |
| 430 WindowMode new_mode = SuggestedWindowMode(monitor_size); |
| 431 ChangeWindowMode(new_mode); |
414 } | 432 } |
415 | 433 |
416 bool Shell::IsScreenLocked() const { | 434 bool Shell::IsScreenLocked() const { |
417 const aura::Window* lock_screen_container = GetContainer( | 435 const aura::Window* lock_screen_container = GetContainer( |
418 internal::kShellWindowId_LockScreenContainer); | 436 internal::kShellWindowId_LockScreenContainer); |
419 return lock_screen_container->StopsEventPropagation(); | 437 return lock_screen_container->StopsEventPropagation(); |
420 } | 438 } |
421 | 439 |
422 bool Shell::IsModalWindowOpen() const { | 440 bool Shell::IsModalWindowOpen() const { |
423 aura::Window* modal_container = | 441 aura::Window* modal_container = |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 539 |
522 // Create the desktop background image. | 540 // Create the desktop background image. |
523 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground()); | 541 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground()); |
524 } | 542 } |
525 | 543 |
526 void Shell::ResetLayoutManager(int container_id) { | 544 void Shell::ResetLayoutManager(int container_id) { |
527 GetContainer(container_id)->SetLayoutManager(NULL); | 545 GetContainer(container_id)->SetLayoutManager(NULL); |
528 } | 546 } |
529 | 547 |
530 } // namespace ash | 548 } // namespace ash |
OLD | NEW |