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

Unified Diff: views/controls/single_split_view.h

Issue 6247001: Re-land 71230.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | « chrome/chrome_tests.gypi ('k') | views/controls/single_split_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/single_split_view.h
===================================================================
--- views/controls/single_split_view.h (revision 71256)
+++ views/controls/single_split_view.h (working copy)
@@ -6,12 +6,16 @@
#define VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_
#pragma once
+#include "base/gtest_prod_util.h"
#include "views/view.h"
namespace views {
-// SingleSplitView lays out two views horizontally. A splitter exists between
-// the two views that the user can drag around to resize the views.
+// SingleSplitView lays out two views next to each other, either horizontally
+// or vertically. A splitter exists between the two views that the user can
+// drag around to resize the views.
+// Observer's SplitHandleMoved notification helps to monitor user initiated
+// layout changes.
class SingleSplitView : public views::View {
public:
enum Orientation {
@@ -19,8 +23,22 @@
VERTICAL_SPLIT
};
- SingleSplitView(View* leading, View* trailing, Orientation orientation);
+ class Observer {
+ public:
+ // Invoked when split handle is moved by the user. |source|'s divider_offset
+ // is already set to the new value, but Layout has not happened yet.
+ // Returns false if the layout has been handled by the observer, returns
+ // true if |source| should do it by itself.
+ virtual bool SplitHandleMoved(SingleSplitView* source) = 0;
+ protected:
+ virtual ~Observer() {}
+ };
+ SingleSplitView(View* leading,
+ View* trailing,
+ Orientation orientation,
+ Observer* observer);
+
virtual void DidChangeBounds(const gfx::Rect& previous,
const gfx::Rect& current);
@@ -36,10 +54,14 @@
virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
const gfx::Point& p);
+ Orientation orientation() const {
+ return is_horizontal_ ? HORIZONTAL_SPLIT : VERTICAL_SPLIT;
+ }
+
void set_divider_offset(int divider_offset) {
divider_offset_ = divider_offset;
}
- int divider_offset() { return divider_offset_; }
+ int divider_offset() const { return divider_offset_; }
// Sets whether the leading component is resized when the split views size
// changes. The default is true. A value of false results in the trailing
@@ -48,21 +70,42 @@
resize_leading_on_bounds_change_ = resize;
}
+ // Calculates ideal leading and trailing view bounds according to the given
+ // split view |bounds|, current divider offset and children visiblity.
+ // Does not change children view bounds.
+ void CalculateChildrenBounds(const gfx::Rect& bounds,
+ gfx::Rect* leading_bounds,
+ gfx::Rect* trailing_bounds) const;
+
protected:
virtual bool OnMousePressed(const MouseEvent& event);
virtual bool OnMouseDragged(const MouseEvent& event);
virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
private:
+ // This test calls OnMouse* functions.
+ FRIEND_TEST_ALL_PREFIXES(SingleSplitViewTest, MouseDrag);
+
// Returns true if |x| or |y| is over the divider.
bool IsPointInDivider(const gfx::Point& p);
+ // Calculates the new |divider_offset| based on the changes of split view
+ // bounds.
+ int CalculateDividerOffset(
+ int divider_offset,
+ const gfx::Rect& previous_bounds,
+ const gfx::Rect& new_bounds) const;
+
+ // Returns divider offset within primary axis size range for given split
+ // view |bounds|.
+ int NormalizeDividerOffset(int divider_offset, const gfx::Rect& bounds) const;
+
// Returns width in case of horizontal split and height otherwise.
- int GetPrimaryAxisSize() {
+ int GetPrimaryAxisSize() const {
return GetPrimaryAxisSize(width(), height());
}
- int GetPrimaryAxisSize(int h, int v) {
+ int GetPrimaryAxisSize(int h, int v) const {
return is_horizontal_ ? h : v;
}
@@ -84,6 +127,9 @@
bool resize_leading_on_bounds_change_;
+ // Observer to notify about user initiated handle movements. Not own by us.
+ Observer* observer_;
+
DISALLOW_COPY_AND_ASSIGN(SingleSplitView);
};
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | views/controls/single_split_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698