| 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/ash_switches.h" |
| 9 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
| 10 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_resizer.h" | 12 #include "ash/wm/window_resizer.h" |
| 12 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 namespace internal { | 19 namespace internal { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 int GetMaxWidth(aura::Window* window) { | 56 int GetMaxWidth(aura::Window* window) { |
| 56 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | 57 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| 57 return std::max(work_area.width() * kMaximumScreenPercent / 100, | 58 return std::max(work_area.width() * kMaximumScreenPercent / 100, |
| 58 GetMinWidth(window)); | 59 GetMinWidth(window)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Returns the width that |window| should be snapped to if resizing is disabled | 62 // Returns the width that |window| should be snapped to if resizing is disabled |
| 62 // in the SnapSizer. | 63 // in the SnapSizer. |
| 63 int GetDefaultWidth(aura::Window* window) { | 64 int GetDefaultWidth(aura::Window* window) { |
| 64 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | 65 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| 65 int width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2); | 66 |
| 67 int width = 0; |
| 68 if (ash::switches::UseAlternateFrameCaptionButtonStyle()) { |
| 69 // Only the 'half of screen' width is supported when using the alternate |
| 70 // visual style for the frame caption buttons (minimize, maximize, restore, |
| 71 // and close). |
| 72 width = work_area.width() / 2; |
| 73 } else { |
| 74 width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2); |
| 75 } |
| 66 | 76 |
| 67 width = std::min(width, GetMaxWidth(window)); | 77 width = std::min(width, GetMaxWidth(window)); |
| 68 return std::max(width, GetMinWidth(window)); | 78 return std::max(width, GetMinWidth(window)); |
| 69 } | 79 } |
| 70 | 80 |
| 71 // Create the list of possible widths for the current screen configuration: | 81 // Create the list of possible widths for the current screen configuration: |
| 72 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on | 82 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on |
| 73 // the screen and supplement it with the 'half of screen' size. Furthermore, | 83 // the screen and supplement it with the 'half of screen' size. Furthermore, |
| 74 // add an entry for 90% of the screen size if it is smaller than the biggest | 84 // add an entry for 90% of the screen size if it is smaller than the biggest |
| 75 // value in the |kIdealWidth| list (to get a step between the values). | 85 // value in the |kIdealWidth| list (to get a step between the values). |
| 76 std::vector<int> BuildIdealWidthList(aura::Window* window) { | 86 std::vector<int> BuildIdealWidthList(aura::Window* window) { |
| 87 if (ash::switches::UseAlternateFrameCaptionButtonStyle()) { |
| 88 // Only the 'half of screen' width is supported when using the alternate |
| 89 // visual style for the frame caption buttons (minimize, maximize, |
| 90 // restore, and close). |
| 91 return std::vector<int>(1u, GetDefaultWidth(window)); |
| 92 } |
| 93 |
| 77 int minimum_width = GetMinWidth(window); | 94 int minimum_width = GetMinWidth(window); |
| 78 int maximum_width = GetMaxWidth(window); | 95 int maximum_width = GetMaxWidth(window); |
| 79 | 96 |
| 80 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | 97 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
| 81 int half_width = work_area.width() / 2; | 98 int half_width = work_area.width() / 2; |
| 82 if (half_width < minimum_width || half_width > maximum_width) | 99 if (half_width < minimum_width || half_width > maximum_width) |
| 83 half_width = 0; | 100 half_width = 0; |
| 84 | 101 |
| 85 std::vector<int> ideal_width_list; | 102 std::vector<int> ideal_width_list; |
| 86 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { | 103 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 int current = 0; | 203 int current = 0; |
| 187 if (!resize_disabled_) { | 204 if (!resize_disabled_) { |
| 188 for (current = usable_width_.size() - 1; current >= 0; current--) { | 205 for (current = usable_width_.size() - 1; current >= 0; current--) { |
| 189 gfx::Rect target = GetTargetBoundsForSize(current); | 206 gfx::Rect target = GetTargetBoundsForSize(current); |
| 190 if (target == bounds) { | 207 if (target == bounds) { |
| 191 ++current; | 208 ++current; |
| 192 break; | 209 break; |
| 193 } | 210 } |
| 194 } | 211 } |
| 195 } | 212 } |
| 213 if (current < 0) |
| 214 current = 0; |
| 196 return GetTargetBoundsForSize(current % usable_width_.size()); | 215 return GetTargetBoundsForSize(current % usable_width_.size()); |
| 197 } | 216 } |
| 198 | 217 |
| 199 void SnapSizer::SelectDefaultSizeAndDisableResize() { | 218 void SnapSizer::SelectDefaultSizeAndDisableResize() { |
| 200 resize_disabled_ = true; | 219 resize_disabled_ = true; |
| 201 size_index_ = 0; | 220 size_index_ = 0; |
| 202 target_bounds_ = GetTargetBounds(); | 221 target_bounds_ = GetTargetBounds(); |
| 203 } | 222 } |
| 204 | 223 |
| 205 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { | 224 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return GetTargetBoundsForSize(size_index_); | 274 return GetTargetBoundsForSize(size_index_); |
| 256 } | 275 } |
| 257 | 276 |
| 258 bool SnapSizer::AlongEdge(int x) const { | 277 bool SnapSizer::AlongEdge(int x) const { |
| 259 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); | 278 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); |
| 260 return (x <= area.x()) || (x >= area.right() - 1); | 279 return (x <= area.x()) || (x >= area.right() - 1); |
| 261 } | 280 } |
| 262 | 281 |
| 263 } // namespace internal | 282 } // namespace internal |
| 264 } // namespace ash | 283 } // namespace ash |
| OLD | NEW |