| 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" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const WmWindow* exclude, | 156 const WmWindow* exclude, |
| 157 bool* single_window) { | 157 bool* single_window) { |
| 158 if (single_window) | 158 if (single_window) |
| 159 *single_window = true; | 159 *single_window = true; |
| 160 // Get the active window. | 160 // Get the active window. |
| 161 WmWindow* active = root_window->GetShell()->GetActiveWindow(); | 161 WmWindow* active = root_window->GetShell()->GetActiveWindow(); |
| 162 if (active && active->GetRootWindow() != root_window) | 162 if (active && active->GetRootWindow() != root_window) |
| 163 active = NULL; | 163 active = NULL; |
| 164 | 164 |
| 165 // Get a list of all windows. | 165 // Get a list of all windows. |
| 166 const std::vector<WmWindow*> windows = root_window->GetShell() | 166 const std::vector<WmWindow*> windows = |
| 167 ->mru_window_tracker() | 167 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
| 168 ->BuildWindowListIgnoreModal(); | |
| 169 | 168 |
| 170 if (windows.empty()) | 169 if (windows.empty()) |
| 171 return nullptr; | 170 return nullptr; |
| 172 | 171 |
| 173 int index = 0; | 172 int index = 0; |
| 174 // Find the index of the current active window. | 173 // Find the index of the current active window. |
| 175 if (active) | 174 if (active) |
| 176 index = std::find(windows.begin(), windows.end(), active) - windows.begin(); | 175 index = std::find(windows.begin(), windows.end(), active) - windows.begin(); |
| 177 | 176 |
| 178 // Scan the cycle list backwards to see which is the second topmost window | 177 // Scan the cycle list backwards to see which is the second topmost window |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // Remember the current location of the window if it's new and push | 368 // Remember the current location of the window if it's new and push |
| 370 // it also to the opposite location if needed. Since it is just | 369 // it also to the opposite location if needed. Since it is just |
| 371 // being shown, we do not need to animate it. | 370 // being shown, we do not need to animate it. |
| 372 gfx::Rect added_bounds = added_window->GetBounds(); | 371 gfx::Rect added_bounds = added_window->GetBounds(); |
| 373 if (!added_window_state->pre_auto_manage_window_bounds()) | 372 if (!added_window_state->pre_auto_manage_window_bounds()) |
| 374 added_window_state->SetPreAutoManageWindowBounds(added_bounds); | 373 added_window_state->SetPreAutoManageWindowBounds(added_bounds); |
| 375 if (MoveRectToOneSide(work_area, !move_other_right, &added_bounds)) | 374 if (MoveRectToOneSide(work_area, !move_other_right, &added_bounds)) |
| 376 added_window->SetBounds(added_bounds); | 375 added_window->SetBounds(added_bounds); |
| 377 } | 376 } |
| 378 | 377 |
| 379 WindowPositioner::WindowPositioner(WmShell* shell) | 378 WindowPositioner::WindowPositioner() |
| 380 : shell_(shell), | 379 : pop_position_offset_increment_x(0), |
| 381 pop_position_offset_increment_x(0), | |
| 382 pop_position_offset_increment_y(0), | 380 pop_position_offset_increment_y(0), |
| 383 popup_position_offset_from_screen_corner_x(0), | 381 popup_position_offset_from_screen_corner_x(0), |
| 384 popup_position_offset_from_screen_corner_y(0), | 382 popup_position_offset_from_screen_corner_y(0), |
| 385 last_popup_position_x_(0), | 383 last_popup_position_x_(0), |
| 386 last_popup_position_y_(0) {} | 384 last_popup_position_y_(0) {} |
| 387 | 385 |
| 388 WindowPositioner::~WindowPositioner() {} | 386 WindowPositioner::~WindowPositioner() {} |
| 389 | 387 |
| 390 gfx::Rect WindowPositioner::GetDefaultWindowBounds( | 388 gfx::Rect WindowPositioner::GetDefaultWindowBounds( |
| 391 const display::Display& display) { | 389 const display::Display& display) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 413 if (!pop_position_offset_increment_x) { | 411 if (!pop_position_offset_increment_x) { |
| 414 // When the popup position increment is 0, the last popup position | 412 // When the popup position increment is 0, the last popup position |
| 415 // was not yet initialized. | 413 // was not yet initialized. |
| 416 last_popup_position_x_ = popup_position_offset_from_screen_corner_x; | 414 last_popup_position_x_ = popup_position_offset_from_screen_corner_x; |
| 417 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; | 415 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; |
| 418 } | 416 } |
| 419 pop_position_offset_increment_x = grid; | 417 pop_position_offset_increment_x = grid; |
| 420 pop_position_offset_increment_y = grid; | 418 pop_position_offset_increment_y = grid; |
| 421 // We handle the Multi monitor support by retrieving the active window's | 419 // We handle the Multi monitor support by retrieving the active window's |
| 422 // work area. | 420 // work area. |
| 423 WmWindow* window = shell_->GetActiveWindow(); | 421 WmWindow* window = WmShell::Get()->GetActiveWindow(); |
| 424 const gfx::Rect work_area = | 422 const gfx::Rect work_area = |
| 425 window && window->IsVisible() | 423 window && window->IsVisible() |
| 426 ? window->GetDisplayNearestWindow().work_area() | 424 ? window->GetDisplayNearestWindow().work_area() |
| 427 : display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 425 : display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 428 // Only try to reposition the popup when it is not spanning the entire | 426 // Only try to reposition the popup when it is not spanning the entire |
| 429 // screen. | 427 // screen. |
| 430 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= | 428 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= |
| 431 work_area.width()) || | 429 work_area.width()) || |
| 432 (old_pos.height() + popup_position_offset_from_screen_corner_y >= | 430 (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
| 433 work_area.height())) | 431 work_area.height())) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 last_popup_position_x_ += pop_position_offset_increment_x; | 470 last_popup_position_x_ += pop_position_offset_increment_x; |
| 473 last_popup_position_y_ += pop_position_offset_increment_y; | 471 last_popup_position_y_ += pop_position_offset_increment_y; |
| 474 } | 472 } |
| 475 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); | 473 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); |
| 476 } | 474 } |
| 477 | 475 |
| 478 gfx::Rect WindowPositioner::SmartPopupPosition(const gfx::Rect& old_pos, | 476 gfx::Rect WindowPositioner::SmartPopupPosition(const gfx::Rect& old_pos, |
| 479 const gfx::Rect& work_area, | 477 const gfx::Rect& work_area, |
| 480 int grid) { | 478 int grid) { |
| 481 const std::vector<WmWindow*> windows = | 479 const std::vector<WmWindow*> windows = |
| 482 shell_->mru_window_tracker()->BuildWindowListIgnoreModal(); | 480 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
| 483 | 481 |
| 484 std::vector<const gfx::Rect*> regions; | 482 std::vector<const gfx::Rect*> regions; |
| 485 // Process the window list and check if we can bail immediately. | 483 // Process the window list and check if we can bail immediately. |
| 486 for (size_t i = 0; i < windows.size(); i++) { | 484 for (size_t i = 0; i < windows.size(); i++) { |
| 487 // We only include opaque and visible windows. | 485 // We only include opaque and visible windows. |
| 488 if (windows[i] && windows[i]->IsVisible() && windows[i]->GetLayer() && | 486 if (windows[i] && windows[i]->IsVisible() && windows[i]->GetLayer() && |
| 489 (windows[i]->GetLayer()->fills_bounds_opaquely() || | 487 (windows[i]->GetLayer()->fills_bounds_opaquely() || |
| 490 windows[i]->GetLayer()->GetTargetOpacity() == 1.0)) { | 488 windows[i]->GetLayer()->GetTargetOpacity() == 1.0)) { |
| 491 wm::WindowState* window_state = windows[i]->GetWindowState(); | 489 wm::WindowState* window_state = windows[i]->GetWindowState(); |
| 492 // When any window is maximized we cannot find any free space. | 490 // When any window is maximized we cannot find any free space. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // If the alignment was pushing the window out of the screen, we ignore the | 554 // If the alignment was pushing the window out of the screen, we ignore the |
| 557 // alignment for that call. | 555 // alignment for that call. |
| 558 if (abs(pos.right() - work_area.right()) < grid) | 556 if (abs(pos.right() - work_area.right()) < grid) |
| 559 x = work_area.right() - w; | 557 x = work_area.right() - w; |
| 560 if (abs(pos.bottom() - work_area.bottom()) < grid) | 558 if (abs(pos.bottom() - work_area.bottom()) < grid) |
| 561 y = work_area.bottom() - h; | 559 y = work_area.bottom() - h; |
| 562 return gfx::Rect(x, y, w, h); | 560 return gfx::Rect(x, y, w, h); |
| 563 } | 561 } |
| 564 | 562 |
| 565 } // namespace ash | 563 } // namespace ash |
| OLD | NEW |