Commit 3d2fdb0f authored by tfarina@chromium.org's avatar tfarina@chromium.org

views: Factor out SingleSplitView Observer into SingleSplitViewListener.

R=sky@chromium.org

Review URL: http://codereview.chromium.org/8351007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107168 0039d316-1c4b-4281-b951-d872f2087c98
parent 9cf240d2
...@@ -1830,9 +1830,9 @@ bool BrowserView::DrawInfoBarArrows(int* x) const { ...@@ -1830,9 +1830,9 @@ bool BrowserView::DrawInfoBarArrows(int* x) const {
return true; return true;
} }
bool BrowserView::SplitHandleMoved(views::SingleSplitView* view) { bool BrowserView::SplitHandleMoved(views::SingleSplitView* sender) {
for (int i = 0; i < view->child_count(); ++i) for (int i = 0; i < sender->child_count(); ++i)
view->child_at(i)->InvalidateLayout(); sender->child_at(i)->InvalidateLayout();
SchedulePaint(); SchedulePaint();
Layout(); Layout();
return false; return false;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "views/controls/single_split_view.h" #include "views/controls/single_split_view_listener.h"
#include "views/widget/widget_delegate.h" #include "views/widget/widget_delegate.h"
#include "views/window/client_view.h" #include "views/window/client_view.h"
...@@ -88,7 +88,7 @@ class BrowserView : public BrowserBubbleHost, ...@@ -88,7 +88,7 @@ class BrowserView : public BrowserBubbleHost,
public views::Widget::Observer, public views::Widget::Observer,
public views::ClientView, public views::ClientView,
public InfoBarContainer::Delegate, public InfoBarContainer::Delegate,
public views::SingleSplitView::Observer { public views::SingleSplitViewListener {
public: public:
// The browser view's class name. // The browser view's class name.
static const char kViewClassName[]; static const char kViewClassName[];
...@@ -407,8 +407,8 @@ class BrowserView : public BrowserBubbleHost, ...@@ -407,8 +407,8 @@ class BrowserView : public BrowserBubbleHost,
virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE; virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE;
virtual bool DrawInfoBarArrows(int* x) const OVERRIDE; virtual bool DrawInfoBarArrows(int* x) const OVERRIDE;
// views::SingleSplitView::Observer overrides: // views::SingleSplitViewListener overrides:
virtual bool SplitHandleMoved(views::SingleSplitView* view) OVERRIDE; virtual bool SplitHandleMoved(views::SingleSplitView* sender) OVERRIDE;
protected: protected:
// Appends to |toolbars| a pointer to each AccessiblePaneView that // Appends to |toolbars| a pointer to each AccessiblePaneView that
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/base/accessibility/accessible_view_state.h" #include "ui/base/accessibility/accessible_view_state.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "views/background.h" #include "views/background.h"
#include "views/controls/single_split_view_listener.h"
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
#include "ui/gfx/gtk_util.h" #include "ui/gfx/gtk_util.h"
...@@ -33,11 +34,11 @@ static const int kDividerSize = 4; ...@@ -33,11 +34,11 @@ static const int kDividerSize = 4;
SingleSplitView::SingleSplitView(View* leading, SingleSplitView::SingleSplitView(View* leading,
View* trailing, View* trailing,
Orientation orientation, Orientation orientation,
Observer* observer) SingleSplitViewListener* listener)
: is_horizontal_(orientation == HORIZONTAL_SPLIT), : is_horizontal_(orientation == HORIZONTAL_SPLIT),
divider_offset_(-1), divider_offset_(-1),
resize_leading_on_bounds_change_(true), resize_leading_on_bounds_change_(true),
observer_(observer) { listener_(listener) {
AddChildView(leading); AddChildView(leading);
AddChildView(trailing); AddChildView(trailing);
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -186,7 +187,7 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { ...@@ -186,7 +187,7 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) {
if (new_size != divider_offset_) { if (new_size != divider_offset_) {
set_divider_offset(new_size); set_divider_offset(new_size);
if (!observer_ || observer_->SplitHandleMoved(this)) if (!listener_ || listener_->SplitHandleMoved(this))
Layout(); Layout();
} }
return true; return true;
...@@ -198,7 +199,7 @@ void SingleSplitView::OnMouseCaptureLost() { ...@@ -198,7 +199,7 @@ void SingleSplitView::OnMouseCaptureLost() {
if (drag_info_.initial_divider_offset != divider_offset_) { if (drag_info_.initial_divider_offset != divider_offset_) {
set_divider_offset(drag_info_.initial_divider_offset); set_divider_offset(drag_info_.initial_divider_offset);
if (!observer_ || observer_->SplitHandleMoved(this)) if (!listener_ || listener_->SplitHandleMoved(this))
Layout(); Layout();
} }
} }
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
namespace views { namespace views {
class SingleSplitViewListener;
// SingleSplitView lays out two views next to each other, either horizontally // SingleSplitView lays out two views next to each other, either horizontally
// or vertically. A splitter exists between the two views that the user can // or vertically. A splitter exists between the two views that the user can
// drag around to resize the views. // drag around to resize the views.
// Observer's SplitHandleMoved notification helps to monitor user initiated // SingleSplitViewListener's SplitHandleMoved notification helps to monitor user
// layout changes. // initiated layout changes.
class VIEWS_EXPORT SingleSplitView : public View { class VIEWS_EXPORT SingleSplitView : public View {
public: public:
enum Orientation { enum Orientation {
...@@ -23,24 +25,12 @@ class VIEWS_EXPORT SingleSplitView : public View { ...@@ -23,24 +25,12 @@ class VIEWS_EXPORT SingleSplitView : public View {
VERTICAL_SPLIT VERTICAL_SPLIT
}; };
// Internal class name
static const char kViewClassName[]; static const char kViewClassName[];
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, SingleSplitView(View* leading,
View* trailing, View* trailing,
Orientation orientation, Orientation orientation,
Observer* observer); SingleSplitViewListener* listener);
virtual void Layout() OVERRIDE; virtual void Layout() OVERRIDE;
virtual std::string GetClassName() const OVERRIDE; virtual std::string GetClassName() const OVERRIDE;
...@@ -95,10 +85,9 @@ class VIEWS_EXPORT SingleSplitView : public View { ...@@ -95,10 +85,9 @@ class VIEWS_EXPORT SingleSplitView : public View {
// Calculates the new |divider_offset| based on the changes of split view // Calculates the new |divider_offset| based on the changes of split view
// bounds. // bounds.
int CalculateDividerOffset( int CalculateDividerOffset(int divider_offset,
int divider_offset, const gfx::Rect& previous_bounds,
const gfx::Rect& previous_bounds, const gfx::Rect& new_bounds) const;
const gfx::Rect& new_bounds) const;
// Returns divider offset within primary axis size range for given split // Returns divider offset within primary axis size range for given split
// view |bounds|. // view |bounds|.
...@@ -131,8 +120,8 @@ class VIEWS_EXPORT SingleSplitView : public View { ...@@ -131,8 +120,8 @@ class VIEWS_EXPORT SingleSplitView : public View {
bool resize_leading_on_bounds_change_; bool resize_leading_on_bounds_change_;
// Observer to notify about user initiated handle movements. Not own by us. // Listener to notify about user initiated handle movements. Not owned.
Observer* observer_; SingleSplitViewListener* listener_;
// The accessible name of this view. // The accessible name of this view.
string16 accessible_name_; string16 accessible_name_;
......
// Copyright (c) 2011 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 VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_LISTENER_H_
#define VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_LISTENER_H_
#pragma once
namespace views {
class SingleSplitView;
// An interface implemented by objects that want to be notified when the
// splitter moves.
class SingleSplitViewListener {
public:
// Invoked when split handle is moved by the user. |sender|'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 listener, returns
// true if |sender| should do it by itself.
virtual bool SplitHandleMoved(SingleSplitView* sender) = 0;
protected:
virtual ~SingleSplitViewListener() {}
};
} // namespace views
#endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_LISTENER_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "views/controls/single_split_view.h" #include "views/controls/single_split_view.h"
#include "views/controls/single_split_view_listener.h"
using ::testing::_; using ::testing::_;
using ::testing::Return; using ::testing::Return;
...@@ -43,7 +44,7 @@ static void VerifySplitViewLayout(const views::SingleSplitView& split) { ...@@ -43,7 +44,7 @@ static void VerifySplitViewLayout(const views::SingleSplitView& split) {
} }
} }
class MockObserver : public views::SingleSplitView::Observer { class MockObserver : public views::SingleSplitViewListener {
public: public:
MOCK_METHOD1(SplitHandleMoved, bool(views::SingleSplitView*)); MOCK_METHOD1(SplitHandleMoved, bool(views::SingleSplitView*));
}; };
......
...@@ -207,6 +207,7 @@ ...@@ -207,6 +207,7 @@
'controls/separator.h', 'controls/separator.h',
'controls/single_split_view.cc', 'controls/single_split_view.cc',
'controls/single_split_view.h', 'controls/single_split_view.h',
'controls/single_split_view_listener.h',
'controls/tabbed_pane/native_tabbed_pane_gtk.cc', 'controls/tabbed_pane/native_tabbed_pane_gtk.cc',
'controls/tabbed_pane/native_tabbed_pane_gtk.h', 'controls/tabbed_pane/native_tabbed_pane_gtk.h',
'controls/tabbed_pane/native_tabbed_pane_win.cc', 'controls/tabbed_pane/native_tabbed_pane_win.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment