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

Side by Side Diff: chrome/browser/views/tabs/base_tab_strip.h

Issue 2124003: More TabStrip refactoring. (Closed)
Patch Set: Merge with trunk Created 10 years, 7 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_VIEWS_TABS_BASE_TAB_STRIP_H_ 5 #ifndef CHROME_BROWSER_VIEWS_TABS_BASE_TAB_STRIP_H_
6 #define CHROME_BROWSER_VIEWS_TABS_BASE_TAB_STRIP_H_ 6 #define CHROME_BROWSER_VIEWS_TABS_BASE_TAB_STRIP_H_
7 7
8 #include <vector>
9
8 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
9 #include "chrome/browser/views/tabs/base_tab_renderer.h" 11 #include "chrome/browser/views/tabs/base_tab_renderer.h"
10 #include "views/view.h" 12 #include "views/view.h"
11 13
14 class BaseTabRenderer;
15 class DraggedTabController;
12 class TabStrip; 16 class TabStrip;
13 class TabStripController; 17 class TabStripController;
14 class ThemeProvider; 18 class ThemeProvider;
15 19
16 // Base class for the view tab strip implementations. 20 // Base class for the view tab strip implementations.
17 class BaseTabStrip : public views::View, 21 class BaseTabStrip : public views::View,
18 public TabController { 22 public TabController {
19 public: 23 public:
20 explicit BaseTabStrip(TabStripController* controller); 24 enum Type {
25 HORIZONTAL_TAB_STRIP,
26 VERTICAL_TAB_STRIP
27 };
28
29 BaseTabStrip(TabStripController* controller, Type type);
21 virtual ~BaseTabStrip(); 30 virtual ~BaseTabStrip();
22 31
32 Type type() const { return type_; }
33
23 // Returns the preferred height of this TabStrip. This is based on the 34 // Returns the preferred height of this TabStrip. This is based on the
24 // typical height of its constituent tabs. 35 // typical height of its constituent tabs.
25 virtual int GetPreferredHeight() = 0; 36 virtual int GetPreferredHeight() = 0;
26 37
27 // Set the background offset used by inactive tabs to match the frame image. 38 // Set the background offset used by inactive tabs to match the frame image.
28 virtual void SetBackgroundOffset(const gfx::Point& offset) = 0; 39 virtual void SetBackgroundOffset(const gfx::Point& offset) = 0;
29 40
30 // Returns true if the specified point(TabStrip coordinates) is 41 // Returns true if the specified point(TabStrip coordinates) is
31 // in the window caption area of the browser window. 42 // in the window caption area of the browser window.
32 virtual bool IsPositionInWindowCaption(const gfx::Point& point) = 0; 43 virtual bool IsPositionInWindowCaption(const gfx::Point& point) = 0;
33 44
34 // Sets the bounds of the tab at the specified |tab_index|. |tab_bounds| are 45 // Sets the bounds of the tab at the specified |tab_index|. |tab_bounds| are
35 // in TabStrip coordinates. 46 // in TabStrip coordinates.
36 virtual void SetDraggedTabBounds(int tab_index, 47 virtual void SetDraggedTabBounds(int tab_index,
37 const gfx::Rect& tab_bounds) = 0; 48 const gfx::Rect& tab_bounds) = 0;
38 49
39 // Returns true if a drag session is currently active.
40 virtual bool IsDragSessionActive() const = 0;
41
42 // Updates the loading animations displayed by tabs in the tabstrip to the 50 // Updates the loading animations displayed by tabs in the tabstrip to the
43 // next frame. 51 // next frame.
44 void UpdateLoadingAnimations(); 52 void UpdateLoadingAnimations();
45 53
46 // Returns true if Tabs in this TabStrip are currently changing size or 54 // Returns true if Tabs in this TabStrip are currently changing size or
47 // position. 55 // position.
48 virtual bool IsAnimating() const = 0; 56 virtual bool IsAnimating() const = 0;
49 57
50 // Returns this object as a TabStrip if it is one. 58 // Returns this object as a TabStrip if it is one.
51 virtual TabStrip* AsTabStrip() = 0; 59 virtual TabStrip* AsTabStrip() = 0;
52 60
53 // Starts highlighting the tab at the specified index. 61 // Starts highlighting the tab at the specified index.
54 virtual void StartHighlight(int model_index) = 0; 62 virtual void StartHighlight(int model_index) = 0;
55 63
56 // Stops all tab higlighting. 64 // Stops all tab higlighting.
57 virtual void StopAllHighlighting() = 0; 65 virtual void StopAllHighlighting() = 0;
58 66
59 // Returns the tab at the specified model index.
60 virtual BaseTabRenderer* GetBaseTabAtModelIndex(int model_index) const = 0;
61
62 // Returns the tab at the specified tab index.
63 virtual BaseTabRenderer* GetBaseTabAtTabIndex(int tab_index) const = 0;
64
65 // Returns the index of the specified tab in the model coordiate system, or
66 // -1 if tab is closing or not valid.
67 virtual int GetModelIndexOfBaseTab(const BaseTabRenderer* tab) const = 0;
68
69 // Returns the number of tabs.
70 virtual int GetTabCount() const = 0;
71
72 // Returns the selected tab. 67 // Returns the selected tab.
73 virtual BaseTabRenderer* GetSelectedBaseTab() const; 68 virtual BaseTabRenderer* GetSelectedBaseTab() const;
74 69
70 // Retrieves the ideal bounds for the Tab at the specified index.
71 const gfx::Rect& ideal_bounds(int tab_data_index) {
72 return tab_data_[tab_data_index].ideal_bounds;
73 }
74
75 // Creates and returns a tab that can be used for dragging. Ownership passes 75 // Creates and returns a tab that can be used for dragging. Ownership passes
76 // to the caller. 76 // to the caller.
77 virtual BaseTabRenderer* CreateTabForDragging() = 0; 77 virtual BaseTabRenderer* CreateTabForDragging() = 0;
78 78
79 // Adds a tab at the specified index. 79 // Adds a tab at the specified index.
80 virtual void AddTabAt(int model_index, 80 void AddTabAt(int model_index,
81 bool foreground, 81 bool foreground,
82 const TabRendererData& data) = 0; 82 const TabRendererData& data);
83 83
84 // Removes a tab at the specified index. If |initiated_close| is true, the 84 // Removes a tab at the specified index. If |initiated_close| is true, the
85 // close was initiated by the tab strip (such as clicking the close button). 85 // close was initiated by the tab strip (such as clicking the close button).
86 virtual void RemoveTabAt(int model_index, bool initiated_close) = 0; 86 virtual void RemoveTabAt(int model_index, bool initiated_close) = 0;
87 87
88 // Selects a tab at the specified index. |old_model_index| is the selected 88 // Selects a tab at the specified index. |old_model_index| is the selected
89 // index prior to the selection change. 89 // index prior to the selection change.
90 virtual void SelectTabAt(int old_model_index, int new_model_index) = 0; 90 virtual void SelectTabAt(int old_model_index, int new_model_index) = 0;
91 91
92 // Moves a tab. 92 // Moves a tab.
93 virtual void MoveTab(int from_model_index, int to_model_index) = 0; 93 virtual void MoveTab(int from_model_index, int to_model_index);
94 94
95 // Invoked when the title of a tab changes and the tab isn't loading. 95 // Invoked when the title of a tab changes and the tab isn't loading.
96 virtual void TabTitleChangedNotLoading(int model_index) = 0; 96 virtual void TabTitleChangedNotLoading(int model_index) = 0;
97 97
98 // Sets the tab data at the specified model index. 98 // Sets the tab data at the specified model index.
99 virtual void SetTabData(int model_index, const TabRendererData& data) = 0; 99 virtual void SetTabData(int model_index, const TabRendererData& data) = 0;
100 100
101 // Cover methods for TabStripController method. 101 // Returns the tab at the specified model index.
102 virtual BaseTabRenderer* GetBaseTabAtModelIndex(int model_index) const;
103
104 // Returns the tab at the specified tab index.
105 BaseTabRenderer* base_tab_at_tab_index(int tab_index) const {
106 return tab_data_[tab_index].tab;
107 }
108
109 // Returns the index of the specified tab in the model coordiate system, or
110 // -1 if tab is closing or not valid.
111 virtual int GetModelIndexOfBaseTab(const BaseTabRenderer* tab) const;
112
113 // Gets the number of Tabs in the tab strip.
114 // WARNING: this is the number of tabs displayed by the tabstrip, which if
115 // an animation is ongoing is not necessarily the same as the number of tabs
116 // in the model.
117 int tab_count() const { return static_cast<int>(tab_data_.size()); }
118
119 // Cover method for TabStripController::GetCount.
102 int GetModelCount() const; 120 int GetModelCount() const;
121
122 // Cover method for TabStripController::IsValidIndex.
103 bool IsValidModelIndex(int model_index) const; 123 bool IsValidModelIndex(int model_index) const;
104 124
125 // Returns the index into |tab_data_| corresponding to the index from the
126 // TabStripModel, or |tab_data_.size()| if there is no tab representing
127 // |model_index|.
128 int ModelIndexToTabIndex(int model_index) const;
129
130 TabStripController* controller() const { return controller_.get(); }
131
132 // Returns true if a drag session is currently active.
133 bool IsDragSessionActive() const;
134
105 // TabController overrides: 135 // TabController overrides:
106 virtual void SelectTab(BaseTabRenderer* tab); 136 virtual void SelectTab(BaseTabRenderer* tab);
107 virtual void CloseTab(BaseTabRenderer* tab); 137 virtual void CloseTab(BaseTabRenderer* tab);
108 virtual void ShowContextMenu(BaseTabRenderer* tab, const gfx::Point& p); 138 virtual void ShowContextMenu(BaseTabRenderer* tab, const gfx::Point& p);
109 virtual bool IsTabSelected(const BaseTabRenderer* tab) const; 139 virtual bool IsTabSelected(const BaseTabRenderer* tab) const;
110 virtual bool IsTabPinned(const BaseTabRenderer* tab) const; 140 virtual bool IsTabPinned(const BaseTabRenderer* tab) const;
111 virtual void MaybeStartDrag(BaseTabRenderer* tab, 141 virtual void MaybeStartDrag(BaseTabRenderer* tab,
112 const views::MouseEvent& event) = 0; 142 const views::MouseEvent& event);
113 virtual void ContinueDrag(const views::MouseEvent& event) = 0; 143 virtual void ContinueDrag(const views::MouseEvent& event);
114 virtual bool EndDrag(bool canceled) = 0; 144 virtual bool EndDrag(bool canceled);
115 145
116 TabStripController* controller() const { return controller_.get(); } 146 // View overrides:
147 virtual void Layout();
148
149 protected:
150 // The Tabs we contain, and their last generated "good" bounds.
151 struct TabData {
152 BaseTabRenderer* tab;
153 gfx::Rect ideal_bounds;
154 };
155
156 // View overrides.
157 virtual bool OnMouseDragged(const views::MouseEvent& event);
158 virtual void OnMouseReleased(const views::MouseEvent& event,
159 bool canceled);
160
161 // Creates and returns a new tab. The caller owners the returned tab.
162 virtual BaseTabRenderer* CreateTab() = 0;
163
164 // Invoked from |AddTabAt| after the newly created tab has been inserted.
165 // Subclasses should either start an animation, or layout.
166 virtual void StartInsertTabAnimation(int model_index, bool foreground) = 0;
167
168 // Invoked from |MoveTab| after |tab_data_| has been updated to animate the
169 // move.
170 virtual void StartMoveTabAnimation() = 0;
171
172 // Cleans up the Tab from the TabStrip. This is called from the tab animation
173 // code and is not a general-purpose method.
174 void RemoveAndDeleteTab(BaseTabRenderer* tab);
175
176 // Resets the bounds of all non-closing tabs.
177 virtual void GenerateIdealBounds() = 0;
178
179 void set_ideal_bounds(int index, const gfx::Rect& bounds) {
180 tab_data_[index].ideal_bounds = bounds;
181 }
182
183 // Returns the index into |tab_data_| corresponding to the specified tab, or
184 // -1 if the tab isn't in |tab_data_|.
185 int TabIndexOfTab(BaseTabRenderer* tab) const;
186
187 // Stops any ongoing animations. If |layout| is true and an animation is
188 // ongoing this does a layout.
189 virtual void StopAnimating(bool layout) = 0;
190
191 // Destroys the active drag controller.
192 void DestroyDragController();
193
194 // Used by DraggedTabController when the user starts or stops dragging a tab.
195 virtual void StartedDraggingTab(BaseTabRenderer* tab) = 0;
196 virtual void StoppedDraggingTab(BaseTabRenderer* tab) = 0;
197
198 // See description above field for details.
199 bool attaching_dragged_tab() const { return attaching_dragged_tab_; }
117 200
118 private: 201 private:
202 friend class DraggedTabController;
203
204 // See description above field for details.
205 void set_attaching_dragged_tab(bool value) { attaching_dragged_tab_ = value; }
206
119 scoped_ptr<TabStripController> controller_; 207 scoped_ptr<TabStripController> controller_;
208
209 const Type type_;
210
211 std::vector<TabData> tab_data_;
212
213 // The controller for a drag initiated from a Tab. Valid for the lifetime of
214 // the drag session.
215 scoped_ptr<DraggedTabController> drag_controller_;
216
217 // If true, the insert is a result of a drag attaching the tab back to the
218 // model.
219 bool attaching_dragged_tab_;
120 }; 220 };
121 221
122 #endif // CHROME_BROWSER_VIEWS_TABS_BASE_TAB_STRIP_H_ 222 #endif // CHROME_BROWSER_VIEWS_TABS_BASE_TAB_STRIP_H_
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/base_tab_renderer.cc ('k') | chrome/browser/views/tabs/base_tab_strip.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698