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