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/magnetism_matcher.h" | 5 #include "ash/wm/workspace/magnetism_matcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 namespace ash { | 10 namespace ash { |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Returns true if |a| is close enough to |b| that the two edges snap. | 13 // Returns true if |a| is close enough to |b| that the two edges snap. |
14 bool IsCloseEnough(int a, int b) { | 14 bool IsCloseEnough(int a, int b) { |
15 return abs(a - b) <= MagnetismMatcher::kMagneticDistance; | 15 return abs(a - b) <= MagnetismMatcher::kMagneticDistance; |
16 } | 16 } |
17 | 17 |
18 // Returns true if the specified SecondaryMagnetismEdge can be matched with a | 18 // Returns true if the specified SecondaryMagnetismEdge can be matched with a |
19 // primary edge of |primary|. |edges| is a bitmask of the allowed | 19 // primary edge of |primary|. |edges| is a bitmask of the allowed |
20 // MagnetismEdges. | 20 // MagnetismEdges. |
21 bool CanMatchSecondaryEdge(MagnetismEdge primary, | 21 bool CanMatchSecondaryEdge(MagnetismEdge primary, |
22 SecondaryMagnetismEdge secondary, | 22 SecondaryMagnetismEdge secondary, |
23 uint32 edges) { | 23 uint32_t edges) { |
24 // Convert |secondary| to a MagnetismEdge so we can compare it to |edges|. | 24 // Convert |secondary| to a MagnetismEdge so we can compare it to |edges|. |
25 MagnetismEdge secondary_as_magnetism_edge = MAGNETISM_EDGE_TOP; | 25 MagnetismEdge secondary_as_magnetism_edge = MAGNETISM_EDGE_TOP; |
26 switch (primary) { | 26 switch (primary) { |
27 case MAGNETISM_EDGE_TOP: | 27 case MAGNETISM_EDGE_TOP: |
28 case MAGNETISM_EDGE_BOTTOM: | 28 case MAGNETISM_EDGE_BOTTOM: |
29 if (secondary == SECONDARY_MAGNETISM_EDGE_LEADING) | 29 if (secondary == SECONDARY_MAGNETISM_EDGE_LEADING) |
30 secondary_as_magnetism_edge = MAGNETISM_EDGE_LEFT; | 30 secondary_as_magnetism_edge = MAGNETISM_EDGE_LEFT; |
31 else if (secondary == SECONDARY_MAGNETISM_EDGE_TRAILING) | 31 else if (secondary == SECONDARY_MAGNETISM_EDGE_TRAILING) |
32 secondary_as_magnetism_edge = MAGNETISM_EDGE_RIGHT; | 32 secondary_as_magnetism_edge = MAGNETISM_EDGE_RIGHT; |
33 else | 33 else |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 // MagnetismMatcher ------------------------------------------------------------ | 118 // MagnetismMatcher ------------------------------------------------------------ |
119 | 119 |
120 // static | 120 // static |
121 const int MagnetismMatcher::kMagneticDistance = 8; | 121 const int MagnetismMatcher::kMagneticDistance = 8; |
122 | 122 |
123 MagnetismMatcher::MagnetismMatcher(const gfx::Rect& bounds, uint32 edges) | 123 MagnetismMatcher::MagnetismMatcher(const gfx::Rect& bounds, uint32_t edges) |
124 : edges_(edges) { | 124 : edges_(edges) { |
125 if (edges & MAGNETISM_EDGE_TOP) | 125 if (edges & MAGNETISM_EDGE_TOP) |
126 matchers_.push_back(new MagnetismEdgeMatcher(bounds, MAGNETISM_EDGE_TOP)); | 126 matchers_.push_back(new MagnetismEdgeMatcher(bounds, MAGNETISM_EDGE_TOP)); |
127 if (edges & MAGNETISM_EDGE_LEFT) | 127 if (edges & MAGNETISM_EDGE_LEFT) |
128 matchers_.push_back(new MagnetismEdgeMatcher(bounds, MAGNETISM_EDGE_LEFT)); | 128 matchers_.push_back(new MagnetismEdgeMatcher(bounds, MAGNETISM_EDGE_LEFT)); |
129 if (edges & MAGNETISM_EDGE_BOTTOM) { | 129 if (edges & MAGNETISM_EDGE_BOTTOM) { |
130 matchers_.push_back(new MagnetismEdgeMatcher(bounds, | 130 matchers_.push_back(new MagnetismEdgeMatcher(bounds, |
131 MAGNETISM_EDGE_BOTTOM)); | 131 MAGNETISM_EDGE_BOTTOM)); |
132 } | 132 } |
133 if (edges & MAGNETISM_EDGE_RIGHT) | 133 if (edges & MAGNETISM_EDGE_RIGHT) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 edges_) && | 182 edges_) && |
183 IsCloseEnough(bounds.right(), src_bounds.right())) { | 183 IsCloseEnough(bounds.right(), src_bounds.right())) { |
184 *secondary_edge = SECONDARY_MAGNETISM_EDGE_TRAILING; | 184 *secondary_edge = SECONDARY_MAGNETISM_EDGE_TRAILING; |
185 } else { | 185 } else { |
186 *secondary_edge = SECONDARY_MAGNETISM_EDGE_NONE; | 186 *secondary_edge = SECONDARY_MAGNETISM_EDGE_NONE; |
187 } | 187 } |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 } // namespace ash | 191 } // namespace ash |
OLD | NEW |