summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 23:45:15 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 23:45:15 +0000
commit137051a0ce6a4ef450ce39bcafd61d1efd0b1682 (patch)
tree30c679b723b5281b4f8d2cdf9b2f7ed0bc9766fe /ui
parent9c1f461f49ba3f0b736537a890aa5bbb4f50d3f3 (diff)
downloadchromium_src-137051a0ce6a4ef450ce39bcafd61d1efd0b1682.zip
chromium_src-137051a0ce6a4ef450ce39bcafd61d1efd0b1682.tar.gz
chromium_src-137051a0ce6a4ef450ce39bcafd61d1efd0b1682.tar.bz2
Reorder methods in class View to better isolate methods that shouldn't be public.
Specifically, move most event handlers and processing functions to protected now that RootView is a friend. BUG=none TEST=compiles, existing unittests Review URL: http://codereview.chromium.org/6286032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/rendering/border_unittest.cc17
-rw-r--r--ui/views/view.cc165
-rw-r--r--ui/views/view.h110
-rw-r--r--ui/views/widget/root_view.cc4
4 files changed, 167 insertions, 129 deletions
diff --git a/ui/views/rendering/border_unittest.cc b/ui/views/rendering/border_unittest.cc
index 52e62bb..507c904 100644
--- a/ui/views/rendering/border_unittest.cc
+++ b/ui/views/rendering/border_unittest.cc
@@ -37,9 +37,22 @@ class TestBorder : public Border {
DISALLOW_COPY_AND_ASSIGN(TestBorder);
};
+class PaintableView : public View {
+ public:
+ PaintableView() {}
+ virtual ~PaintableView() {}
+
+ void CallOnPaintWithNULLCanvas() {
+ OnPaint(NULL);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PaintableView);
+};
+
TEST_F(BorderTest, Basic) {
const int kViewSize = 100;
- View v;
+ PaintableView v;
v.SetBounds(10, 10, kViewSize, kViewSize);
// With no border, the content size is the view size.
@@ -56,7 +69,7 @@ TEST_F(BorderTest, Basic) {
TestBorder* border = new TestBorder;
v.SetBorder(border);
- v.OnPaint(NULL);
+ v.CallOnPaintWithNULLCanvas();
EXPECT_TRUE(border->painted());
}
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 5057afe..f4fe78c 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -273,27 +273,6 @@ bool View::Contains(View* child) {
return false;
}
-View* View::GetViewForPoint(const gfx::Point& point) const {
- ViewVector::const_reverse_iterator it = children_.rbegin();
- for (; it != children_.rend(); ++it) {
- View* child = *it;
- if (!child->visible())
- continue;
-
- gfx::Point point_in_child_coords(point);
- View::ConvertPointToView(const_cast<View*>(this), child,
- &point_in_child_coords);
- if (child->HitTest(point_in_child_coords))
- return child->GetViewForPoint(point_in_child_coords);
- }
- return const_cast<View*>(this);
-}
-
-bool View::HitTest(const gfx::Point& point) const {
- // TODO(beng): Hit test mask support.
- return gfx::Rect(0, 0, width(), height()).Contains(point);
-}
-
View* View::GetViewById(int id) const {
if (id_ == id)
return const_cast<View*>(this);
@@ -314,16 +293,28 @@ void View::GetViewsWithGroup(int group, ViewVector* vec) const {
(*it)->GetViewsWithGroup(group, vec);
}
-void View::OnViewAdded(View* parent, View* child) {
-}
+// Painting --------------------------------------------------------------------
-void View::OnViewRemoved(View* parent, View* child) {
+void View::Invalidate() {
+ InvalidateRect(gfx::Rect(0, 0, width(), height()));
}
-void View::OnViewAddedToWidget() {
+void View::InvalidateRect(const gfx::Rect& invalid_rect) {
+ if (!visible_)
+ return;
+
+ if (parent_) {
+ gfx::Rect r = invalid_rect;
+ r.Offset(bounds_.origin());
+ parent_->InvalidateRect(r);
+ }
}
-void View::OnViewRemovedFromWidget() {
+// Input -----------------------------------------------------------------------
+
+bool View::HitTest(const gfx::Point& point) const {
+ // TODO(beng): Hit test mask support.
+ return gfx::Rect(0, 0, width(), height()).Contains(point);
}
// Accelerators ----------------------------------------------------------------
@@ -337,10 +328,6 @@ void View::RemoveAccelerator(const Accelerator& accelerator) {
void View::RemoveAllAccelerators() {
}
-bool View::OnAcceleratorPressed(const Accelerator& accelerator) {
- return false;
-}
-
// Focus -----------------------------------------------------------------------
FocusManager* View::GetFocusManager() const {
@@ -359,10 +346,6 @@ View* View::GetPreviousFocusableView() const {
return NULL;
}
-bool View::SkipDefaultKeyEventProcessing(const KeyEvent& event) const {
- return false;
-}
-
bool View::IsFocusable() const {
return false;
}
@@ -374,6 +357,42 @@ bool View::HasFocus() const {
void View::RequestFocus() {
}
+// Resources -------------------------------------------------------------------
+
+ThemeProvider* View::GetThemeProvider() const {
+ Widget* widget = GetWidget();
+ return widget ? widget->GetThemeProvider() : NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// View, protected:
+
+// Tree operations -------------------------------------------------------------
+
+void View::OnViewAdded(View* parent, View* child) {
+}
+
+void View::OnViewRemoved(View* parent, View* child) {
+}
+
+void View::OnViewAddedToWidget() {
+}
+
+void View::OnViewRemovedFromWidget() {
+}
+
+// Accelerators ----------------------------------------------------------------
+
+bool View::OnAcceleratorPressed(const Accelerator& accelerator) {
+ return false;
+}
+
+// Focus -----------------------------------------------------------------------
+
+bool View::SkipDefaultKeyEventProcessing(const KeyEvent& event) const {
+ return false;
+}
+
void View::OnFocus(/* const FocusEvent& event */) {
}
@@ -382,6 +401,26 @@ void View::OnBlur() {
// Input -----------------------------------------------------------------------
+View* View::GetEventHandlerForPoint(const gfx::Point& point) const {
+ ViewVector::const_reverse_iterator it = children_.rbegin();
+ for (; it != children_.rend(); ++it) {
+ View* child = *it;
+ if (!child->visible())
+ continue;
+
+ gfx::Point point_in_child_coords(point);
+ View::ConvertPointToView(const_cast<View*>(this), child,
+ &point_in_child_coords);
+ if (child->HitTest(point_in_child_coords))
+ return child->GetEventHandlerForPoint(point_in_child_coords);
+ }
+ return const_cast<View*>(this);
+}
+
+gfx::NativeCursor View::GetCursorForPoint(const gfx::Point& point) {
+ return NULL;
+}
+
bool View::OnKeyPressed(const KeyEvent& event) {
return true;
}
@@ -422,42 +461,8 @@ void View::OnMouseExited(const MouseEvent& event) {
}
-gfx::NativeCursor View::GetCursorForPoint(const gfx::Point& point) {
- return NULL;
-}
-
// Painting --------------------------------------------------------------------
-void View::Invalidate() {
- InvalidateRect(gfx::Rect(0, 0, width(), height()));
-}
-
-void View::InvalidateRect(const gfx::Rect& invalid_rect) {
- if (!visible_)
- return;
-
- if (parent_) {
- gfx::Rect r = invalid_rect;
- r.Offset(bounds_.origin());
- parent_->InvalidateRect(r);
- }
-}
-
-void View::Paint(gfx::Canvas* canvas) {
- // Invisible views are not painted.
- if (!visible_)
- return;
-
- ScopedCanvasState canvas_state(canvas);
- if (canvas->ClipRectInt(x(), y(), width(), height())) {
- canvas->TranslateInt(x(), y());
- // TODO(beng): RTL
- ScopedCanvasState canvas_state(canvas);
- OnPaint(canvas);
- PaintChildren(canvas);
- }
-}
-
void View::PaintChildren(gfx::Canvas* canvas) {
// TODO(beng): use for_each.
// std::for_each(children_.begin(), children_.end(),
@@ -485,13 +490,6 @@ void View::OnPaintBorder(gfx::Canvas* canvas) {
void View::OnPaintFocusBorder(gfx::Canvas* canvas) {
}
-// Resources -------------------------------------------------------------------
-
-ThemeProvider* View::GetThemeProvider() const {
- Widget* widget = GetWidget();
- return widget ? widget->GetThemeProvider() : NULL;
-}
-
////////////////////////////////////////////////////////////////////////////////
// View, private:
@@ -505,6 +503,23 @@ void View::DragInfo::PossibleDrag(const gfx::Point& point) {
press_point = point;
}
+// Painting --------------------------------------------------------------------
+
+void View::Paint(gfx::Canvas* canvas) {
+ // Invisible views are not painted.
+ if (!visible_)
+ return;
+
+ ScopedCanvasState canvas_state(canvas);
+ if (canvas->ClipRectInt(x(), y(), width(), height())) {
+ canvas->TranslateInt(x(), y());
+ // TODO(beng): RTL
+ ScopedCanvasState canvas_state(canvas);
+ OnPaint(canvas);
+ PaintChildren(canvas);
+ }
+}
+
// Drag & Drop -----------------------------------------------------------------
int View::GetDragOperations(const gfx::Point& point) {
diff --git a/ui/views/view.h b/ui/views/view.h
index bcb1451..f5c674532 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -148,20 +148,6 @@ class View {
// an indirect descendant. Will return true if child is also this View.
bool Contains(View* child);
- // Returns the visible View that most closely contains the specified point.
- // |point| is in this View's coordinates.
- // This function is used by the event processing system in the Widget to
- // locate views for event targeting. Override this function if you wish to
- // specify a view other than the one most closely enclosing |point| to receive
- // notifications for events within it.
- // TODO(beng): This is [ab]used primarily for event handling. Should be
- // renamed to something like GetViewForEvent().
- virtual View* GetViewForPoint(const gfx::Point& point) const;
-
- // Returns true if the specified point is contained within this View or its
- // hit test mask. |point| is in this View's coordinates.
- bool HitTest(const gfx::Point& point) const;
-
int id() const { return id_; }
void set_id(int id) { id_ = id; }
int group() const { return group_; }
@@ -175,13 +161,19 @@ class View {
// match the specified group id.
void GetViewsWithGroup(int group, ViewVector* vec) const;
- // Called on every view in the hierarchy when a view is added or removed.
- virtual void OnViewAdded(View* parent, View* child);
- virtual void OnViewRemoved(View* parent, View* child);
+ // Painting ------------------------------------------------------------------
- // Called on a View when it is added or removed from a Widget.
- virtual void OnViewAddedToWidget();
- virtual void OnViewRemovedFromWidget();
+ // Add all or part of a View's bounds to the enclosing Widget's invalid
+ // rectangle. This will result in those areas being re-painted on the next
+ // update.
+ void Invalidate();
+ virtual void InvalidateRect(const gfx::Rect& invalid_rect);
+
+ // Input ---------------------------------------------------------------------
+
+ // Returns true if the specified point is contained within this View or its
+ // hit test mask. |point| is in this View's coordinates.
+ bool HitTest(const gfx::Point& point) const;
// Accelerators --------------------------------------------------------------
@@ -190,8 +182,6 @@ class View {
void RemoveAccelerator(const Accelerator& accelerator);
void RemoveAllAccelerators();
- virtual bool OnAcceleratorPressed(const Accelerator& accelerator);
-
// Focus ---------------------------------------------------------------------
// Manager.
@@ -203,18 +193,56 @@ class View {
View* GetPreviousFocusableView() const;
// Attributes.
- virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) const;
void set_focusable(bool focusable) { focusable_ = focusable; }
bool IsFocusable() const;
bool HasFocus() const;
void RequestFocus();
+ // Context menus -------------------------------------------------------------
+
+ void set_context_menu_controller(
+ ContextMenuController* context_menu_controller) {
+ context_menu_controller_ = context_menu_controller;
+ }
+
+ // Resources -----------------------------------------------------------------
+
+ ThemeProvider* GetThemeProvider() const;
+
+ protected:
+ // Tree operations -----------------------------------------------------------
+
+ // Called on every view in the hierarchy when a view is added or removed.
+ virtual void OnViewAdded(View* parent, View* child);
+ virtual void OnViewRemoved(View* parent, View* child);
+
+ // Called on a View when it is added or removed from a Widget.
+ virtual void OnViewAddedToWidget();
+ virtual void OnViewRemovedFromWidget();
+
+ // Accelerators --------------------------------------------------------------
+
+ virtual bool OnAcceleratorPressed(const Accelerator& accelerator);
+
+ // Focus ---------------------------------------------------------------------
+ virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) const;
+
virtual void OnFocus(/* const FocusEvent& event */);
virtual void OnBlur();
// Input ---------------------------------------------------------------------
+ // Returns the visible View that would like to handle events occurring at the
+ // specified |point|, in this View's coordinates.
+ // This function is used by the event processing system in the Widget to
+ // locate views for event targeting. Override this function if you wish to
+ // specify a view other than the one most closely enclosing |point| to receive
+ // notifications for events within it.
+ virtual View* GetEventHandlerForPoint(const gfx::Point& point) const;
+
+ virtual gfx::NativeCursor GetCursorForPoint(const gfx::Point& point);
+
virtual bool OnKeyPressed(const KeyEvent& event);
virtual bool OnKeyReleased(const KeyEvent& event);
virtual bool OnMouseWheel(const MouseWheelEvent& event);
@@ -228,23 +256,8 @@ class View {
virtual void OnMouseEntered(const MouseEvent& event);
virtual void OnMouseExited(const MouseEvent& event);
- virtual gfx::NativeCursor GetCursorForPoint(const gfx::Point& point);
-
// Painting ------------------------------------------------------------------
- // Add all or part of a View's bounds to the enclosing Widget's invalid
- // rectangle. This will result in those areas being re-painted on the next
- // update.
- void Invalidate();
- virtual void InvalidateRect(const gfx::Rect& invalid_rect);
-
- // Called by the framework to paint a View. Performs translation and clipping
- // for View coordinates and language direction as required, allows the View
- // to paint itself via the various OnPaint*() event handlers and then paints
- // the hierarchy beneath it.
- // TODO(beng): Make private?
- void Paint(gfx::Canvas* canvas);
-
// Responsible for calling Paint() on child Views. Override to control the
// order child Views are painted.
virtual void PaintChildren(gfx::Canvas* canvas);
@@ -266,17 +279,6 @@ class View {
// relevant contents.
virtual void OnPaintFocusBorder(gfx::Canvas* canvas);
- // Context menus -------------------------------------------------------------
-
- void set_context_menu_controller(
- ContextMenuController* context_menu_controller) {
- context_menu_controller_ = context_menu_controller;
- }
-
- // Resources -----------------------------------------------------------------
-
- ThemeProvider* GetThemeProvider() const;
-
private:
friend internal::RootView;
@@ -299,6 +301,14 @@ class View {
gfx::Point press_point;
};
+ // Painting ------------------------------------------------------------------
+
+ // Called by the framework to paint a View. Performs translation and clipping
+ // for View coordinates and language direction as required, allows the View
+ // to paint itself via the various OnPaint*() event handlers and then paints
+ // the hierarchy beneath it.
+ void Paint(gfx::Canvas* canvas);
+
// Drag & Drop ---------------------------------------------------------------
int GetDragOperations(const gfx::Point& point);
void WriteDragData(const gfx::Point& point, OSExchangeData* data);
@@ -316,7 +326,7 @@ class View {
void NotifyHierarchyChanged(View* parent, View* child, bool is_add);
void NotifyHierarchyChangedUp(View* parent, View* child, bool is_add);
void NotifyHierarchyChangedDown(View* parent, View* child, bool is_add,
- bool has_widget);
+ bool has_widget);
void CallViewNotification(View* target,
View* parent,
View* child,
diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc
index 47371cd..6ca3cb3 100644
--- a/ui/views/widget/root_view.cc
+++ b/ui/views/widget/root_view.cc
@@ -49,7 +49,7 @@ bool RootView::OnMousePressed(const MouseEvent& event) {
// Find the most View most tightly enclosing the event location that wants to
// handle events.
- mouse_pressed_handler_ = GetViewForPoint(event.location());
+ mouse_pressed_handler_ = GetEventHandlerForPoint(event.location());
// Walk up the tree from that View until we find one that handles it.
while (mouse_pressed_handler_ && mouse_pressed_handler_ != this) {
@@ -100,7 +100,7 @@ void RootView::OnMouseCaptureLost() {
void RootView::OnMouseMoved(const MouseEvent& event) {
// TODO(beng): Update cursor.
- View* v = GetViewForPoint(event.location());
+ View* v = GetEventHandlerForPoint(event.location());
while (v && !v->enabled() && (v != mouse_move_handler_))
v = v->parent();
if (v && v != this) {