Chromium Code Reviews| Index: ash/wm/workspace/snap_sizer.cc |
| diff --git a/ash/wm/workspace/snap_sizer.cc b/ash/wm/workspace/snap_sizer.cc |
| index 11b59470fcd87d5be27e934cc992feac57b7c90a..09039019e9e91b082955c944e743e6afd66a96f4 100644 |
| --- a/ash/wm/workspace/snap_sizer.cc |
| +++ b/ash/wm/workspace/snap_sizer.cc |
| @@ -11,6 +11,7 @@ |
| #include "ash/wm/window_resizer.h" |
| #include "ash/wm/window_util.h" |
| #include "ui/aura/window.h" |
| +#include "ui/aura/window_delegate.h" |
| #include "ui/gfx/screen.h" |
| namespace ash { |
| @@ -18,7 +19,7 @@ namespace internal { |
| namespace { |
| -// A list of ideal window width in pixel which will be used to populate the |
| +// A list of ideal window widths in DIP which will be used to populate the |
| // |usable_width_| list. |
| const int kIdealWidth[] = { 1280, 1024, 768, 640 }; |
| @@ -33,33 +34,66 @@ const int kDelayBeforeIncreaseMS = 500; |
| const int kMovesBeforeAdjust = 25; |
| const int kPixelsBeforeAdjust = 100; |
| -// When the smallest resolution does not fit on the screen, we take this |
| -// fraction of the available space. |
| -const int kMinimumScreenPercent = 90; |
| +// The maximum fraction of the screen width that a snapped window is allowed |
| +// to take up. |
| +const int kMaximumScreenPercent = 90; |
| -// Create the list of possible width for the current screen configuration: |
| +// Returns the minimum width that |window| can be snapped to. The returned width |
| +// may not be in the width list generated by BuildIdealWidthList(). |
| +int GetMinWidth(aura::Window* window) { |
| + return window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; |
| +} |
| + |
| +// Returns the maximum width that |window| can be snapped to. The returned width |
| +// may not be in the width list generated by BuildIdealWidthList(). |
| +int GetMaxWidth(aura::Window* window) { |
| + gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| + return std::max(work_area.width() * kMaximumScreenPercent / 100, |
| + GetMinWidth(window)); |
| + // The aura::WindowDelegate's max size is ignored because |
| + // ash::wm::CanSnapWindow() returns false when a max size is specified. |
|
Mr4D (OOO till 08-26)
2013/09/08 17:31:30
This comment is oddly placed. Can you move it into
|
| +} |
| + |
| +// Returns the width that |window| should be snapped to if resizing is disabled |
| +// in the SnapSizer. |
| +int GetDefaultWidth(aura::Window* window) { |
| + gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| + int width = std::max(1024, work_area.width() / 2); |
|
Mr4D (OOO till 08-26)
2013/09/08 17:31:30
The 1024 should probably be a constant.
|
| + |
| + width = std::min(width, GetMaxWidth(window)); |
| + return std::max(width, GetMinWidth(window)); |
| +} |
| + |
| +// Create the list of possible widths for the current screen configuration: |
| // Fill the |usable_width_| list with items from |kIdealWidth| which fit on |
| // the screen and supplement it with the 'half of screen' size. Furthermore, |
| -// add an entry for 90% of the screen size if it is smaller then the biggest |
| +// add an entry for 90% of the screen size if it is smaller than the biggest |
| // value in the |kIdealWidth| list (to get a step between the values). |
| std::vector<int> BuildIdealWidthList(aura::Window* window) { |
| - std::vector<int> ideal_width_list; |
| + int minimum_width = GetMinWidth(window); |
| + int maximum_width = GetMaxWidth(window); |
| + |
| gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| - int half_size = work_area.width() / 2; |
| - int maximum_width = (kMinimumScreenPercent * work_area.width()) / 100; |
| + int half_width = work_area.width() / 2; |
| + if (half_width < minimum_width || half_width > maximum_width) |
| + half_width = 0; |
| + |
| + std::vector<int> ideal_width_list; |
| for (size_t i = 0; i < arraysize(kIdealWidth); i++) { |
| - if (maximum_width >= kIdealWidth[i]) { |
| + if (kIdealWidth[i] >= minimum_width && kIdealWidth[i] <= maximum_width) { |
| if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i]) |
| ideal_width_list.push_back(maximum_width); |
| - if (half_size > kIdealWidth[i]) |
| - ideal_width_list.push_back(half_size); |
| - if (half_size >= kIdealWidth[i]) |
| - half_size = 0; |
| + if (half_width > kIdealWidth[i]) |
| + ideal_width_list.push_back(half_width); |
| + if (half_width >= kIdealWidth[i]) |
| + half_width = 0; |
| ideal_width_list.push_back(kIdealWidth[i]); |
| } |
| } |
| - if (half_size) |
| - ideal_width_list.push_back(half_size); |
| + if (half_width) |
| + ideal_width_list.push_back(half_width); |
| + if (ideal_width_list.empty()) |
| + ideal_width_list.push_back(minimum_width); |
|
Mr4D (OOO till 08-26)
2013/09/08 17:31:30
minimum_width might be 0.
pkotwicz
2013/09/09 02:22:45
I now check if |minimum_width| == 0. Of note, it i
|
| return ideal_width_list; |
| } |
| @@ -163,15 +197,10 @@ void SnapSizer::SelectDefaultSizeAndDisableResize() { |
| gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { |
| gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); |
| int y = work_area.y(); |
| - // We don't align to the bottom of the grid as the launcher may not |
| - // necessarily align to the grid (happens when auto-hidden). |
| int max_y = work_area.bottom(); |
| int width = 0; |
| if (resize_disabled_) { |
| - // Make sure that we keep the size of the window smaller then a certain |
| - // fraction of the screen space. |
| - int minimum_size = (kMinimumScreenPercent * work_area.width()) / 100; |
| - width = std::max(std::min(minimum_size, 1024), work_area.width() / 2); |
| + width = GetDefaultWidth(window_); |
| } else { |
| DCHECK(size_index < usable_width_.size()); |
| width = usable_width_[size_index]; |