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/window_resizer.h" | 10 #include "ash/wm/window_resizer.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 for (size_t i = 0; i < arraysize(kPercents); ++i) { | |
71 gfx::Rect target = GetTargetBoundsForPercent(i); | |
72 if (target != bounds && target.width() > bounds.width()) | |
sky
2012/04/25 19:23:20
Can you use rect == to find the current snap bound
sadrul
2012/04/25 19:37:54
Done.
| |
73 return target; | |
74 } | |
75 return target_bounds_; | |
76 } | |
77 | |
69 int SnapSizer::CalculateIncrement(int x, int reference_x) const { | 78 int SnapSizer::CalculateIncrement(int x, int reference_x) const { |
70 if (AlongEdge(x)) | 79 if (AlongEdge(x)) |
71 return 1; | 80 return 1; |
72 if (x == reference_x) | 81 if (x == reference_x) |
73 return 0; | 82 return 0; |
74 if (edge_ == LEFT_EDGE) { | 83 if (edge_ == LEFT_EDGE) { |
75 if (x < reference_x) | 84 if (x < reference_x) |
76 return 1; | 85 return 1; |
77 return -1; | 86 return -1; |
78 } | 87 } |
79 // edge_ == RIGHT_EDGE. | 88 // edge_ == RIGHT_EDGE. |
80 if (x > reference_x) | 89 if (x > reference_x) |
81 return 1; | 90 return 1; |
82 return -1; | 91 return -1; |
83 } | 92 } |
84 | 93 |
85 void SnapSizer::ChangeBounds(int x, int delta) { | 94 void SnapSizer::ChangeBounds(int x, int delta) { |
86 int index = std::min(static_cast<int>(arraysize(kPercents)) - 1, | 95 int index = std::min(static_cast<int>(arraysize(kPercents)) - 1, |
87 std::max(percent_index_ + delta, 0)); | 96 std::max(percent_index_ + delta, 0)); |
88 if (index != percent_index_) { | 97 if (index != percent_index_) { |
89 percent_index_ = index; | 98 percent_index_ = index; |
90 target_bounds_ = GetTargetBounds(); | 99 target_bounds_ = GetTargetBounds(); |
91 } | 100 } |
92 num_moves_since_adjust_ = 0; | 101 num_moves_since_adjust_ = 0; |
93 last_adjust_x_ = x; | 102 last_adjust_x_ = x; |
94 } | 103 } |
95 | 104 |
96 gfx::Rect SnapSizer::GetTargetBounds() const { | 105 gfx::Rect SnapSizer::GetTargetBounds() const { |
106 return GetTargetBoundsForPercent(percent_index_); | |
107 } | |
108 | |
109 gfx::Rect SnapSizer::GetTargetBoundsForPercent(int percent_index) const { | |
97 gfx::Rect work_area(ScreenAsh::GetUnmaximizedWorkAreaBounds(window_)); | 110 gfx::Rect work_area(ScreenAsh::GetUnmaximizedWorkAreaBounds(window_)); |
98 int y = WindowResizer::AlignToGridRoundUp(work_area.y(), grid_size_); | 111 int y = WindowResizer::AlignToGridRoundUp(work_area.y(), grid_size_); |
99 // We don't align to the bottom of the grid as the launcher may not | 112 // We don't align to the bottom of the grid as the launcher may not |
100 // necessarily align to the grid (happens when auto-hidden). | 113 // necessarily align to the grid (happens when auto-hidden). |
101 int max_y = work_area.bottom(); | 114 int max_y = work_area.bottom(); |
102 int width = static_cast<float>(work_area.width()) * kPercents[percent_index_]; | 115 int width = static_cast<float>(work_area.width()) * kPercents[percent_index]; |
103 if (edge_ == LEFT_EDGE) { | 116 if (edge_ == LEFT_EDGE) { |
104 int x = WindowResizer::AlignToGridRoundUp(work_area.x(), grid_size_); | 117 int x = WindowResizer::AlignToGridRoundUp(work_area.x(), grid_size_); |
105 int mid_x = WindowResizer::AlignToGridRoundUp( | 118 int mid_x = WindowResizer::AlignToGridRoundUp( |
106 work_area.x() + width, grid_size_); | 119 work_area.x() + width, grid_size_); |
107 return gfx::Rect(x, y, mid_x - x, max_y - y); | 120 return gfx::Rect(x, y, mid_x - x, max_y - y); |
108 } | 121 } |
109 int max_x = | 122 int max_x = |
110 WindowResizer::AlignToGridRoundDown(work_area.right(), grid_size_); | 123 WindowResizer::AlignToGridRoundDown(work_area.right(), grid_size_); |
111 int x = WindowResizer::AlignToGridRoundUp(max_x - width, grid_size_); | 124 int x = WindowResizer::AlignToGridRoundUp(max_x - width, grid_size_); |
112 return gfx::Rect(x , y, max_x - x, max_y - y); | 125 return gfx::Rect(x , y, max_x - x, max_y - y); |
113 } | 126 } |
114 | 127 |
115 bool SnapSizer::AlongEdge(int x) const { | 128 bool SnapSizer::AlongEdge(int x) const { |
116 // TODO: need to support multi-monitor. | 129 // TODO: need to support multi-monitor. |
117 gfx::Rect area(gfx::Screen::GetMonitorAreaNearestWindow(window_)); | 130 gfx::Rect area(gfx::Screen::GetMonitorAreaNearestWindow(window_)); |
118 return (x <= area.x()) || (x >= area.right() - 1); | 131 return (x <= area.x()) || (x >= area.right() - 1); |
119 } | 132 } |
120 | 133 |
121 } // namespace internal | 134 } // namespace internal |
122 } // namespace ash | 135 } // namespace ash |
OLD | NEW |