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