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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 #include "ui/gfx/compositor/layer_animator.h" | 50 #include "ui/gfx/compositor/layer_animator.h" |
51 #include "ui/gfx/screen.h" | 51 #include "ui/gfx/screen.h" |
52 #include "ui/gfx/size.h" | 52 #include "ui/gfx/size.h" |
53 #include "ui/views/widget/native_widget_aura.h" | 53 #include "ui/views/widget/native_widget_aura.h" |
54 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
55 | 55 |
56 namespace ash { | 56 namespace ash { |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 using aura::Window; | |
60 using views::Widget; | 61 using views::Widget; |
61 | 62 |
62 // Screen width at or below which we automatically start in compact window mode, | 63 // Screen width at or below which we automatically start in compact window mode, |
63 // in pixels. Should be at least 1366 pixels, the resolution of ChromeOS ZGB | 64 // in pixels. Should be at least 1366 pixels, the resolution of ChromeOS ZGB |
64 // device displays, as we traditionally used a single window on those devices. | 65 // device displays, as we traditionally used a single window on those devices. |
65 const int kCompactWindowModeWidthThreshold = 1366; | 66 const int kCompactWindowModeWidthThreshold = 1366; |
66 | 67 |
67 // Creates each of the special window containers that holds windows of various | 68 // Creates each of the special window containers that holds windows of various |
68 // types in the shell UI. They are added to |containers| from back to front in | 69 // types in the shell UI. They are added to |containers| from back to front in |
69 // the z-index. | 70 // the z-index. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 180 |
180 Shell::Shell(ShellDelegate* delegate) | 181 Shell::Shell(ShellDelegate* delegate) |
181 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 182 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
182 accelerator_controller_(new AcceleratorController), | 183 accelerator_controller_(new AcceleratorController), |
183 delegate_(delegate), | 184 delegate_(delegate), |
184 window_mode_(MODE_OVERLAPPING), | 185 window_mode_(MODE_OVERLAPPING), |
185 root_window_layout_(NULL), | 186 root_window_layout_(NULL), |
186 status_widget_(NULL) { | 187 status_widget_(NULL) { |
187 aura::RootWindow::GetInstance()->SetEventFilter( | 188 aura::RootWindow::GetInstance()->SetEventFilter( |
188 new internal::RootWindowEventFilter); | 189 new internal::RootWindowEventFilter); |
190 aura::RootWindow::GetInstance()->AddRootWindowObserver(this); | |
189 } | 191 } |
190 | 192 |
191 Shell::~Shell() { | 193 Shell::~Shell() { |
194 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); | |
192 RemoveRootWindowEventFilter(input_method_filter_.get()); | 195 RemoveRootWindowEventFilter(input_method_filter_.get()); |
193 RemoveRootWindowEventFilter(window_modality_controller_.get()); | 196 RemoveRootWindowEventFilter(window_modality_controller_.get()); |
194 RemoveRootWindowEventFilter(accelerator_filter_.get()); | 197 RemoveRootWindowEventFilter(accelerator_filter_.get()); |
195 | 198 |
196 // TooltipController needs a valid shell instance. We delete it before | 199 // TooltipController needs a valid shell instance. We delete it before |
197 // deleting the shell |instance_|. | 200 // deleting the shell |instance_|. |
198 RemoveRootWindowEventFilter(tooltip_controller_.get()); | 201 RemoveRootWindowEventFilter(tooltip_controller_.get()); |
199 aura::client::SetTooltipClient(NULL); | 202 aura::client::SetTooltipClient(NULL); |
200 | 203 |
201 // The LayoutManagers for the default and status containers talk to | 204 // The LayoutManagers for the default and status containers talk to |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 DCHECK(instance_); | 248 DCHECK(instance_); |
246 return instance_; | 249 return instance_; |
247 } | 250 } |
248 | 251 |
249 // static | 252 // static |
250 void Shell::DeleteInstance() { | 253 void Shell::DeleteInstance() { |
251 delete instance_; | 254 delete instance_; |
252 instance_ = NULL; | 255 instance_ = NULL; |
253 } | 256 } |
254 | 257 |
258 void Shell::OnRootWindowResized(const gfx::Size& new_size) { | |
259 // Developers often run the Aura shell in small windows on their desktop. | |
260 // Don't switch window modes for them. | |
261 if (!aura::RootWindow::use_fullscreen_host_window()) | |
262 return; | |
263 | |
264 // If we're running on a device, a resize event means the user plugged in or | |
265 // unplugged an external monitor. Change window mode to be appropriate for | |
266 // the new screen resolution. | |
267 gfx::Size monitor_size = gfx::Screen::GetPrimaryMonitorSize(); | |
268 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
269 WindowMode new_mode = ComputeWindowMode(monitor_size, command_line); | |
270 ChangeWindowMode(new_mode); | |
271 } | |
272 | |
255 void Shell::Init() { | 273 void Shell::Init() { |
256 // InputMethodEventFilter must be added first since it has the highest | 274 // InputMethodEventFilter must be added first since it has the highest |
257 // priority. | 275 // priority. |
258 DCHECK(!GetRootWindowEventFilterCount()); | 276 DCHECK(!GetRootWindowEventFilterCount()); |
259 input_method_filter_.reset(new internal::InputMethodEventFilter); | 277 input_method_filter_.reset(new internal::InputMethodEventFilter); |
260 AddRootWindowEventFilter(input_method_filter_.get()); | 278 AddRootWindowEventFilter(input_method_filter_.get()); |
261 | 279 |
262 // On small screens we automatically enable --aura-window-mode=compact if the | 280 // On small screens we automatically enable --aura-window-mode=compact if the |
263 // user has not explicitly set a window mode flag. This must happen before | 281 // user has not explicitly set a window mode flag. This must happen before |
264 // we create containers or layout managers. | 282 // we create containers or layout managers. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 | 412 |
395 void Shell::ChangeWindowMode(WindowMode mode) { | 413 void Shell::ChangeWindowMode(WindowMode mode) { |
396 if (mode == window_mode_) | 414 if (mode == window_mode_) |
397 return; | 415 return; |
398 // Window mode must be set before we resize/layout the windows. | 416 // Window mode must be set before we resize/layout the windows. |
399 window_mode_ = mode; | 417 window_mode_ = mode; |
400 if (window_mode_ == MODE_COMPACT) | 418 if (window_mode_ == MODE_COMPACT) |
401 SetupCompactWindowMode(); | 419 SetupCompactWindowMode(); |
402 else | 420 else |
403 SetupNonCompactWindowMode(); | 421 SetupNonCompactWindowMode(); |
404 // Force a layout. | 422 // Force a layout of all containers. |
405 aura::RootWindow::GetInstance()->layout_manager()->OnWindowResized(); | 423 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
424 root_window->layout_manager()->OnWindowResized(); | |
425 for (Window::Windows::const_iterator it = root_window->children().begin(); | |
sky
2012/02/03 21:47:42
Don't the children handle this themselves?
James Cook
2012/02/03 22:02:44
They do, but too early for it to be useful for me.
| |
426 it != root_window->children().end(); | |
427 ++it) { | |
428 if ((*it)->layout_manager()) | |
429 (*it)->layout_manager()->OnWindowResized(); | |
430 } | |
406 } | 431 } |
407 | 432 |
408 bool Shell::IsScreenLocked() const { | 433 bool Shell::IsScreenLocked() const { |
409 const aura::Window* lock_screen_container = GetContainer( | 434 const aura::Window* lock_screen_container = GetContainer( |
410 internal::kShellWindowId_LockScreenContainer); | 435 internal::kShellWindowId_LockScreenContainer); |
411 return lock_screen_container->StopsEventPropagation(); | 436 return lock_screen_container->StopsEventPropagation(); |
412 } | 437 } |
413 | 438 |
414 bool Shell::IsModalWindowOpen() const { | 439 bool Shell::IsModalWindowOpen() const { |
415 aura::Window* modal_container = | 440 aura::Window* modal_container = |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 | 538 |
514 // Create the desktop background image. | 539 // Create the desktop background image. |
515 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground()); | 540 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground()); |
516 } | 541 } |
517 | 542 |
518 void Shell::ResetLayoutManager(int container_id) { | 543 void Shell::ResetLayoutManager(int container_id) { |
519 GetContainer(container_id)->SetLayoutManager(NULL); | 544 GetContainer(container_id)->SetLayoutManager(NULL); |
520 } | 545 } |
521 | 546 |
522 } // namespace ash | 547 } // namespace ash |
OLD | NEW |