Chromium Code Reviews| 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..ada10e2e3b974baa3b71d14578fa9fdeb041a69c 100644 |
| --- a/chrome/browser/ui/touch/tabs/touch_tab_strip.cc |
| +++ b/chrome/browser/ui/touch/tabs/touch_tab_strip.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/ui/touch/tabs/touch_tab_strip.h" |
| +#include <cmath> |
| +#include <algorithm> |
| #include "chrome/browser/ui/touch/tabs/touch_tab.h" |
|
sky
2011/03/25 21:05:25
newline between 8 and 9
wyck
2011/03/28 14:21:43
Done.
|
| #include "chrome/browser/ui/view_ids.h" |
| #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" |
| @@ -15,12 +17,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 +137,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); |
|
sky
2011/03/25 21:05:25
Yow, how about some spaces?
|
| + } |
| + 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); |
|
sky
2011/03/25 21:05:25
What about max_scroll_offset_?
wyck
2011/03/28 14:21:43
max_scroll_offset_ is technically always just zero
|
| } |
| void TouchTabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, |
| @@ -150,6 +165,96 @@ int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) { |
| return 0; |
| } |
| +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) { |
| + EndScroll(event.location()); |
|
sky
2011/03/25 21:05:25
If canceled do you want to revert the scroll?
wyck
2011/03/28 14:21:43
Sorry, I don't understand a "canceled" Mouse Relea
sky
2011/03/28 15:10:17
There are certain events that can cause mouse drag
|
| + SchedulePaint(); |
| +} |
| + |
| +void TouchTabStrip::BeginScroll(const gfx::Point& point ) { |
| + initial_mouse_x_ = point.x(); |
| + initial_scroll_offset_ = scroll_offset_; |
| + initial_tab_ = GetTabAtLocal(point); |
|
sky
2011/03/25 21:05:25
This doesn't seem to be used, is it needed?
wyck
2011/03/28 14:21:43
The intent was to make sure that a very small drag
|
| +} |
| + |
| +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 = GetTabAtLocal(point); |
| + if (tab) |
| + SelectTab(tab); |
| + DoLayout(); |
| + } |
| + initial_tab_ = NULL; |
| +} |
| + |
| +void TouchTabStrip::ScrollTo(int delta_x) { |
| + scroll_offset_ = initial_scroll_offset_ + delta_x; |
| + // and limit the scrolling here |
| + int max_scroll_offset = 0; |
|
wyck
2011/03/28 14:21:43
Added an explanation here too.
|
| + if (scroll_offset_ > max_scroll_offset) { |
| + if (scrolling_) { |
| + scroll_offset_ = max_scroll_offset |
| + + std::min((scroll_offset_ - max_scroll_offset) / 4, |
|
sky
2011/03/25 21:05:25
Where does the /4 come from?
wyck
2011/03/28 14:21:43
Until I decide what the springiness of the rubber-
|
| + 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::GetTabAtLocal( |
| + const gfx::Point& local_point) { |
|
sky
2011/03/25 21:05:25
This is nearly identical to GetTabAt. If you're go
wyck
2011/03/28 14:21:43
Done.
|
| + views::View* view = GetEventHandlerForPoint(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->parent(); |
| + |
| + return view && view->GetID() == VIEW_ID_TAB ? |
| + static_cast<TouchTab*>(view) : NULL; |
| +} |
| + |
| + |
| TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const { |
| return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index)); |
| } |