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

Unified Diff: views/controls/single_split_view.h

Issue 5606012: Streamline the layout of the BrowserView's children TabContents views.... (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
Index: views/controls/single_split_view.h
===================================================================
--- views/controls/single_split_view.h (revision 70475)
+++ views/controls/single_split_view.h (working copy)
@@ -10,8 +10,15 @@
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.
+// When non-NULL observer is provided at the construction time, SingleSplitView
+// expects the entity resizing the SingleSplitView itself to resize its children
+// views (CalculateChildrenBounds and ResizeChildren functions are handy for
+// this). Observer's SplitHandleMoved notification helps to handle user
+// initiated layout changes.
+// When observer is NULL, SingleSplitView resizes children views automatically.
class SingleSplitView : public views::View {
public:
enum Orientation {
@@ -19,8 +26,17 @@
VERTICAL_SPLIT
};
- SingleSplitView(View* leading, View* trailing, Orientation orientation);
+ class Observer {
+ public:
+ // Invoked when split handle is moved by the user.
+ virtual void SplitHandleMoved(SingleSplitView* source) = 0;
+ protected:
+ virtual ~Observer() {}
+ };
+ SingleSplitView(View* leading, View* trailing, Orientation orientation,
sky 2011/01/07 21:35:40 each arg on its own line.
Aleksey Shlyapnikov 2011/01/07 23:06:00 Done.
+ Observer* observer);
+
virtual void DidChangeBounds(const gfx::Rect& previous,
const gfx::Rect& current);
@@ -39,7 +55,7 @@
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,6 +64,16 @@
resize_leading_on_bounds_change_ = resize;
}
+ // Calculates ideal leading and trailing view bounds according to the current
+ // split view bounds, divider offset and children visiblity.
+ // Does not change children view bounds.
+ void CalculateChildrenBounds(gfx::Rect* leading_bounds,
+ gfx::Rect* trailing_bounds) const;
+
+ // Resizes children views to the leading_bounds and trailing_bounds.
+ void ResizeChildren(const gfx::Rect& leading_bounds,
+ const gfx::Rect& trailing_bounds) const;
+
protected:
virtual bool OnMousePressed(const MouseEvent& event);
virtual bool OnMouseDragged(const MouseEvent& event);
@@ -57,12 +83,15 @@
// Returns true if |x| or |y| is over the divider.
bool IsPointInDivider(const gfx::Point& p);
+ // Returns divider offset within primary axis size range.
+ int NormalizeDividerOffset(int divider_offset) 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 +113,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);
};

Powered by Google App Engine
This is Rietveld 408576698