diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 14:13:08 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 14:13:08 +0000 |
commit | e46318ec4c9a1409396fd4f9df2bb114ffad0ce3 (patch) | |
tree | bb72b3c62fc3683727faaa26d8e16ee4fe8b34b4 /views/controls | |
parent | 51f3f3b0920d3960fbbfa798b9b69b4885a87bac (diff) | |
download | chromium_src-e46318ec4c9a1409396fd4f9df2bb114ffad0ce3.zip chromium_src-e46318ec4c9a1409396fd4f9df2bb114ffad0ce3.tar.gz chromium_src-e46318ec4c9a1409396fd4f9df2bb114ffad0ce3.tar.bz2 |
Add 'resize_leading_on_bounds_change' property into the SingleSplitView.
When it is turned on, leading component is resized when split view gets new bounds.
Review URL: http://codereview.chromium.org/155214
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/single_split_view.cc | 17 | ||||
-rw-r--r-- | views/controls/single_split_view.h | 12 |
2 files changed, 28 insertions, 1 deletions
diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index dadf4b2..7915171 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.cc @@ -21,7 +21,8 @@ SingleSplitView::SingleSplitView(View* leading, View* trailing, Orientation orientation) : is_horizontal_(orientation == HORIZONTAL_SPLIT), - divider_offset_(-1) { + divider_offset_(-1), + resize_leading_on_bounds_change_(true) { AddChildView(leading); AddChildView(trailing); #if defined(OS_WIN) @@ -31,6 +32,20 @@ SingleSplitView::SingleSplitView(View* leading, #endif } +void SingleSplitView::DidChangeBounds(const gfx::Rect& previous, + const gfx::Rect& current) { + if (resize_leading_on_bounds_change_) { + if (is_horizontal_) + divider_offset_ += current.width() - previous.width(); + else + divider_offset_ += current.height() - previous.height(); + + if (divider_offset_ < 0) + divider_offset_ = kDividerSize; + } + View::DidChangeBounds(previous, current); +} + void SingleSplitView::Layout() { if (GetChildViewCount() != 2) return; diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h index 74377df..af982e4 100644 --- a/views/controls/single_split_view.h +++ b/views/controls/single_split_view.h @@ -20,6 +20,9 @@ class SingleSplitView : public views::View { SingleSplitView(View* leading, View* trailing, Orientation orientation); + virtual void DidChangeBounds(const gfx::Rect& previous, + const gfx::Rect& current); + virtual void Layout(); // SingleSplitView's preferred size is the sum of the preferred widths @@ -36,6 +39,13 @@ class SingleSplitView : public views::View { } int divider_offset() { 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 + // component resizing on a bounds change. + void set_resize_leading_on_bounds_change(bool resize) { + resize_leading_on_bounds_change_ = resize; + } + protected: virtual bool OnMousePressed(const MouseEvent& event); virtual bool OnMouseDragged(const MouseEvent& event); @@ -70,6 +80,8 @@ class SingleSplitView : public views::View { // Position of the divider. int divider_offset_; + bool resize_leading_on_bounds_change_; + DISALLOW_COPY_AND_ASSIGN(SingleSplitView); }; |