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

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

Issue 10223014: Revert 133982 because it broke build on chromeos due to mid-air collision with 133961. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « ash/wm/workspace/snap_sizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/wm/window_resizer.h" 10 #include "ash/wm/window_resizer.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (std::abs(location.x() - last_adjust_x_) >= kPixelsBeforeAdjust || 59 if (std::abs(location.x() - last_adjust_x_) >= kPixelsBeforeAdjust ||
60 (along_edge && num_moves_since_adjust_ >= kMovesBeforeAdjust)) { 60 (along_edge && num_moves_since_adjust_ >= kMovesBeforeAdjust)) {
61 ChangeBounds(location.x(), 61 ChangeBounds(location.x(),
62 CalculateIncrement(location.x(), last_adjust_x_)); 62 CalculateIncrement(location.x(), last_adjust_x_));
63 } 63 }
64 } 64 }
65 last_update_x_ = location.x(); 65 last_update_x_ = location.x();
66 time_last_update_ = base::TimeTicks::Now(); 66 time_last_update_ = base::TimeTicks::Now();
67 } 67 }
68 68
69 gfx::Rect SnapSizer::GetSnapBounds(const gfx::Rect& bounds) {
70 size_t current;
71 for (current = 0; current < arraysize(kPercents); ++current) {
72 gfx::Rect target = GetTargetBoundsForPercent(current);
73 if (target == bounds) {
74 ++current;
75 break;
76 }
77 }
78 return GetTargetBoundsForPercent(current % arraysize(kPercents));
79 }
80
81 int SnapSizer::CalculateIncrement(int x, int reference_x) const { 69 int SnapSizer::CalculateIncrement(int x, int reference_x) const {
82 if (AlongEdge(x)) 70 if (AlongEdge(x))
83 return 1; 71 return 1;
84 if (x == reference_x) 72 if (x == reference_x)
85 return 0; 73 return 0;
86 if (edge_ == LEFT_EDGE) { 74 if (edge_ == LEFT_EDGE) {
87 if (x < reference_x) 75 if (x < reference_x)
88 return 1; 76 return 1;
89 return -1; 77 return -1;
90 } 78 }
91 // edge_ == RIGHT_EDGE. 79 // edge_ == RIGHT_EDGE.
92 if (x > reference_x) 80 if (x > reference_x)
93 return 1; 81 return 1;
94 return -1; 82 return -1;
95 } 83 }
96 84
97 void SnapSizer::ChangeBounds(int x, int delta) { 85 void SnapSizer::ChangeBounds(int x, int delta) {
98 int index = std::min(static_cast<int>(arraysize(kPercents)) - 1, 86 int index = std::min(static_cast<int>(arraysize(kPercents)) - 1,
99 std::max(percent_index_ + delta, 0)); 87 std::max(percent_index_ + delta, 0));
100 if (index != percent_index_) { 88 if (index != percent_index_) {
101 percent_index_ = index; 89 percent_index_ = index;
102 target_bounds_ = GetTargetBounds(); 90 target_bounds_ = GetTargetBounds();
103 } 91 }
104 num_moves_since_adjust_ = 0; 92 num_moves_since_adjust_ = 0;
105 last_adjust_x_ = x; 93 last_adjust_x_ = x;
106 } 94 }
107 95
108 gfx::Rect SnapSizer::GetTargetBounds() const { 96 gfx::Rect SnapSizer::GetTargetBounds() const {
109 return GetTargetBoundsForPercent(percent_index_);
110 }
111
112 gfx::Rect SnapSizer::GetTargetBoundsForPercent(int percent_index) const {
113 gfx::Rect work_area(ScreenAsh::GetUnmaximizedWorkAreaBounds(window_)); 97 gfx::Rect work_area(ScreenAsh::GetUnmaximizedWorkAreaBounds(window_));
114 int y = WindowResizer::AlignToGridRoundUp(work_area.y(), grid_size_); 98 int y = WindowResizer::AlignToGridRoundUp(work_area.y(), grid_size_);
115 // We don't align to the bottom of the grid as the launcher may not 99 // We don't align to the bottom of the grid as the launcher may not
116 // necessarily align to the grid (happens when auto-hidden). 100 // necessarily align to the grid (happens when auto-hidden).
117 int max_y = work_area.bottom(); 101 int max_y = work_area.bottom();
118 int width = static_cast<float>(work_area.width()) * kPercents[percent_index]; 102 int width = static_cast<float>(work_area.width()) * kPercents[percent_index_];
119 if (edge_ == LEFT_EDGE) { 103 if (edge_ == LEFT_EDGE) {
120 int x = WindowResizer::AlignToGridRoundUp(work_area.x(), grid_size_); 104 int x = WindowResizer::AlignToGridRoundUp(work_area.x(), grid_size_);
121 int mid_x = WindowResizer::AlignToGridRoundUp( 105 int mid_x = WindowResizer::AlignToGridRoundUp(
122 work_area.x() + width, grid_size_); 106 work_area.x() + width, grid_size_);
123 return gfx::Rect(x, y, mid_x - x, max_y - y); 107 return gfx::Rect(x, y, mid_x - x, max_y - y);
124 } 108 }
125 int max_x = 109 int max_x =
126 WindowResizer::AlignToGridRoundDown(work_area.right(), grid_size_); 110 WindowResizer::AlignToGridRoundDown(work_area.right(), grid_size_);
127 int x = WindowResizer::AlignToGridRoundUp(max_x - width, grid_size_); 111 int x = WindowResizer::AlignToGridRoundUp(max_x - width, grid_size_);
128 return gfx::Rect(x , y, max_x - x, max_y - y); 112 return gfx::Rect(x , y, max_x - x, max_y - y);
129 } 113 }
130 114
131 bool SnapSizer::AlongEdge(int x) const { 115 bool SnapSizer::AlongEdge(int x) const {
132 // TODO: need to support multi-monitor. 116 // TODO: need to support multi-monitor.
133 gfx::Rect area(gfx::Screen::GetMonitorNearestWindow(window_).bounds()); 117 gfx::Rect area(gfx::Screen::GetMonitorNearestWindow(window_).bounds());
134 return (x <= area.x()) || (x >= area.right() - 1); 118 return (x <= area.x()) || (x >= area.right() - 1);
135 } 119 }
136 120
137 } // namespace internal 121 } // namespace internal
138 } // namespace ash 122 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/snap_sizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698