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
|
// Copyright (c) 2009 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_TAB_STRIP_2_H_
#define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
#include <vector>
#include "base/task.h"
#include "chrome/browser/views/tabs/tab_2.h"
#include "views/animator.h"
#include "views/view.h"
namespace gfx {
class Canvas;
}
// An interface implemented by an object that provides state for objects in the
// TabStrip2. This object is never owned by the TabStrip2.
// TODO(beng): maybe TabStrip2Delegate?
class TabStrip2Model {
public:
// Get presentation state for a particular Tab2.
virtual string16 GetTitle(int index) const = 0;
virtual bool IsSelected(int index) const = 0;
// The Tab2 at the specified index has been selected.
virtual void SelectTabAt(int index) = 0;
// Returns true if Tab2s can be dragged.
virtual bool CanDragTabs() const = 0;
// The Tab2 at the specified source index has moved to the specified
// destination index.
virtual void MoveTabAt(int index, int to_index) = 0;
// The Tab2 at the specified index was detached. |window_bounds| are the
// screen bounds of the current window, and |tab_bounds| are the bounds of the
// Tab2 in screen coordinates.
virtual void DetachTabAt(int index,
const gfx::Rect& window_bounds,
const gfx::Rect& tab_bounds) = 0;
};
// A TabStrip view.
class TabStrip2 : public views::View,
public Tab2Model,
public views::AnimatorDelegate {
public:
explicit TabStrip2(TabStrip2Model* model);
virtual ~TabStrip2();
// Returns true if the new TabStrip is enabled.
static bool Enabled();
// API for adding, removing, selecting and moving tabs around.
void AddTabAt(int index);
void RemoveTabAt(int index, Tab2Model* removing_model);
void SelectTabAt(int index);
void MoveTabAt(int index, int to_index);
int GetTabCount() const;
Tab2* GetTabAt(int index) const;
int GetTabIndex(Tab2* tab) const;
// Returns the index to insert an item into the TabStrip at for a drop at the
// specified point in TabStrip coordinates.
int GetInsertionIndexForPoint(const gfx::Point& point) const;
// Returns the bounds of the Tab2 under |screen_point| in screen coordinates.
gfx::Rect GetDraggedTabScreenBounds(const gfx::Point& screen_point);
// Sets the bounds of the Tab2 at the specified index to |tab_bounds|.
void SetDraggedTabBounds(int index, const gfx::Rect& tab_bounds);
// Animates the dragged Tab2 to the location implied by its index in the
// model.
void SendDraggedTabHome();
// Continue a drag operation on the Tab2 at the specified index.
void ResumeDraggingTab(int index, const gfx::Rect& tab_bounds);
// Returns true if the mouse pointer at the specified point (screen bounds)
// constitutes a rearrange rather than a detach.
static bool IsDragRearrange(TabStrip2* tabstrip,
const gfx::Point& screen_point);
// Overridden from Tab2Model:
virtual string16 GetTitle(Tab2* tab) const;
virtual bool IsSelected(Tab2* tab) const;
virtual void SelectTab(Tab2* tab);
virtual void CaptureDragInfo(Tab2* tab, const views::MouseEvent& drag_event);
virtual bool DragTab(Tab2* tab, const views::MouseEvent& drag_event);
virtual void DragEnded(Tab2* tab);
virtual views::AnimatorDelegate* AsAnimatorDelegate();
// Overridden from views::View:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
virtual void Paint(gfx::Canvas* canvas);
private:
virtual void PaintChildren(gfx::Canvas* canvas);
// Overridden from views::AnimatorDelegate:
virtual views::View* GetClampedView(views::View* host);
virtual void AnimationCompletedForHost(View* host);
// Specifies what kind of TabStrip2 operation initiated the Layout, so the
// heuristic can adapt accordingly.
enum LayoutSource {
LS_TAB_ADD,
LS_TAB_REMOVE,
LS_TAB_SELECT,
LS_TAB_DRAG_REORDER,
LS_TAB_DRAG_NORMALIZE,
LS_OTHER
};
// Returns the animation directions for the specified layout source event.
int GetAnimateFlagsForLayoutSource(LayoutSource source) const;
// Lays out the contents of the TabStrip2.
void LayoutImpl(LayoutSource source);
// Execute the tab detach operation after a return to the message loop.
void DragDetachTabImpl(Tab2* tab, int index);
// Execute the drag initiation operation after a return to the message loop.
void StartDragTabImpl(int index, const gfx::Rect& tab_bounds);
// Returns the index into |tabs_| that corresponds to a publicly visible
// index. The index spaces are different since when a tab is closed we retain
// the tab in the presentation (and this our tab vector) until the tab has
// animated itself out of existence, but the clients of our API expect that
// index to be synchronously removed.
int GetInternalIndex(int public_index) const;
TabStrip2Model* model_;
// A vector of our Tabs. Stored separately from the child views, the child
// view order does not map directly to the presentation order, and because
// we can have child views that aren't Tab2s.
std::vector<Tab2*> tabs_;
// The position of the mouse relative to the widget when drag information was
// captured.
gfx::Point mouse_tab_offset_;
// The last position of the mouse along the horizontal axis of the TabStrip
// prior to the current drag event. Used to determine that the mouse has moved
// beyond the minimum horizontal threshold to initiate a drag operation.
int last_move_screen_x_;
// Factories to help break up work and avoid nesting message loops.
ScopedRunnableMethodFactory<TabStrip2> detach_factory_;
ScopedRunnableMethodFactory<TabStrip2> drag_start_factory_;
DISALLOW_COPY_AND_ASSIGN(TabStrip2);
};
#endif // #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
|