OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
22 #include "ui/views/mouse_watcher.h" | 22 #include "ui/views/mouse_watcher.h" |
23 #include "ui/views/view_model.h" | 23 #include "ui/views/view_model.h" |
24 | 24 |
25 class BaseTab; | 25 class BaseTab; |
26 class NewTabButton; | 26 class NewTabButton; |
27 class Tab; | 27 class Tab; |
28 class TabDragController; | 28 class TabDragController; |
29 class TabStripController; | 29 class TabStripController; |
30 class TabStripSelectionModel; | 30 class TabStripSelectionModel; |
| 31 class TouchTabStripLayout; |
31 | 32 |
32 namespace views { | 33 namespace views { |
33 class ImageView; | 34 class ImageView; |
34 } | 35 } |
35 | 36 |
36 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
37 // | 38 // |
38 // TabStrip | 39 // TabStrip |
39 // | 40 // |
40 // A View that represents the TabStripModel. The TabStrip has the | 41 // A View that represents the TabStripModel. The TabStrip has the |
(...skipping 22 matching lines...) Expand all Loading... |
63 // strip. | 64 // strip. |
64 bool SizeTabButtonToTopOfTabStrip(); | 65 bool SizeTabButtonToTopOfTabStrip(); |
65 | 66 |
66 // Starts highlighting the tab at the specified index. | 67 // Starts highlighting the tab at the specified index. |
67 void StartHighlight(int model_index); | 68 void StartHighlight(int model_index); |
68 | 69 |
69 // Stops all tab higlighting. | 70 // Stops all tab higlighting. |
70 void StopAllHighlighting(); | 71 void StopAllHighlighting(); |
71 | 72 |
72 // Adds a tab at the specified index. | 73 // Adds a tab at the specified index. |
73 void AddTabAt(int model_index, const TabRendererData& data); | 74 void AddTabAt(int model_index, const TabRendererData& data, bool is_active); |
74 | 75 |
75 // Moves a tab. | 76 // Moves a tab. |
76 void MoveTab(int from_model_index, int to_model_index); | 77 void MoveTab(int from_model_index, |
| 78 int to_model_index, |
| 79 const TabRendererData& data); |
77 | 80 |
78 // Removes a tab at the specified index. | 81 // Removes a tab at the specified index. |
79 void RemoveTabAt(int model_index); | 82 void RemoveTabAt(int model_index); |
80 | 83 |
81 // Sets the tab data at the specified model index. | 84 // Sets the tab data at the specified model index. |
82 void SetTabData(int model_index, const TabRendererData& data); | 85 void SetTabData(int model_index, const TabRendererData& data); |
83 | 86 |
84 // Invoked from the controller when the close initiates from the TabController | 87 // Invoked from the controller when the close initiates from the TabController |
85 // (the user clicked the tab close button or middle clicked the tab). This is | 88 // (the user clicked the tab close button or middle clicked the tab). This is |
86 // invoked from Close. Because of unload handlers Close is not always | 89 // invoked from Close. Because of unload handlers Close is not always |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Creates and returns a tab that can be used for dragging. Ownership passes | 124 // Creates and returns a tab that can be used for dragging. Ownership passes |
122 // to the caller. | 125 // to the caller. |
123 BaseTab* CreateTabForDragging(); | 126 BaseTab* CreateTabForDragging(); |
124 | 127 |
125 // Returns true if a drag session is currently active. | 128 // Returns true if a drag session is currently active. |
126 bool IsDragSessionActive() const; | 129 bool IsDragSessionActive() const; |
127 | 130 |
128 // Returns true if a tab is being dragged into this tab strip. | 131 // Returns true if a tab is being dragged into this tab strip. |
129 bool IsActiveDropTarget() const; | 132 bool IsActiveDropTarget() const; |
130 | 133 |
131 // Returns true if this tab strip is in stacking mode. | |
132 bool IsStacking() const; | |
133 | |
134 // TabController overrides: | 134 // TabController overrides: |
135 virtual const TabStripSelectionModel& GetSelectionModel() OVERRIDE; | 135 virtual const TabStripSelectionModel& GetSelectionModel() OVERRIDE; |
| 136 virtual bool SupportsMultipleSelection() OVERRIDE; |
136 virtual void SelectTab(BaseTab* tab) OVERRIDE; | 137 virtual void SelectTab(BaseTab* tab) OVERRIDE; |
137 virtual void ExtendSelectionTo(BaseTab* tab) OVERRIDE; | 138 virtual void ExtendSelectionTo(BaseTab* tab) OVERRIDE; |
138 virtual void ToggleSelected(BaseTab* tab) OVERRIDE; | 139 virtual void ToggleSelected(BaseTab* tab) OVERRIDE; |
139 virtual void AddSelectionFromAnchorTo(BaseTab* tab) OVERRIDE; | 140 virtual void AddSelectionFromAnchorTo(BaseTab* tab) OVERRIDE; |
140 virtual void CloseTab(BaseTab* tab) OVERRIDE; | 141 virtual void CloseTab(BaseTab* tab) OVERRIDE; |
141 virtual void ShowContextMenuForTab(BaseTab* tab, | 142 virtual void ShowContextMenuForTab(BaseTab* tab, |
142 const gfx::Point& p) OVERRIDE; | 143 const gfx::Point& p) OVERRIDE; |
143 virtual bool IsActiveTab(const BaseTab* tab) const OVERRIDE; | 144 virtual bool IsActiveTab(const BaseTab* tab) const OVERRIDE; |
144 virtual bool IsTabSelected(const BaseTab* tab) const OVERRIDE; | 145 virtual bool IsTabSelected(const BaseTab* tab) const OVERRIDE; |
145 virtual bool IsTabPinned(const BaseTab* tab) const OVERRIDE; | 146 virtual bool IsTabPinned(const BaseTab* tab) const OVERRIDE; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 190 } |
190 | 191 |
191 // Returns the number of mini-tabs. | 192 // Returns the number of mini-tabs. |
192 int GetMiniTabCount() const; | 193 int GetMiniTabCount() const; |
193 | 194 |
194 // views::ButtonListener implementation: | 195 // views::ButtonListener implementation: |
195 virtual void ButtonPressed(views::Button* sender, | 196 virtual void ButtonPressed(views::Button* sender, |
196 const views::Event& event) OVERRIDE; | 197 const views::Event& event) OVERRIDE; |
197 | 198 |
198 // View overrides. | 199 // View overrides. |
199 virtual void ViewHierarchyChanged(bool is_add, | |
200 views::View* parent, | |
201 views::View* child) OVERRIDE; | |
202 virtual const views::View* GetViewByID(int id) const OVERRIDE; | 200 virtual const views::View* GetViewByID(int id) const OVERRIDE; |
203 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | 201 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |
204 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 202 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
205 virtual void OnMouseCaptureLost() OVERRIDE; | 203 virtual void OnMouseCaptureLost() OVERRIDE; |
206 | 204 |
207 private: | 205 private: |
208 typedef std::map<int, std::vector<BaseTab*> > TabsClosingMap; | 206 typedef std::map<int, std::vector<BaseTab*> > TabsClosingMap; |
209 | 207 |
210 class RemoveTabDelegate; | 208 class RemoveTabDelegate; |
211 | 209 |
(...skipping 22 matching lines...) Expand all Loading... |
234 // Renders the drop indicator. | 232 // Renders the drop indicator. |
235 views::Widget* arrow_window; | 233 views::Widget* arrow_window; |
236 views::ImageView* arrow_view; | 234 views::ImageView* arrow_view; |
237 | 235 |
238 private: | 236 private: |
239 DISALLOW_COPY_AND_ASSIGN(DropInfo); | 237 DISALLOW_COPY_AND_ASSIGN(DropInfo); |
240 }; | 238 }; |
241 | 239 |
242 void Init(); | 240 void Init(); |
243 | 241 |
244 // Creates the new tab button. | |
245 void InitTabStripButtons(); | |
246 | |
247 // Creates and returns a new tab. The caller owners the returned tab. | 242 // Creates and returns a new tab. The caller owners the returned tab. |
248 BaseTab* CreateTab(); | 243 BaseTab* CreateTab(); |
249 | 244 |
250 // Invoked from |AddTabAt| after the newly created tab has been inserted. | 245 // Invoked from |AddTabAt| after the newly created tab has been inserted. |
251 void StartInsertTabAnimation(int model_index); | 246 void StartInsertTabAnimation(int model_index); |
252 | 247 |
253 // Invoked from |MoveTab| after |tab_data_| has been updated to animate the | 248 // Invoked from |MoveTab| after |tab_data_| has been updated to animate the |
254 // move. | 249 // move. |
255 void StartMoveTabAnimation(); | 250 void StartMoveTabAnimation(); |
256 | 251 |
257 // Starts the remove tab animation. | 252 // Starts the remove tab animation. |
258 void StartRemoveTabAnimation(int model_index); | 253 void StartRemoveTabAnimation(int model_index); |
259 | 254 |
| 255 // Schedules the animations and bounds changes necessary for a remove tab |
| 256 // animation. |
| 257 void ScheduleRemoveTabAnimation(BaseTab* tab); |
| 258 |
260 // Stops any ongoing animations. If |layout| is true and an animation is | 259 // Stops any ongoing animations. If |layout| is true and an animation is |
261 // ongoing this does a layout. | 260 // ongoing this does a layout. |
262 void StopAnimating(bool layout); | 261 void StopAnimating(bool layout); |
263 | 262 |
264 // Animates all the views to their ideal bounds. | 263 // Animates all the views to their ideal bounds. |
265 // NOTE: this does *not* invoke GenerateIdealBounds, it uses the bounds | 264 // NOTE: this does *not* invoke GenerateIdealBounds, it uses the bounds |
266 // currently set in ideal_bounds. | 265 // currently set in ideal_bounds. |
267 void AnimateToIdealBounds(); | 266 void AnimateToIdealBounds(); |
268 | 267 |
269 // Returns whether the highlight button should be highlighted after a remove. | 268 // Returns whether the highlight button should be highlighted after a remove. |
270 bool ShouldHighlightCloseButtonAfterRemove(); | 269 bool ShouldHighlightCloseButtonAfterRemove(); |
271 | 270 |
272 // Invoked from Layout if the size changes or layout is really needed. | 271 // Invoked from Layout if the size changes or layout is really needed. |
273 void DoLayout(); | 272 void DoLayout(); |
274 | 273 |
275 // Invoked during drag to layout the tabs being dragged in |tabs| at | 274 // Invoked during drag to layout the tabs being dragged in |tabs| at |
276 // |location|. If |initial_drag| is true, this is the initial layout after the | 275 // |location|. If |initial_drag| is true, this is the initial layout after the |
277 // user moved the mouse far enough to trigger a drag. | 276 // user moved the mouse far enough to trigger a drag. |
278 void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, | 277 void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, |
279 BaseTab* active_tab, | 278 BaseTab* active_tab, |
280 const gfx::Point& location, | 279 const gfx::Point& location, |
281 bool initial_drag); | 280 bool initial_drag); |
282 | 281 |
283 // Invoked during drag to layout all tabs when in stacking mode, with | |
284 // |active_tab| positioned at |location|. | |
285 void LayoutDraggedTabsAtWithStacking(BaseTab* active_tab, | |
286 const gfx::Point& location); | |
287 | |
288 // Calculates the bounds needed for each of the tabs, placing the result in | 282 // Calculates the bounds needed for each of the tabs, placing the result in |
289 // |bounds|. | 283 // |bounds|. |
290 void CalculateBoundsForDraggedTabs( | 284 void CalculateBoundsForDraggedTabs( |
291 const std::vector<BaseTab*>& tabs, | 285 const std::vector<BaseTab*>& tabs, |
292 std::vector<gfx::Rect>* bounds); | 286 std::vector<gfx::Rect>* bounds); |
293 | 287 |
294 // Returns the size needed for the specified tabs. This is invoked during drag | 288 // Returns the size needed for the specified tabs. This is invoked during drag |
295 // and drop to calculate offsets and positioning. | 289 // and drop to calculate offsets and positioning. |
296 int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs); | 290 int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs); |
297 | 291 |
(...skipping 28 matching lines...) Expand all Loading... |
326 // Takes ownership of |controller|. | 320 // Takes ownership of |controller|. |
327 void OwnDragController(TabDragController* controller); | 321 void OwnDragController(TabDragController* controller); |
328 | 322 |
329 // Destroys the current TabDragController. This cancel the existing drag | 323 // Destroys the current TabDragController. This cancel the existing drag |
330 // operation. | 324 // operation. |
331 void DestroyDragController(); | 325 void DestroyDragController(); |
332 | 326 |
333 // Releases ownership of the current TabDragController. | 327 // Releases ownership of the current TabDragController. |
334 TabDragController* ReleaseDragController(); | 328 TabDragController* ReleaseDragController(); |
335 | 329 |
336 // Returns the number of non-closing tabs between |index1| and |index2|. | |
337 int NumNonClosingTabs(int index1, int index2) const; | |
338 | |
339 // Updates |num_visible_tabs_| based on |width| and the specified tab size. | |
340 // Additionally updates |first_visible_tab_index_|. | |
341 void UpdateNumVisibleTabs(int non_closing_tab_count, | |
342 int width, | |
343 double tab_size); | |
344 | |
345 // Makes sure |model_index| is within the set of visible tabs. Only does | |
346 // something if stacking. | |
347 void EnsureModelIndexIsVisible(int model_index); | |
348 | |
349 // Paints all the tabs in |tabs_closing_map_[index]|. | 330 // Paints all the tabs in |tabs_closing_map_[index]|. |
350 void PaintClosingTabs(gfx::Canvas* canvas, int index); | 331 void PaintClosingTabs(gfx::Canvas* canvas, int index); |
351 | 332 |
352 // -- Tab Resize Layout ----------------------------------------------------- | 333 // -- Tab Resize Layout ----------------------------------------------------- |
353 | 334 |
354 // Returns the exact (unrounded) current width of each tab. | 335 // Returns the exact (unrounded) current width of each tab. |
355 void GetCurrentTabWidths(double* unselected_width, | 336 void GetCurrentTabWidths(double* unselected_width, |
356 double* selected_width) const; | 337 double* selected_width) const; |
357 | 338 |
358 // Returns the exact (unrounded) desired width of each tab, based on the | 339 // Returns the exact (unrounded) desired width of each tab, based on the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 // position. | 385 // position. |
405 bool IsAnimating() const; | 386 bool IsAnimating() const; |
406 | 387 |
407 // Invoked prior to starting a new animation. | 388 // Invoked prior to starting a new animation. |
408 void PrepareForAnimation(); | 389 void PrepareForAnimation(); |
409 | 390 |
410 // Generates the ideal bounds for each of the tabs as well as the new tab | 391 // Generates the ideal bounds for each of the tabs as well as the new tab |
411 // button. | 392 // button. |
412 void GenerateIdealBounds(); | 393 void GenerateIdealBounds(); |
413 | 394 |
414 // Same as GenerateIdealBounds, except used with in stacking mode. Only | 395 // Generates the ideal bounds for the mini tabs. Returns the index to position |
415 // intended to be called by GenerateIdealBounds. Returns location for | 396 // the first non-mini tab and sets |first_non_mini_index| to the index of the |
416 // new tab button. | 397 // first non-mini tab. |
417 double GenerateIdealBoundsWithStacking(int mini_tab_count, | 398 int GenerateIdealBoundsForMiniTabs(int* first_non_mini_index); |
418 int non_closing_tab_count, | 399 |
419 double new_tab_x, | 400 // Returns the width needed for the new tab button (and padding). |
420 double selected_size); | 401 int new_tab_button_width() const; |
421 | 402 |
422 // Starts various types of TabStrip animations. | 403 // Starts various types of TabStrip animations. |
423 void StartResizeLayoutAnimation(); | 404 void StartResizeLayoutAnimation(); |
424 void StartMiniTabAnimation(); | 405 void StartMiniTabAnimation(); |
425 void StartMouseInitiatedRemoveTabAnimation(int model_index); | 406 void StartMouseInitiatedRemoveTabAnimation(int model_index); |
426 | 407 |
427 // Returns true if the specified point in TabStrip coords is within the | 408 // Returns true if the specified point in TabStrip coords is within the |
428 // hit-test region of the specified Tab. | 409 // hit-test region of the specified Tab. |
429 bool IsPointInTab(Tab* tab, const gfx::Point& point_in_tabstrip_coords); | 410 bool IsPointInTab(Tab* tab, const gfx::Point& point_in_tabstrip_coords); |
430 | 411 |
| 412 // -- Touch Layout ---------------------------------------------------------- |
| 413 |
| 414 // Returns the position normal tabs start at. |
| 415 int GetStartXForNormalTabs() const; |
| 416 |
| 417 // Returns the tab to use for event handling starting at index |start| and |
| 418 // iterating by |delta|. |
| 419 Tab* FindTabForEvent(const gfx::Point& point, int start, int delta); |
| 420 |
431 // -- Member Variables ------------------------------------------------------ | 421 // -- Member Variables ------------------------------------------------------ |
432 | 422 |
433 // There is a one-to-one mapping between each of the tabs in the | 423 // There is a one-to-one mapping between each of the tabs in the |
434 // TabStripController (TabStripModel) and |tabs_|. Because we animate tab | 424 // TabStripController (TabStripModel) and |tabs_|. Because we animate tab |
435 // removal there exists a period of time where a tab is displayed but not in | 425 // removal there exists a period of time where a tab is displayed but not in |
436 // the model. When this occurs the tab is removed from |tabs_| and placed in | 426 // the model. When this occurs the tab is removed from |tabs_| and placed in |
437 // |tabs_closing_map_|. When the animation completes the tab is removed from | 427 // |tabs_closing_map_|. When the animation completes the tab is removed from |
438 // |tabs_closing_map_|. The painting code ensures both sets of tabs are | 428 // |tabs_closing_map_|. The painting code ensures both sets of tabs are |
439 // painted, and the event handling code ensures only tabs in |tabs_| are used. | 429 // painted, and the event handling code ensures only tabs in |tabs_| are used. |
440 views::ViewModel tabs_; | 430 views::ViewModel tabs_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 488 |
499 // The controller for a drag initiated from a Tab. Valid for the lifetime of | 489 // The controller for a drag initiated from a Tab. Valid for the lifetime of |
500 // the drag session. | 490 // the drag session. |
501 scoped_ptr<TabDragController> drag_controller_; | 491 scoped_ptr<TabDragController> drag_controller_; |
502 | 492 |
503 views::BoundsAnimator bounds_animator_; | 493 views::BoundsAnimator bounds_animator_; |
504 | 494 |
505 // Size we last layed out at. | 495 // Size we last layed out at. |
506 gfx::Size last_layout_size_; | 496 gfx::Size last_layout_size_; |
507 | 497 |
508 // If |stacking_| is true this is the index (into tab_data_) of the first | 498 // Only used while in touch mode. |
509 // tab completely shown. | 499 scoped_ptr<TouchTabStripLayout> touch_layout_; |
510 int first_visible_tab_index_; | |
511 | |
512 // If |stacking_| is true this is the number of tabs totally visible, the | |
513 // rest are compresses on the left/right edge. | |
514 int num_visible_tabs_; | |
515 | |
516 // Are we in stacking/scrolling mode? | |
517 bool stacking_; | |
518 | 500 |
519 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 501 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
520 }; | 502 }; |
521 | 503 |
522 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ | 504 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ |
OLD | NEW |