diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 16:40:15 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 16:40:15 +0000 |
commit | 8979ccea27f79faf5bee441547600a95c8eedce4 (patch) | |
tree | d1556a6cc2e31d737cffe079508e75a98c03a64c /chrome | |
parent | 0e76c9c9a560fd966c8f06719331179502a350ce (diff) | |
download | chromium_src-8979ccea27f79faf5bee441547600a95c8eedce4.zip chromium_src-8979ccea27f79faf5bee441547600a95c8eedce4.tar.gz chromium_src-8979ccea27f79faf5bee441547600a95c8eedce4.tar.bz2 |
Improves responsiveness when rapdily clicking to close tabs. If the
tab is already closing it's possible for the tab to no longer contain
the coordinates of the release event. I've changed it so that if the
tab is closing and the tab doesn't contain the mouse on the release
event we see if another tab does and if so close it.
BUG=48209
TEST=none
Review URL: http://codereview.chromium.org/2841038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/view_id_util_browsertest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/view_ids.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/tabs/base_tab.cc | 18 | ||||
-rw-r--r-- | chrome/browser/views/tabs/base_tab_strip.cc | 17 | ||||
-rw-r--r-- | chrome/browser/views/tabs/base_tab_strip.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_controller.h | 5 |
6 files changed, 45 insertions, 3 deletions
diff --git a/chrome/browser/gtk/view_id_util_browsertest.cc b/chrome/browser/gtk/view_id_util_browsertest.cc index c7a4aae..b647900 100644 --- a/chrome/browser/gtk/view_id_util_browsertest.cc +++ b/chrome/browser/gtk/view_id_util_browsertest.cc @@ -41,7 +41,8 @@ IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) { if (i == VIEW_ID_CONTENTS_SPLIT || i == VIEW_ID_INFO_BAR_CONTAINER || i == VIEW_ID_DOWNLOAD_SHELF || - i == VIEW_ID_BOOKMARK_BAR_ELEMENT) { + i == VIEW_ID_BOOKMARK_BAR_ELEMENT || + i == VIEW_ID_TAB) { continue; } diff --git a/chrome/browser/view_ids.h b/chrome/browser/view_ids.h index 317c030..639776a 100644 --- a/chrome/browser/view_ids.h +++ b/chrome/browser/view_ids.h @@ -27,6 +27,9 @@ enum ViewID { VIEW_ID_TAB_9, VIEW_ID_TAB_LAST, + // ID for any tab. Currently only used on views. + VIEW_ID_TAB, + VIEW_ID_EXTENSION_APP_ICON, VIEW_ID_EXTENSION_APP_TITLE, VIEW_ID_TAB_STRIP, diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc index 5441379..06c3321 100644 --- a/chrome/browser/views/tabs/base_tab.cc +++ b/chrome/browser/views/tabs/base_tab.cc @@ -16,6 +16,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/tabs/tab_controller.h" +#include "chrome/browser/view_ids.h" #include "chrome/common/chrome_switches.h" #include "gfx/canvas_skia.h" #include "gfx/favicon_size.h" @@ -150,6 +151,8 @@ BaseTab::BaseTab(TabController* controller) should_display_crashed_favicon_(false) { BaseTab::InitResources(); + SetID(VIEW_ID_TAB); + // Add the Close Button. TabCloseButton* close_button = new TabCloseButton(this); close_button_ = close_button; @@ -284,8 +287,19 @@ void BaseTab::OnMouseReleased(const views::MouseEvent& event, bool canceled) { // Close tab on middle click, but only if the button is released over the tab // (normal windows behavior is to discard presses of a UI element where the // releases happen off the element). - if (event.IsMiddleMouseButton() && HitTest(event.location())) - controller()->CloseTab(this); + if (event.IsMiddleMouseButton()) { + if (HitTest(event.location())) { + controller()->CloseTab(this); + } else if (closing_) { + // We're animating closed and a middle mouse button was pushed on us but + // we don't contain the mouse anymore. We assume the user is clicking + // quicker than the animation and we should close the tab that falls under + // the mouse. + BaseTab* closest_tab = controller()->GetTabAt(this, event.location()); + if (closest_tab) + controller()->CloseTab(closest_tab); + } + } } bool BaseTab::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { diff --git a/chrome/browser/views/tabs/base_tab_strip.cc b/chrome/browser/views/tabs/base_tab_strip.cc index 316f038..4e95535 100644 --- a/chrome/browser/views/tabs/base_tab_strip.cc +++ b/chrome/browser/views/tabs/base_tab_strip.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/tabs/base_tab_strip.h" #include "base/logging.h" +#include "chrome/browser/view_ids.h" #include "chrome/browser/views/tabs/dragged_tab_controller.h" #include "chrome/browser/views/tabs/tab_strip_controller.h" #include "views/widget/root_view.h" @@ -308,6 +309,22 @@ bool BaseTabStrip::EndDrag(bool canceled) { return started_drag; } +BaseTab* BaseTabStrip::GetTabAt(BaseTab* tab, + const gfx::Point& tab_in_tab_coordinates) { + gfx::Point local_point = tab_in_tab_coordinates; + ConvertPointToView(tab, this, &local_point); + views::View* view = GetViewForPoint(local_point); + if (!view) + return NULL; // No tab contains the point. + + // Walk up the view hierarchy until we find a tab, or the TabStrip. + while (view && view != this && view->GetID() != VIEW_ID_TAB) + view = view->GetParent(); + + return view && view->GetID() == VIEW_ID_TAB ? + static_cast<BaseTab*>(view) : NULL; +} + void BaseTabStrip::Layout() { StopAnimating(false); diff --git a/chrome/browser/views/tabs/base_tab_strip.h b/chrome/browser/views/tabs/base_tab_strip.h index ece3321..8751266 100644 --- a/chrome/browser/views/tabs/base_tab_strip.h +++ b/chrome/browser/views/tabs/base_tab_strip.h @@ -149,6 +149,8 @@ class BaseTabStrip : public views::View, const views::MouseEvent& event); virtual void ContinueDrag(const views::MouseEvent& event); virtual bool EndDrag(bool canceled); + virtual BaseTab* GetTabAt(BaseTab* tab, + const gfx::Point& tab_in_tab_coordinates); // View overrides: virtual void Layout(); diff --git a/chrome/browser/views/tabs/tab_controller.h b/chrome/browser/views/tabs/tab_controller.h index 937d3be..e5ff26d 100644 --- a/chrome/browser/views/tabs/tab_controller.h +++ b/chrome/browser/views/tabs/tab_controller.h @@ -43,6 +43,11 @@ class TabController { // destroyed. virtual bool EndDrag(bool canceled) = 0; + // Returns the tab that contains the specified coordinates, in terms of |tab|, + // or NULL if there is no tab that contains the specified point. + virtual BaseTab* GetTabAt(BaseTab* tab, + const gfx::Point& tab_in_tab_coordinates) = 0; + protected: virtual ~TabController() {} }; |