| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ | 5 #ifndef CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ |
| 6 #define CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ | 6 #define CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" | 9 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" |
| 10 | 10 |
| 11 class TouchTab; | 11 class TouchTab; |
| 12 | 12 |
| 13 /////////////////////////////////////////////////////////////////////////////// | 13 /////////////////////////////////////////////////////////////////////////////// |
| 14 // | 14 // |
| 15 // TouchTabStrip | 15 // TouchTabStrip |
| 16 // | 16 // |
| 17 // A View that represents the TabStripModel. The TouchTabStrip has the | 17 // A View that represents the TabStripModel. The TouchTabStrip has the |
| 18 // following responsibilities: | 18 // following responsibilities: |
| 19 // - It implements the TabStripModelObserver interface, and acts as a | 19 // - It implements the TabStripModelObserver interface, and acts as a |
| 20 // container for Tabs, and is also responsible for creating them. | 20 // container for Tabs, and is also responsible for creating them. |
| 21 // | 21 // |
| 22 // TODO(wyck): Use transformable views for scrolling. |
| 22 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
| 23 class TouchTabStrip : public BaseTabStrip { | 24 class TouchTabStrip : public BaseTabStrip { |
| 24 public: | 25 public: |
| 25 explicit TouchTabStrip(TabStripController* controller); | 26 explicit TouchTabStrip(TabStripController* controller); |
| 26 virtual ~TouchTabStrip(); | 27 virtual ~TouchTabStrip(); |
| 27 | 28 |
| 28 // AbstractTabStripView implementation: | 29 // AbstractTabStripView implementation: |
| 29 virtual bool IsPositionInWindowCaption(const gfx::Point& point); | 30 virtual bool IsPositionInWindowCaption(const gfx::Point& point); |
| 30 virtual void SetBackgroundOffset(const gfx::Point& offset); | 31 virtual void SetBackgroundOffset(const gfx::Point& offset); |
| 31 | 32 |
| 32 // BaseTabStrip implementation: | 33 // BaseTabStrip implementation: |
| 33 virtual void PrepareForCloseAt(int model_index); | 34 virtual void PrepareForCloseAt(int model_index); |
| 34 virtual void StartHighlight(int model_index); | 35 virtual void StartHighlight(int model_index); |
| 35 virtual void StopAllHighlighting(); | 36 virtual void StopAllHighlighting(); |
| 36 virtual BaseTab* CreateTabForDragging(); | 37 virtual BaseTab* CreateTabForDragging(); |
| 37 virtual void RemoveTabAt(int model_index); | 38 virtual void RemoveTabAt(int model_index); |
| 38 virtual void SelectTabAt(int old_model_index, int new_model_index); | 39 virtual void SelectTabAt(int old_model_index, int new_model_index); |
| 39 virtual void TabTitleChangedNotLoading(int model_index); | 40 virtual void TabTitleChangedNotLoading(int model_index); |
| 40 virtual BaseTab* CreateTab(); | 41 virtual BaseTab* CreateTab(); |
| 41 virtual void StartInsertTabAnimation(int model_index); | 42 virtual void StartInsertTabAnimation(int model_index); |
| 42 virtual void AnimateToIdealBounds(); | 43 virtual void AnimateToIdealBounds(); |
| 43 virtual bool ShouldHighlightCloseButtonAfterRemove(); | 44 virtual bool ShouldHighlightCloseButtonAfterRemove(); |
| 44 virtual void GenerateIdealBounds(); | 45 virtual void GenerateIdealBounds(); |
| 45 virtual void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, | 46 virtual void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, |
| 46 BaseTab* active_tab, | 47 BaseTab* active_tab, |
| 47 const gfx::Point& location, | 48 const gfx::Point& location, |
| 48 bool initial_drag); | 49 bool initial_drag); |
| 49 virtual int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs); | 50 virtual int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs); |
| 50 | 51 |
| 52 // views::View overrides: |
| 53 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
| 54 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |
| 55 virtual void OnMouseReleased(const views::MouseEvent& event, |
| 56 bool canceled) OVERRIDE; |
| 57 |
| 51 // Retrieves the Tab at the specified index. Remember, the specified index | 58 // Retrieves the Tab at the specified index. Remember, the specified index |
| 52 // is in terms of tab_data, *not* the model. | 59 // is in terms of tab_data, *not* the model. |
| 53 TouchTab* GetTabAtTabDataIndex(int tab_data_index) const; | 60 TouchTab* GetTabAtTabDataIndex(int tab_data_index) const; |
| 54 | 61 |
| 55 private: | 62 private: |
| 56 void Init(); | 63 void Init(); |
| 57 | 64 |
| 58 // Overridden from views::View. | 65 // Overridden from views::View. |
| 59 virtual gfx::Size GetPreferredSize() OVERRIDE; | 66 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 60 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 67 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
| 61 virtual views::View::TouchStatus OnTouchEvent( | 68 virtual views::View::TouchStatus OnTouchEvent( |
| 62 const views::TouchEvent& event) OVERRIDE; | 69 const views::TouchEvent& event) OVERRIDE; |
| 63 virtual void ViewHierarchyChanged(bool is_add, | 70 virtual void ViewHierarchyChanged(bool is_add, |
| 64 View* parent, | 71 View* parent, |
| 65 View* child) OVERRIDE; | 72 View* child) OVERRIDE; |
| 66 | 73 |
| 74 // Adjusts the state of scroll interaction when a mouse press occurs at the |
| 75 // given point. Sets an appropriate |initial_scroll_offset_|. |
| 76 void BeginScroll(const gfx::Point& point); |
| 77 |
| 78 // Adjusts the state of scroll interaction when the mouse is dragged to the |
| 79 // given point. If the scroll is not beyond the minimum threshold, the tabs |
| 80 // will not actually scroll. |
| 81 void ContinueScroll(const gfx::Point& point); |
| 82 |
| 83 // Adjusts the state of scroll interaction when the mouse is released. Either |
| 84 // scrolls to the final mouse release point or selects the current tab |
| 85 // depending on whether the mouse was dragged beyone the minimum threshold. |
| 86 void EndScroll(const gfx::Point& point); |
| 87 |
| 88 // Adjust the positions of the tabs to perform a scroll of |delta_x| relative |
| 89 // to the |initial_scroll_offset_|. |
| 90 void ScrollTo(int delta_x); |
| 91 |
| 67 // True if PrepareForCloseAt has been invoked. When true remove animations | 92 // True if PrepareForCloseAt has been invoked. When true remove animations |
| 68 // preserve current tab bounds. | 93 // preserve current tab bounds. |
| 69 bool in_tab_close_; | 94 bool in_tab_close_; |
| 70 | 95 |
| 71 // Last time the tabstrip was tapped. | 96 // Last time the tabstrip was tapped. |
| 72 base::Time last_tap_time_; | 97 base::Time last_tap_time_; |
| 73 | 98 |
| 74 // The view that was tapped last. | 99 // The view that was tapped last. |
| 75 View* last_tapped_view_; | 100 View* last_tapped_view_; |
| 76 | 101 |
| 102 // Records the mouse x coordinate at the start of a drag operation. |
| 103 int initial_mouse_x_; |
| 104 |
| 105 // Records the scroll offset at the time of the start of a drag operation. |
| 106 int initial_scroll_offset_; |
| 107 |
| 108 // The current offset of the view. Positive scroll offsets move the icons to |
| 109 // the left. Negative scroll offsets move the icons to the right. |
| 110 int scroll_offset_; |
| 111 |
| 112 // State of the scrolling interaction. Will be true once the drag has been |
| 113 // displaced beyond the minimum dragging threshold. |
| 114 bool scrolling_; |
| 115 |
| 116 // Records the tab that was under the initial mouse press. Must match the |
| 117 // tab that was under the final mouse release in order for the tab to |
| 118 // be selected. |
| 119 TouchTab* initial_tab_; |
| 120 |
| 121 // The minimum value that |scroll_offset_| can have. Based on the total |
| 122 // width of all the content to be scrolled, less the viewport size. |
| 123 int min_scroll_offset_; |
| 124 |
| 77 DISALLOW_COPY_AND_ASSIGN(TouchTabStrip); | 125 DISALLOW_COPY_AND_ASSIGN(TouchTabStrip); |
| 78 }; | 126 }; |
| 79 | 127 |
| 80 #endif // CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ | 128 #endif // CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_ |
| OLD | NEW |