summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 19:20:28 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 19:20:28 +0000
commitafcea9b86d92d41ef6bd761d827c665f8df1b15d (patch)
tree743f28b29bcee1348c4a03e30320e900dd5a2582 /chrome
parente17adb5300aeaf14b2a13333c4bc32487248fea5 (diff)
downloadchromium_src-afcea9b86d92d41ef6bd761d827c665f8df1b15d.zip
chromium_src-afcea9b86d92d41ef6bd761d827c665f8df1b15d.tar.gz
chromium_src-afcea9b86d92d41ef6bd761d827c665f8df1b15d.tar.bz2
touch: Double tap gesture for the tabstrip.
Double-tapping a tab will close it, and double-tapping the empty space in the tabstrip will open a new tab. BUG=none TEST=manually Review URL: http://codereview.chromium.org/6683013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.cc21
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.h3
-rw-r--r--chrome/browser/ui/touch/tabs/touch_tab.h1
-rw-r--r--chrome/browser/ui/touch/tabs/touch_tab_strip.cc68
-rw-r--r--chrome/browser/ui/touch/tabs/touch_tab_strip.h19
-rw-r--r--chrome/browser/ui/views/frame/opaque_browser_frame_view.h4
6 files changed, 93 insertions, 23 deletions
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
index 72e9be2..3f5da66 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
@@ -18,6 +18,7 @@
#include "content/common/notification_type.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/gfx/rect.h"
+#include "views/controls/button/image_button.h"
#include "views/controls/textfield/textfield.h"
namespace {
@@ -174,6 +175,26 @@ TouchBrowserFrameView::VirtualKeyboardType
return NONE;
}
+bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const {
+ if (OpaqueBrowserFrameView::HitTest(point))
+ return true;
+
+ if (close_button()->IsVisible() &&
+ close_button()->GetMirroredBounds().Contains(point))
+ return true;
+ if (restore_button()->IsVisible() &&
+ restore_button()->GetMirroredBounds().Contains(point))
+ return true;
+ if (maximize_button()->IsVisible() &&
+ maximize_button()->GetMirroredBounds().Contains(point))
+ return true;
+ if (minimize_button()->IsVisible() &&
+ minimize_button()->GetMirroredBounds().Contains(point))
+ return true;
+
+ return false;
+}
+
void TouchBrowserFrameView::TabSelectedAt(TabContentsWrapper* old_contents,
TabContentsWrapper* new_contents,
int index,
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
index 5489cbf..7fa8813 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
@@ -56,6 +56,9 @@ class TouchBrowserFrameView : public OpaqueBrowserFrameView,
virtual void UpdateKeyboardAndLayout(bool should_show_keyboard);
virtual VirtualKeyboardType DecideKeyboardStateForView(views::View* view);
+ // Overridden from views::View
+ virtual bool HitTest(const gfx::Point& point) const OVERRIDE;
+
// Overrridden from TabStripModelObserver.
virtual void TabSelectedAt(TabContentsWrapper* old_contents,
TabContentsWrapper* new_contents,
diff --git a/chrome/browser/ui/touch/tabs/touch_tab.h b/chrome/browser/ui/touch/tabs/touch_tab.h
index 614f18e..23d28de 100644
--- a/chrome/browser/ui/touch/tabs/touch_tab.h
+++ b/chrome/browser/ui/touch/tabs/touch_tab.h
@@ -12,7 +12,6 @@
#include "chrome/browser/ui/views/tabs/base_tab.h"
#include "ui/gfx/point.h"
-
///////////////////////////////////////////////////////////////////////////////
//
// TouchTab
diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip.cc b/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
index 8dbaabb..6d49be3 100644
--- a/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
+++ b/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
@@ -6,7 +6,9 @@
#include "chrome/browser/ui/touch/tabs/touch_tab.h"
#include "chrome/browser/ui/view_ids.h"
+#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include "ui/gfx/canvas_skia.h"
+#include "views/metrics.h"
#include "views/window/non_client_view.h"
#include "views/window/window.h"
@@ -16,7 +18,9 @@ static const int kTouchTabHeight = 64;
TouchTabStrip::TouchTabStrip(TabStripController* controller)
: BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP),
- in_tab_close_(false) {
+ in_tab_close_(false),
+ last_tap_time_(base::Time::FromInternalValue(0)),
+ last_tapped_view_(NULL) {
Init();
}
@@ -36,15 +40,7 @@ TouchTabStrip::~TouchTabStrip() {
// TouchTabStrip, AbstractTabStripView implementation:
bool TouchTabStrip::IsPositionInWindowCaption(const gfx::Point& point) {
- views::View* v = GetEventHandlerForPoint(point);
-
- // If there is no control at this location, claim the hit was in the title
- // bar to get a move action.
- if (v == this)
- return true;
-
- // All other regions, should be considered part of the containing Window's
- // client area so that regular events can be processed for them.
+ // The entire tabstrip is mine. No part of it belongs to the window caption.
return false;
}
@@ -152,8 +148,19 @@ int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) {
return 0;
}
+TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const {
+ return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TouchTabStrip, private:
+
+void TouchTabStrip::Init() {
+ SetID(VIEW_ID_TAB_STRIP);
+}
+
////////////////////////////////////////////////////////////////////////////////
-// TouchTabStrip, views::View overrides:
+// TouchTabStrip, views::View overrides, private:
gfx::Size TouchTabStrip::GetPreferredSize() {
return gfx::Size(0, kTouchTabStripHeight);
@@ -198,14 +205,39 @@ void TouchTabStrip::PaintChildren(gfx::Canvas* canvas) {
dragging_tab->Paint(canvas);
}
-TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const {
- return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index));
-}
+views::View::TouchStatus TouchTabStrip::OnTouchEvent(
+ const views::TouchEvent& event) {
+ if (event.type() != ui::ET_TOUCH_PRESSED)
+ return TOUCH_STATUS_UNKNOWN;
-////////////////////////////////////////////////////////////////////////////////
-// TouchTabStrip, private:
+ views::View* view = GetEventHandlerForPoint(event.location());
+ if (view && view != this && view->GetID() != VIEW_ID_TAB)
+ return TOUCH_STATUS_UNKNOWN;
-void TouchTabStrip::Init() {
- SetID(VIEW_ID_TAB_STRIP);
+ base::TimeDelta delta = event.time_stamp() - last_tap_time_;
+
+ if (delta.InMilliseconds() < views::GetDoubleClickInterval() &&
+ view == last_tapped_view_) {
+ // If double tapped the empty space, open a new tab. If double tapped a tab,
+ // close it.
+ if (view == this)
+ controller()->CreateNewTab();
+ else
+ CloseTab(static_cast<BaseTab*>(view));
+
+ last_tap_time_ = base::Time::FromInternalValue(0);
+ last_tapped_view_ = NULL;
+ return TOUCH_STATUS_END;
+ }
+
+ last_tap_time_ = event.time_stamp();
+ last_tapped_view_ = view;
+ return TOUCH_STATUS_UNKNOWN;
}
+void TouchTabStrip::ViewHierarchyChanged(bool is_add,
+ View* parent,
+ View* child) {
+ if (!is_add && last_tapped_view_ == child)
+ last_tapped_view_ = NULL;
+}
diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip.h b/chrome/browser/ui/touch/tabs/touch_tab_strip.h
index cfcc80a..c4b74bc 100644
--- a/chrome/browser/ui/touch/tabs/touch_tab_strip.h
+++ b/chrome/browser/ui/touch/tabs/touch_tab_strip.h
@@ -46,10 +46,6 @@ class TouchTabStrip : public BaseTabStrip {
const gfx::Point& location);
virtual int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs);
- // views::View overrides
- virtual gfx::Size GetPreferredSize();
- virtual void PaintChildren(gfx::Canvas* canvas);
-
// Retrieves the Tab at the specified index. Remember, the specified index
// is in terms of tab_data, *not* the model.
TouchTab* GetTabAtTabDataIndex(int tab_data_index) const;
@@ -57,10 +53,25 @@ class TouchTabStrip : public BaseTabStrip {
private:
void Init();
+ // Overridden from views::View.
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
+ virtual views::View::TouchStatus OnTouchEvent(
+ const views::TouchEvent& event) OVERRIDE;
+ virtual void ViewHierarchyChanged(bool is_add,
+ View* parent,
+ View* child) OVERRIDE;
+
// True if PrepareForCloseAt has been invoked. When true remove animations
// preserve current tab bounds.
bool in_tab_close_;
+ // Last time the tabstrip was tapped.
+ base::Time last_tap_time_;
+
+ // The view that was tapped last.
+ View* last_tapped_view_;
+
DISALLOW_COPY_AND_ASSIGN(TouchTabStrip);
};
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 8737534..945c24f 100644
--- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.h
+++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.h
@@ -38,6 +38,10 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
protected:
BrowserView* browser_view() const { return browser_view_; }
+ views::ImageButton* minimize_button() const { return minimize_button_; }
+ views::ImageButton* maximize_button() const { return maximize_button_; }
+ views::ImageButton* restore_button() const { return restore_button_; }
+ views::ImageButton* close_button() const { return close_button_; }
// Used to allow subclasses to reserve height for other components they
// will add. The space is reserved below the ClientView.