| 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 #ifndef ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ | 5 #ifndef ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ |
| 6 #define ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ | 6 #define ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <utility> | 10 #include <utility> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "ash/ash_export.h" | 13 #include "ash/ash_export.h" |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 16 | 19 |
| 17 namespace ash { | 20 namespace ash { |
| 18 | 21 |
| 19 enum MagnetismEdge { | 22 enum MagnetismEdge { |
| 20 MAGNETISM_EDGE_TOP = 1 << 0, | 23 MAGNETISM_EDGE_TOP = 1 << 0, |
| 21 MAGNETISM_EDGE_LEFT = 1 << 1, | 24 MAGNETISM_EDGE_LEFT = 1 << 1, |
| 22 MAGNETISM_EDGE_BOTTOM = 1 << 2, | 25 MAGNETISM_EDGE_BOTTOM = 1 << 2, |
| 23 MAGNETISM_EDGE_RIGHT = 1 << 3, | 26 MAGNETISM_EDGE_RIGHT = 1 << 3, |
| 24 }; | 27 }; |
| 25 | 28 |
| 26 const uint32 kAllMagnetismEdges = | 29 const uint32_t kAllMagnetismEdges = MAGNETISM_EDGE_TOP | MAGNETISM_EDGE_LEFT | |
| 27 MAGNETISM_EDGE_TOP | MAGNETISM_EDGE_LEFT | MAGNETISM_EDGE_BOTTOM | | 30 MAGNETISM_EDGE_BOTTOM | |
| 28 MAGNETISM_EDGE_RIGHT; | 31 MAGNETISM_EDGE_RIGHT; |
| 29 | 32 |
| 30 // 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 |
| 31 // 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 |
| 32 // care of all edges. | 35 // care of all edges. |
| 33 // MagnetismEdgeMatcher maintains a range of the visible portions of the | 36 // MagnetismEdgeMatcher maintains a range of the visible portions of the |
| 34 // edge. As ShouldAttach() is invoked the visible range is updated. | 37 // edge. As ShouldAttach() is invoked the visible range is updated. |
| 35 class MagnetismEdgeMatcher { | 38 class MagnetismEdgeMatcher { |
| 36 public: | 39 public: |
| 37 MagnetismEdgeMatcher(const gfx::Rect& bounds, MagnetismEdge edge); | 40 MagnetismEdgeMatcher(const gfx::Rect& bounds, MagnetismEdge edge); |
| 38 ~MagnetismEdgeMatcher(); | 41 ~MagnetismEdgeMatcher(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // . Create it with the bounds of the window being dragged. | 155 // . Create it with the bounds of the window being dragged. |
| 153 // . Iterate over the child windows checking if the window being dragged should | 156 // . Iterate over the child windows checking if the window being dragged should |
| 154 // attach to it using ShouldAttach(). | 157 // attach to it using ShouldAttach(). |
| 155 // . Use AreEdgesObscured() to test if no other windows can match (because all | 158 // . Use AreEdgesObscured() to test if no other windows can match (because all |
| 156 // edges are completely obscured). | 159 // edges are completely obscured). |
| 157 class ASH_EXPORT MagnetismMatcher { | 160 class ASH_EXPORT MagnetismMatcher { |
| 158 public: | 161 public: |
| 159 static const int kMagneticDistance; | 162 static const int kMagneticDistance; |
| 160 | 163 |
| 161 // |edges| is a bitmask of MagnetismEdges to match against. | 164 // |edges| is a bitmask of MagnetismEdges to match against. |
| 162 MagnetismMatcher(const gfx::Rect& bounds, uint32 edges); | 165 MagnetismMatcher(const gfx::Rect& bounds, uint32_t edges); |
| 163 ~MagnetismMatcher(); | 166 ~MagnetismMatcher(); |
| 164 | 167 |
| 165 // Returns true if |bounds| is close enough to the initial bounds that the two | 168 // Returns true if |bounds| is close enough to the initial bounds that the two |
| 166 // should be attached. If true is returned |edge| is set to indicates how the | 169 // should be attached. If true is returned |edge| is set to indicates how the |
| 167 // two should snap together. See description of MatchedEdge for details. | 170 // two should snap together. See description of MatchedEdge for details. |
| 168 bool ShouldAttach(const gfx::Rect& bounds, MatchedEdge* edge); | 171 bool ShouldAttach(const gfx::Rect& bounds, MatchedEdge* edge); |
| 169 | 172 |
| 170 // Returns true if no other matches are possible. | 173 // Returns true if no other matches are possible. |
| 171 bool AreEdgesObscured() const; | 174 bool AreEdgesObscured() const; |
| 172 | 175 |
| 173 private: | 176 private: |
| 174 // Sets |secondary_edge| based on whether the secondary edges should snap. | 177 // Sets |secondary_edge| based on whether the secondary edges should snap. |
| 175 void AttachToSecondaryEdge(const gfx::Rect& bounds, | 178 void AttachToSecondaryEdge(const gfx::Rect& bounds, |
| 176 MagnetismEdge edge, | 179 MagnetismEdge edge, |
| 177 SecondaryMagnetismEdge* secondary_edge) const; | 180 SecondaryMagnetismEdge* secondary_edge) const; |
| 178 | 181 |
| 179 // The edges to match against. | 182 // The edges to match against. |
| 180 const int32 edges_; | 183 const int32_t edges_; |
| 181 | 184 |
| 182 ScopedVector<MagnetismEdgeMatcher> matchers_; | 185 ScopedVector<MagnetismEdgeMatcher> matchers_; |
| 183 | 186 |
| 184 DISALLOW_COPY_AND_ASSIGN(MagnetismMatcher); | 187 DISALLOW_COPY_AND_ASSIGN(MagnetismMatcher); |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 } // namespace ash | 190 } // namespace ash |
| 188 | 191 |
| 189 #endif // ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ | 192 #endif // ASH_WM_WORKSPACE_MAGNETISM_MATCHER_H_ |
| OLD | NEW |