Chromium Code Reviews| 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/wm/workspace/snap_sizer.h" | 5 #include "ash/wm/workspace/snap_sizer.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_resizer.h" | 11 #include "ash/wm/window_resizer.h" |
| 12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | |
| 14 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
| 15 | 16 |
| 16 namespace ash { | 17 namespace ash { |
| 17 namespace internal { | 18 namespace internal { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // A list of ideal window width in pixel which will be used to populate the | 22 // A list of ideal window widths in DIP which will be used to populate the |
| 22 // |usable_width_| list. | 23 // |usable_width_| list. |
| 23 const int kIdealWidth[] = { 1280, 1024, 768, 640 }; | 24 const int kIdealWidth[] = { 1280, 1024, 768, 640 }; |
| 24 | 25 |
| 25 // Windows are initially snapped to the size in |usable_width_| at index 0. | 26 // Windows are initially snapped to the size in |usable_width_| at index 0. |
| 26 // The index into |usable_width_| is changed if any of the following happen: | 27 // The index into |usable_width_| is changed if any of the following happen: |
| 27 // . The user stops moving the mouse for |kDelayBeforeIncreaseMS| and then | 28 // . The user stops moving the mouse for |kDelayBeforeIncreaseMS| and then |
| 28 // moves the mouse again. | 29 // moves the mouse again. |
| 29 // . The mouse moves |kPixelsBeforeAdjust| horizontal pixels. | 30 // . The mouse moves |kPixelsBeforeAdjust| horizontal pixels. |
| 30 // . The mouse is against the edge of the screen and the mouse is moved | 31 // . The mouse is against the edge of the screen and the mouse is moved |
| 31 // |kMovesBeforeAdjust| times. | 32 // |kMovesBeforeAdjust| times. |
| 32 const int kDelayBeforeIncreaseMS = 500; | 33 const int kDelayBeforeIncreaseMS = 500; |
| 33 const int kMovesBeforeAdjust = 25; | 34 const int kMovesBeforeAdjust = 25; |
| 34 const int kPixelsBeforeAdjust = 100; | 35 const int kPixelsBeforeAdjust = 100; |
| 35 | 36 |
| 36 // When the smallest resolution does not fit on the screen, we take this | 37 // The maximum fraction of the screen width that a snapped window is allowed |
| 37 // fraction of the available space. | 38 // to take up. |
| 38 const int kMinimumScreenPercent = 90; | 39 const int kMaximumScreenPercent = 90; |
| 39 | 40 |
| 40 // Create the list of possible width for the current screen configuration: | 41 // Returns the minimum width that |window| can be snapped to. The returned width |
| 42 // may not be in the width list generated by BuildIdealWidthList(). | |
| 43 int GetMinWidth(aura::Window* window) { | |
| 44 return window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; | |
| 45 } | |
| 46 | |
| 47 // Returns the maximum width that |window| can be snapped to. The returned width | |
| 48 // may not be in the width list generated by BuildIdealWidthList(). | |
| 49 int GetMaxWidth(aura::Window* window) { | |
| 50 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | |
| 51 return std::max(work_area.width() * kMaximumScreenPercent / 100, | |
| 52 GetMinWidth(window)); | |
| 53 // The aura::WindowDelegate's max size is ignored because | |
| 54 // 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
| |
| 55 } | |
| 56 | |
| 57 // Returns the width that |window| should be snapped to if resizing is disabled | |
| 58 // in the SnapSizer. | |
| 59 int GetDefaultWidth(aura::Window* window) { | |
| 60 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | |
| 61 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.
| |
| 62 | |
| 63 width = std::min(width, GetMaxWidth(window)); | |
| 64 return std::max(width, GetMinWidth(window)); | |
| 65 } | |
| 66 | |
| 67 // Create the list of possible widths for the current screen configuration: | |
| 41 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on | 68 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on |
| 42 // the screen and supplement it with the 'half of screen' size. Furthermore, | 69 // the screen and supplement it with the 'half of screen' size. Furthermore, |
| 43 // add an entry for 90% of the screen size if it is smaller then the biggest | 70 // add an entry for 90% of the screen size if it is smaller than the biggest |
| 44 // value in the |kIdealWidth| list (to get a step between the values). | 71 // value in the |kIdealWidth| list (to get a step between the values). |
| 45 std::vector<int> BuildIdealWidthList(aura::Window* window) { | 72 std::vector<int> BuildIdealWidthList(aura::Window* window) { |
| 73 int minimum_width = GetMinWidth(window); | |
| 74 int maximum_width = GetMaxWidth(window); | |
| 75 | |
| 76 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | |
| 77 int half_width = work_area.width() / 2; | |
| 78 if (half_width < minimum_width || half_width > maximum_width) | |
| 79 half_width = 0; | |
| 80 | |
| 46 std::vector<int> ideal_width_list; | 81 std::vector<int> ideal_width_list; |
| 47 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | |
| 48 int half_size = work_area.width() / 2; | |
| 49 int maximum_width = (kMinimumScreenPercent * work_area.width()) / 100; | |
| 50 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { | 82 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { |
| 51 if (maximum_width >= kIdealWidth[i]) { | 83 if (kIdealWidth[i] >= minimum_width && kIdealWidth[i] <= maximum_width) { |
| 52 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i]) | 84 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i]) |
| 53 ideal_width_list.push_back(maximum_width); | 85 ideal_width_list.push_back(maximum_width); |
| 54 if (half_size > kIdealWidth[i]) | 86 if (half_width > kIdealWidth[i]) |
| 55 ideal_width_list.push_back(half_size); | 87 ideal_width_list.push_back(half_width); |
| 56 if (half_size >= kIdealWidth[i]) | 88 if (half_width >= kIdealWidth[i]) |
| 57 half_size = 0; | 89 half_width = 0; |
| 58 ideal_width_list.push_back(kIdealWidth[i]); | 90 ideal_width_list.push_back(kIdealWidth[i]); |
| 59 } | 91 } |
| 60 } | 92 } |
| 61 if (half_size) | 93 if (half_width) |
| 62 ideal_width_list.push_back(half_size); | 94 ideal_width_list.push_back(half_width); |
| 95 if (ideal_width_list.empty()) | |
| 96 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
| |
| 63 | 97 |
| 64 return ideal_width_list; | 98 return ideal_width_list; |
| 65 } | 99 } |
| 66 | 100 |
| 67 } // namespace | 101 } // namespace |
| 68 | 102 |
| 69 SnapSizer::SnapSizer(aura::Window* window, | 103 SnapSizer::SnapSizer(aura::Window* window, |
| 70 const gfx::Point& start, | 104 const gfx::Point& start, |
| 71 Edge edge, | 105 Edge edge, |
| 72 InputType input_type) | 106 InputType input_type) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 190 |
| 157 void SnapSizer::SelectDefaultSizeAndDisableResize() { | 191 void SnapSizer::SelectDefaultSizeAndDisableResize() { |
| 158 resize_disabled_ = true; | 192 resize_disabled_ = true; |
| 159 size_index_ = 0; | 193 size_index_ = 0; |
| 160 target_bounds_ = GetTargetBounds(); | 194 target_bounds_ = GetTargetBounds(); |
| 161 } | 195 } |
| 162 | 196 |
| 163 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { | 197 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { |
| 164 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); | 198 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); |
| 165 int y = work_area.y(); | 199 int y = work_area.y(); |
| 166 // We don't align to the bottom of the grid as the launcher may not | |
| 167 // necessarily align to the grid (happens when auto-hidden). | |
| 168 int max_y = work_area.bottom(); | 200 int max_y = work_area.bottom(); |
| 169 int width = 0; | 201 int width = 0; |
| 170 if (resize_disabled_) { | 202 if (resize_disabled_) { |
| 171 // Make sure that we keep the size of the window smaller then a certain | 203 width = GetDefaultWidth(window_); |
| 172 // fraction of the screen space. | |
| 173 int minimum_size = (kMinimumScreenPercent * work_area.width()) / 100; | |
| 174 width = std::max(std::min(minimum_size, 1024), work_area.width() / 2); | |
| 175 } else { | 204 } else { |
| 176 DCHECK(size_index < usable_width_.size()); | 205 DCHECK(size_index < usable_width_.size()); |
| 177 width = usable_width_[size_index]; | 206 width = usable_width_[size_index]; |
| 178 } | 207 } |
| 179 | 208 |
| 180 if (edge_ == LEFT_EDGE) { | 209 if (edge_ == LEFT_EDGE) { |
| 181 int x = work_area.x(); | 210 int x = work_area.x(); |
| 182 int mid_x = x + width; | 211 int mid_x = x + width; |
| 183 return gfx::Rect(x, y, mid_x - x, max_y - y); | 212 return gfx::Rect(x, y, mid_x - x, max_y - y); |
| 184 } | 213 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return GetTargetBoundsForSize(size_index_); | 247 return GetTargetBoundsForSize(size_index_); |
| 219 } | 248 } |
| 220 | 249 |
| 221 bool SnapSizer::AlongEdge(int x) const { | 250 bool SnapSizer::AlongEdge(int x) const { |
| 222 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); | 251 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); |
| 223 return (x <= area.x()) || (x >= area.right() - 1); | 252 return (x <= area.x()) || (x >= area.right() - 1); |
| 224 } | 253 } |
| 225 | 254 |
| 226 } // namespace internal | 255 } // namespace internal |
| 227 } // namespace ash | 256 } // namespace ash |
| OLD | NEW |