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

Side by Side Diff: ash/wm/common/workspace/magnetism_matcher.h

Issue 1933303002: Moves windowsresizers to ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WorkspaceWindowResizer Created 4 years, 7 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
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 #ifndef ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ 5 #ifndef ASH_WM_COMMON_WORKSPACE_MAGNETISM_MATCHER_H_
6 #define ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ 6 #define ASH_WM_COMMON_WORKSPACE_MAGNETISM_MATCHER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/ash_export.h" 13 #include "ash/ash_export.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
19 19
20 namespace ash { 20 namespace ash {
21 21
22 enum MagnetismEdge { 22 enum MagnetismEdge {
23 MAGNETISM_EDGE_TOP = 1 << 0, 23 MAGNETISM_EDGE_TOP = 1 << 0,
24 MAGNETISM_EDGE_LEFT = 1 << 1, 24 MAGNETISM_EDGE_LEFT = 1 << 1,
25 MAGNETISM_EDGE_BOTTOM = 1 << 2, 25 MAGNETISM_EDGE_BOTTOM = 1 << 2,
26 MAGNETISM_EDGE_RIGHT = 1 << 3, 26 MAGNETISM_EDGE_RIGHT = 1 << 3,
27 }; 27 };
28 28
29 const uint32_t kAllMagnetismEdges = MAGNETISM_EDGE_TOP | MAGNETISM_EDGE_LEFT | 29 const uint32_t kAllMagnetismEdges = MAGNETISM_EDGE_TOP | MAGNETISM_EDGE_LEFT |
30 MAGNETISM_EDGE_BOTTOM | 30 MAGNETISM_EDGE_BOTTOM |
31 MAGNETISM_EDGE_RIGHT; 31 MAGNETISM_EDGE_RIGHT;
32 32
33 // MagnetismEdgeMatcher is used for matching a particular edge of a window. You 33 // MagnetismEdgeMatcher is used for matching a particular edge of a window. You
34 // shouldn't need to use this directly, instead use MagnetismMatcher which takes 34 // shouldn't need to use this directly, instead use MagnetismMatcher which takes
35 // care of all edges. 35 // care of all edges.
36 // MagnetismEdgeMatcher maintains a range of the visible portions of the 36 // MagnetismEdgeMatcher maintains a range of the visible portions of the
37 // edge. As ShouldAttach() is invoked the visible range is updated. 37 // edge. As ShouldAttach() is invoked the visible range is updated.
38 class MagnetismEdgeMatcher { 38 class MagnetismEdgeMatcher {
39 public: 39 public:
40 MagnetismEdgeMatcher(const gfx::Rect& bounds, MagnetismEdge edge); 40 MagnetismEdgeMatcher(const gfx::Rect& bounds, MagnetismEdge edge);
41 ~MagnetismEdgeMatcher(); 41 ~MagnetismEdgeMatcher();
42 42
43 MagnetismEdge edge() const { return edge_; } 43 MagnetismEdge edge() const { return edge_; }
44 const gfx::Rect& bounds() const { return bounds_; } 44 const gfx::Rect& bounds() const { return bounds_; }
45 45
46 // Returns true if the edge is completely obscured. If true ShouldAttach() 46 // Returns true if the edge is completely obscured. If true ShouldAttach()
47 // will return false. 47 // will return false.
48 bool is_edge_obscured() const { return ranges_.empty(); } 48 bool is_edge_obscured() const { return ranges_.empty(); }
49 49
50 // Returns true if should attach to the specified bounds. 50 // Returns true if should attach to the specified bounds.
51 bool ShouldAttach(const gfx::Rect& bounds); 51 bool ShouldAttach(const gfx::Rect& bounds);
52 52
53 private: 53 private:
54 typedef std::pair<int,int> Range; 54 typedef std::pair<int, int> Range;
55 typedef std::vector<Range> Ranges; 55 typedef std::vector<Range> Ranges;
56 56
57 // Removes |range| from |ranges_|. 57 // Removes |range| from |ranges_|.
58 void UpdateRanges(const Range& range); 58 void UpdateRanges(const Range& range);
59 59
60 static int GetPrimaryCoordinate(const gfx::Rect& bounds, MagnetismEdge edge) { 60 static int GetPrimaryCoordinate(const gfx::Rect& bounds, MagnetismEdge edge) {
61 switch (edge) { 61 switch (edge) {
62 case MAGNETISM_EDGE_TOP: 62 case MAGNETISM_EDGE_TOP:
63 return bounds.y(); 63 return bounds.y();
64 case MAGNETISM_EDGE_LEFT: 64 case MAGNETISM_EDGE_LEFT:
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // The edges to match against. 182 // The edges to match against.
183 const int32_t edges_; 183 const int32_t edges_;
184 184
185 ScopedVector<MagnetismEdgeMatcher> matchers_; 185 ScopedVector<MagnetismEdgeMatcher> matchers_;
186 186
187 DISALLOW_COPY_AND_ASSIGN(MagnetismMatcher); 187 DISALLOW_COPY_AND_ASSIGN(MagnetismMatcher);
188 }; 188 };
189 189
190 } // namespace ash 190 } // namespace ash
191 191
192 #endif // ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ 192 #endif // ASH_WM_COMMON_WORKSPACE_MAGNETISM_MATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698