summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc7
-rw-r--r--views/controls/single_split_view.cc92
-rw-r--r--views/controls/single_split_view.h39
3 files changed, 95 insertions, 43 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 4673c71..e85c8a2 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -182,7 +182,8 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
this, true);
tools_menu_button->SetID(kToolsMenuButtonID);
- split_view_ = new views::SingleSplitView(tree_view_, table_view_);
+ split_view_ = new views::SingleSplitView(tree_view_, table_view_,
+ views::SingleSplitView::HORIZONTAL_SPLIT);
split_view_->set_background(
views::Background::CreateSolidBackground(kBackgroundColorBottom));
@@ -349,7 +350,7 @@ std::wstring BookmarkManagerView::GetWindowName() const {
void BookmarkManagerView::WindowClosing() {
g_browser_process->local_state()->SetInteger(
- prefs::kBookmarkManagerSplitLocation, split_view_->divider_x());
+ prefs::kBookmarkManagerSplitLocation, split_view_->divider_offset());
}
bool BookmarkManagerView::AcceleratorPressed(
@@ -644,7 +645,7 @@ void BookmarkManagerView::PrepareForShow() {
// Make sure the user can see both the tree/table.
split_x = std::min(split_view_->width() - min_split_size,
std::max(min_split_size, split_x));
- split_view_->set_divider_x(split_x);
+ split_view_->set_divider_offset(split_x);
if (!GetBookmarkModel()->IsLoaded()) {
search_tf_->SetReadOnly(true);
return;
diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc
index c741233..1ddf229 100644
--- a/views/controls/single_split_view.cc
+++ b/views/controls/single_split_view.cc
@@ -17,8 +17,11 @@ namespace views {
// Size of the divider in pixels.
static const int kDividerSize = 4;
-SingleSplitView::SingleSplitView(View* leading, View* trailing)
- : divider_x_(-1) {
+SingleSplitView::SingleSplitView(View* leading,
+ View* trailing,
+ Orientation orientation)
+ : is_horizontal_(orientation == HORIZONTAL_SPLIT),
+ divider_offset_(-1) {
AddChildView(leading);
AddChildView(trailing);
set_background(
@@ -32,13 +35,21 @@ void SingleSplitView::Layout() {
View* leading = GetChildViewAt(0);
View* trailing = GetChildViewAt(1);
- if (divider_x_ < 0)
- divider_x_ = (width() - kDividerSize) / 2;
+ if (divider_offset_ < 0)
+ divider_offset_ = (GetPrimaryAxisSize() - kDividerSize) / 2;
else
- divider_x_ = std::min(divider_x_, width() - kDividerSize);
- leading->SetBounds(0, 0, divider_x_, height());
- trailing->SetBounds(divider_x_ + kDividerSize, 0,
- width() - divider_x_ - kDividerSize, height());
+ divider_offset_ = std::min(divider_offset_,
+ GetPrimaryAxisSize() - kDividerSize);
+
+ if (is_horizontal_) {
+ leading->SetBounds(0, 0, divider_offset_, height());
+ trailing->SetBounds(divider_offset_ + kDividerSize, 0,
+ width() - divider_offset_ - kDividerSize, height());
+ } else {
+ leading->SetBounds(0, 0, width(), divider_offset_);
+ trailing->SetBounds(0, divider_offset_ + kDividerSize,
+ width(), height() - divider_offset_ - kDividerSize);
+ }
SchedulePaint();
@@ -52,31 +63,42 @@ gfx::Size SingleSplitView::GetPreferredSize() {
for (int i = 0; i < 2 && i < GetChildViewCount(); ++i) {
View* view = GetChildViewAt(i);
gfx::Size pref = view->GetPreferredSize();
- width += pref.width();
- height = std::max(height, pref.height());
+ if (is_horizontal_) {
+ width += pref.width();
+ height = std::max(height, pref.height());
+ } else {
+ width = std::max(width, pref.width());
+ height += pref.height();
+ }
}
- width += kDividerSize;
+ if (is_horizontal_)
+ width += kDividerSize;
+ else
+ height += kDividerSize;
return gfx::Size(width, height);
}
gfx::NativeCursor SingleSplitView::GetCursorForPoint(Event::EventType event_type,
int x, int y) {
- if (IsPointInDivider(x)) {
+ if (IsPointInDivider(x, y)) {
#if defined(OS_WIN)
- static HCURSOR resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
+ static HCURSOR resize_cursor = LoadCursor(NULL,
+ is_horizontal_ ? IDC_SIZEWE : IDC_SIZENS);
return resize_cursor;
#elif defined(OS_LINUX)
- return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
+ return gdk_cursor_new(is_horizontal_ ?
+ GDK_SB_H_DOUBLE_ARROW :
+ GDK_SB_V_DOUBLE_ARROW);
#endif
}
return NULL;
}
bool SingleSplitView::OnMousePressed(const MouseEvent& event) {
- if (!IsPointInDivider(event.x()))
+ if (!IsPointInDivider(event.x(), event.y()))
return false;
- drag_info_.initial_mouse_x = event.x();
- drag_info_.initial_divider_x = divider_x_;
+ drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y());
+ drag_info_.initial_divider_offset = divider_offset_;
return true;
}
@@ -84,18 +106,20 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) {
if (GetChildViewCount() < 2)
return false;
- int delta_x = event.x() - drag_info_.initial_mouse_x;
- if (UILayoutIsRightToLeft())
- delta_x *= -1;
+ int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) -
+ drag_info_.initial_mouse_offset;
+ if (is_horizontal_ && UILayoutIsRightToLeft())
+ delta_offset *= -1;
// Honor the minimum size when resizing.
- int new_width = std::max(GetChildViewAt(0)->GetMinimumSize().width(),
- drag_info_.initial_divider_x + delta_x);
+ gfx::Size min = GetChildViewAt(0)->GetMinimumSize();
+ int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()),
+ drag_info_.initial_divider_offset + delta_offset);
// And don't let the view get bigger than our width.
- new_width = std::min(width() - kDividerSize, new_width);
+ new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size);
- if (new_width != divider_x_) {
- set_divider_x(new_width);
+ if (new_size != divider_offset_) {
+ set_divider_offset(new_size);
Layout();
}
return true;
@@ -105,19 +129,25 @@ void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) {
if (GetChildViewCount() < 2)
return;
- if (canceled && drag_info_.initial_divider_x != divider_x_) {
- set_divider_x(drag_info_.initial_divider_x);
+ if (canceled && drag_info_.initial_divider_offset != divider_offset_) {
+ set_divider_offset(drag_info_.initial_divider_offset);
Layout();
}
}
-bool SingleSplitView::IsPointInDivider(int x) {
+bool SingleSplitView::IsPointInDivider(int x, int y) {
if (GetChildViewCount() < 2)
return false;
- int divider_relative_x =
- x - GetChildViewAt(UILayoutIsRightToLeft() ? 1 : 0)->width();
- return (divider_relative_x >= 0 && divider_relative_x < kDividerSize);
+ int divider_relative_offset;
+ if (is_horizontal_) {
+ divider_relative_offset =
+ x - GetChildViewAt(UILayoutIsRightToLeft() ? 1 : 0)->width();
+ } else {
+ divider_relative_offset = y - GetChildViewAt(0)->height();
+ }
+ return (divider_relative_offset >= 0 &&
+ divider_relative_offset < kDividerSize);
}
} // namespace views
diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h
index 9d25918..74377df 100644
--- a/views/controls/single_split_view.h
+++ b/views/controls/single_split_view.h
@@ -13,7 +13,12 @@ namespace views {
// the two views that the user can drag around to resize the views.
class SingleSplitView : public views::View {
public:
- SingleSplitView(View* leading, View* trailing);
+ enum Orientation {
+ HORIZONTAL_SPLIT,
+ VERTICAL_SPLIT
+ };
+
+ SingleSplitView(View* leading, View* trailing, Orientation orientation);
virtual void Layout();
@@ -22,10 +27,14 @@ class SingleSplitView : public views::View {
virtual gfx::Size GetPreferredSize();
// Overriden to return a resize cursor when over the divider.
- virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, int x, int y);
+ virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
+ int x,
+ int y);
- void set_divider_x(int divider_x) { divider_x_ = divider_x; }
- int divider_x() { return divider_x_; }
+ void set_divider_offset(int divider_offset) {
+ divider_offset_ = divider_offset;
+ }
+ int divider_offset() { return divider_offset_; }
protected:
virtual bool OnMousePressed(const MouseEvent& event);
@@ -33,21 +42,33 @@ class SingleSplitView : public views::View {
virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
private:
- // Returns true if |x| is over the divider.
- bool IsPointInDivider(int x);
+ // Returns true if |x| or |y| is over the divider.
+ bool IsPointInDivider(int x, int y);
+
+ // Returns width in case of horizontal split and height otherwise.
+ int GetPrimaryAxisSize() {
+ return GetPrimaryAxisSize(width(), height());
+ }
+
+ int GetPrimaryAxisSize(int h, int v) {
+ return is_horizontal_ ? h : v;
+ }
// Used to track drag info.
struct DragInfo {
// The initial coordinate of the mouse when the user started the drag.
- int initial_mouse_x;
+ int initial_mouse_offset;
// The initial position of the divider when the user started the drag.
- int initial_divider_x;
+ int initial_divider_offset;
};
DragInfo drag_info_;
+ // Orientation of the split view.
+ bool is_horizontal_;
+
// Position of the divider.
- int divider_x_;
+ int divider_offset_;
DISALLOW_COPY_AND_ASSIGN(SingleSplitView);
};