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

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: addressing reviewer issues Created 9 years, 9 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..b894fdb6183ec104477012059aea8903ccdfc0dc 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>
+#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,85 @@ int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) {
return 0;
}
+bool TouchTabStrip::OnMousePressed(const views::MouseEvent& event) {
rjkroege 2011/03/28 22:07:40 these need unit tests.
wyck 2011/03/30 15:53:11 Unit tests are 100% completely new territory for m
wyck 2011/04/06 14:51:09 Is this what's holding up this CL?
+ // When we press the mouse button, we begin a drag
+ BeginScroll(event.location());
rjkroege 2011/03/28 22:07:40 I thought we had discussed creating synthetic even
wyck 2011/03/30 15:53:11 We did. I have added a TODO comment.
+ 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) {
+ 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
+}
+
+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_)
+ SelectTab(tab);
+ DoLayout();
+ }
+ initial_tab_ = NULL;
+}
+
+void TouchTabStrip::ScrollTo(int delta_x) {
rjkroege 2011/03/28 22:07:40 I would have thought that there should be a schedu
wyck 2011/03/30 15:53:11 This function is just doing the math for setting t
+ 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