Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: chrome/browser/ui/touch/tabs/touch_tab_strip.cc

Issue 6750007: Scrolling Tabs (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: TODO for transformable views Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/touch/tabs/touch_tab_strip.cc
diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip.cc b/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
index e749eac56ebf395b813687895b3c258f816f799b..80cc9750de07766d4eacd1a59613c9f30af9f7a5 100644
--- a/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
+++ b/chrome/browser/ui/touch/tabs/touch_tab_strip.cc
@@ -4,6 +4,9 @@
#include "chrome/browser/ui/touch/tabs/touch_tab_strip.h"
+#include <cmath>
sky 2011/04/06 15:11:50 Can these be sorted?
wyck 2011/04/06 20:14:24 Done.
+#include <algorithm>
+
#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"
@@ -15,12 +18,19 @@
static const int kTouchTabStripHeight = 64;
static const int kTouchTabWidth = 64;
static const int kTouchTabHeight = 64;
+static const int kScrollThreshold = 4;
TouchTabStrip::TouchTabStrip(TabStripController* controller)
: BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP),
in_tab_close_(false),
last_tap_time_(base::Time::FromInternalValue(0)),
- last_tapped_view_(NULL) {
+ last_tapped_view_(NULL),
+ initial_mouse_x_(0),
+ initial_scroll_offset_(0),
+ scroll_offset_(0),
+ scrolling_(false),
+ initial_tab_(NULL),
+ min_scroll_offset_(0) {
Init();
}
@@ -128,12 +138,18 @@ void TouchTabStrip::GenerateIdealBounds() {
for (int i = 0; i < tab_count(); ++i) {
TouchTab* tab = GetTabAtTabDataIndex(i);
if (!tab->closing()) {
- set_ideal_bounds(i, gfx::Rect(tab_x, tab_y, kTouchTabWidth,
- kTouchTabHeight));
+ int x = tab_x + scroll_offset_;
+ if (tab->IsSelected()) {
+ // limit the extent to which this tab can be displaced.
+ x = std::min(std::max(0, x), width() - kTouchTabWidth);
+ }
+ set_ideal_bounds(i, gfx::Rect(x, tab_y,
+ kTouchTabWidth, kTouchTabHeight));
// offset the next tab to the right by the width of this tab
tab_x += kTouchTabWidth;
}
}
+ min_scroll_offset_ = std::min(0, width() - tab_x);
}
void TouchTabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs,
@@ -150,6 +166,98 @@ int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) {
return 0;
}
+// TODO(wyck): Someday we might like to get a "scroll" interaction event by way
+// of views, triggered by the gesture manager, and/or mouse scroll wheel.
+// For now, we're just handling a single scroll with these mouse events:
+// OnMousePressed, OnMouseDragged, and OnMouseReleased.
+
+bool TouchTabStrip::OnMousePressed(const views::MouseEvent& event) {
+ // When we press the mouse button, we begin a drag
+ BeginScroll(event.location());
+ return true;
+}
+
+bool TouchTabStrip::OnMouseDragged(const views::MouseEvent& event) {
+ ContinueScroll(event.location());
+ DoLayout();
+ SchedulePaint();
+ return true;
+}
+
+void TouchTabStrip::OnMouseReleased(const views::MouseEvent& event,
+ bool canceled) {
+ if (canceled) {
+ // Cancel the scroll by scrolling back to the initial position (deltax = 0).
+ ScrollTo(0);
+ StopAnimating(false);
+ GenerateIdealBounds();
+ AnimateToIdealBounds();
+ } else {
+ EndScroll(event.location());
+ }
+ SchedulePaint();
+}
+
+void TouchTabStrip::BeginScroll(const gfx::Point& point ) {
+ initial_mouse_x_ = point.x();
+ initial_scroll_offset_ = scroll_offset_;
+ initial_tab_ = static_cast<TouchTab*>(GetTabAtLocal(point));
+}
+
+void TouchTabStrip::ContinueScroll(const gfx::Point& point) {
+ int delta_x = point.x() - initial_mouse_x_;
+ if (std::abs(delta_x) > kScrollThreshold)
+ scrolling_ = true;
+ if (scrolling_)
+ ScrollTo(delta_x);
+ // and layout
sky 2011/04/06 15:11:50 This comment doesn't make sense.
wyck 2011/04/06 20:14:24 Right, sorry. That was a note to myself to move t
+}
+
+void TouchTabStrip::EndScroll(const gfx::Point& point) {
+ int delta_x = point.x() - initial_mouse_x_;
+ if (scrolling_) {
+ scrolling_ = false;
+ ScrollTo(delta_x);
+ StopAnimating(false);
+ GenerateIdealBounds();
+ AnimateToIdealBounds();
+ } else {
+ TouchTab* tab = static_cast<TouchTab*>(GetTabAtLocal(point));
+ if (tab && tab == initial_tab_)
sky 2011/04/06 15:11:50 Don't you always want to select the tab at the loc
wyck 2011/04/06 20:14:24 No, I was thinking it works like a button, where i
+ SelectTab(tab);
+ DoLayout();
+ }
+ initial_tab_ = NULL;
+}
+
+void TouchTabStrip::ScrollTo(int delta_x) {
+ scroll_offset_ = initial_scroll_offset_ + delta_x;
+ // Limit the scrolling here.
+ // When scrolling beyond the limits of min and max offsets, the displacement
+ // is adjusted to 25% of what would normally applied (divided by 4).
+ // Perhaps in the future, Hooke's law could be used to model more physically
+ // based spring-like behavior.
+ int max_scroll_offset = 0; // Because there's never content to the left of 0.
+ if (scroll_offset_ > max_scroll_offset) {
+ if (scrolling_) {
+ scroll_offset_ = max_scroll_offset
+ + std::min((scroll_offset_ - max_scroll_offset) / 4,
+ kTouchTabWidth);
+ } else {
+ scroll_offset_ = max_scroll_offset;
+ }
+ }
+ if (scroll_offset_ < min_scroll_offset_) {
+ if (scrolling_) {
+ scroll_offset_ = min_scroll_offset_
+ + std::max((scroll_offset_ - min_scroll_offset_) / 4,
+ -kTouchTabWidth);
+ } else {
+ scroll_offset_ = min_scroll_offset_;
+ }
+ }
+}
+
TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const {
return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index));
}

Powered by Google App Engine
This is Rietveld 408576698