Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ash/wm/workspace/snap_sizer.cc

Issue 138003007: [Cleanup] Screen cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make sure screen_for_shutdown is reset everytime Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ash_switches.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_util.h"
11 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
12 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_delegate.h" 16 #include "ui/aura/window_delegate.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace internal { 20 namespace internal {
(...skipping 27 matching lines...) Expand all
48 // may not be in the width list generated by BuildIdealWidthList(). 48 // may not be in the width list generated by BuildIdealWidthList().
49 int GetMinWidth(aura::Window* window) { 49 int GetMinWidth(aura::Window* window) {
50 return window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; 50 return window->delegate() ? window->delegate()->GetMinimumSize().width() : 0;
51 } 51 }
52 52
53 // Returns the maximum width that |window| can be snapped to. The returned width 53 // Returns the maximum width that |window| can be snapped to. The returned width
54 // may not be in the width list generated by BuildIdealWidthList(). 54 // may not be in the width list generated by BuildIdealWidthList().
55 // The aura::WindowDelegate's max size is ignored because 55 // The aura::WindowDelegate's max size is ignored because
56 // ash::wm::CanSnapWindow() returns false when a max size is specified. 56 // ash::wm::CanSnapWindow() returns false when a max size is specified.
57 int GetMaxWidth(aura::Window* window) { 57 int GetMaxWidth(aura::Window* window) {
58 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); 58 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(window));
59 return std::max(work_area.width() * kMaximumScreenPercent / 100, 59 return std::max(work_area.width() * kMaximumScreenPercent / 100,
60 GetMinWidth(window)); 60 GetMinWidth(window));
61 } 61 }
62 62
63 // Returns the width that |window| should be snapped to if resizing is disabled 63 // Returns the width that |window| should be snapped to if resizing is disabled
64 // in the SnapSizer. 64 // in the SnapSizer.
65 int GetDefaultWidth(aura::Window* window) { 65 int GetDefaultWidth(aura::Window* window) {
66 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); 66 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(window));
67 67
68 int width = 0; 68 int width = 0;
69 if (!CommandLine::ForCurrentProcess()->HasSwitch( 69 if (!CommandLine::ForCurrentProcess()->HasSwitch(
70 switches::kAshMultipleSnapWindowWidths)) { 70 switches::kAshMultipleSnapWindowWidths)) {
71 width = work_area.width() / 2; 71 width = work_area.width() / 2;
72 } else { 72 } else {
73 width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2); 73 width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2);
74 } 74 }
75 75
76 width = std::min(width, GetMaxWidth(window)); 76 width = std::min(width, GetMaxWidth(window));
77 return std::max(width, GetMinWidth(window)); 77 return std::max(width, GetMinWidth(window));
78 } 78 }
79 79
80 // Creates the list of possible width for the current screen configuration: 80 // Creates the list of possible width for the current screen configuration:
81 // Returns a list with items from |kIdealWidth| which fit on the screen and 81 // Returns a list with items from |kIdealWidth| which fit on the screen and
82 // supplement it with the 'half of screen' size. Furthermore, add an entry for 82 // supplement it with the 'half of screen' size. Furthermore, add an entry for
83 // 90% of the screen size if it is smaller than the biggest value in the 83 // 90% of the screen size if it is smaller than the biggest value in the
84 // |kIdealWidth| list (to get a step between the values). 84 // |kIdealWidth| list (to get a step between the values).
85 std::vector<int> BuildIdealWidthList(aura::Window* window) { 85 std::vector<int> BuildIdealWidthList(aura::Window* window) {
86 if (!CommandLine::ForCurrentProcess()->HasSwitch( 86 if (!CommandLine::ForCurrentProcess()->HasSwitch(
87 switches::kAshMultipleSnapWindowWidths)) { 87 switches::kAshMultipleSnapWindowWidths)) {
88 return std::vector<int>(1u, GetDefaultWidth(window)); 88 return std::vector<int>(1u, GetDefaultWidth(window));
89 } 89 }
90 90
91 int minimum_width = GetMinWidth(window); 91 int minimum_width = GetMinWidth(window);
92 int maximum_width = GetMaxWidth(window); 92 int maximum_width = GetMaxWidth(window);
93 93
94 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); 94 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(window));
95 int half_width = work_area.width() / 2; 95 int half_width = work_area.width() / 2;
96 if (half_width < minimum_width || half_width > maximum_width) 96 if (half_width < minimum_width || half_width > maximum_width)
97 half_width = 0; 97 half_width = 0;
98 98
99 std::vector<int> ideal_width_list; 99 std::vector<int> ideal_width_list;
100 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { 100 for (size_t i = 0; i < arraysize(kIdealWidth); i++) {
101 if (kIdealWidth[i] >= minimum_width && kIdealWidth[i] <= maximum_width) { 101 if (kIdealWidth[i] >= minimum_width && kIdealWidth[i] <= maximum_width) {
102 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i]) 102 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i])
103 ideal_width_list.push_back(maximum_width); 103 ideal_width_list.push_back(maximum_width);
104 if (half_width > kIdealWidth[i]) 104 if (half_width > kIdealWidth[i])
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 220 }
221 221
222 void SnapSizer::SelectDefaultSizeAndDisableResize() { 222 void SnapSizer::SelectDefaultSizeAndDisableResize() {
223 resize_disabled_ = true; 223 resize_disabled_ = true;
224 size_index_ = 0; 224 size_index_ = 0;
225 end_of_sequence_ = false; 225 end_of_sequence_ = false;
226 target_bounds_ = GetTargetBounds(); 226 target_bounds_ = GetTargetBounds();
227 } 227 }
228 228
229 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { 229 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const {
230 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 230 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
231 window_state_->window())); 231 window_state_->window()));
232 int y = work_area.y(); 232 int y = work_area.y();
233 int max_y = work_area.bottom(); 233 int max_y = work_area.bottom();
234 int width = 0; 234 int width = 0;
235 if (resize_disabled_) { 235 if (resize_disabled_) {
236 width = GetDefaultWidth(window_state_->window()); 236 width = GetDefaultWidth(window_state_->window());
237 } else { 237 } else {
238 DCHECK(size_index < usable_width_.size()); 238 DCHECK(size_index < usable_width_.size());
239 width = usable_width_[size_index]; 239 width = usable_width_[size_index];
240 } 240 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 num_moves_since_adjust_ = 0; 277 num_moves_since_adjust_ = 0;
278 last_adjust_x_ = x; 278 last_adjust_x_ = x;
279 } 279 }
280 280
281 gfx::Rect SnapSizer::GetTargetBounds() const { 281 gfx::Rect SnapSizer::GetTargetBounds() const {
282 return GetTargetBoundsForSize(size_index_); 282 return GetTargetBoundsForSize(size_index_);
283 } 283 }
284 284
285 bool SnapSizer::AlongEdge(int x) const { 285 bool SnapSizer::AlongEdge(int x) const {
286 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 286 gfx::Rect area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
287 window_state_->window())); 287 window_state_->window()));
288 return (x <= area.x()) || (x >= area.right() - 1); 288 return (x <= area.x()) || (x >= area.right() - 1);
289 } 289 }
290 290
291 } // namespace internal 291 } // namespace internal
292 } // namespace ash 292 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/multi_window_resize_controller.cc ('k') | ash/wm/workspace/snap_sizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698