| 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_layout_type.h" | |
| 14 #include "chrome/browser/ui/views/tabs/tab.h" | 13 #include "chrome/browser/ui/views/tabs/tab.h" |
| 15 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 14 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 16 #include "ui/gfx/animation/animation_container.h" | 15 #include "ui/gfx/animation/animation_container.h" |
| 17 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 18 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 19 #include "ui/views/animation/bounds_animator.h" | 18 #include "ui/views/animation/bounds_animator.h" |
| 20 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/mouse_watcher.h" | 20 #include "ui/views/mouse_watcher.h" |
| 22 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 23 #include "ui/views/view_model.h" | 22 #include "ui/views/view_model.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 public: | 56 public: |
| 58 static const char kViewClassName[]; | 57 static const char kViewClassName[]; |
| 59 | 58 |
| 60 explicit TabStrip(TabStripController* controller); | 59 explicit TabStrip(TabStripController* controller); |
| 61 virtual ~TabStrip(); | 60 virtual ~TabStrip(); |
| 62 | 61 |
| 63 // Add and remove observers to changes within this TabStrip. | 62 // Add and remove observers to changes within this TabStrip. |
| 64 void AddObserver(TabStripObserver* observer); | 63 void AddObserver(TabStripObserver* observer); |
| 65 void RemoveObserver(TabStripObserver* observer); | 64 void RemoveObserver(TabStripObserver* observer); |
| 66 | 65 |
| 67 // Sets the layout type. If |adjust_layout| is true the layout type changes | 66 // If |adjust_layout| is true the layout type changes |
| 68 // based on whether the user uses a mouse or touch device with the tabstrip. | 67 // based on whether the user uses a mouse or touch device with the tabstrip. |
| 69 // If |adjust_layout| is false the layout is fixed to |layout_type|. | 68 void set_adjust_layout(bool adjust_layout) { adjust_layout_ = adjust_layout; } |
| 70 void SetLayoutType(TabStripLayoutType layout_type, bool adjust_layout); | 69 |
| 71 TabStripLayoutType layout_type() const { return layout_type_; } | 70 // |stacked_layout_| defines what should happen when the tabs won't fit at |
| 71 // their ideal size. When |stacked_layout_| is true the tabs are always sized |
| 72 // to their ideal size and stacked on top of each other so that only a certain |
| 73 // set of tabs are visible. This is used when the user uses a touch device. |
| 74 // When |stacked_layout_| is false the tabs shrink to accommodate the |
| 75 // available space. This is the default. |
| 76 bool stacked_layout() const { return stacked_layout_; } |
| 77 |
| 78 // Sets if the layout type is stacked and animates if necessary. |
| 79 void SetStackedLayout(bool stacked_layout); |
| 72 | 80 |
| 73 // Returns the bounds of the new tab button. | 81 // Returns the bounds of the new tab button. |
| 74 gfx::Rect GetNewTabButtonBounds(); | 82 gfx::Rect GetNewTabButtonBounds(); |
| 75 | 83 |
| 76 // Returns true if the new tab button should be sized to the top of the tab | 84 // Returns true if the new tab button should be sized to the top of the tab |
| 77 // strip. | 85 // strip. |
| 78 bool SizeTabButtonToTopOfTabStrip(); | 86 bool SizeTabButtonToTopOfTabStrip(); |
| 79 | 87 |
| 80 // Starts highlighting the tab at the specified index. | 88 // Starts highlighting the tab at the specified index. |
| 81 void StartHighlight(int model_index); | 89 void StartHighlight(int model_index); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 void SwapLayoutIfNecessary(); | 544 void SwapLayoutIfNecessary(); |
| 537 | 545 |
| 538 // Returns true if |touch_layout_| is needed. | 546 // Returns true if |touch_layout_| is needed. |
| 539 bool NeedsTouchLayout() const; | 547 bool NeedsTouchLayout() const; |
| 540 | 548 |
| 541 // Sets the value of |reset_to_shrink_on_exit_|. If true |mouse_watcher_| is | 549 // Sets the value of |reset_to_shrink_on_exit_|. If true |mouse_watcher_| is |
| 542 // used to track when the mouse truly exits the tabstrip and the layout type | 550 // used to track when the mouse truly exits the tabstrip and the layout type |
| 543 // is reset. | 551 // is reset. |
| 544 void SetResetToShrinkOnExit(bool value); | 552 void SetResetToShrinkOnExit(bool value); |
| 545 | 553 |
| 546 // Should the layout dynamically adjust? | |
| 547 bool GetAdjustLayout() const; | |
| 548 | |
| 549 // -- Member Variables ------------------------------------------------------ | 554 // -- Member Variables ------------------------------------------------------ |
| 550 | 555 |
| 551 // There is a one-to-one mapping between each of the tabs in the | 556 // There is a one-to-one mapping between each of the tabs in the |
| 552 // TabStripController (TabStripModel) and |tabs_|. Because we animate tab | 557 // TabStripController (TabStripModel) and |tabs_|. Because we animate tab |
| 553 // removal there exists a period of time where a tab is displayed but not in | 558 // removal there exists a period of time where a tab is displayed but not in |
| 554 // the model. When this occurs the tab is removed from |tabs_| and placed in | 559 // the model. When this occurs the tab is removed from |tabs_| and placed in |
| 555 // |tabs_closing_map_|. When the animation completes the tab is removed from | 560 // |tabs_closing_map_|. When the animation completes the tab is removed from |
| 556 // |tabs_closing_map_|. The painting code ensures both sets of tabs are | 561 // |tabs_closing_map_|. The painting code ensures both sets of tabs are |
| 557 // painted, and the event handling code ensures only tabs in |tabs_| are used. | 562 // painted, and the event handling code ensures only tabs in |tabs_| are used. |
| 558 views::ViewModel tabs_; | 563 views::ViewModel tabs_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 589 // Valid for the lifetime of a drag over us. | 594 // Valid for the lifetime of a drag over us. |
| 590 scoped_ptr<DropInfo> drop_info_; | 595 scoped_ptr<DropInfo> drop_info_; |
| 591 | 596 |
| 592 // To ensure all tabs pulse at the same time they share the same animation | 597 // To ensure all tabs pulse at the same time they share the same animation |
| 593 // container. This is that animation container. | 598 // container. This is that animation container. |
| 594 scoped_refptr<gfx::AnimationContainer> animation_container_; | 599 scoped_refptr<gfx::AnimationContainer> animation_container_; |
| 595 | 600 |
| 596 // MouseWatcher is used for two things: | 601 // MouseWatcher is used for two things: |
| 597 // . When a tab is closed to reset the layout. | 602 // . When a tab is closed to reset the layout. |
| 598 // . When a mouse is used and the layout dynamically adjusts and is currently | 603 // . When a mouse is used and the layout dynamically adjusts and is currently |
| 599 // TAB_STRIP_LAYOUT_STACKED. | 604 // stacked (|stacked_layout_| is true). |
| 600 scoped_ptr<views::MouseWatcher> mouse_watcher_; | 605 scoped_ptr<views::MouseWatcher> mouse_watcher_; |
| 601 | 606 |
| 602 // The controller for a drag initiated from a Tab. Valid for the lifetime of | 607 // The controller for a drag initiated from a Tab. Valid for the lifetime of |
| 603 // the drag session. | 608 // the drag session. |
| 604 scoped_ptr<TabDragController> drag_controller_; | 609 scoped_ptr<TabDragController> drag_controller_; |
| 605 | 610 |
| 606 views::BoundsAnimator bounds_animator_; | 611 views::BoundsAnimator bounds_animator_; |
| 607 | 612 |
| 608 // Size we last layed out at. | 613 // Size we last layed out at. |
| 609 gfx::Size last_layout_size_; | 614 gfx::Size last_layout_size_; |
| 610 | 615 |
| 611 TabStripLayoutType layout_type_; | 616 // See description above stacked_layout(). |
| 617 bool stacked_layout_; |
| 612 | 618 |
| 613 // See description above SetLayoutType(). | 619 // Should the layout dynamically adjust? |
| 614 bool adjust_layout_; | 620 bool adjust_layout_; |
| 615 | 621 |
| 616 // Only used while in touch mode. | 622 // Only used while in touch mode. |
| 617 scoped_ptr<StackedTabStripLayout> touch_layout_; | 623 scoped_ptr<StackedTabStripLayout> touch_layout_; |
| 618 | 624 |
| 619 // If true the layout type is set to TAB_STRIP_LAYOUT_SHRINK when the mouse | 625 // If true the layout type is set to not stacked when the mouse exits the |
| 620 // exits the tabstrip (as determined using MouseWatcher). | 626 // tabstrip (as determined using MouseWatcher). |
| 621 bool reset_to_shrink_on_exit_; | 627 bool reset_to_shrink_on_exit_; |
| 622 | 628 |
| 623 // Location of the mouse at the time of the last move. | 629 // Location of the mouse at the time of the last move. |
| 624 gfx::Point last_mouse_move_location_; | 630 gfx::Point last_mouse_move_location_; |
| 625 | 631 |
| 626 // Time of the last mouse move event. | 632 // Time of the last mouse move event. |
| 627 base::TimeTicks last_mouse_move_time_; | 633 base::TimeTicks last_mouse_move_time_; |
| 628 | 634 |
| 629 // Number of mouse moves. | 635 // Number of mouse moves. |
| 630 int mouse_move_count_; | 636 int mouse_move_count_; |
| 631 | 637 |
| 632 // Timer used when a tab is closed and we need to relayout. Only used when a | 638 // Timer used when a tab is closed and we need to relayout. Only used when a |
| 633 // tab close comes from a touch device. | 639 // tab close comes from a touch device. |
| 634 base::OneShotTimer<TabStrip> resize_layout_timer_; | 640 base::OneShotTimer<TabStrip> resize_layout_timer_; |
| 635 | 641 |
| 636 // True if tabs are painted as rectangular light-bars. | 642 // True if tabs are painted as rectangular light-bars. |
| 637 bool immersive_style_; | 643 bool immersive_style_; |
| 638 | 644 |
| 639 // Our observers. | 645 // Our observers. |
| 640 typedef ObserverList<TabStripObserver> TabStripObservers; | 646 typedef ObserverList<TabStripObserver> TabStripObservers; |
| 641 TabStripObservers observers_; | 647 TabStripObservers observers_; |
| 642 | 648 |
| 643 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 649 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
| 644 }; | 650 }; |
| 645 | 651 |
| 646 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ | 652 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_H_ |
| OLD | NEW |