diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-03 21:26:41 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-03 21:26:41 +0000 |
commit | dda9db85dfd14a0424d1da962ee2fd88e6de4e8b (patch) | |
tree | 0d127171a0f9382e5844087d81b2302b9bb0674a /chrome | |
parent | 781a29f287deb3a2df33885e061e780ce0086504 (diff) | |
download | chromium_src-dda9db85dfd14a0424d1da962ee2fd88e6de4e8b.zip chromium_src-dda9db85dfd14a0424d1da962ee2fd88e6de4e8b.tar.gz chromium_src-dda9db85dfd14a0424d1da962ee2fd88e6de4e8b.tar.bz2 |
Create a well-defined region that closely matches the shape of the tab to use for hit testing in the Linux tabstrip.
Review URL: http://codereview.chromium.org/62013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/tabs/tab_gtk.cc | 52 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_gtk.h | 11 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.h | 3 |
4 files changed, 35 insertions, 36 deletions
diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index bd555f4..3cd6869 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -26,6 +26,13 @@ TabGtk::TabGtk(TabDelegate* delegate) TabGtk::~TabGtk() { } +bool TabGtk::IsPointInBounds(const gfx::Point& point) { + GdkRegion* region = MakeRegionForTab(); + bool in_bounds = (gdk_region_point_in(region, point.x(), point.y()) == TRUE); + gdk_region_destroy(region); + return in_bounds; +} + /////////////////////////////////////////////////////////////////////////////// // TabGtk, TabRendererGtk overrides: @@ -36,28 +43,25 @@ bool TabGtk::IsSelected() const { /////////////////////////////////////////////////////////////////////////////// // TabGtk, private: -void TabGtk::MakePathForTab(gfx::Path* path) const { - DCHECK(path); - - SkScalar h = SkIntToScalar(height()); - SkScalar w = SkIntToScalar(width()); - - path->moveTo(0, h); - - // Left end cap. - path->lineTo(kTabBottomCurveWidth, h - kTabBottomCurveWidth); - path->lineTo(kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth); - path->lineTo(kTabCapWidth, 0); - - // Connect to the right cap. - path->lineTo(w - kTabCapWidth, 0); - - // Right end cap. - path->lineTo(w - kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth); - path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth); - path->lineTo(w, h); - - // Close out the path. - path->lineTo(0, h); - path->close(); +GdkRegion* TabGtk::MakeRegionForTab()const { + int w = width(); + int h = height(); + static const int kNumRegionPoints = 9; + + GdkPoint polygon[kNumRegionPoints] = { + { 0, h }, + { kTabBottomCurveWidth, h - kTabBottomCurveWidth }, + { kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth }, + { kTabCapWidth, 0 }, + { w - kTabCapWidth, 0 }, + { w - kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth }, + { w - kTabBottomCurveWidth, h - kTabBottomCurveWidth }, + { w, h }, + { 0, h }, + }; + + GdkRegion* region = gdk_region_polygon(polygon, kNumRegionPoints, + GDK_WINDING_RULE); + gdk_region_offset(region, x(), y()); + return region; } diff --git a/chrome/browser/gtk/tabs/tab_gtk.h b/chrome/browser/gtk/tabs/tab_gtk.h index 6dda29c..c63e046 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.h +++ b/chrome/browser/gtk/tabs/tab_gtk.h @@ -68,13 +68,16 @@ class TabGtk : public TabRendererGtk { void set_closing(bool closing) { closing_ = closing; } bool closing() const { return closing_; } - // TabRenderer overrides: + // Checks whether |point| is inside the bounds of the tab. + bool IsPointInBounds(const gfx::Point& point); + + // TabRendererGtk overrides: virtual bool IsSelected() const; private: - // Creates a path that contains the clickable region of the tab's visual - // representation. Used by GetViewForPoint for hit-testing. - void MakePathForTab(gfx::Path* path) const; + // Creates a clickable region of the tab's visual representation. Used for + // hit-testing. Caller is responsible for destroying the region. + GdkRegion* MakeRegionForTab() const; // An instance of a delegate object that can perform various actions based on // user gestures. diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 14e20ae..958dadd 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -186,11 +186,6 @@ void TabRendererGtk::SetBounds(const gfx::Rect& bounds) { Layout(); } -bool TabRendererGtk::IsPointInBounds(const gfx::Point& coord) { - // TODO(jhawkins): Use a GdkRegion that better maps to the shape of the tab. - return bounds_.Contains(coord); -} - //////////////////////////////////////////////////////////////////////////////// // TabRendererGtk, protected: diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index 27dd00b..ce03cad 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -59,9 +59,6 @@ class TabRendererGtk { // Paints the tab into |canvas|. void Paint(ChromeCanvasPaint* canvas); - // Checks whether |coord| is inside the bounds of the tab. - bool IsPointInBounds(const gfx::Point& coord); - // Sets the hovering status of the tab. void SetHovering(bool hovering) { hovering_ = hovering; } |