summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/tabs
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/tabs')
-rw-r--r--chrome/browser/views/tabs/base_tab.cc18
-rw-r--r--chrome/browser/views/tabs/base_tab_strip.cc17
-rw-r--r--chrome/browser/views/tabs/base_tab_strip.h2
-rw-r--r--chrome/browser/views/tabs/tab_controller.h5
4 files changed, 40 insertions, 2 deletions
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() {}
};