summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortdanderson@chromium.org <tdanderson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 01:00:10 +0000
committertdanderson@chromium.org <tdanderson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 01:00:10 +0000
commit2e6db30dd6e75716c8f68ec47f7bbcd9985da442 (patch)
tree9946a33eac72e438ab4f15323a94a1660d8c0c45
parent5f41cb5074d900a8332fd72db387e1d48f92f8f3 (diff)
downloadchromium_src-2e6db30dd6e75716c8f68ec47f7bbcd9985da442.zip
chromium_src-2e6db30dd6e75716c8f68ec47f7bbcd9985da442.tar.gz
chromium_src-2e6db30dd6e75716c8f68ec47f7bbcd9985da442.tar.bz2
Remove remaining overrides of View::HitTestRect()
Remove the remaining overrides of View::HitTestRect() and instead implement View::ViewTargeterDelegate::DoesIntersectRect(). Make View::HitTestRect() non-virtual. BUG=388838 TEST=none Review URL: https://codereview.chromium.org/380813003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283312 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/frame/custom_frame_view_ash.cc39
-rw-r--r--ash/frame/custom_frame_view_ash.h9
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc56
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h13
-rw-r--r--chrome/browser/ui/views/frame/glass_browser_frame_view.cc21
-rw-r--r--chrome/browser/ui/views/frame/glass_browser_frame_view.h13
-rw-r--r--chrome/browser/ui/views/frame/opaque_browser_frame_view.cc85
-rw-r--r--chrome/browser/ui/views/frame/opaque_browser_frame_view.h19
-rw-r--r--chrome/browser/ui/views/profiles/avatar_menu_button.cc16
-rw-r--r--chrome/browser/ui/views/profiles/avatar_menu_button.h9
-rw-r--r--chrome/browser/ui/views/toolbar/toolbar_view.cc28
-rw-r--r--chrome/browser/ui/views/toolbar/toolbar_view.h30
-rw-r--r--ui/views/view.cc2
-rw-r--r--ui/views/view.h10
-rw-r--r--ui/views/window/non_client_view.cc22
-rw-r--r--ui/views/window/non_client_view.h11
16 files changed, 227 insertions, 156 deletions
diff --git a/ash/frame/custom_frame_view_ash.cc b/ash/frame/custom_frame_view_ash.cc
index 3aa503c..60e1a02 100644
--- a/ash/frame/custom_frame_view_ash.cc
+++ b/ash/frame/custom_frame_view_ash.cc
@@ -31,6 +31,7 @@
#include "ui/gfx/size.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"
+#include "ui/views/view_targeter.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -349,16 +350,20 @@ CustomFrameViewAsh::HeaderView::GetVisibleBoundsInScreen() const {
// View which takes up the entire widget and contains the HeaderView. HeaderView
// is a child of OverlayView to avoid creating a larger texture than necessary
// when painting the HeaderView to its own layer.
-class CustomFrameViewAsh::OverlayView : public views::View {
+class CustomFrameViewAsh::OverlayView : public views::View,
+ public views::ViewTargeterDelegate {
public:
explicit OverlayView(HeaderView* header_view);
virtual ~OverlayView();
- // views::View override:
+ // views::View:
virtual void Layout() OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
private:
+ // views::ViewTargeterDelegate:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
HeaderView* header_view_;
DISALLOW_COPY_AND_ASSIGN(OverlayView);
@@ -367,6 +372,8 @@ class CustomFrameViewAsh::OverlayView : public views::View {
CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view)
: header_view_(header_view) {
AddChildView(header_view);
+ SetEventTargeter(
+ scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
}
CustomFrameViewAsh::OverlayView::~OverlayView() {
@@ -390,7 +397,13 @@ void CustomFrameViewAsh::OverlayView::Layout() {
}
}
-bool CustomFrameViewAsh::OverlayView::HitTestRect(const gfx::Rect& rect) const {
+///////////////////////////////////////////////////////////////////////////////
+// CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides:
+
+bool CustomFrameViewAsh::OverlayView::DoesIntersectRect(
+ const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
// Grab events in the header view. Return false for other events so that they
// can be handled by the client view.
return header_view_->HitTestRect(rect);
@@ -513,18 +526,15 @@ void CustomFrameViewAsh::SchedulePaintInRect(const gfx::Rect& r) {
}
}
-bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
- // NonClientView hit tests the NonClientFrameView first instead of going in
- // z-order. Return false so that events get to the OverlayView.
- return false;
-}
-
void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from,
bool is_visible) {
if (is_visible)
header_view_->UpdateAvatarIcon();
}
+////////////////////////////////////////////////////////////////////////////////
+// CustomFrameViewAsh, views::ViewTargeterDelegate overrides:
+
views::View* CustomFrameViewAsh::GetHeaderView() {
return header_view_;
}
@@ -536,6 +546,15 @@ const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, private:
+// views::NonClientFrameView:
+bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+ // NonClientView hit tests the NonClientFrameView first instead of going in
+ // z-order. Return false so that events get to the OverlayView.
+ return false;
+}
+
FrameCaptionButtonContainerView* CustomFrameViewAsh::
GetFrameCaptionButtonContainerViewForTest() {
return header_view_->caption_button_container();
diff --git a/ash/frame/custom_frame_view_ash.h b/ash/frame/custom_frame_view_ash.h
index 3706eb1..92d6f61 100644
--- a/ash/frame/custom_frame_view_ash.h
+++ b/ash/frame/custom_frame_view_ash.h
@@ -41,7 +41,7 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView {
void InitImmersiveFullscreenControllerForView(
ImmersiveFullscreenController* immersive_fullscreen_controller);
- // views::NonClientFrameView overrides:
+ // views::NonClientFrameView:
virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const OVERRIDE;
@@ -52,13 +52,12 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView {
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;
- // views::View overrides:
+ // views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
virtual void VisibilityChanged(views::View* starting_from,
bool is_visible) OVERRIDE;
@@ -71,6 +70,10 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView {
class OverlayView;
friend class TestWidgetConstraintsDelegate;
+ // views::NonClientFrameView:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Returns the container for the minimize/maximize/close buttons that is held
// by the HeaderView. Used in testing.
FrameCaptionButtonContainerView* GetFrameCaptionButtonContainerViewForTest();
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
index 947622c..1d42889 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
@@ -296,32 +296,6 @@ const char* BrowserNonClientFrameViewAsh::GetClassName() const {
return kViewClassName;
}
-bool BrowserNonClientFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
- if (!views::View::HitTestRect(rect)) {
- // |rect| is outside BrowserNonClientFrameViewAsh's bounds.
- return false;
- }
-
- TabStrip* tabstrip = browser_view()->tabstrip();
- if (tabstrip && browser_view()->IsTabStripVisible()) {
- // Claim |rect| only if it is above the bottom of the tabstrip in a non-tab
- // portion.
- gfx::RectF rect_in_tabstrip_coords_f(rect);
- View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
- gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
- rect_in_tabstrip_coords_f);
-
- if (rect_in_tabstrip_coords.y() > tabstrip->height())
- return false;
-
- return !tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
- tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
- }
-
- // Claim |rect| if it is above the top of the topmost view in the client area.
- return rect.y() < GetTopInset();
-}
-
void BrowserNonClientFrameViewAsh::GetAccessibleState(
ui::AXViewState* state) {
state->role = ui::AX_ROLE_TITLE_BAR;
@@ -380,6 +354,36 @@ gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() {
///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewAsh, private:
+// views::NonClientFrameView:
+bool BrowserNonClientFrameViewAsh::DoesIntersectRect(
+ const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+ if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) {
+ // |rect| is outside BrowserNonClientFrameViewAsh's bounds.
+ return false;
+ }
+
+ TabStrip* tabstrip = browser_view()->tabstrip();
+ if (tabstrip && browser_view()->IsTabStripVisible()) {
+ // Claim |rect| only if it is above the bottom of the tabstrip in a non-tab
+ // portion.
+ gfx::RectF rect_in_tabstrip_coords_f(rect);
+ View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
+ gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
+ rect_in_tabstrip_coords_f);
+
+ if (rect_in_tabstrip_coords.y() > tabstrip->height())
+ return false;
+
+ return !tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
+ tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
+ }
+
+ // Claim |rect| if it is above the top of the topmost view in the client area.
+ return rect.y() < GetTopInset();
+}
+
int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
return avatar_button() ? kAvatarSideSpacing +
browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing :
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h
index 6b805ea..ef01238 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h
@@ -35,13 +35,13 @@ class BrowserNonClientFrameViewAsh
void Init();
- // BrowserNonClientFrameView overrides:
+ // BrowserNonClientFrameView:
virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
virtual int GetTopInset() const OVERRIDE;
virtual int GetThemeBackgroundXInset() const OVERRIDE;
virtual void UpdateThrobber(bool running) OVERRIDE;
- // views::NonClientFrameView overrides:
+ // views::NonClientFrameView:
virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const OVERRIDE;
@@ -52,11 +52,10 @@ class BrowserNonClientFrameViewAsh
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;
- // views::View overrides:
+ // views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
@@ -64,7 +63,7 @@ class BrowserNonClientFrameViewAsh
virtual void OnMaximizeModeStarted() OVERRIDE;
virtual void OnMaximizeModeEnded() OVERRIDE;
- // Overridden from chrome::TabIconViewModel:
+ // chrome::TabIconViewModel:
virtual bool ShouldTabIconViewAnimate() const OVERRIDE;
virtual gfx::ImageSkia GetFaviconForTabIconView() OVERRIDE;
@@ -77,6 +76,10 @@ class BrowserNonClientFrameViewAsh
FRIEND_TEST_ALL_PREFIXES(BrowserNonClientFrameViewAshTest,
ToggleMaximizeModeRelayout);
+ // views::NonClientFrameView:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Distance between the left edge of the NonClientFrameView and the tab strip.
int GetTabStripLeftInset() const;
diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
index 0813fa3..8d651d8 100644
--- a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
+++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
@@ -273,15 +273,6 @@ void GlassBrowserFrameView::Layout() {
LayoutClientView();
}
-bool GlassBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
- bool hit_avatar_button = avatar_button() &&
- avatar_button()->GetMirroredBounds().Intersects(rect);
- bool hit_new_avatar_button = new_avatar_button() &&
- new_avatar_button()->GetMirroredBounds().Intersects(rect);
- return hit_avatar_button || hit_new_avatar_button ||
- !frame()->client_view()->bounds().Intersects(rect);
-}
-
///////////////////////////////////////////////////////////////////////////////
// GlassBrowserFrameView, views::ButtonListener overrides:
void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
@@ -296,6 +287,18 @@ void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
///////////////////////////////////////////////////////////////////////////////
// GlassBrowserFrameView, private:
+// views::NonClientFrameView:
+bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+ bool hit_avatar_button = avatar_button() &&
+ avatar_button()->GetMirroredBounds().Intersects(rect);
+ bool hit_new_avatar_button = new_avatar_button() &&
+ new_avatar_button()->GetMirroredBounds().Intersects(rect);
+ return hit_avatar_button || hit_new_avatar_button ||
+ !frame()->client_view()->bounds().Intersects(rect);
+}
+
int GlassBrowserFrameView::FrameBorderThickness() const {
return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.h b/chrome/browser/ui/views/frame/glass_browser_frame_view.h
index 0080fd3..5244dd3 100644
--- a/chrome/browser/ui/views/frame/glass_browser_frame_view.h
+++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.h
@@ -22,14 +22,14 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView,
GlassBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
virtual ~GlassBrowserFrameView();
- // Overridden from BrowserNonClientFrameView:
+ // BrowserNonClientFrameView:
virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
virtual int GetTopInset() const OVERRIDE;
virtual int GetThemeBackgroundXInset() const OVERRIDE;
virtual void UpdateThrobber(bool running) OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
- // Overridden from views::NonClientFrameView:
+ // views::NonClientFrameView:
virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const OVERRIDE;
@@ -41,16 +41,19 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView,
virtual void UpdateWindowTitle() OVERRIDE {}
protected:
- // Overridden from views::View:
+ // views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void Layout() OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
- // Overidden from views::ButtonListener:
+ // views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
private:
+ // views::NonClientFrameView:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Returns the thickness of the border that makes up the window frame edges.
// This does not include any client edge.
int FrameBorderThickness() const;
diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
index 77a1562..9e4cdc0 100644
--- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
+++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
@@ -289,47 +289,6 @@ void OpaqueBrowserFrameView::UpdateWindowTitle() {
///////////////////////////////////////////////////////////////////////////////
// OpaqueBrowserFrameView, views::View overrides:
-bool OpaqueBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
- if (!views::View::HitTestRect(rect)) {
- // |rect| is outside OpaqueBrowserFrameView's bounds.
- return false;
- }
-
- // If the rect is outside the bounds of the client area, claim it.
- gfx::RectF rect_in_client_view_coords_f(rect);
- View::ConvertRectToTarget(this, frame()->client_view(),
- &rect_in_client_view_coords_f);
- gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect(
- rect_in_client_view_coords_f);
- if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords))
- return true;
-
- // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in
- // a non-tab portion.
- TabStrip* tabstrip = browser_view()->tabstrip();
- if (!tabstrip || !browser_view()->IsTabStripVisible())
- return false;
-
- gfx::RectF rect_in_tabstrip_coords_f(rect);
- View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
- gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
- rect_in_tabstrip_coords_f);
- if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) {
- // |rect| is below the tabstrip.
- return false;
- }
-
- if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) {
- // Claim |rect| if it is in a non-tab portion of the tabstrip.
- return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
- }
-
- // We claim |rect| because it is above the bottom of the tabstrip, but
- // not in the tabstrip itself. In particular, the avatar label/button is left
- // of the tabstrip and the window controls are right of the tabstrip.
- return true;
-}
-
void OpaqueBrowserFrameView::GetAccessibleState(
ui::AXViewState* state) {
state->role = ui::AX_ROLE_TITLE_BAR;
@@ -521,6 +480,50 @@ void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
///////////////////////////////////////////////////////////////////////////////
// OpaqueBrowserFrameView, private:
+// views::NonClientFrameView:
+bool OpaqueBrowserFrameView::DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+ if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) {
+ // |rect| is outside OpaqueBrowserFrameView's bounds.
+ return false;
+ }
+
+ // If the rect is outside the bounds of the client area, claim it.
+ gfx::RectF rect_in_client_view_coords_f(rect);
+ View::ConvertRectToTarget(this, frame()->client_view(),
+ &rect_in_client_view_coords_f);
+ gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect(
+ rect_in_client_view_coords_f);
+ if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords))
+ return true;
+
+ // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in
+ // a non-tab portion.
+ TabStrip* tabstrip = browser_view()->tabstrip();
+ if (!tabstrip || !browser_view()->IsTabStripVisible())
+ return false;
+
+ gfx::RectF rect_in_tabstrip_coords_f(rect);
+ View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
+ gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
+ rect_in_tabstrip_coords_f);
+ if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) {
+ // |rect| is below the tabstrip.
+ return false;
+ }
+
+ if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) {
+ // Claim |rect| if it is in a non-tab portion of the tabstrip.
+ return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
+ }
+
+ // We claim |rect| because it is above the bottom of the tabstrip, but
+ // not in the tabstrip itself. In particular, the avatar label/button is left
+ // of the tabstrip and the window controls are right of the tabstrip.
+ return true;
+}
+
views::ImageButton* OpaqueBrowserFrameView::InitWindowCaptionButton(
int normal_image_id,
int hot_image_id,
diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view.h b/chrome/browser/ui/views/frame/opaque_browser_frame_view.h
index 8be9445..fe265639 100644
--- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.h
+++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.h
@@ -40,14 +40,14 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
OpaqueBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
virtual ~OpaqueBrowserFrameView();
- // Overridden from BrowserNonClientFrameView:
+ // BrowserNonClientFrameView:
virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
virtual int GetTopInset() const OVERRIDE;
virtual int GetThemeBackgroundXInset() const OVERRIDE;
virtual void UpdateThrobber(bool running) OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
- // Overridden from views::NonClientFrameView:
+ // views::NonClientFrameView:
virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const OVERRIDE;
@@ -58,19 +58,18 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;
- // Overridden from views::View:
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
+ // views::View:
virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
- // Overridden from views::ButtonListener:
+ // views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, const ui::Event& event)
OVERRIDE;
- // Overridden from views::MenuButtonListener:
+ // views::MenuButtonListener:
virtual void OnMenuButtonClicked(views::View* source, const gfx::Point& point)
OVERRIDE;
- // Overridden from chrome::TabIconViewModel:
+ // chrome::TabIconViewModel:
virtual bool ShouldTabIconViewAnimate() const OVERRIDE;
virtual gfx::ImageSkia GetFaviconForTabIconView() OVERRIDE;
@@ -103,10 +102,14 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
views::ImageButton* restore_button() const { return restore_button_; }
views::ImageButton* close_button() const { return close_button_; }
- // Overridden from views::View:
+ // views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
private:
+ // views::NonClientFrameView:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Creates, adds and returns a new image button with |this| as its listener.
// Memory is owned by the caller.
views::ImageButton* InitWindowCaptionButton(int normal_image_id,
diff --git a/chrome/browser/ui/views/profiles/avatar_menu_button.cc b/chrome/browser/ui/views/profiles/avatar_menu_button.cc
index 046095f..3c3deb1 100644
--- a/chrome/browser/ui/views/profiles/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_menu_button.cc
@@ -20,6 +20,7 @@
#include "components/signin/core/common/profile_management_switches.h"
#include "content/public/browser/notification_service.h"
#include "ui/gfx/canvas.h"
+#include "ui/views/view_targeter.h"
#include "ui/views/widget/widget.h"
static inline int Round(double x) {
@@ -38,6 +39,9 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled)
button_on_right_(false) {
// In RTL mode, the avatar icon should be looking the opposite direction.
EnableCanvasFlippingForRTLUI(true);
+
+ SetEventTargeter(
+ scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
}
AvatarMenuButton::~AvatarMenuButton() {
@@ -78,10 +82,6 @@ void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false);
}
-bool AvatarMenuButton::HitTestRect(const gfx::Rect& rect) const {
- return !disabled_ && views::MenuButton::HitTestRect(rect);
-}
-
void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon,
bool is_rectangle) {
icon_.reset(new gfx::Image(icon));
@@ -90,6 +90,14 @@ void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon,
SchedulePaint();
}
+// views::ViewTargeterDelegate:
+bool AvatarMenuButton::DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+ return !disabled_ &&
+ views::ViewTargeterDelegate::DoesIntersectRect(target, rect);
+}
+
// views::MenuButtonListener implementation
void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
const gfx::Point& point) {
diff --git a/chrome/browser/ui/views/profiles/avatar_menu_button.h b/chrome/browser/ui/views/profiles/avatar_menu_button.h
index 0114297..85086fa 100644
--- a/chrome/browser/ui/views/profiles/avatar_menu_button.h
+++ b/chrome/browser/ui/views/profiles/avatar_menu_button.h
@@ -11,6 +11,7 @@
#include "ui/base/models/simple_menu_model.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/menu_button_listener.h"
+#include "ui/views/view_targeter_delegate.h"
namespace gfx {
class Canvas;
@@ -24,7 +25,8 @@ class Browser;
// The button can optionally have a menu attached to it.
class AvatarMenuButton : public views::MenuButton,
- public views::MenuButtonListener {
+ public views::MenuButtonListener,
+ public views::ViewTargeterDelegate {
public:
// Internal class name.
static const char kViewClassName[];
@@ -38,7 +40,6 @@ class AvatarMenuButton : public views::MenuButton,
// views::MenuButton:
virtual const char* GetClassName() const OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
// Sets the image for the avatar button. Rectangular images, as opposed
// to Chrome avatar icons, will be resized and modified for the title bar.
@@ -50,6 +51,10 @@ class AvatarMenuButton : public views::MenuButton,
bool button_on_right() { return button_on_right_; }
private:
+ // views::ViewTargeterDelegate:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// views::MenuButtonListener:
virtual void OnMenuButtonClicked(views::View* source,
const gfx::Point& point) OVERRIDE;
diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.cc b/chrome/browser/ui/views/toolbar/toolbar_view.cc
index 107005e..e9aacdf 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc
@@ -67,6 +67,7 @@
#include "ui/native_theme/native_theme_aura.h"
#include "ui/views/controls/menu/menu_listener.h"
#include "ui/views/focus/view_storage.h"
+#include "ui/views/view_targeter.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"
@@ -140,6 +141,9 @@ ToolbarView::ToolbarView(Browser* browser)
this)) {
set_id(VIEW_ID_TOOLBAR);
+ SetEventTargeter(
+ scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
+
chrome::AddCommandObserver(browser_, IDC_BACK, this);
chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
chrome::AddCommandObserver(browser_, IDC_RELOAD, this);
@@ -632,16 +636,6 @@ void ToolbarView::Layout() {
app_menu_->SetBounds(next_element_x, child_y, app_menu_width, child_height);
}
-bool ToolbarView::HitTestRect(const gfx::Rect& rect) const {
- // Fall through to the tab strip above us if none of |rect| intersects
- // with this view (intersection with the top shadow edge does not
- // count as intersection with this view).
- if (rect.bottom() < content_shadow_height())
- return false;
- // Otherwise let our superclass take care of it.
- return AccessiblePaneView::HitTestRect(rect);
-}
-
void ToolbarView::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas);
@@ -706,6 +700,20 @@ void ToolbarView::RemovePaneFocus() {
////////////////////////////////////////////////////////////////////////////////
// ToolbarView, private:
+// views::ViewTargeterDelegate:
+bool ToolbarView::DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+
+ // Fall through to the tab strip above us if none of |rect| intersects
+ // with this view (intersection with the top shadow edge does not
+ // count as intersection with this view).
+ if (rect.bottom() < content_shadow_height())
+ return false;
+ // Otherwise let our superclass take care of it.
+ return ViewTargeterDelegate::DoesIntersectRect(this, rect);
+}
+
bool ToolbarView::ShouldShowUpgradeRecommended() {
#if defined(OS_CHROMEOS)
// In chromeos, the update recommendation is shown in the system tray. So it
diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.h b/chrome/browser/ui/views/toolbar/toolbar_view.h
index d841465..d634a7b 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_view.h
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.h
@@ -48,7 +48,8 @@ class ToolbarView : public views::AccessiblePaneView,
public content::NotificationObserver,
public CommandObserver,
public views::ButtonListener,
- public views::WidgetObserver {
+ public views::WidgetObserver,
+ public views::ViewTargeterDelegate {
public:
// The view class name.
static const char kViewClassName[];
@@ -97,7 +98,7 @@ class ToolbarView : public views::AccessiblePaneView,
// Shows the extension's browser action, if present.
void ShowBrowserActionPopup(const extensions::Extension* extension);
- // Accessors...
+ // Accessors.
Browser* browser() const { return browser_; }
BrowserActionsContainer* browser_actions() const { return browser_actions_; }
ReloadButton* reload_button() const { return reload_; }
@@ -105,15 +106,15 @@ class ToolbarView : public views::AccessiblePaneView,
views::MenuButton* app_menu() const;
HomeButton* home_button() const { return home_; }
- // Overridden from AccessiblePaneView
+ // AccessiblePaneView:
virtual bool SetPaneFocus(View* initial_focus) OVERRIDE;
virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
- // Overridden from views::MenuButtonListener:
+ // views::MenuButtonListener:
virtual void OnMenuButtonClicked(views::View* source,
const gfx::Point& point) OVERRIDE;
- // Overridden from LocationBarView::Delegate:
+ // LocationBarView::Delegate:
virtual content::WebContents* GetWebContents() OVERRIDE;
virtual ToolbarModel* GetToolbarModel() OVERRIDE;
virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
@@ -128,31 +129,30 @@ class ToolbarView : public views::AccessiblePaneView,
const GURL& url,
const content::SSLStatus& ssl) OVERRIDE;
- // Overridden from CommandObserver:
+ // CommandObserver:
virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
- // Overridden from views::ButtonListener:
+ // views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
- // Overridden from views::WidgetObserver:
+ // views::WidgetObserver:
virtual void OnWidgetVisibilityChanged(views::Widget* widget,
bool visible) OVERRIDE;
- // Overridden from content::NotificationObserver:
+ // content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // Overridden from ui::AcceleratorProvider:
+ // ui::AcceleratorProvider:
virtual bool GetAcceleratorForCommandId(
int command_id, ui::Accelerator* accelerator) OVERRIDE;
- // Overridden from views::View:
+ // views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual void Layout() OVERRIDE;
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnThemeChanged() OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
@@ -176,7 +176,7 @@ class ToolbarView : public views::AccessiblePaneView,
};
protected:
- // Overridden from AccessiblePaneView
+ // AccessiblePaneView:
virtual bool SetPaneFocusAndFocusDefault() OVERRIDE;
virtual void RemovePaneFocus() OVERRIDE;
@@ -188,6 +188,10 @@ class ToolbarView : public views::AccessiblePaneView,
// bar, used for popups.
};
+ // views::ViewTargeterDelegate:
+ virtual bool DoesIntersectRect(const views::View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Returns true if we should show the upgrade recommended dot.
bool ShouldShowUpgradeRecommended();
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 0f57d89..2961ed7 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -948,8 +948,6 @@ bool View::HitTestPoint(const gfx::Point& point) const {
}
bool View::HitTestRect(const gfx::Rect& rect) const {
- // If no ViewTargeter is installed on |this|, use the ViewTargeter installed
- // on our root view instead.
ViewTargeter* view_targeter = targeter();
if (!view_targeter)
view_targeter = GetWidget()->GetRootView()->targeter();
diff --git a/ui/views/view.h b/ui/views/view.h
index 1bdee37..510a6ba 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -577,16 +577,14 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// the cursor is a shared resource.
virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event);
- // TODO(tdanderson): HitTestPoint() and HitTestRect() will be removed once
- // their logic is moved into ViewTargeter and its
- // derived classes. See crbug.com/355425.
-
// A convenience function which calls HitTestRect() with a rect of size
// 1x1 and an origin of |point|.
bool HitTestPoint(const gfx::Point& point) const;
- // Tests whether |rect| intersects this view's bounds.
- virtual bool HitTestRect(const gfx::Rect& rect) const;
+ // Tests whether |rect| intersects this view's bounds using the ViewTargeter
+ // installed on |this|. If there is no ViewTargeter installed on |this|, the
+ // ViewTargeter installed on the root view is used instead.
+ bool HitTestRect(const gfx::Rect& rect) const;
// Returns true if this view or any of its descendants are permitted to
// be the target of an event.
diff --git a/ui/views/window/non_client_view.cc b/ui/views/window/non_client_view.cc
index e4068db..43b2e70 100644
--- a/ui/views/window/non_client_view.cc
+++ b/ui/views/window/non_client_view.cc
@@ -8,6 +8,7 @@
#include "ui/base/hit_test.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/views/rect_based_targeting_utils.h"
+#include "ui/views/view_targeter.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"
@@ -301,15 +302,6 @@ int NonClientFrameView::GetHTComponentForFrame(const gfx::Point& point,
}
////////////////////////////////////////////////////////////////////////////////
-// NonClientFrameView, View overrides:
-
-bool NonClientFrameView::HitTestRect(const gfx::Rect& rect) const {
- // For the default case, we assume the non-client frame view never overlaps
- // the client view.
- return !GetWidget()->client_view()->bounds().Intersects(rect);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// NonClientFrameView, protected:
void NonClientFrameView::GetAccessibleState(ui::AXViewState* state) {
@@ -326,6 +318,18 @@ void NonClientFrameView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
}
NonClientFrameView::NonClientFrameView() : inactive_rendering_disabled_(false) {
+ SetEventTargeter(
+ scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
+}
+
+// ViewTargeterDelegate:
+bool NonClientFrameView::DoesIntersectRect(const View* target,
+ const gfx::Rect& rect) const {
+ CHECK_EQ(target, this);
+
+ // For the default case, we assume the non-client frame view never overlaps
+ // the client view.
+ return !GetWidget()->client_view()->bounds().Intersects(rect);
}
} // namespace views
diff --git a/ui/views/window/non_client_view.h b/ui/views/window/non_client_view.h
index 7718142..9466afa 100644
--- a/ui/views/window/non_client_view.h
+++ b/ui/views/window/non_client_view.h
@@ -6,6 +6,7 @@
#define UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
#include "ui/views/view.h"
+#include "ui/views/view_targeter_delegate.h"
namespace gfx {
class Path;
@@ -22,7 +23,8 @@ class ClientView;
// responds to events within the frame portions of the non-client area of a
// window. This view does _not_ contain the ClientView, but rather is a sibling
// of it.
-class VIEWS_EXPORT NonClientFrameView : public View {
+class VIEWS_EXPORT NonClientFrameView : public View,
+ public ViewTargeterDelegate {
public:
// Internal class name.
static const char kViewClassName[];
@@ -78,8 +80,7 @@ class VIEWS_EXPORT NonClientFrameView : public View {
virtual void UpdateWindowIcon() = 0;
virtual void UpdateWindowTitle() = 0;
- // Overridden from View:
- virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
+ // View:
virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
@@ -89,6 +90,10 @@ class VIEWS_EXPORT NonClientFrameView : public View {
NonClientFrameView();
private:
+ // ViewTargeterDelegate:
+ virtual bool DoesIntersectRect(const View* target,
+ const gfx::Rect& rect) const OVERRIDE;
+
// Prevents the non-client frame view from being rendered as inactive when
// true.
bool inactive_rendering_disabled_;