summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-14 22:55:00 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-14 22:55:00 +0000
commitcfc61ce86192b2514061bff965770d00feedfdf0 (patch)
treee90a563b3af56d02040527b9a53e7e049ae4e520 /chrome/browser
parenta9f3bf6312aba4689d8b60bd13069b281453e6e1 (diff)
downloadchromium_src-cfc61ce86192b2514061bff965770d00feedfdf0.zip
chromium_src-cfc61ce86192b2514061bff965770d00feedfdf0.tar.gz
chromium_src-cfc61ce86192b2514061bff965770d00feedfdf0.tar.bz2
Hit test zone for the new tab button should follow its visible shape.
B=2270 Review URL: http://codereview.chromium.org/2843 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/tabs/tab_strip.cc58
1 files changed, 57 insertions, 1 deletions
diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc
index 1bafdca..748b9e7 100644
--- a/chrome/browser/views/tabs/tab_strip.cc
+++ b/chrome/browser/views/tabs/tab_strip.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/web_contents.h"
#include "chrome/common/drag_drop_types.h"
#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/gfx/path.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/os_exchange_data.h"
#include "chrome/common/pref_names.h"
@@ -55,6 +56,49 @@ static inline int Round(double x) {
}
///////////////////////////////////////////////////////////////////////////////
+// NewTabButton
+//
+// A subclass of button that hit-tests to the shape of the new tab button.
+
+class NewTabButton : public ChromeViews::Button {
+ public:
+ NewTabButton() {}
+ virtual ~NewTabButton() {}
+
+ protected:
+ // Overridden from ChromeViews::View:
+ virtual bool HitTest(const CPoint &l) const {
+ gfx::Path path;
+ MakePathForButton(&path);
+ ScopedHRGN rgn(path.CreateHRGN());
+ return !!PtInRegion(rgn, l.x, l.y);
+ }
+
+ private:
+ void MakePathForButton(gfx::Path* path) const {
+ DCHECK(path);
+
+ SkScalar h = SkIntToScalar(GetHeight());
+ SkScalar w = SkIntToScalar(GetWidth());
+
+ // These values are defined by the shape of the new tab bitmap. Should that
+ // bitmap ever change, these values will need to be updated. They're so
+ // custom it's not really worth defining constants for.
+ path->moveTo(0, 1);
+ path->lineTo(w - 7, 1);
+ path->lineTo(w - 4, 4);
+ path->lineTo(w, 16);
+ path->lineTo(w - 1, 17);
+ path->lineTo(7, 17);
+ path->lineTo(4, 13);
+ path->lineTo(0, 1);
+ path->close();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(NewTabButton);
+};
+
+///////////////////////////////////////////////////////////////////////////////
//
// TabAnimation
//
@@ -500,6 +544,18 @@ bool TabStrip::PointIsWithinWindowCaption(const CPoint& point) {
if (v->GetClassName() == Tab::kTabClassName && !HasAvailableDragActions())
return true;
+ // Check to see if the point is within the non-button parts of the new tab
+ // button. The button has a non-rectangular shape, so if it's not in the
+ // visual portions of the button we treat it as a click to the caption.
+ CRect bounds;
+ newtab_button_->GetBounds(&bounds);
+ CPoint point_in_newtab_coords(point);
+ View::ConvertPointToView(this, newtab_button_, &point_in_newtab_coords);
+ if (bounds.PtInRect(point) &&
+ !newtab_button_->HitTest(point_in_newtab_coords)) {
+ return true;
+ }
+
// All other regions, including the new Tab button, should be considered part
// of the containing Window's client area so that regular events can be
// processed for them.
@@ -1053,7 +1109,7 @@ void TabStrip::DidProcessMessage(const MSG& msg) {
void TabStrip::Init() {
model_->AddObserver(this);
- newtab_button_ = new ChromeViews::Button;
+ newtab_button_ = new NewTabButton;
newtab_button_->SetListener(this, TabStripModel::kNoTab);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
SkBitmap* bitmap;