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

Side by Side Diff: chrome/browser/ui/views/tabs/touch_tab_strip_layout.h

Issue 10213011: Attempt 3 at a better touch tabstrip. There is still a bunch to do, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Tab::GetTouchModeMinimumSize Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TOUCH_TAB_STRIP_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_TABS_TOUCH_TAB_STRIP_LAYOUT_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "ui/gfx/size.h"
11 #include "ui/views/view_model.h"
12
13 namespace views {
14 class ViewModel;
15 }
16
17 // TouchTabStripLayout is used by TabStrip in touch mode. TouchTabStripLayout is
18 // responsible for managing the bounds of the tabs. TouchTabStripLayout differs
19 // from the normal layout in that it stacks tabs. Stacked tabs are tabs placed
20 // nearly on top of each other, and if enough consecutive stacked tabs exist
21 // they are placed on top of each other. Normally stacked tabs are placed after
22 // mini-tabs, or at the end of the tabstrip, but during dragging tabs may be
23 // stacked before or after the active tab.
24 class TouchTabStripLayout {
25 public:
26 static const int kAddTypeMini = 1 << 0;
27 static const int kAddTypeActive = 1 << 1;
28
29 // |size| is the size for tabs, |padding| the padding between consecutive
30 // tabs, |stacked_padding| the padding between stacked tabs,
31 // |max_stacked_count| the maximum number of consecutive tabs that can be
32 // stacked before they are placed on top of each other, |view_model| is the
33 // ViewModel the bounds of the tabs are placed in.
34 TouchTabStripLayout(const gfx::Size& size,
35 int padding,
36 int stacked_padding,
37 int max_stacked_count,
38 views::ViewModel* view_model);
39 ~TouchTabStripLayout();
40
41 // Sets the x-coordinate the normal tabs start at as well as the mini-tab
42 // count. This is only useful if the mini-tab count or x-coordinate change.
43 void SetXAndMiniCount(int x, int mini_tab_count);
44
45 // Sets the width available for sizing the tabs to.
46 void SetWidth(int width);
47
48 int width() const { return width_; }
49
50 // Sets the index of the active tab.
51 void SetActiveIndex(int index);
52
53 // Drags the active tab.
54 void DragActiveTab(int delta);
55
56 // Adds a new tab at the specified index. |add_types| is a bitmask of
57 // kAddType*. |start_x| is the new x-coordinate non-mini tabs start at.
58 void AddTab(int index, int add_types, int start_x);
59
60 // Removes the tab at the specified index. |start_x| is the new x-coordinate
61 // normal tabs start at, and |old_x| the old x-coordinate of the tab. It is
62 // expected that the ViewModel hash been updated at the time this is invoked.
63 void RemoveTab(int index, int start_x, int old_x);
64
65 // Moves the tab from |from| to |to|. |new_active_index| is the index of the
66 // currently active tab.
67 void MoveTab(int from,
68 int to,
69 int new_active_index,
70 int start_x,
71 int mini_tab_count);
72
73 // Returns the active index as used by this class. The active index dictates
74 // stacking and what tabs are visible. As mini-tabs are never stacked,
75 // TouchTabStripLayout forces the active index to be in the normal tabs.
76 int active_index() const {
77 return active_index_ < mini_tab_count_ ? mini_tab_count_ : active_index_;
78 }
79
80 private:
81 friend class TouchTabStripLayoutTest;
82
83 // Sets the x-coordinate normal tabs start at, width mini-tab count and
84 // active index at once.
85 void Reset(int x, int width, int mini_tab_count, int active_index);
86
87 // Resets to an ideal layout state.
88 void ResetToIdealState();
89
90 // Returns the x-coordinate for the active tab constrained by the current tab
91 // counts.
92 int ConstrainActiveX(int x) const;
93
94 // Reset the bounds of the active tab (based on ConstrainActiveX()) and resets
95 // the bounds of the remaining tabs by way of LayoutUsingCurrent*.
96 void SetActiveBoundsAndLayoutFromActiveTab();
97
98 // Sets the bounds of the tabs after |index| relative to the position of the
99 // tab at |index|. Each tab is placed |tab_offset()| pixels after the previous
100 // tab, stacking as necessary.
101 void LayoutByTabOffsetAfter(int index);
102
103 // Same as LayoutByTabOffsetAfter(), but iterates toward
104 // |mini_tab_count_|.
105 void LayoutByTabOffsetBefore(int index);
106
107 // Similar to LayoutByTabOffsetAfter(), but uses the current x-coordinate
108 // if possible.
109 void LayoutUsingCurrentAfter(int index);
110 void LayoutUsingCurrentBefore(int index);
111
112 // Used when the tabs are stacked at one side. The remaining tabs are stacked
113 // against the |active_index()|. |delta| is the amount of space to resize the
114 // the tabs by.
115 void ExpandTabsBefore(int index, int delta);
116 void ExpandTabsAfter(int index, int delta);
117
118 // Adjusts the stacked tabs so that if there are more than
119 // |max_stacked_count_| tabs, the set > max_stacked_count_ have an
120 // x-coordinate of |x_|. Similarly those at the end have the same x-coordinate
121 // and are pushed all the way to the right.
122 void AdjustStackedTabs();
123 void AdjustLeadingStackedTabs();
124 void AdjustTrailingStackedTabs();
125
126 // Sets the bounds of the tab at |index|.
127 void SetIdealBoundsAt(int index, int x);
128
129 // Returns the min x-coordinate for the sepcified index. This is calculated
130 // assuming all the tabs before |index| are stacked.
131 int GetMinX(int index) const;
132
133 // Returns the max x-coordinage for the speficifed index. This is calculated
134 // assuming all the tabs after |index| are stacked.
135 int GetMaxX(int index) const;
136
137 // Returns the max x-coordinate for the tab at |index|. This is relative
138 // to the |active_index()| and is only useful when the active tab is pushed
139 // against the right side.
140 int GetMaxXCompressed(int index) const;
141
142 // Returns the min x-coordinate for the tab at |index|. This is relative
143 // to the |active_index()| and is only useful when the active tab is pushed
144 // against the left side.
145 int GetMinXCompressed(int index) const;
146
147 // Width needed to display |count| tabs.
148 int width_for_count(int count) const {
149 return count == 0 ? 0 :
150 (count * size_.width()) + (std::max(count - 1, 0) * padding_);
151 }
152
153 // Padding needed for |count| stacked tabs.
154 int stacked_padding_for_count(int count) const {
155 return std::min(count, max_stacked_count_) * stacked_padding_;
156 }
157
158 // Max stacked padding.
159 int max_stacked_width() const {
160 return stacked_padding_ * max_stacked_count_;
161 }
162
163 int ideal_x(int index) const { return view_model_->ideal_bounds(index).x(); }
164
165 // Returns true if some of the tabs need to be stacked.
166 bool requires_stacking() const {
167 return tab_count() != mini_tab_count_ &&
168 x_ + width_for_count(tab_count() - mini_tab_count_) > width_;
169 }
170
171 // Number of tabs.
172 int tab_count() const { return view_model_->view_size(); }
173
174 // Number of normal (non-mini) tabs.
175 int normal_tab_count() const { return tab_count() - mini_tab_count_; }
176
177 // Distance between one tab to the next.
178 int tab_offset() const { return size_.width() + padding_; }
179
180 #if !defined(NDEBUG)
181 std::string BoundsString() const;
182 #endif
183
184 // Size of tabs.
185 const gfx::Size size_;
186
187 // Padding between tabs.
188 const int padding_;
189
190 // Padding between stacked tabs.
191 const int stacked_padding_;
192
193 // Max number of stacked tabs.
194 const int max_stacked_count_;
195
196 // Where bounds are placed. This is owned by TabStrip.
197 views::ViewModel* view_model_;
198
199 // x-coordinate normal tabs start at.
200 int x_;
201
202 // Available width.
203 int width_;
204
205 // Number of mini-tabs.
206 int mini_tab_count_;
207
208 // Index of the active tab.
209 int active_index_;
210
211 DISALLOW_COPY_AND_ASSIGN(TouchTabStripLayout);
212 };
213
214 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TOUCH_TAB_STRIP_LAYOUT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip_unittest.cc ('k') | chrome/browser/ui/views/tabs/touch_tab_strip_layout.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698