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

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

Issue 42490: Experiments with a new tabstrip + animator (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« no previous file with comments | « chrome/browser/views/tabs/tab_2.cc ('k') | chrome/browser/views/tabs/tab_strip_2.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
6 #define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
7
8 #include <vector>
9
10 #include "base/task.h"
11 #include "chrome/browser/views/tabs/tab_2.h"
12 #include "views/animator.h"
13 #include "views/view.h"
14
15 namespace gfx {
16 class Canvas;
17 }
18
19 // An interface implemented by an object that provides state for objects in the
20 // TabStrip2. This object is never owned by the TabStrip2.
21 // TODO(beng): maybe TabStrip2Delegate?
22 class TabStrip2Model {
23 public:
24 // Get presentation state for a particular Tab2.
25 virtual string16 GetTitle(int index) const = 0;
26 virtual bool IsSelected(int index) const = 0;
27
28 // The Tab2 at the specified index has been selected.
29 virtual void SelectTabAt(int index) = 0;
30
31 // Returns true if Tab2s can be dragged.
32 virtual bool CanDragTabs() const = 0;
33
34 // The Tab2 at the specified source index has moved to the specified
35 // destination index.
36 virtual void MoveTabAt(int index, int to_index) = 0;
37
38 // The Tab2 at the specified index was detached. |window_bounds| are the
39 // screen bounds of the current window, and |tab_bounds| are the bounds of the
40 // Tab2 in screen coordinates.
41 virtual void DetachTabAt(int index,
42 const gfx::Rect& window_bounds,
43 const gfx::Rect& tab_bounds) = 0;
44 };
45
46 // A TabStrip view.
47 class TabStrip2 : public views::View,
48 public Tab2Model,
49 public views::AnimatorDelegate {
50 public:
51 explicit TabStrip2(TabStrip2Model* model);
52 virtual ~TabStrip2();
53
54 // Returns true if the new TabStrip is enabled.
55 static bool Enabled();
56
57 // API for adding, removing, selecting and moving tabs around.
58 void AddTabAt(int index);
59 void RemoveTabAt(int index, Tab2Model* removing_model);
60 void SelectTabAt(int index);
61 void MoveTabAt(int index, int to_index);
62
63 int GetTabCount() const;
64 Tab2* GetTabAt(int index) const;
65 int GetTabIndex(Tab2* tab) const;
66
67 // Returns the index to insert an item into the TabStrip at for a drop at the
68 // specified point in TabStrip coordinates.
69 int GetInsertionIndexForPoint(const gfx::Point& point) const;
70
71 // Returns the bounds of the Tab2 under |screen_point| in screen coordinates.
72 gfx::Rect GetDraggedTabScreenBounds(const gfx::Point& screen_point);
73
74 // Sets the bounds of the Tab2 at the specified index to |tab_bounds|.
75 void SetDraggedTabBounds(int index, const gfx::Rect& tab_bounds);
76
77 // Animates the dragged Tab2 to the location implied by its index in the
78 // model.
79 void SendDraggedTabHome();
80
81 // Continue a drag operation on the Tab2 at the specified index.
82 void ResumeDraggingTab(int index, const gfx::Rect& tab_bounds);
83
84 // Returns true if the mouse pointer at the specified point (screen bounds)
85 // constitutes a rearrange rather than a detach.
86 static bool IsDragRearrange(TabStrip2* tabstrip,
87 const gfx::Point& screen_point);
88
89 // Overridden from Tab2Model:
90 virtual string16 GetTitle(Tab2* tab) const;
91 virtual bool IsSelected(Tab2* tab) const;
92 virtual void SelectTab(Tab2* tab);
93 virtual void CaptureDragInfo(Tab2* tab, const views::MouseEvent& drag_event);
94 virtual bool DragTab(Tab2* tab, const views::MouseEvent& drag_event);
95 virtual void DragEnded(Tab2* tab);
96 virtual views::AnimatorDelegate* AsAnimatorDelegate();
97
98 // Overridden from views::View:
99 virtual gfx::Size GetPreferredSize();
100 virtual void Layout();
101 virtual void Paint(gfx::Canvas* canvas);
102
103 private:
104 virtual void PaintChildren(gfx::Canvas* canvas);
105
106 // Overridden from views::AnimatorDelegate:
107 virtual views::View* GetClampedView(views::View* host);
108 virtual void AnimationCompletedForHost(View* host);
109
110 // Specifies what kind of TabStrip2 operation initiated the Layout, so the
111 // heuristic can adapt accordingly.
112 enum LayoutSource {
113 LS_TAB_ADD,
114 LS_TAB_REMOVE,
115 LS_TAB_SELECT,
116 LS_TAB_DRAG_REORDER,
117 LS_TAB_DRAG_NORMALIZE,
118 LS_OTHER
119 };
120
121 // Returns the animation directions for the specified layout source event.
122 int GetAnimateFlagsForLayoutSource(LayoutSource source) const;
123
124 // Lays out the contents of the TabStrip2.
125 void LayoutImpl(LayoutSource source);
126
127 // Execute the tab detach operation after a return to the message loop.
128 void DragDetachTabImpl(Tab2* tab, int index);
129
130 // Execute the drag initiation operation after a return to the message loop.
131 void StartDragTabImpl(int index, const gfx::Rect& tab_bounds);
132
133 // Returns the index into |tabs_| that corresponds to a publicly visible
134 // index. The index spaces are different since when a tab is closed we retain
135 // the tab in the presentation (and this our tab vector) until the tab has
136 // animated itself out of existence, but the clients of our API expect that
137 // index to be synchronously removed.
138 int GetInternalIndex(int public_index) const;
139
140 TabStrip2Model* model_;
141
142 // A vector of our Tabs. Stored separately from the child views, the child
143 // view order does not map directly to the presentation order, and because
144 // we can have child views that aren't Tab2s.
145 std::vector<Tab2*> tabs_;
146
147 // The position of the mouse relative to the widget when drag information was
148 // captured.
149 gfx::Point mouse_tab_offset_;
150
151 // The last position of the mouse along the horizontal axis of the TabStrip
152 // prior to the current drag event. Used to determine that the mouse has moved
153 // beyond the minimum horizontal threshold to initiate a drag operation.
154 int last_move_screen_x_;
155
156 // Factories to help break up work and avoid nesting message loops.
157 ScopedRunnableMethodFactory<TabStrip2> detach_factory_;
158 ScopedRunnableMethodFactory<TabStrip2> drag_start_factory_;
159
160 DISALLOW_COPY_AND_ASSIGN(TabStrip2);
161 };
162
163 #endif // #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/tab_2.cc ('k') | chrome/browser/views/tabs/tab_strip_2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698