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

Side by Side 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: self review 1 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/touch/tabs/touch_tab_strip.h" 5 #include "chrome/browser/ui/touch/tabs/touch_tab_strip.h"
6 6
7 #include <cmath>
8 #include <algorithm>
7 #include "chrome/browser/ui/touch/tabs/touch_tab.h" 9 #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.
8 #include "chrome/browser/ui/view_ids.h" 10 #include "chrome/browser/ui/view_ids.h"
9 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" 11 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
10 #include "ui/gfx/canvas_skia.h" 12 #include "ui/gfx/canvas_skia.h"
11 #include "views/metrics.h" 13 #include "views/metrics.h"
12 #include "views/window/non_client_view.h" 14 #include "views/window/non_client_view.h"
13 #include "views/window/window.h" 15 #include "views/window/window.h"
14 16
15 static const int kTouchTabStripHeight = 64; 17 static const int kTouchTabStripHeight = 64;
16 static const int kTouchTabWidth = 64; 18 static const int kTouchTabWidth = 64;
17 static const int kTouchTabHeight = 64; 19 static const int kTouchTabHeight = 64;
20 static const int kScrollThreshold = 4;
18 21
19 TouchTabStrip::TouchTabStrip(TabStripController* controller) 22 TouchTabStrip::TouchTabStrip(TabStripController* controller)
20 : BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP), 23 : BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP),
21 in_tab_close_(false), 24 in_tab_close_(false),
22 last_tap_time_(base::Time::FromInternalValue(0)), 25 last_tap_time_(base::Time::FromInternalValue(0)),
23 last_tapped_view_(NULL) { 26 last_tapped_view_(NULL),
27 initial_mouse_x_(0),
28 initial_scroll_offset_(0),
29 scroll_offset_(0),
30 scrolling_(false),
31 initial_tab_(NULL),
32 min_scroll_offset_(0) {
24 Init(); 33 Init();
25 } 34 }
26 35
27 TouchTabStrip::~TouchTabStrip() { 36 TouchTabStrip::~TouchTabStrip() {
28 // The animations may reference the tabs. Shut down the animation before we 37 // The animations may reference the tabs. Shut down the animation before we
29 // delete the tabs. 38 // delete the tabs.
30 StopAnimating(false); 39 StopAnimating(false);
31 40
32 DestroyDragController(); 41 DestroyDragController();
33 42
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return in_tab_close_; 130 return in_tab_close_;
122 } 131 }
123 132
124 void TouchTabStrip::GenerateIdealBounds() { 133 void TouchTabStrip::GenerateIdealBounds() {
125 gfx::Rect bounds; 134 gfx::Rect bounds;
126 int tab_x = 0; 135 int tab_x = 0;
127 int tab_y = 0; 136 int tab_y = 0;
128 for (int i = 0; i < tab_count(); ++i) { 137 for (int i = 0; i < tab_count(); ++i) {
129 TouchTab* tab = GetTabAtTabDataIndex(i); 138 TouchTab* tab = GetTabAtTabDataIndex(i);
130 if (!tab->closing()) { 139 if (!tab->closing()) {
131 set_ideal_bounds(i, gfx::Rect(tab_x, tab_y, kTouchTabWidth, 140 int x = tab_x + scroll_offset_;
132 kTouchTabHeight)); 141 if (tab->IsSelected()) {
142 // limit the extent to which this tab can be displaced.
143 x = std::min(std::max(0,x),width()-kTouchTabWidth);
sky 2011/03/25 21:05:25 Yow, how about some spaces?
144 }
145 set_ideal_bounds(i, gfx::Rect(x, tab_y,
146 kTouchTabWidth, kTouchTabHeight));
133 // offset the next tab to the right by the width of this tab 147 // offset the next tab to the right by the width of this tab
134 tab_x += kTouchTabWidth; 148 tab_x += kTouchTabWidth;
135 } 149 }
136 } 150 }
151 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
137 } 152 }
138 153
139 void TouchTabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, 154 void TouchTabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs,
140 BaseTab* active_tab, 155 BaseTab* active_tab,
141 const gfx::Point& location, 156 const gfx::Point& location,
142 bool initial_drag) { 157 bool initial_drag) {
143 // Not needed as dragging isn't supported. 158 // Not needed as dragging isn't supported.
144 NOTIMPLEMENTED(); 159 NOTIMPLEMENTED();
145 } 160 }
146 161
147 int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) { 162 int TouchTabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) {
148 // Not needed as dragging isn't supported. 163 // Not needed as dragging isn't supported.
149 NOTIMPLEMENTED(); 164 NOTIMPLEMENTED();
150 return 0; 165 return 0;
151 } 166 }
152 167
168 bool TouchTabStrip::OnMousePressed(const views::MouseEvent& event) {
169 // When we press the mouse button, we begin a drag
170 BeginScroll(event.location());
171 return true;
172 }
173
174 bool TouchTabStrip::OnMouseDragged(const views::MouseEvent& event) {
175 ContinueScroll(event.location());
176 DoLayout();
177 SchedulePaint();
178 return true;
179 }
180
181 void TouchTabStrip::OnMouseReleased(const views::MouseEvent& event,
182 bool canceled) {
183 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
184 SchedulePaint();
185 }
186
187 void TouchTabStrip::BeginScroll(const gfx::Point& point ) {
188 initial_mouse_x_ = point.x();
189 initial_scroll_offset_ = scroll_offset_;
190 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
191 }
192
193 void TouchTabStrip::ContinueScroll(const gfx::Point& point) {
194 int delta_x = point.x() - initial_mouse_x_;
195 if (std::abs(delta_x) > kScrollThreshold)
196 scrolling_ = true;
197 if (scrolling_)
198 ScrollTo(delta_x);
199 // and layout
200 }
201
202 void TouchTabStrip::EndScroll(const gfx::Point& point) {
203 int delta_x = point.x() - initial_mouse_x_;
204 if (scrolling_) {
205 scrolling_ = false;
206 ScrollTo(delta_x);
207 StopAnimating(false);
208 GenerateIdealBounds();
209 AnimateToIdealBounds();
210 } else {
211 TouchTab* tab = GetTabAtLocal(point);
212 if (tab)
213 SelectTab(tab);
214 DoLayout();
215 }
216 initial_tab_ = NULL;
217 }
218
219 void TouchTabStrip::ScrollTo(int delta_x) {
220 scroll_offset_ = initial_scroll_offset_ + delta_x;
221 // and limit the scrolling here
222 int max_scroll_offset = 0;
wyck 2011/03/28 14:21:43 Added an explanation here too.
223 if (scroll_offset_ > max_scroll_offset) {
224 if (scrolling_) {
225 scroll_offset_ = max_scroll_offset
226 + 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-
227 kTouchTabWidth);
228 } else {
229 scroll_offset_ = max_scroll_offset;
230 }
231 }
232 if (scroll_offset_ < min_scroll_offset_) {
233 if (scrolling_) {
234 scroll_offset_ = min_scroll_offset_
235 + std::max((scroll_offset_ - min_scroll_offset_) / 4,
236 -kTouchTabWidth);
237 } else {
238 scroll_offset_ = min_scroll_offset_;
239 }
240 }
241 }
242
243 TouchTab* TouchTabStrip::GetTabAtLocal(
244 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.
245 views::View* view = GetEventHandlerForPoint(local_point);
246 if (!view)
247 return NULL; // No tab contains the point.
248
249 // Walk up the view hierarchy until we find a tab, or the TabStrip.
250 while (view && view != this && view->GetID() != VIEW_ID_TAB)
251 view = view->parent();
252
253 return view && view->GetID() == VIEW_ID_TAB ?
254 static_cast<TouchTab*>(view) : NULL;
255 }
256
257
153 TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const { 258 TouchTab* TouchTabStrip::GetTabAtTabDataIndex(int tab_data_index) const {
154 return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index)); 259 return static_cast<TouchTab*>(base_tab_at_tab_index(tab_data_index));
155 } 260 }
156 261
157 //////////////////////////////////////////////////////////////////////////////// 262 ////////////////////////////////////////////////////////////////////////////////
158 // TouchTabStrip, private: 263 // TouchTabStrip, private:
159 264
160 void TouchTabStrip::Init() { 265 void TouchTabStrip::Init() {
161 SetID(VIEW_ID_TAB_STRIP); 266 SetID(VIEW_ID_TAB_STRIP);
162 } 267 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 last_tapped_view_ = view; 341 last_tapped_view_ = view;
237 return TOUCH_STATUS_UNKNOWN; 342 return TOUCH_STATUS_UNKNOWN;
238 } 343 }
239 344
240 void TouchTabStrip::ViewHierarchyChanged(bool is_add, 345 void TouchTabStrip::ViewHierarchyChanged(bool is_add,
241 View* parent, 346 View* parent,
242 View* child) { 347 View* child) {
243 if (!is_add && last_tapped_view_ == child) 348 if (!is_add && last_tapped_view_ == child)
244 last_tapped_view_ = NULL; 349 last_tapped_view_ = NULL;
245 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698