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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/wm/workspace/snap_sizer.h
diff --git a/ash/wm/workspace/snap_sizer.h b/ash/wm/workspace/snap_sizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..e389de7a70dd88fbb706496394dd4315beb8a16d
--- /dev/null
+++ b/ash/wm/workspace/snap_sizer.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_WM_WORKSPACE_SNAP_SIZER_H_
+#define ASH_WM_WORKSPACE_SNAP_SIZER_H_
+#pragma once
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+#include "base/time.h"
+#include "ui/gfx/rect.h"
+
+namespace aura {
+class Window;
+}
+
+namespace ash {
+namespace internal {
+
+// SnapSizer is responsible for determining the resulting bounds of a window
+// that is being snapped to the left or right side of the screen.
+class ASH_EXPORT SnapSizer {
+ public:
+ enum Edge {
+ LEFT_EDGE,
+ RIGHT_EDGE
+ };
+
+ SnapSizer(aura::Window* window,
+ const gfx::Point& start,
+ Edge edge,
+ int grid_size);
+
+ // Updates the target bounds based on a mouse move.
+ void Update(const gfx::Point& location);
+
+ // Bounds to position the window at.
+ const gfx::Rect& target_bounds() const { return target_bounds_; }
+
+ private:
+ // Calculates the amount to increment by. This returns one of -1, 0 or 1 and
+ // is intended to by applied to |percent_index_|. |x| is the current
+ // x-coordinate, and |reference_x| is used to determine whether to increase
+ // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|.
+ int CalculateIncrement(int x, int reference_x) const;
+
+ // Changes the bounds. |x| is the current x-coordinate and |delta| the amount
+ // to increase by. |delta| comes from CalculateIncrement() and is applied
+ // to |percent_index_|.
+ void ChangeBounds(int x, int delta);
+
+ // Returns the target bounds based on the edge and |percent_index_|.
+ gfx::Rect GetTargetBounds() const;
+
+ // Returns true if the specified point is along the edge of the screen.
+ bool AlongEdge(int x) const;
+
+ // Window being snapped.
+ aura::Window* window_;
+
+ const Edge edge_;
+ const int grid_size_;
+
+ // Current target bounds for the snap.
+ gfx::Rect target_bounds_;
+
+ // Time Update() was last invoked.
+ base::TimeTicks time_last_update_;
+
+ // Index into |kPercents| that dictates the width of the screen the target
+ // bounds should get.
+ int percent_index_;
+
+ // Number of times Update() has been invoked since last ChangeBounds().
+ int num_moves_since_adjust_;
+
+ // X-coordinate the last time ChangeBounds() was invoked.
+ int last_adjust_x_;
+
+ // X-coordinate last supplied to Update().
+ int last_update_x_;
+
+ DISALLOW_COPY_AND_ASSIGN(SnapSizer);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_WM_WORKSPACE_SNAP_SIZER_H_
« 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