| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/wm/window_positioner.h" | 5 #include "ash/common/wm/window_positioner.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/mru_window_tracker.h" | 7 #include "ash/common/wm/mru_window_tracker.h" |
| 8 #include "ash/common/wm/window_positioning_utils.h" | 8 #include "ash/common/wm/window_positioning_utils.h" |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/common/wm/wm_screen_util.h" | 10 #include "ash/common/wm/wm_screen_util.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/wm/window_util.h" |
| 14 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
| 15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 16 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 17 #include "ui/gfx/geometry/insets.h" | 18 #include "ui/gfx/geometry/insets.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 | 21 |
| 21 const int WindowPositioner::kMinimumWindowOffset = 32; | 22 const int WindowPositioner::kMinimumWindowOffset = 32; |
| 22 | 23 |
| 23 // The number of pixels which are kept free top, left and right when a window | 24 // The number of pixels which are kept free top, left and right when a window |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 window->SetBounds(bounds); | 152 window->SetBounds(bounds); |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Get the first open (non minimized) window which is on the screen defined. | 155 // Get the first open (non minimized) window which is on the screen defined. |
| 155 WmWindow* GetReferenceWindow(const WmWindow* root_window, | 156 WmWindow* GetReferenceWindow(const WmWindow* root_window, |
| 156 const WmWindow* exclude, | 157 const WmWindow* exclude, |
| 157 bool* single_window) { | 158 bool* single_window) { |
| 158 if (single_window) | 159 if (single_window) |
| 159 *single_window = true; | 160 *single_window = true; |
| 160 // Get the active window. | 161 // Get the active window. |
| 161 WmWindow* active = root_window->GetShell()->GetActiveWindow(); | 162 WmWindow* active = WmWindow::Get(wm::GetActiveWindow()); |
| 162 if (active && active->GetRootWindow() != root_window) | 163 if (active && active->GetRootWindow() != root_window) |
| 163 active = NULL; | 164 active = NULL; |
| 164 | 165 |
| 165 // Get a list of all windows. | 166 // Get a list of all windows. |
| 166 const std::vector<WmWindow*> windows = | 167 const std::vector<WmWindow*> windows = |
| 167 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | 168 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
| 168 | 169 |
| 169 if (windows.empty()) | 170 if (windows.empty()) |
| 170 return nullptr; | 171 return nullptr; |
| 171 | 172 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (!pop_position_offset_increment_x) { | 412 if (!pop_position_offset_increment_x) { |
| 412 // When the popup position increment is 0, the last popup position | 413 // When the popup position increment is 0, the last popup position |
| 413 // was not yet initialized. | 414 // was not yet initialized. |
| 414 last_popup_position_x_ = popup_position_offset_from_screen_corner_x; | 415 last_popup_position_x_ = popup_position_offset_from_screen_corner_x; |
| 415 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; | 416 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; |
| 416 } | 417 } |
| 417 pop_position_offset_increment_x = grid; | 418 pop_position_offset_increment_x = grid; |
| 418 pop_position_offset_increment_y = grid; | 419 pop_position_offset_increment_y = grid; |
| 419 // We handle the Multi monitor support by retrieving the active window's | 420 // We handle the Multi monitor support by retrieving the active window's |
| 420 // work area. | 421 // work area. |
| 421 WmWindow* window = WmShell::Get()->GetActiveWindow(); | 422 WmWindow* window = WmWindow::Get(wm::GetActiveWindow()); |
| 422 const gfx::Rect work_area = | 423 const gfx::Rect work_area = |
| 423 window && window->IsVisible() | 424 window && window->IsVisible() |
| 424 ? window->GetDisplayNearestWindow().work_area() | 425 ? window->GetDisplayNearestWindow().work_area() |
| 425 : display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 426 : display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 426 // Only try to reposition the popup when it is not spanning the entire | 427 // Only try to reposition the popup when it is not spanning the entire |
| 427 // screen. | 428 // screen. |
| 428 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= | 429 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= |
| 429 work_area.width()) || | 430 work_area.width()) || |
| 430 (old_pos.height() + popup_position_offset_from_screen_corner_y >= | 431 (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
| 431 work_area.height())) | 432 work_area.height())) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 // If the alignment was pushing the window out of the screen, we ignore the | 555 // If the alignment was pushing the window out of the screen, we ignore the |
| 555 // alignment for that call. | 556 // alignment for that call. |
| 556 if (abs(pos.right() - work_area.right()) < grid) | 557 if (abs(pos.right() - work_area.right()) < grid) |
| 557 x = work_area.right() - w; | 558 x = work_area.right() - w; |
| 558 if (abs(pos.bottom() - work_area.bottom()) < grid) | 559 if (abs(pos.bottom() - work_area.bottom()) < grid) |
| 559 y = work_area.bottom() - h; | 560 y = work_area.bottom() - h; |
| 560 return gfx::Rect(x, y, w, h); | 561 return gfx::Rect(x, y, w, h); |
| 561 } | 562 } |
| 562 | 563 |
| 563 } // namespace ash | 564 } // namespace ash |
| OLD | NEW |