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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 247193002: Remove touch layout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/ui/views/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" 27 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
28 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" 28 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h"
29 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" 29 #include "chrome/browser/ui/views/touch_uma/touch_uma.h"
30 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
33 #include "ui/accessibility/ax_view_state.h" 33 #include "ui/accessibility/ax_view_state.h"
34 #include "ui/base/default_theme_provider.h" 34 #include "ui/base/default_theme_provider.h"
35 #include "ui/base/dragdrop/drag_drop_types.h" 35 #include "ui/base/dragdrop/drag_drop_types.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/layout.h"
38 #include "ui/base/models/list_selection_model.h" 37 #include "ui/base/models/list_selection_model.h"
39 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/gfx/animation/animation_container.h" 39 #include "ui/gfx/animation/animation_container.h"
41 #include "ui/gfx/animation/throb_animation.h" 40 #include "ui/gfx/animation/throb_animation.h"
42 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
43 #include "ui/gfx/display.h" 42 #include "ui/gfx/display.h"
44 #include "ui/gfx/image/image_skia.h" 43 #include "ui/gfx/image/image_skia.h"
45 #include "ui/gfx/image/image_skia_operations.h" 44 #include "ui/gfx/image/image_skia_operations.h"
46 #include "ui/gfx/path.h" 45 #include "ui/gfx/path.h"
47 #include "ui/gfx/rect_conversions.h" 46 #include "ui/gfx/rect_conversions.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #if !defined(USE_ASH) 100 #if !defined(USE_ASH)
102 const int kMouseMoveTimeMS = 200; 101 const int kMouseMoveTimeMS = 200;
103 const int kMouseMoveCountBeforeConsiderReal = 3; 102 const int kMouseMoveCountBeforeConsiderReal = 3;
104 #endif 103 #endif
105 104
106 // Amount of time we delay before resizing after a close from a touch. 105 // Amount of time we delay before resizing after a close from a touch.
107 const int kTouchResizeLayoutTimeMS = 2000; 106 const int kTouchResizeLayoutTimeMS = 2000;
108 107
109 // Horizontal offset for the new tab button to bring it closer to the 108 // Horizontal offset for the new tab button to bring it closer to the
110 // rightmost tab. 109 // rightmost tab.
111 int newtab_button_h_offset() { 110 const int kNewTabButtonHorizontalOffset = -11;
112 static int value = -1;
113 if (value == -1) {
114 switch (ui::GetDisplayLayout()) {
115 case ui::LAYOUT_DESKTOP:
116 value = -11;
117 break;
118 case ui::LAYOUT_TOUCH:
119 value = -13;
120 break;
121 default:
122 NOTREACHED();
123 }
124 }
125 return value;
126 }
127 111
128 // Vertical offset for the new tab button to bring it closer to the 112 // Vertical offset for the new tab button to bring it closer to the
129 // rightmost tab. 113 // rightmost tab.
130 int newtab_button_v_offset() { 114 const int kNewTabButtonVerticalOffset = 7;
131 static int value = -1;
132 if (value == -1) {
133 switch (ui::GetDisplayLayout()) {
134 case ui::LAYOUT_DESKTOP:
135 value = 7;
136 break;
137 case ui::LAYOUT_TOUCH:
138 value = 8;
139 break;
140 default:
141 NOTREACHED();
142 }
143 }
144 return value;
145 }
146 115
147 // Amount the left edge of a tab is offset from the rectangle of the tab's 116 // Amount the left edge of a tab is offset from the rectangle of the tab's
148 // favicon/title/close box. Related to the width of IDR_TAB_ACTIVE_LEFT. 117 // favicon/title/close box. Related to the width of IDR_TAB_ACTIVE_LEFT.
149 // Affects the size of the "V" between adjacent tabs. 118 // Affects the size of the "V" between adjacent tabs.
150 int tab_h_offset() { 119 const int kTabHorizontalOffset = -26;
151 static int value = -1;
152 if (value == -1) {
153 switch (ui::GetDisplayLayout()) {
154 case ui::LAYOUT_DESKTOP:
155 value = -26;
156 break;
157 case ui::LAYOUT_TOUCH:
158 value = -34;
159 break;
160 default:
161 NOTREACHED();
162 }
163 }
164 return value;
165 }
166 120
167 // The size of the new tab button must be hardcoded because we need to be 121 // The size of the new tab button must be hardcoded because we need to be
168 // able to lay it out before we are able to get its image from the 122 // able to lay it out before we are able to get its image from the
169 // ui::ThemeProvider. It also makes sense to do this, because the size of the 123 // ui::ThemeProvider. It also makes sense to do this, because the size of the
170 // new tab button should not need to be calculated dynamically. 124 // new tab button should not need to be calculated dynamically.
171 int newtab_button_asset_width() { 125 const int kNewTabButtonAssetWidth = 34;
172 static int value = -1; 126 const int kNewTabButtonAssetHeight = 18;
173 if (value == -1) {
174 switch (ui::GetDisplayLayout()) {
175 case ui::LAYOUT_DESKTOP:
176 value = 34;
177 break;
178 case ui::LAYOUT_TOUCH:
179 value = 46;
180 break;
181 default:
182 NOTREACHED();
183 }
184 }
185 return value;
186 }
187
188 int newtab_button_asset_height() {
189 static int value = -1;
190 if (value == -1) {
191 switch (ui::GetDisplayLayout()) {
192 case ui::LAYOUT_DESKTOP:
193 value = 18;
194 break;
195 case ui::LAYOUT_TOUCH:
196 value = 24;
197 break;
198 default:
199 NOTREACHED();
200 }
201 }
202 return value;
203 }
204 127
205 // Amount to adjust the clip by when the tab is stacked before the active index. 128 // Amount to adjust the clip by when the tab is stacked before the active index.
206 int stacked_tab_left_clip() { 129 const int kStackedTabLeftClip = 20;
207 static int value = -1;
208 if (value == -1) {
209 switch (ui::GetDisplayLayout()) {
210 case ui::LAYOUT_DESKTOP:
211 value = 20;
212 break;
213 case ui::LAYOUT_TOUCH:
214 value = 26;
215 break;
216 default:
217 NOTREACHED();
218 }
219 }
220 return value;
221 }
222 130
223 // Amount to adjust the clip by when the tab is stacked after the active index. 131 // Amount to adjust the clip by when the tab is stacked after the active index.
224 int stacked_tab_right_clip() { 132 const int kStackedTabRightClip = 20;
225 static int value = -1;
226 if (value == -1) {
227 switch (ui::GetDisplayLayout()) {
228 case ui::LAYOUT_DESKTOP:
229 value = 20;
230 break;
231 case ui::LAYOUT_TOUCH:
232 value = 26;
233 break;
234 default:
235 NOTREACHED();
236 }
237 }
238 return value;
239 }
240 133
241 base::string16 GetClipboardText() { 134 base::string16 GetClipboardText() {
242 if (!ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) 135 if (!ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION))
243 return base::string16(); 136 return base::string16();
244 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 137 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
245 CHECK(clipboard); 138 CHECK(clipboard);
246 base::string16 clipboard_text; 139 base::string16 clipboard_text;
247 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &clipboard_text); 140 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &clipboard_text);
248 return clipboard_text; 141 return clipboard_text;
249 } 142 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // When the button is sized to the top of the tab strip we want the user to 263 // When the button is sized to the top of the tab strip we want the user to
371 // be able to click on complete bounds, and so don't return a custom hit 264 // be able to click on complete bounds, and so don't return a custom hit
372 // mask. 265 // mask.
373 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); 266 return !tab_strip_->SizeTabButtonToTopOfTabStrip();
374 } 267 }
375 268
376 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const { 269 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const {
377 DCHECK(path); 270 DCHECK(path);
378 271
379 SkScalar w = SkIntToScalar(width()); 272 SkScalar w = SkIntToScalar(width());
380 SkScalar v_offset = SkIntToScalar(newtab_button_v_offset()); 273 SkScalar v_offset = SkIntToScalar(kNewTabButtonVerticalOffset);
381 274
382 // These values are defined by the shape of the new tab image. Should that 275 // These values are defined by the shape of the new tab image. Should that
383 // image ever change, these values will need to be updated. They're so 276 // image ever change, these values will need to be updated. They're so
384 // custom it's not really worth defining constants for. 277 // custom it's not really worth defining constants for.
385 // These values are correct for regular and USE_ASH versions of the image. 278 // These values are correct for regular and USE_ASH versions of the image.
386 path->moveTo(0, v_offset + 1); 279 path->moveTo(0, v_offset + 1);
387 path->lineTo(w - 7, v_offset + 1); 280 path->lineTo(w - 7, v_offset + 1);
388 path->lineTo(w - 4, v_offset + 4); 281 path->lineTo(w - 4, v_offset + 4);
389 path->lineTo(w, v_offset + 16); 282 path->lineTo(w, v_offset + 16);
390 path->lineTo(w - 1, v_offset + 17); 283 path->lineTo(w - 1, v_offset + 17);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // The new tab background is mirrored in RTL mode, but the theme background 372 // The new tab background is mirrored in RTL mode, but the theme background
480 // should never be mirrored. Mirror it here to compensate. 373 // should never be mirrored. Mirror it here to compensate.
481 float x_scale = 1.0f; 374 float x_scale = 1.0f;
482 int x = GetMirroredX() + background_offset_.x(); 375 int x = GetMirroredX() + background_offset_.x();
483 if (base::i18n::IsRTL()) { 376 if (base::i18n::IsRTL()) {
484 x_scale = -1.0f; 377 x_scale = -1.0f;
485 // Offset by |width| such that the same region is painted as if there was no 378 // Offset by |width| such that the same region is painted as if there was no
486 // flip. 379 // flip.
487 x += width; 380 x += width;
488 } 381 }
489 canvas.TileImageInt(*background, x, newtab_button_v_offset() + offset_y, 382 canvas.TileImageInt(*background, x, kNewTabButtonVerticalOffset + offset_y,
490 x_scale, 1.0f, 0, 0, width, height); 383 x_scale, 1.0f, 0, 0, width, height);
491 384
492 if (alpha != 255) { 385 if (alpha != 255) {
493 SkPaint paint; 386 SkPaint paint;
494 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); 387 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255));
495 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 388 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
496 paint.setStyle(SkPaint::kFill_Style); 389 paint.setStyle(SkPaint::kFill_Style);
497 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); 390 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint);
498 } 391 }
499 392
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 713
821 int model_count = GetModelCount(); 714 int model_count = GetModelCount();
822 if (model_index + 1 != model_count && model_count > 1) { 715 if (model_index + 1 != model_count && model_count > 1) {
823 // The user is about to close a tab other than the last tab. Set 716 // The user is about to close a tab other than the last tab. Set
824 // available_width_for_tabs_ so that if we do a layout we don't position a 717 // available_width_for_tabs_ so that if we do a layout we don't position a
825 // tab past the end of the second to last tab. We do this so that as the 718 // tab past the end of the second to last tab. We do this so that as the
826 // user closes tabs with the mouse a tab continues to fall under the mouse. 719 // user closes tabs with the mouse a tab continues to fall under the mouse.
827 Tab* last_tab = tab_at(model_count - 1); 720 Tab* last_tab = tab_at(model_count - 1);
828 Tab* tab_being_removed = tab_at(model_index); 721 Tab* tab_being_removed = tab_at(model_index);
829 available_width_for_tabs_ = last_tab->x() + last_tab->width() - 722 available_width_for_tabs_ = last_tab->x() + last_tab->width() -
830 tab_being_removed->width() - tab_h_offset(); 723 tab_being_removed->width() - kTabHorizontalOffset;
831 if (model_index == 0 && tab_being_removed->data().mini && 724 if (model_index == 0 && tab_being_removed->data().mini &&
832 !tab_at(1)->data().mini) { 725 !tab_at(1)->data().mini) {
833 available_width_for_tabs_ -= kMiniToNonMiniGap; 726 available_width_for_tabs_ -= kMiniToNonMiniGap;
834 } 727 }
835 } 728 }
836 729
837 in_tab_close_ = true; 730 in_tab_close_ = true;
838 resize_layout_timer_.Stop(); 731 resize_layout_timer_.Stop();
839 if (source == CLOSE_TAB_FROM_TOUCH) { 732 if (source == CLOSE_TAB_FROM_TOUCH) {
840 StartResizeLayoutTabsFromTouchTimer(); 733 StartResizeLayoutTabsFromTouchTimer();
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 active_index--; 1087 active_index--;
1195 1088
1196 if (index < active_index) { 1089 if (index < active_index) {
1197 if (tab_at(index)->x() == tab_at(index + 1)->x()) 1090 if (tab_at(index)->x() == tab_at(index + 1)->x())
1198 return false; 1091 return false;
1199 1092
1200 if (tab_at(index)->x() > tab_at(index + 1)->x()) 1093 if (tab_at(index)->x() > tab_at(index + 1)->x())
1201 return true; // Can happen during dragging. 1094 return true; // Can happen during dragging.
1202 1095
1203 clip->SetRect(0, 0, tab_at(index + 1)->x() - tab_at(index)->x() + 1096 clip->SetRect(0, 0, tab_at(index + 1)->x() - tab_at(index)->x() +
1204 stacked_tab_left_clip(), 1097 kStackedTabLeftClip,
1205 tab_at(index)->height()); 1098 tab_at(index)->height());
1206 } else if (index > active_index && index > 0) { 1099 } else if (index > active_index && index > 0) {
1207 const gfx::Rect& tab_bounds(tab_at(index)->bounds()); 1100 const gfx::Rect& tab_bounds(tab_at(index)->bounds());
1208 const gfx::Rect& previous_tab_bounds(tab_at(index - 1)->bounds()); 1101 const gfx::Rect& previous_tab_bounds(tab_at(index - 1)->bounds());
1209 if (tab_bounds.x() == previous_tab_bounds.x()) 1102 if (tab_bounds.x() == previous_tab_bounds.x())
1210 return false; 1103 return false;
1211 1104
1212 if (tab_bounds.x() < previous_tab_bounds.x()) 1105 if (tab_bounds.x() < previous_tab_bounds.x())
1213 return true; // Can happen during dragging. 1106 return true; // Can happen during dragging.
1214 1107
1215 if (previous_tab_bounds.right() + tab_h_offset() != tab_bounds.x()) { 1108 if (previous_tab_bounds.right() + kTabHorizontalOffset != tab_bounds.x()) {
1216 int x = previous_tab_bounds.right() - tab_bounds.x() - 1109 int x = previous_tab_bounds.right() - tab_bounds.x() -
1217 stacked_tab_right_clip(); 1110 kStackedTabRightClip;
1218 clip->SetRect(x, 0, tab_bounds.width() - x, tab_bounds.height()); 1111 clip->SetRect(x, 0, tab_bounds.width() - x, tab_bounds.height());
1219 } 1112 }
1220 } 1113 }
1221 return true; 1114 return true;
1222 } 1115 }
1223 1116
1224 bool TabStrip::IsImmersiveStyle() const { 1117 bool TabStrip::IsImmersiveStyle() const {
1225 return immersive_style_; 1118 return immersive_style_;
1226 } 1119 }
1227 1120
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1536
1644 /////////////////////////////////////////////////////////////////////////////// 1537 ///////////////////////////////////////////////////////////////////////////////
1645 // TabStrip, private: 1538 // TabStrip, private:
1646 1539
1647 void TabStrip::Init() { 1540 void TabStrip::Init() {
1648 set_id(VIEW_ID_TAB_STRIP); 1541 set_id(VIEW_ID_TAB_STRIP);
1649 // So we get enter/exit on children to switch layout type. 1542 // So we get enter/exit on children to switch layout type.
1650 set_notify_enter_exit_on_child(true); 1543 set_notify_enter_exit_on_child(true);
1651 newtab_button_bounds_.SetRect(0, 1544 newtab_button_bounds_.SetRect(0,
1652 0, 1545 0,
1653 newtab_button_asset_width(), 1546 kNewTabButtonAssetWidth,
1654 newtab_button_asset_height() + 1547 kNewTabButtonAssetHeight +
1655 newtab_button_v_offset()); 1548 kNewTabButtonVerticalOffset);
1656 newtab_button_ = new NewTabButton(this, this); 1549 newtab_button_ = new NewTabButton(this, this);
1657 newtab_button_->SetTooltipText( 1550 newtab_button_->SetTooltipText(
1658 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); 1551 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB));
1659 newtab_button_->SetAccessibleName( 1552 newtab_button_->SetAccessibleName(
1660 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); 1553 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB));
1661 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1554 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1662 views::ImageButton::ALIGN_BOTTOM); 1555 views::ImageButton::ALIGN_BOTTOM);
1663 AddChildView(newtab_button_); 1556 AddChildView(newtab_button_);
1664 if (drop_indicator_width == 0) { 1557 if (drop_indicator_width == 0) {
1665 // Direction doesn't matter, both images are the same size. 1558 // Direction doesn't matter, both images are the same size.
(...skipping 17 matching lines...) Expand all
1683 available_width_for_tabs_ = -1; 1576 available_width_for_tabs_ = -1;
1684 1577
1685 GenerateIdealBounds(); 1578 GenerateIdealBounds();
1686 1579
1687 Tab* tab = tab_at(model_index); 1580 Tab* tab = tab_at(model_index);
1688 if (model_index == 0) { 1581 if (model_index == 0) {
1689 tab->SetBounds(0, ideal_bounds(model_index).y(), 0, 1582 tab->SetBounds(0, ideal_bounds(model_index).y(), 0,
1690 ideal_bounds(model_index).height()); 1583 ideal_bounds(model_index).height());
1691 } else { 1584 } else {
1692 Tab* last_tab = tab_at(model_index - 1); 1585 Tab* last_tab = tab_at(model_index - 1);
1693 tab->SetBounds(last_tab->bounds().right() + tab_h_offset(), 1586 tab->SetBounds(last_tab->bounds().right() + kTabHorizontalOffset,
1694 ideal_bounds(model_index).y(), 0, 1587 ideal_bounds(model_index).y(), 0,
1695 ideal_bounds(model_index).height()); 1588 ideal_bounds(model_index).height());
1696 } 1589 }
1697 1590
1698 AnimateToIdealBounds(); 1591 AnimateToIdealBounds();
1699 } 1592 }
1700 1593
1701 void TabStrip::StartMoveTabAnimation() { 1594 void TabStrip::StartMoveTabAnimation() {
1702 PrepareForAnimation(); 1595 PrepareForAnimation();
1703 GenerateIdealBounds(); 1596 GenerateIdealBounds();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 void TabStrip::CalculateBoundsForDraggedTabs(const std::vector<Tab*>& tabs, 1802 void TabStrip::CalculateBoundsForDraggedTabs(const std::vector<Tab*>& tabs,
1910 std::vector<gfx::Rect>* bounds) { 1803 std::vector<gfx::Rect>* bounds) {
1911 int x = 0; 1804 int x = 0;
1912 for (size_t i = 0; i < tabs.size(); ++i) { 1805 for (size_t i = 0; i < tabs.size(); ++i) {
1913 Tab* tab = tabs[i]; 1806 Tab* tab = tabs[i];
1914 if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini) 1807 if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini)
1915 x += kMiniToNonMiniGap; 1808 x += kMiniToNonMiniGap;
1916 gfx::Rect new_bounds = tab->bounds(); 1809 gfx::Rect new_bounds = tab->bounds();
1917 new_bounds.set_origin(gfx::Point(x, 0)); 1810 new_bounds.set_origin(gfx::Point(x, 0));
1918 bounds->push_back(new_bounds); 1811 bounds->push_back(new_bounds);
1919 x += tab->width() + tab_h_offset(); 1812 x += tab->width() + kTabHorizontalOffset;
1920 } 1813 }
1921 } 1814 }
1922 1815
1923 int TabStrip::GetSizeNeededForTabs(const std::vector<Tab*>& tabs) { 1816 int TabStrip::GetSizeNeededForTabs(const std::vector<Tab*>& tabs) {
1924 int width = 0; 1817 int width = 0;
1925 for (size_t i = 0; i < tabs.size(); ++i) { 1818 for (size_t i = 0; i < tabs.size(); ++i) {
1926 Tab* tab = tabs[i]; 1819 Tab* tab = tabs[i];
1927 width += tab->width(); 1820 width += tab->width();
1928 if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini) 1821 if (i > 0 && tab->data().mini != tabs[i - 1]->data().mini)
1929 width += kMiniToNonMiniGap; 1822 width += kMiniToNonMiniGap;
1930 } 1823 }
1931 if (tabs.size() > 0) 1824 if (tabs.size() > 0)
1932 width += tab_h_offset() * static_cast<int>(tabs.size() - 1); 1825 width += kTabHorizontalOffset * static_cast<int>(tabs.size() - 1);
1933 return width; 1826 return width;
1934 } 1827 }
1935 1828
1936 void TabStrip::RemoveTabFromViewModel(int index) { 1829 void TabStrip::RemoveTabFromViewModel(int index) {
1937 // We still need to paint the tab until we actually remove it. Put it 1830 // We still need to paint the tab until we actually remove it. Put it
1938 // in tabs_closing_map_ so we can find it. 1831 // in tabs_closing_map_ so we can find it.
1939 tabs_closing_map_[index].push_back(tab_at(index)); 1832 tabs_closing_map_[index].push_back(tab_at(index));
1940 UpdateTabsClosingMap(index + 1, -1); 1833 UpdateTabsClosingMap(index + 1, -1);
1941 tabs_.Remove(index); 1834 tabs_.Remove(index);
1942 } 1835 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 // width here; the first preserves the consistent "leave the last tab under 2097 // width here; the first preserves the consistent "leave the last tab under
2205 // the user's mouse so they can close many tabs" behavior at the cost of 2098 // the user's mouse so they can close many tabs" behavior at the cost of
2206 // prolonging the glitchy appearance of the overflow state, while the second 2099 // prolonging the glitchy appearance of the overflow state, while the second
2207 // gets us out of overflow as soon as possible but forces the user to move 2100 // gets us out of overflow as soon as possible but forces the user to move
2208 // their mouse for a few tabs' worth of closing. We choose visual 2101 // their mouse for a few tabs' worth of closing. We choose visual
2209 // imperfection over behavioral imperfection and select the first option. 2102 // imperfection over behavioral imperfection and select the first option.
2210 available_width = available_width_for_tabs_; 2103 available_width = available_width_for_tabs_;
2211 } 2104 }
2212 2105
2213 if (mini_tab_count > 0) { 2106 if (mini_tab_count > 0) {
2214 available_width -= mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()); 2107 available_width -=
2108 mini_tab_count * (Tab::GetMiniWidth() + kTabHorizontalOffset);
2215 tab_count -= mini_tab_count; 2109 tab_count -= mini_tab_count;
2216 if (tab_count == 0) { 2110 if (tab_count == 0) {
2217 *selected_width = *unselected_width = Tab::GetStandardSize().width(); 2111 *selected_width = *unselected_width = Tab::GetStandardSize().width();
2218 return; 2112 return;
2219 } 2113 }
2220 // Account for gap between the last mini-tab and first non-mini-tab. 2114 // Account for gap between the last mini-tab and first non-mini-tab.
2221 available_width -= kMiniToNonMiniGap; 2115 available_width -= kMiniToNonMiniGap;
2222 } 2116 }
2223 2117
2224 // Calculate the desired tab widths by dividing the available space into equal 2118 // Calculate the desired tab widths by dividing the available space into equal
2225 // portions. Don't let tabs get larger than the "standard width" or smaller 2119 // portions. Don't let tabs get larger than the "standard width" or smaller
2226 // than the minimum width for each type, respectively. 2120 // than the minimum width for each type, respectively.
2227 const int total_offset = tab_h_offset() * (tab_count - 1); 2121 const int total_offset = kTabHorizontalOffset * (tab_count - 1);
2228 const double desired_tab_width = std::min((static_cast<double>( 2122 const double desired_tab_width = std::min((static_cast<double>(
2229 available_width - total_offset) / static_cast<double>(tab_count)), 2123 available_width - total_offset) / static_cast<double>(tab_count)),
2230 static_cast<double>(Tab::GetStandardSize().width())); 2124 static_cast<double>(Tab::GetStandardSize().width()));
2231 *unselected_width = std::max(desired_tab_width, min_unselected_width); 2125 *unselected_width = std::max(desired_tab_width, min_unselected_width);
2232 *selected_width = std::max(desired_tab_width, min_selected_width); 2126 *selected_width = std::max(desired_tab_width, min_selected_width);
2233 2127
2234 // When there are multiple tabs, we'll have one selected and some unselected 2128 // When there are multiple tabs, we'll have one selected and some unselected
2235 // tabs. If the desired width was between the minimum sizes of these types, 2129 // tabs. If the desired width was between the minimum sizes of these types,
2236 // try to shrink the tabs with the smaller minimum. For example, if we have 2130 // try to shrink the tabs with the smaller minimum. For example, if we have
2237 // a strip of width 10 with 4 tabs, the desired width per tab will be 2.5. If 2131 // a strip of width 10 with 4 tabs, the desired width per tab will be 2.5. If
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 } 2217 }
2324 2218
2325 gfx::Rect TabStrip::GetDropBounds(int drop_index, 2219 gfx::Rect TabStrip::GetDropBounds(int drop_index,
2326 bool drop_before, 2220 bool drop_before,
2327 bool* is_beneath) { 2221 bool* is_beneath) {
2328 DCHECK_NE(drop_index, -1); 2222 DCHECK_NE(drop_index, -1);
2329 int center_x; 2223 int center_x;
2330 if (drop_index < tab_count()) { 2224 if (drop_index < tab_count()) {
2331 Tab* tab = tab_at(drop_index); 2225 Tab* tab = tab_at(drop_index);
2332 if (drop_before) 2226 if (drop_before)
2333 center_x = tab->x() - (tab_h_offset() / 2); 2227 center_x = tab->x() - (kTabHorizontalOffset / 2);
2334 else 2228 else
2335 center_x = tab->x() + (tab->width() / 2); 2229 center_x = tab->x() + (tab->width() / 2);
2336 } else { 2230 } else {
2337 Tab* last_tab = tab_at(drop_index - 1); 2231 Tab* last_tab = tab_at(drop_index - 1);
2338 center_x = last_tab->x() + last_tab->width() + (tab_h_offset() / 2); 2232 center_x = last_tab->x() + last_tab->width() + (kTabHorizontalOffset / 2);
2339 } 2233 }
2340 2234
2341 // Mirror the center point if necessary. 2235 // Mirror the center point if necessary.
2342 center_x = GetMirroredXInView(center_x); 2236 center_x = GetMirroredXInView(center_x);
2343 2237
2344 // Determine the screen bounds. 2238 // Determine the screen bounds.
2345 gfx::Point drop_loc(center_x - drop_indicator_width / 2, 2239 gfx::Point drop_loc(center_x - drop_indicator_width / 2,
2346 -drop_indicator_height); 2240 -drop_indicator_height);
2347 ConvertPointToScreen(this, &drop_loc); 2241 ConvertPointToScreen(this, &drop_loc);
2348 gfx::Rect drop_bounds(drop_loc.x(), drop_loc.y(), drop_indicator_width, 2242 gfx::Rect drop_bounds(drop_loc.x(), drop_loc.y(), drop_indicator_width,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 } 2370 }
2477 2371
2478 void TabStrip::GenerateIdealBounds() { 2372 void TabStrip::GenerateIdealBounds() {
2479 int new_tab_y = 0; 2373 int new_tab_y = 0;
2480 2374
2481 if (touch_layout_.get()) { 2375 if (touch_layout_.get()) {
2482 if (tabs_.view_size() == 0) 2376 if (tabs_.view_size() == 0)
2483 return; 2377 return;
2484 2378
2485 int new_tab_x = tabs_.ideal_bounds(tabs_.view_size() - 1).right() + 2379 int new_tab_x = tabs_.ideal_bounds(tabs_.view_size() - 1).right() +
2486 newtab_button_h_offset(); 2380 kNewTabButtonHorizontalOffset;
2487 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y)); 2381 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y));
2488 return; 2382 return;
2489 } 2383 }
2490 2384
2491 double unselected, selected; 2385 double unselected, selected;
2492 GetDesiredTabWidths(tab_count(), GetMiniTabCount(), &unselected, &selected); 2386 GetDesiredTabWidths(tab_count(), GetMiniTabCount(), &unselected, &selected);
2493 current_unselected_width_ = unselected; 2387 current_unselected_width_ = unselected;
2494 current_selected_width_ = selected; 2388 current_selected_width_ = selected;
2495 2389
2496 // NOTE: This currently assumes a tab's height doesn't differ based on 2390 // NOTE: This currently assumes a tab's height doesn't differ based on
2497 // selected state or the number of tabs in the strip! 2391 // selected state or the number of tabs in the strip!
2498 int tab_height = Tab::GetStandardSize().height(); 2392 int tab_height = Tab::GetStandardSize().height();
2499 int first_non_mini_index = 0; 2393 int first_non_mini_index = 0;
2500 double tab_x = GenerateIdealBoundsForMiniTabs(&first_non_mini_index); 2394 double tab_x = GenerateIdealBoundsForMiniTabs(&first_non_mini_index);
2501 for (int i = first_non_mini_index; i < tab_count(); ++i) { 2395 for (int i = first_non_mini_index; i < tab_count(); ++i) {
2502 Tab* tab = tab_at(i); 2396 Tab* tab = tab_at(i);
2503 DCHECK(!tab->data().mini); 2397 DCHECK(!tab->data().mini);
2504 double tab_width = tab->IsActive() ? selected : unselected; 2398 double tab_width = tab->IsActive() ? selected : unselected;
2505 double end_of_tab = tab_x + tab_width; 2399 double end_of_tab = tab_x + tab_width;
2506 int rounded_tab_x = Round(tab_x); 2400 int rounded_tab_x = Round(tab_x);
2507 set_ideal_bounds( 2401 set_ideal_bounds(
2508 i, 2402 i,
2509 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, 2403 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x,
2510 tab_height)); 2404 tab_height));
2511 tab_x = end_of_tab + tab_h_offset(); 2405 tab_x = end_of_tab + kTabHorizontalOffset;
2512 } 2406 }
2513 2407
2514 // Update bounds of new tab button. 2408 // Update bounds of new tab button.
2515 int new_tab_x; 2409 int new_tab_x;
2516 if (abs(Round(unselected) - Tab::GetStandardSize().width()) > 1 && 2410 if (abs(Round(unselected) - Tab::GetStandardSize().width()) > 1 &&
2517 !in_tab_close_) { 2411 !in_tab_close_) {
2518 // We're shrinking tabs, so we need to anchor the New Tab button to the 2412 // We're shrinking tabs, so we need to anchor the New Tab button to the
2519 // right edge of the TabStrip's bounds, rather than the right edge of the 2413 // right edge of the TabStrip's bounds, rather than the right edge of the
2520 // right-most Tab, otherwise it'll bounce when animating. 2414 // right-most Tab, otherwise it'll bounce when animating.
2521 new_tab_x = width() - newtab_button_bounds_.width(); 2415 new_tab_x = width() - newtab_button_bounds_.width();
2522 } else { 2416 } else {
2523 new_tab_x = Round(tab_x - tab_h_offset()) + newtab_button_h_offset(); 2417 new_tab_x = Round(tab_x - kTabHorizontalOffset) +
2418 kNewTabButtonHorizontalOffset;
2524 } 2419 }
2525 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y)); 2420 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y));
2526 } 2421 }
2527 2422
2528 int TabStrip::GenerateIdealBoundsForMiniTabs(int* first_non_mini_index) { 2423 int TabStrip::GenerateIdealBoundsForMiniTabs(int* first_non_mini_index) {
2529 int next_x = 0; 2424 int next_x = 0;
2530 int mini_width = Tab::GetMiniWidth(); 2425 int mini_width = Tab::GetMiniWidth();
2531 int tab_height = Tab::GetStandardSize().height(); 2426 int tab_height = Tab::GetStandardSize().height();
2532 int index = 0; 2427 int index = 0;
2533 for (; index < tab_count() && tab_at(index)->data().mini; ++index) { 2428 for (; index < tab_count() && tab_at(index)->data().mini; ++index) {
2534 set_ideal_bounds(index, 2429 set_ideal_bounds(index,
2535 gfx::Rect(next_x, 0, mini_width, tab_height)); 2430 gfx::Rect(next_x, 0, mini_width, tab_height));
2536 next_x += mini_width + tab_h_offset(); 2431 next_x += mini_width + kTabHorizontalOffset;
2537 } 2432 }
2538 if (index > 0 && index < tab_count()) 2433 if (index > 0 && index < tab_count())
2539 next_x += kMiniToNonMiniGap; 2434 next_x += kMiniToNonMiniGap;
2540 if (first_non_mini_index) 2435 if (first_non_mini_index)
2541 *first_non_mini_index = index; 2436 *first_non_mini_index = index;
2542 return next_x; 2437 return next_x;
2543 } 2438 }
2544 2439
2545 // static 2440 // static
2546 int TabStrip::new_tab_button_width() { 2441 int TabStrip::new_tab_button_width() {
2547 return newtab_button_asset_width() + newtab_button_h_offset(); 2442 return kNewTabButtonAssetWidth + kNewTabButtonHorizontalOffset;
2548 } 2443 }
2549 2444
2550 // static 2445 // static
2551 int TabStrip::button_v_offset() { 2446 int TabStrip::button_v_offset() {
2552 return newtab_button_v_offset(); 2447 return kNewTabButtonVerticalOffset;
2553 } 2448 }
2554 2449
2555 int TabStrip::tab_area_width() const { 2450 int TabStrip::tab_area_width() const {
2556 return width() - new_tab_button_width(); 2451 return width() - new_tab_button_width();
2557 } 2452 }
2558 2453
2559 void TabStrip::StartResizeLayoutAnimation() { 2454 void TabStrip::StartResizeLayoutAnimation() {
2560 PrepareForAnimation(); 2455 PrepareForAnimation();
2561 GenerateIdealBounds(); 2456 GenerateIdealBounds();
2562 AnimateToIdealBounds(); 2457 AnimateToIdealBounds();
2563 } 2458 }
2564 2459
2565 void TabStrip::StartMiniTabAnimation() { 2460 void TabStrip::StartMiniTabAnimation() {
2566 in_tab_close_ = false; 2461 in_tab_close_ = false;
2567 available_width_for_tabs_ = -1; 2462 available_width_for_tabs_ = -1;
2568 2463
2569 PrepareForAnimation(); 2464 PrepareForAnimation();
2570 2465
2571 GenerateIdealBounds(); 2466 GenerateIdealBounds();
2572 AnimateToIdealBounds(); 2467 AnimateToIdealBounds();
2573 } 2468 }
2574 2469
2575 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) { 2470 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) {
2576 // The user initiated the close. We want to persist the bounds of all the 2471 // The user initiated the close. We want to persist the bounds of all the
2577 // existing tabs, so we manually shift ideal_bounds then animate. 2472 // existing tabs, so we manually shift ideal_bounds then animate.
2578 Tab* tab_closing = tab_at(model_index); 2473 Tab* tab_closing = tab_at(model_index);
2579 int delta = tab_closing->width() + tab_h_offset(); 2474 int delta = tab_closing->width() + kTabHorizontalOffset;
2580 // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to 2475 // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to
2581 // add the extra padding. 2476 // add the extra padding.
2582 DCHECK_NE(model_index + 1, tab_count()); 2477 DCHECK_NE(model_index + 1, tab_count());
2583 if (tab_closing->data().mini && model_index + 1 < tab_count() && 2478 if (tab_closing->data().mini && model_index + 1 < tab_count() &&
2584 !tab_at(model_index + 1)->data().mini) { 2479 !tab_at(model_index + 1)->data().mini) {
2585 delta += kMiniToNonMiniGap; 2480 delta += kMiniToNonMiniGap;
2586 } 2481 }
2587 2482
2588 for (int i = model_index + 1; i < tab_count(); ++i) { 2483 for (int i = model_index + 1; i < tab_count(); ++i) {
2589 gfx::Rect bounds = ideal_bounds(i); 2484 gfx::Rect bounds = ideal_bounds(i);
(...skipping 29 matching lines...) Expand all
2619 const gfx::Point& point_in_tabstrip_coords) { 2514 const gfx::Point& point_in_tabstrip_coords) {
2620 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); 2515 gfx::Point point_in_tab_coords(point_in_tabstrip_coords);
2621 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); 2516 View::ConvertPointToTarget(this, tab, &point_in_tab_coords);
2622 return tab->HitTestPoint(point_in_tab_coords); 2517 return tab->HitTestPoint(point_in_tab_coords);
2623 } 2518 }
2624 2519
2625 int TabStrip::GetStartXForNormalTabs() const { 2520 int TabStrip::GetStartXForNormalTabs() const {
2626 int mini_tab_count = GetMiniTabCount(); 2521 int mini_tab_count = GetMiniTabCount();
2627 if (mini_tab_count == 0) 2522 if (mini_tab_count == 0)
2628 return 0; 2523 return 0;
2629 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + 2524 return mini_tab_count * (Tab::GetMiniWidth() + kTabHorizontalOffset) +
2630 kMiniToNonMiniGap; 2525 kMiniToNonMiniGap;
2631 } 2526 }
2632 2527
2633 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { 2528 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) {
2634 if (touch_layout_.get()) { 2529 if (touch_layout_.get()) {
2635 int active_tab_index = touch_layout_->active_index(); 2530 int active_tab_index = touch_layout_->active_index();
2636 if (active_tab_index != -1) { 2531 if (active_tab_index != -1) {
2637 Tab* tab = FindTabForEventFrom(point, active_tab_index, -1); 2532 Tab* tab = FindTabForEventFrom(point, active_tab_index, -1);
2638 if (!tab) 2533 if (!tab)
2639 tab = FindTabForEventFrom(point, active_tab_index + 1, 1); 2534 tab = FindTabForEventFrom(point, active_tab_index + 1, 1);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 bool needs_touch = NeedsTouchLayout(); 2585 bool needs_touch = NeedsTouchLayout();
2691 bool using_touch = touch_layout_.get() != NULL; 2586 bool using_touch = touch_layout_.get() != NULL;
2692 if (needs_touch == using_touch) 2587 if (needs_touch == using_touch)
2693 return; 2588 return;
2694 2589
2695 if (needs_touch) { 2590 if (needs_touch) {
2696 gfx::Size tab_size(Tab::GetMinimumSelectedSize()); 2591 gfx::Size tab_size(Tab::GetMinimumSelectedSize());
2697 tab_size.set_width(Tab::GetTouchWidth()); 2592 tab_size.set_width(Tab::GetTouchWidth());
2698 touch_layout_.reset(new StackedTabStripLayout( 2593 touch_layout_.reset(new StackedTabStripLayout(
2699 tab_size, 2594 tab_size,
2700 tab_h_offset(), 2595 kTabHorizontalOffset,
2701 kStackedPadding, 2596 kStackedPadding,
2702 kMaxStackedCount, 2597 kMaxStackedCount,
2703 &tabs_)); 2598 &tabs_));
2704 touch_layout_->SetWidth(width() - new_tab_button_width()); 2599 touch_layout_->SetWidth(width() - new_tab_button_width());
2705 // This has to be after SetWidth() as SetWidth() is going to reset the 2600 // This has to be after SetWidth() as SetWidth() is going to reset the
2706 // bounds of the mini-tabs (since StackedTabStripLayout doesn't yet know how 2601 // bounds of the mini-tabs (since StackedTabStripLayout doesn't yet know how
2707 // many mini-tabs there are). 2602 // many mini-tabs there are).
2708 GenerateIdealBoundsForMiniTabs(NULL); 2603 GenerateIdealBoundsForMiniTabs(NULL);
2709 touch_layout_->SetXAndMiniCount(GetStartXForNormalTabs(), 2604 touch_layout_->SetXAndMiniCount(GetStartXForNormalTabs(),
2710 GetMiniTabCount()); 2605 GetMiniTabCount());
(...skipping 10 matching lines...) Expand all
2721 if (layout_type_ == TAB_STRIP_LAYOUT_SHRINK) 2616 if (layout_type_ == TAB_STRIP_LAYOUT_SHRINK)
2722 return false; 2617 return false;
2723 2618
2724 int mini_tab_count = GetMiniTabCount(); 2619 int mini_tab_count = GetMiniTabCount();
2725 int normal_count = tab_count() - mini_tab_count; 2620 int normal_count = tab_count() - mini_tab_count;
2726 if (normal_count <= 1 || normal_count == mini_tab_count) 2621 if (normal_count <= 1 || normal_count == mini_tab_count)
2727 return false; 2622 return false;
2728 int x = GetStartXForNormalTabs(); 2623 int x = GetStartXForNormalTabs();
2729 int available_width = width() - x - new_tab_button_width(); 2624 int available_width = width() - x - new_tab_button_width();
2730 return (Tab::GetTouchWidth() * normal_count + 2625 return (Tab::GetTouchWidth() * normal_count +
2731 tab_h_offset() * (normal_count - 1)) > available_width; 2626 kTabHorizontalOffset * (normal_count - 1)) > available_width;
2732 } 2627 }
2733 2628
2734 void TabStrip::SetResetToShrinkOnExit(bool value) { 2629 void TabStrip::SetResetToShrinkOnExit(bool value) {
2735 if (!GetAdjustLayout()) 2630 if (!GetAdjustLayout())
2736 return; 2631 return;
2737 2632
2738 if (value && layout_type_ == TAB_STRIP_LAYOUT_SHRINK) 2633 if (value && layout_type_ == TAB_STRIP_LAYOUT_SHRINK)
2739 value = false; // We're already at TAB_STRIP_LAYOUT_SHRINK. 2634 value = false; // We're already at TAB_STRIP_LAYOUT_SHRINK.
2740 2635
2741 if (value == reset_to_shrink_on_exit_) 2636 if (value == reset_to_shrink_on_exit_)
2742 return; 2637 return;
2743 2638
2744 reset_to_shrink_on_exit_ = value; 2639 reset_to_shrink_on_exit_ = value;
2745 // Add an observer so we know when the mouse moves out of the tabstrip. 2640 // Add an observer so we know when the mouse moves out of the tabstrip.
2746 if (reset_to_shrink_on_exit_) 2641 if (reset_to_shrink_on_exit_)
2747 AddMessageLoopObserver(); 2642 AddMessageLoopObserver();
2748 else 2643 else
2749 RemoveMessageLoopObserver(); 2644 RemoveMessageLoopObserver();
2750 } 2645 }
2751 2646
2752 bool TabStrip::GetAdjustLayout() const { 2647 bool TabStrip::GetAdjustLayout() const {
2753 if (!adjust_layout_) 2648 if (!adjust_layout_)
2754 return false; 2649 return false;
2755
2756 return chrome::GetHostDesktopTypeForNativeView( 2650 return chrome::GetHostDesktopTypeForNativeView(
2757 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; 2651 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH;
2758 } 2652 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698