| 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/wm/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
| 6 | 6 |
| 7 #include "ash/wm/common/window_positioning_utils.h" | 7 #include "ash/wm/common/window_positioning_utils.h" |
| 8 #include "ash/wm/common/window_state.h" | 8 #include "ash/wm/common/window_state.h" |
| 9 #include "ash/wm/common/wm_globals.h" | 9 #include "ash/wm/common/wm_globals.h" |
| 10 #include "ash/wm/common/wm_screen_util.h" | 10 #include "ash/wm/common/wm_screen_util.h" |
| 11 #include "ash/wm/common/wm_window.h" | 11 #include "ash/wm/common/wm_window.h" |
| 12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/display/screen.h" |
| 13 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
| 14 #include "ui/gfx/screen.h" | |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 const int WindowPositioner::kMinimumWindowOffset = 32; | 18 const int WindowPositioner::kMinimumWindowOffset = 32; |
| 19 | 19 |
| 20 // The number of pixels which are kept free top, left and right when a window | 20 // The number of pixels which are kept free top, left and right when a window |
| 21 // gets positioned to its default location. | 21 // gets positioned to its default location. |
| 22 // static | 22 // static |
| 23 const int WindowPositioner::kDesktopBorderSize = 16; | 23 const int WindowPositioner::kDesktopBorderSize = 16; |
| 24 | 24 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 pop_position_offset_increment_y(0), | 379 pop_position_offset_increment_y(0), |
| 380 popup_position_offset_from_screen_corner_x(0), | 380 popup_position_offset_from_screen_corner_x(0), |
| 381 popup_position_offset_from_screen_corner_y(0), | 381 popup_position_offset_from_screen_corner_y(0), |
| 382 last_popup_position_x_(0), | 382 last_popup_position_x_(0), |
| 383 last_popup_position_y_(0) {} | 383 last_popup_position_y_(0) {} |
| 384 | 384 |
| 385 WindowPositioner::~WindowPositioner() { | 385 WindowPositioner::~WindowPositioner() { |
| 386 } | 386 } |
| 387 | 387 |
| 388 gfx::Rect WindowPositioner::GetDefaultWindowBounds( | 388 gfx::Rect WindowPositioner::GetDefaultWindowBounds( |
| 389 const gfx::Display& display) { | 389 const display::Display& display) { |
| 390 const gfx::Rect work_area = display.work_area(); | 390 const gfx::Rect work_area = display.work_area(); |
| 391 // There should be a 'desktop' border around the window at the left and right | 391 // There should be a 'desktop' border around the window at the left and right |
| 392 // side. | 392 // side. |
| 393 int default_width = work_area.width() - 2 * kDesktopBorderSize; | 393 int default_width = work_area.width() - 2 * kDesktopBorderSize; |
| 394 // There should also be a 'desktop' border around the window at the top. | 394 // There should also be a 'desktop' border around the window at the top. |
| 395 // Since the workspace excludes the tray area we only need one border size. | 395 // Since the workspace excludes the tray area we only need one border size. |
| 396 int default_height = work_area.height() - kDesktopBorderSize; | 396 int default_height = work_area.height() - kDesktopBorderSize; |
| 397 int offset_x = kDesktopBorderSize; | 397 int offset_x = kDesktopBorderSize; |
| 398 if (default_width > kMaximumWindowWidth) { | 398 if (default_width > kMaximumWindowWidth) { |
| 399 // The window should get centered on the screen and not follow the grid. | 399 // The window should get centered on the screen and not follow the grid. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 417 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; | 417 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; |
| 418 } | 418 } |
| 419 pop_position_offset_increment_x = grid; | 419 pop_position_offset_increment_x = grid; |
| 420 pop_position_offset_increment_y = grid; | 420 pop_position_offset_increment_y = grid; |
| 421 // We handle the Multi monitor support by retrieving the active window's | 421 // We handle the Multi monitor support by retrieving the active window's |
| 422 // work area. | 422 // work area. |
| 423 wm::WmWindow* window = globals_->GetActiveWindow(); | 423 wm::WmWindow* window = globals_->GetActiveWindow(); |
| 424 const gfx::Rect work_area = | 424 const gfx::Rect work_area = |
| 425 window && window->IsVisible() | 425 window && window->IsVisible() |
| 426 ? window->GetDisplayNearestWindow().work_area() | 426 ? window->GetDisplayNearestWindow().work_area() |
| 427 : gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 427 : display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 428 // Only try to reposition the popup when it is not spanning the entire | 428 // Only try to reposition the popup when it is not spanning the entire |
| 429 // screen. | 429 // screen. |
| 430 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= | 430 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= |
| 431 work_area.width()) || | 431 work_area.width()) || |
| 432 (old_pos.height() + popup_position_offset_from_screen_corner_y >= | 432 (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
| 433 work_area.height())) | 433 work_area.height())) |
| 434 return AlignPopupPosition(old_pos, work_area, grid); | 434 return AlignPopupPosition(old_pos, work_area, grid); |
| 435 const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); | 435 const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); |
| 436 if (!result.IsEmpty()) | 436 if (!result.IsEmpty()) |
| 437 return AlignPopupPosition(result, work_area, grid); | 437 return AlignPopupPosition(result, work_area, grid); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // If the alignment was pushing the window out of the screen, we ignore the | 559 // If the alignment was pushing the window out of the screen, we ignore the |
| 560 // alignment for that call. | 560 // alignment for that call. |
| 561 if (abs(pos.right() - work_area.right()) < grid) | 561 if (abs(pos.right() - work_area.right()) < grid) |
| 562 x = work_area.right() - w; | 562 x = work_area.right() - w; |
| 563 if (abs(pos.bottom() - work_area.bottom()) < grid) | 563 if (abs(pos.bottom() - work_area.bottom()) < grid) |
| 564 y = work_area.bottom() - h; | 564 y = work_area.bottom() - h; |
| 565 return gfx::Rect(x, y, w, h); | 565 return gfx::Rect(x, y, w, h); |
| 566 } | 566 } |
| 567 | 567 |
| 568 } // namespace ash | 568 } // namespace ash |
| OLD | NEW |