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

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

Issue 9706059: Centralizes snap sizing and implements spec'd behavior. Three resize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better comments Created 8 years, 9 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/frame_maximize_button.cc ('k') | ash/wm/workspace/snap_sizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ASH_WM_WORKSPACE_SNAP_SIZER_H_
6 #define ASH_WM_WORKSPACE_SNAP_SIZER_H_
7 #pragma once
8
9 #include "ash/ash_export.h"
10 #include "base/basictypes.h"
11 #include "base/time.h"
12 #include "ui/gfx/rect.h"
13
14 namespace aura {
15 class Window;
16 }
17
18 namespace ash {
19 namespace internal {
20
21 // SnapSizer is responsible for determining the resulting bounds of a window
22 // that is being snapped to the left or right side of the screen.
23 class ASH_EXPORT SnapSizer {
24 public:
25 enum Edge {
26 LEFT_EDGE,
27 RIGHT_EDGE
28 };
29
30 SnapSizer(aura::Window* window,
31 const gfx::Point& start,
32 Edge edge,
33 int grid_size);
34
35 // Updates the target bounds based on a mouse move.
36 void Update(const gfx::Point& location);
37
38 // Bounds to position the window at.
39 const gfx::Rect& target_bounds() const { return target_bounds_; }
40
41 private:
42 // Calculates the amount to increment by. This returns one of -1, 0 or 1 and
43 // is intended to by applied to |percent_index_|. |x| is the current
44 // x-coordinate, and |reference_x| is used to determine whether to increase
45 // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|.
46 int CalculateIncrement(int x, int reference_x) const;
47
48 // Changes the bounds. |x| is the current x-coordinate and |delta| the amount
49 // to increase by. |delta| comes from CalculateIncrement() and is applied
50 // to |percent_index_|.
51 void ChangeBounds(int x, int delta);
52
53 // Returns the target bounds based on the edge and |percent_index_|.
54 gfx::Rect GetTargetBounds() const;
55
56 // Returns true if the specified point is along the edge of the screen.
57 bool AlongEdge(int x) const;
58
59 // Window being snapped.
60 aura::Window* window_;
61
62 const Edge edge_;
63 const int grid_size_;
64
65 // Current target bounds for the snap.
66 gfx::Rect target_bounds_;
67
68 // Time Update() was last invoked.
69 base::TimeTicks time_last_update_;
70
71 // Index into |kPercents| that dictates the width of the screen the target
72 // bounds should get.
73 int percent_index_;
74
75 // Number of times Update() has been invoked since last ChangeBounds().
76 int num_moves_since_adjust_;
77
78 // X-coordinate the last time ChangeBounds() was invoked.
79 int last_adjust_x_;
80
81 // X-coordinate last supplied to Update().
82 int last_update_x_;
83
84 DISALLOW_COPY_AND_ASSIGN(SnapSizer);
85 };
86
87 } // namespace internal
88 } // namespace ash
89
90 #endif // ASH_WM_WORKSPACE_SNAP_SIZER_H_
OLDNEW
« no previous file with comments | « ash/wm/workspace/frame_maximize_button.cc ('k') | ash/wm/workspace/snap_sizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698