| 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 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 const TabSizeInfo& GetTabSizeInfo() { | 246 const TabSizeInfo& GetTabSizeInfo() { |
| 247 static TabSizeInfo* tab_size_info = nullptr; | 247 static TabSizeInfo* tab_size_info = nullptr; |
| 248 if (tab_size_info) | 248 if (tab_size_info) |
| 249 return *tab_size_info; | 249 return *tab_size_info; |
| 250 | 250 |
| 251 tab_size_info = new TabSizeInfo; | 251 tab_size_info = new TabSizeInfo; |
| 252 tab_size_info->pinned_tab_width = Tab::GetPinnedWidth(); | 252 tab_size_info->pinned_tab_width = Tab::GetPinnedWidth(); |
| 253 tab_size_info->min_active_width = Tab::GetMinimumActiveSize().width(); | 253 tab_size_info->min_active_width = Tab::GetMinimumActiveSize().width(); |
| 254 tab_size_info->min_inactive_width = Tab::GetMinimumInactiveSize().width(); | 254 tab_size_info->min_inactive_width = Tab::GetMinimumInactiveSize().width(); |
| 255 tab_size_info->max_size = Tab::GetStandardSize(); | 255 tab_size_info->max_size = Tab::GetStandardSize(); |
| 256 tab_size_info->tab_overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 256 tab_size_info->tab_overlap = Tab::kOverlap; |
| 257 tab_size_info->pinned_to_normal_offset = kPinnedToNonPinnedOffset; | 257 tab_size_info->pinned_to_normal_offset = kPinnedToNonPinnedOffset; |
| 258 return *tab_size_info; | 258 return *tab_size_info; |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace | 261 } // namespace |
| 262 | 262 |
| 263 /////////////////////////////////////////////////////////////////////////////// | 263 /////////////////////////////////////////////////////////////////////////////// |
| 264 // NewTabButton | 264 // NewTabButton |
| 265 // | 265 // |
| 266 // A subclass of button that hit-tests to the shape of the new tab button and | 266 // A subclass of button that hit-tests to the shape of the new tab button and |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 | 865 |
| 866 int model_count = GetModelCount(); | 866 int model_count = GetModelCount(); |
| 867 if (model_count > 1 && model_index != model_count - 1) { | 867 if (model_count > 1 && model_index != model_count - 1) { |
| 868 // The user is about to close a tab other than the last tab. Set | 868 // The user is about to close a tab other than the last tab. Set |
| 869 // available_width_for_tabs_ so that if we do a layout we don't position a | 869 // available_width_for_tabs_ so that if we do a layout we don't position a |
| 870 // tab past the end of the second to last tab. We do this so that as the | 870 // tab past the end of the second to last tab. We do this so that as the |
| 871 // user closes tabs with the mouse a tab continues to fall under the mouse. | 871 // user closes tabs with the mouse a tab continues to fall under the mouse. |
| 872 Tab* last_tab = tab_at(model_count - 1); | 872 Tab* last_tab = tab_at(model_count - 1); |
| 873 Tab* tab_being_removed = tab_at(model_index); | 873 Tab* tab_being_removed = tab_at(model_index); |
| 874 available_width_for_tabs_ = last_tab->x() + last_tab->width() - | 874 available_width_for_tabs_ = last_tab->x() + last_tab->width() - |
| 875 tab_being_removed->width() + GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 875 tab_being_removed->width() + Tab::kOverlap; |
| 876 if (model_index == 0 && tab_being_removed->data().pinned && | 876 if (model_index == 0 && tab_being_removed->data().pinned && |
| 877 !tab_at(1)->data().pinned) { | 877 !tab_at(1)->data().pinned) { |
| 878 available_width_for_tabs_ -= kPinnedToNonPinnedOffset; | 878 available_width_for_tabs_ -= kPinnedToNonPinnedOffset; |
| 879 } | 879 } |
| 880 } | 880 } |
| 881 | 881 |
| 882 in_tab_close_ = true; | 882 in_tab_close_ = true; |
| 883 resize_layout_timer_.Stop(); | 883 resize_layout_timer_.Stop(); |
| 884 if (source == CLOSE_TAB_FROM_TOUCH) { | 884 if (source == CLOSE_TAB_FROM_TOUCH) { |
| 885 StartResizeLayoutTabsFromTouchTimer(); | 885 StartResizeLayoutTabsFromTouchTimer(); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 clip->offset(SkIntToScalar(next_x - current_x), 0); | 1290 clip->offset(SkIntToScalar(next_x - current_x), 0); |
| 1291 } else if (index > active_index && index > 0) { | 1291 } else if (index > active_index && index > 0) { |
| 1292 const gfx::Rect& previous_bounds(tab_at(index - 1)->bounds()); | 1292 const gfx::Rect& previous_bounds(tab_at(index - 1)->bounds()); |
| 1293 const int previous_x = previous_bounds.x(); | 1293 const int previous_x = previous_bounds.x(); |
| 1294 if (current_x == previous_x) | 1294 if (current_x == previous_x) |
| 1295 return false; | 1295 return false; |
| 1296 | 1296 |
| 1297 if (current_x < previous_x) | 1297 if (current_x < previous_x) |
| 1298 return true; // Can happen during dragging. | 1298 return true; // Can happen during dragging. |
| 1299 | 1299 |
| 1300 if (previous_bounds.right() - GetLayoutConstant(TABSTRIP_TAB_OVERLAP) != | 1300 if (previous_bounds.right() - Tab::kOverlap != current_x) { |
| 1301 current_x) { | |
| 1302 *clip = border_callback.Run(tab_at(index - 1)->size()); | 1301 *clip = border_callback.Run(tab_at(index - 1)->size()); |
| 1303 clip->offset(SkIntToScalar(previous_x - current_x), 0); | 1302 clip->offset(SkIntToScalar(previous_x - current_x), 0); |
| 1304 } | 1303 } |
| 1305 } | 1304 } |
| 1306 return true; | 1305 return true; |
| 1307 } | 1306 } |
| 1308 | 1307 |
| 1309 bool TabStrip::CanPaintThrobberToLayer() const { | 1308 bool TabStrip::CanPaintThrobberToLayer() const { |
| 1310 // Disable layer-painting of throbbers if dragging, if any tab animation is in | 1309 // Disable layer-painting of throbbers if dragging, if any tab animation is in |
| 1311 // progress, or if stacked tabs are enabled. Also disable in fullscreen: when | 1310 // progress, or if stacked tabs are enabled. Also disable in fullscreen: when |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 // Otherwise the minimum width is based on the actual number of tabs. | 1489 // Otherwise the minimum width is based on the actual number of tabs. |
| 1491 const int pinned_tab_count = GetPinnedTabCount(); | 1490 const int pinned_tab_count = GetPinnedTabCount(); |
| 1492 needed_tab_width = pinned_tab_count * Tab::GetPinnedWidth(); | 1491 needed_tab_width = pinned_tab_count * Tab::GetPinnedWidth(); |
| 1493 const int remaining_tab_count = tab_count() - pinned_tab_count; | 1492 const int remaining_tab_count = tab_count() - pinned_tab_count; |
| 1494 const int min_selected_width = Tab::GetMinimumActiveSize().width(); | 1493 const int min_selected_width = Tab::GetMinimumActiveSize().width(); |
| 1495 const int min_unselected_width = Tab::GetMinimumInactiveSize().width(); | 1494 const int min_unselected_width = Tab::GetMinimumInactiveSize().width(); |
| 1496 if (remaining_tab_count > 0) { | 1495 if (remaining_tab_count > 0) { |
| 1497 needed_tab_width += kPinnedToNonPinnedOffset + min_selected_width + | 1496 needed_tab_width += kPinnedToNonPinnedOffset + min_selected_width + |
| 1498 ((remaining_tab_count - 1) * min_unselected_width); | 1497 ((remaining_tab_count - 1) * min_unselected_width); |
| 1499 } | 1498 } |
| 1500 const int tab_overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | |
| 1501 if (tab_count() > 1) | 1499 if (tab_count() > 1) |
| 1502 needed_tab_width -= (tab_count() - 1) * tab_overlap; | 1500 needed_tab_width -= (tab_count() - 1) * Tab::kOverlap; |
| 1503 | 1501 |
| 1504 // Don't let the tabstrip shrink smaller than is necessary to show one tab, | 1502 // Don't let the tabstrip shrink smaller than is necessary to show one tab, |
| 1505 // and don't force it to be larger than is necessary to show 20 tabs. | 1503 // and don't force it to be larger than is necessary to show 20 tabs. |
| 1506 const int largest_min_tab_width = | 1504 const int largest_min_tab_width = |
| 1507 min_selected_width + 19 * (min_unselected_width - tab_overlap); | 1505 min_selected_width + 19 * (min_unselected_width - Tab::kOverlap); |
| 1508 needed_tab_width = std::min( | 1506 needed_tab_width = std::min( |
| 1509 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); | 1507 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); |
| 1510 } | 1508 } |
| 1511 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), | 1509 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), |
| 1512 immersive_style_ ? Tab::GetImmersiveHeight() | 1510 immersive_style_ ? Tab::GetImmersiveHeight() |
| 1513 : Tab::GetMinimumInactiveSize().height()); | 1511 : Tab::GetMinimumInactiveSize().height()); |
| 1514 } | 1512 } |
| 1515 | 1513 |
| 1516 void TabStrip::OnDragEntered(const DropTargetEvent& event) { | 1514 void TabStrip::OnDragEntered(const DropTargetEvent& event) { |
| 1517 // Force animations to stop, otherwise it makes the index calculation tricky. | 1515 // Force animations to stop, otherwise it makes the index calculation tricky. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 available_width_for_tabs_ = -1; | 1650 available_width_for_tabs_ = -1; |
| 1653 | 1651 |
| 1654 GenerateIdealBounds(); | 1652 GenerateIdealBounds(); |
| 1655 | 1653 |
| 1656 Tab* tab = tab_at(model_index); | 1654 Tab* tab = tab_at(model_index); |
| 1657 if (model_index == 0) { | 1655 if (model_index == 0) { |
| 1658 tab->SetBounds(0, ideal_bounds(model_index).y(), 0, | 1656 tab->SetBounds(0, ideal_bounds(model_index).y(), 0, |
| 1659 ideal_bounds(model_index).height()); | 1657 ideal_bounds(model_index).height()); |
| 1660 } else { | 1658 } else { |
| 1661 Tab* last_tab = tab_at(model_index - 1); | 1659 Tab* last_tab = tab_at(model_index - 1); |
| 1662 tab->SetBounds( | 1660 tab->SetBounds(last_tab->bounds().right() - Tab::kOverlap, |
| 1663 last_tab->bounds().right() - GetLayoutConstant(TABSTRIP_TAB_OVERLAP), | 1661 ideal_bounds(model_index).y(), 0, |
| 1664 ideal_bounds(model_index).y(), 0, ideal_bounds(model_index).height()); | 1662 ideal_bounds(model_index).height()); |
| 1665 } | 1663 } |
| 1666 | 1664 |
| 1667 AnimateToIdealBounds(); | 1665 AnimateToIdealBounds(); |
| 1668 } | 1666 } |
| 1669 | 1667 |
| 1670 void TabStrip::StartMoveTabAnimation() { | 1668 void TabStrip::StartMoveTabAnimation() { |
| 1671 PrepareForAnimation(); | 1669 PrepareForAnimation(); |
| 1672 GenerateIdealBounds(); | 1670 GenerateIdealBounds(); |
| 1673 AnimateToIdealBounds(); | 1671 AnimateToIdealBounds(); |
| 1674 } | 1672 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 void TabStrip::CalculateBoundsForDraggedTabs(const Tabs& tabs, | 1900 void TabStrip::CalculateBoundsForDraggedTabs(const Tabs& tabs, |
| 1903 std::vector<gfx::Rect>* bounds) { | 1901 std::vector<gfx::Rect>* bounds) { |
| 1904 int x = 0; | 1902 int x = 0; |
| 1905 for (size_t i = 0; i < tabs.size(); ++i) { | 1903 for (size_t i = 0; i < tabs.size(); ++i) { |
| 1906 Tab* tab = tabs[i]; | 1904 Tab* tab = tabs[i]; |
| 1907 if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) | 1905 if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) |
| 1908 x += kPinnedToNonPinnedOffset; | 1906 x += kPinnedToNonPinnedOffset; |
| 1909 gfx::Rect new_bounds = tab->bounds(); | 1907 gfx::Rect new_bounds = tab->bounds(); |
| 1910 new_bounds.set_origin(gfx::Point(x, 0)); | 1908 new_bounds.set_origin(gfx::Point(x, 0)); |
| 1911 bounds->push_back(new_bounds); | 1909 bounds->push_back(new_bounds); |
| 1912 x += tab->width() - GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 1910 x += tab->width() - Tab::kOverlap; |
| 1913 } | 1911 } |
| 1914 } | 1912 } |
| 1915 | 1913 |
| 1916 int TabStrip::GetSizeNeededForTabs(const Tabs& tabs) { | 1914 int TabStrip::GetSizeNeededForTabs(const Tabs& tabs) { |
| 1917 int width = 0; | 1915 int width = 0; |
| 1918 for (size_t i = 0; i < tabs.size(); ++i) { | 1916 for (size_t i = 0; i < tabs.size(); ++i) { |
| 1919 Tab* tab = tabs[i]; | 1917 Tab* tab = tabs[i]; |
| 1920 width += tab->width(); | 1918 width += tab->width(); |
| 1921 if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) | 1919 if (i > 0 && tab->data().pinned != tabs[i - 1]->data().pinned) |
| 1922 width += kPinnedToNonPinnedOffset; | 1920 width += kPinnedToNonPinnedOffset; |
| 1923 } | 1921 } |
| 1924 if (!tabs.empty()) | 1922 if (!tabs.empty()) |
| 1925 width -= GetLayoutConstant(TABSTRIP_TAB_OVERLAP) * (tabs.size() - 1); | 1923 width -= Tab::kOverlap * (tabs.size() - 1); |
| 1926 return width; | 1924 return width; |
| 1927 } | 1925 } |
| 1928 | 1926 |
| 1929 int TabStrip::GetPinnedTabCount() const { | 1927 int TabStrip::GetPinnedTabCount() const { |
| 1930 int pinned_count = 0; | 1928 int pinned_count = 0; |
| 1931 while (pinned_count < tab_count() && tab_at(pinned_count)->data().pinned) | 1929 while (pinned_count < tab_count() && tab_at(pinned_count)->data().pinned) |
| 1932 pinned_count++; | 1930 pinned_count++; |
| 1933 return pinned_count; | 1931 return pinned_count; |
| 1934 } | 1932 } |
| 1935 | 1933 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 | 2247 |
| 2250 void TabStrip::RemoveMessageLoopObserver() { | 2248 void TabStrip::RemoveMessageLoopObserver() { |
| 2251 mouse_watcher_.reset(NULL); | 2249 mouse_watcher_.reset(NULL); |
| 2252 } | 2250 } |
| 2253 | 2251 |
| 2254 gfx::Rect TabStrip::GetDropBounds(int drop_index, | 2252 gfx::Rect TabStrip::GetDropBounds(int drop_index, |
| 2255 bool drop_before, | 2253 bool drop_before, |
| 2256 bool* is_beneath) { | 2254 bool* is_beneath) { |
| 2257 DCHECK_NE(drop_index, -1); | 2255 DCHECK_NE(drop_index, -1); |
| 2258 int center_x; | 2256 int center_x; |
| 2259 const int tab_overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | |
| 2260 if (drop_index < tab_count()) { | 2257 if (drop_index < tab_count()) { |
| 2261 Tab* tab = tab_at(drop_index); | 2258 Tab* tab = tab_at(drop_index); |
| 2262 center_x = tab->x() + ((drop_before ? tab_overlap : tab->width()) / 2); | 2259 center_x = tab->x() + ((drop_before ? Tab::kOverlap : tab->width()) / 2); |
| 2263 } else { | 2260 } else { |
| 2264 Tab* last_tab = tab_at(drop_index - 1); | 2261 Tab* last_tab = tab_at(drop_index - 1); |
| 2265 center_x = last_tab->x() + last_tab->width() - (tab_overlap / 2); | 2262 center_x = last_tab->x() + last_tab->width() - (Tab::kOverlap / 2); |
| 2266 } | 2263 } |
| 2267 | 2264 |
| 2268 // Mirror the center point if necessary. | 2265 // Mirror the center point if necessary. |
| 2269 center_x = GetMirroredXInView(center_x); | 2266 center_x = GetMirroredXInView(center_x); |
| 2270 | 2267 |
| 2271 // Determine the screen bounds. | 2268 // Determine the screen bounds. |
| 2272 gfx::Point drop_loc(center_x - drop_indicator_width / 2, | 2269 gfx::Point drop_loc(center_x - drop_indicator_width / 2, |
| 2273 -drop_indicator_height); | 2270 -drop_indicator_height); |
| 2274 ConvertPointToScreen(this, &drop_loc); | 2271 ConvertPointToScreen(this, &drop_loc); |
| 2275 gfx::Rect drop_bounds(drop_loc.x(), drop_loc.y(), drop_indicator_width, | 2272 gfx::Rect drop_bounds(drop_loc.x(), drop_loc.y(), drop_indicator_width, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2443 if (num_pinned_tabs == 0) | 2440 if (num_pinned_tabs == 0) |
| 2444 return 0; | 2441 return 0; |
| 2445 | 2442 |
| 2446 std::vector<gfx::Rect> tab_bounds(tab_count()); | 2443 std::vector<gfx::Rect> tab_bounds(tab_count()); |
| 2447 CalculateBoundsForPinnedTabs(GetTabSizeInfo(), num_pinned_tabs, tab_count(), | 2444 CalculateBoundsForPinnedTabs(GetTabSizeInfo(), num_pinned_tabs, tab_count(), |
| 2448 &tab_bounds); | 2445 &tab_bounds); |
| 2449 for (int i = 0; i < num_pinned_tabs; ++i) | 2446 for (int i = 0; i < num_pinned_tabs; ++i) |
| 2450 tabs_.set_ideal_bounds(i, tab_bounds[i]); | 2447 tabs_.set_ideal_bounds(i, tab_bounds[i]); |
| 2451 return (num_pinned_tabs < tab_count()) | 2448 return (num_pinned_tabs < tab_count()) |
| 2452 ? tab_bounds[num_pinned_tabs].x() | 2449 ? tab_bounds[num_pinned_tabs].x() |
| 2453 : tab_bounds[num_pinned_tabs - 1].right() - | 2450 : tab_bounds[num_pinned_tabs - 1].right() - Tab::kOverlap; |
| 2454 GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | |
| 2455 } | 2451 } |
| 2456 | 2452 |
| 2457 int TabStrip::GetTabAreaWidth() const { | 2453 int TabStrip::GetTabAreaWidth() const { |
| 2458 return width() - GetNewTabButtonWidth(); | 2454 return width() - GetNewTabButtonWidth(); |
| 2459 } | 2455 } |
| 2460 | 2456 |
| 2461 void TabStrip::StartResizeLayoutAnimation() { | 2457 void TabStrip::StartResizeLayoutAnimation() { |
| 2462 PrepareForAnimation(); | 2458 PrepareForAnimation(); |
| 2463 GenerateIdealBounds(); | 2459 GenerateIdealBounds(); |
| 2464 AnimateToIdealBounds(); | 2460 AnimateToIdealBounds(); |
| 2465 } | 2461 } |
| 2466 | 2462 |
| 2467 void TabStrip::StartPinnedTabAnimation() { | 2463 void TabStrip::StartPinnedTabAnimation() { |
| 2468 in_tab_close_ = false; | 2464 in_tab_close_ = false; |
| 2469 available_width_for_tabs_ = -1; | 2465 available_width_for_tabs_ = -1; |
| 2470 | 2466 |
| 2471 PrepareForAnimation(); | 2467 PrepareForAnimation(); |
| 2472 | 2468 |
| 2473 GenerateIdealBounds(); | 2469 GenerateIdealBounds(); |
| 2474 AnimateToIdealBounds(); | 2470 AnimateToIdealBounds(); |
| 2475 } | 2471 } |
| 2476 | 2472 |
| 2477 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) { | 2473 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) { |
| 2478 // The user initiated the close. We want to persist the bounds of all the | 2474 // The user initiated the close. We want to persist the bounds of all the |
| 2479 // existing tabs, so we manually shift ideal_bounds then animate. | 2475 // existing tabs, so we manually shift ideal_bounds then animate. |
| 2480 Tab* tab_closing = tab_at(model_index); | 2476 Tab* tab_closing = tab_at(model_index); |
| 2481 int delta = tab_closing->width() - GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 2477 int delta = tab_closing->width() - Tab::kOverlap; |
| 2482 // If the tab being closed is a pinned tab next to a non-pinned tab, be sure | 2478 // If the tab being closed is a pinned tab next to a non-pinned tab, be sure |
| 2483 // to add the extra padding. | 2479 // to add the extra padding. |
| 2484 DCHECK_LT(model_index, tab_count() - 1); | 2480 DCHECK_LT(model_index, tab_count() - 1); |
| 2485 if (tab_closing->data().pinned && !tab_at(model_index + 1)->data().pinned) | 2481 if (tab_closing->data().pinned && !tab_at(model_index + 1)->data().pinned) |
| 2486 delta += kPinnedToNonPinnedOffset; | 2482 delta += kPinnedToNonPinnedOffset; |
| 2487 | 2483 |
| 2488 for (int i = model_index + 1; i < tab_count(); ++i) { | 2484 for (int i = model_index + 1; i < tab_count(); ++i) { |
| 2489 gfx::Rect bounds = ideal_bounds(i); | 2485 gfx::Rect bounds = ideal_bounds(i); |
| 2490 bounds.set_x(bounds.x() - delta); | 2486 bounds.set_x(bounds.x() - delta); |
| 2491 tabs_.set_ideal_bounds(i, bounds); | 2487 tabs_.set_ideal_bounds(i, bounds); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2524 const gfx::Point& point_in_tabstrip_coords) { | 2520 const gfx::Point& point_in_tabstrip_coords) { |
| 2525 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 2521 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
| 2526 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); | 2522 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); |
| 2527 return tab->HitTestPoint(point_in_tab_coords); | 2523 return tab->HitTestPoint(point_in_tab_coords); |
| 2528 } | 2524 } |
| 2529 | 2525 |
| 2530 int TabStrip::GetStartXForNormalTabs() const { | 2526 int TabStrip::GetStartXForNormalTabs() const { |
| 2531 int pinned_tab_count = GetPinnedTabCount(); | 2527 int pinned_tab_count = GetPinnedTabCount(); |
| 2532 if (pinned_tab_count == 0) | 2528 if (pinned_tab_count == 0) |
| 2533 return 0; | 2529 return 0; |
| 2534 const int overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 2530 return pinned_tab_count * (Tab::GetPinnedWidth() - Tab::kOverlap) + |
| 2535 return pinned_tab_count * (Tab::GetPinnedWidth() - overlap) + | |
| 2536 kPinnedToNonPinnedOffset; | 2531 kPinnedToNonPinnedOffset; |
| 2537 } | 2532 } |
| 2538 | 2533 |
| 2539 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 2534 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { |
| 2540 DCHECK(touch_layout_); | 2535 DCHECK(touch_layout_); |
| 2541 int active_tab_index = touch_layout_->active_index(); | 2536 int active_tab_index = touch_layout_->active_index(); |
| 2542 Tab* tab = FindTabForEventFrom(point, active_tab_index, -1); | 2537 Tab* tab = FindTabForEventFrom(point, active_tab_index, -1); |
| 2543 return tab ? tab : FindTabForEventFrom(point, active_tab_index + 1, 1); | 2538 return tab ? tab : FindTabForEventFrom(point, active_tab_index + 1, 1); |
| 2544 } | 2539 } |
| 2545 | 2540 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2594 void TabStrip::SwapLayoutIfNecessary() { | 2589 void TabStrip::SwapLayoutIfNecessary() { |
| 2595 bool needs_touch = NeedsTouchLayout(); | 2590 bool needs_touch = NeedsTouchLayout(); |
| 2596 bool using_touch = touch_layout_ != NULL; | 2591 bool using_touch = touch_layout_ != NULL; |
| 2597 if (needs_touch == using_touch) | 2592 if (needs_touch == using_touch) |
| 2598 return; | 2593 return; |
| 2599 | 2594 |
| 2600 if (needs_touch) { | 2595 if (needs_touch) { |
| 2601 gfx::Size tab_size(Tab::GetMinimumActiveSize()); | 2596 gfx::Size tab_size(Tab::GetMinimumActiveSize()); |
| 2602 tab_size.set_width(Tab::GetTouchWidth()); | 2597 tab_size.set_width(Tab::GetTouchWidth()); |
| 2603 touch_layout_.reset(new StackedTabStripLayout( | 2598 touch_layout_.reset(new StackedTabStripLayout( |
| 2604 tab_size, | 2599 tab_size, Tab::kOverlap, kStackedPadding, kMaxStackedCount, &tabs_)); |
| 2605 GetLayoutConstant(TABSTRIP_TAB_OVERLAP), | |
| 2606 kStackedPadding, | |
| 2607 kMaxStackedCount, | |
| 2608 &tabs_)); | |
| 2609 touch_layout_->SetWidth(GetTabAreaWidth()); | 2600 touch_layout_->SetWidth(GetTabAreaWidth()); |
| 2610 // 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 |
| 2611 // bounds of the pinned tabs (since StackedTabStripLayout doesn't yet know | 2602 // bounds of the pinned tabs (since StackedTabStripLayout doesn't yet know |
| 2612 // how many pinned tabs there are). | 2603 // how many pinned tabs there are). |
| 2613 GenerateIdealBoundsForPinnedTabs(NULL); | 2604 GenerateIdealBoundsForPinnedTabs(NULL); |
| 2614 touch_layout_->SetXAndPinnedCount(GetStartXForNormalTabs(), | 2605 touch_layout_->SetXAndPinnedCount(GetStartXForNormalTabs(), |
| 2615 GetPinnedTabCount()); | 2606 GetPinnedTabCount()); |
| 2616 touch_layout_->SetActiveIndex(controller_->GetActiveIndex()); | 2607 touch_layout_->SetActiveIndex(controller_->GetActiveIndex()); |
| 2617 | 2608 |
| 2618 content::RecordAction(UserMetricsAction("StackedTab_EnteredStackedLayout")); | 2609 content::RecordAction(UserMetricsAction("StackedTab_EnteredStackedLayout")); |
| 2619 } else { | 2610 } else { |
| 2620 touch_layout_.reset(); | 2611 touch_layout_.reset(); |
| 2621 } | 2612 } |
| 2622 PrepareForAnimation(); | 2613 PrepareForAnimation(); |
| 2623 GenerateIdealBounds(); | 2614 GenerateIdealBounds(); |
| 2624 SetTabVisibility(); | 2615 SetTabVisibility(); |
| 2625 AnimateToIdealBounds(); | 2616 AnimateToIdealBounds(); |
| 2626 } | 2617 } |
| 2627 | 2618 |
| 2628 bool TabStrip::NeedsTouchLayout() const { | 2619 bool TabStrip::NeedsTouchLayout() const { |
| 2629 if (!stacked_layout_) | 2620 if (!stacked_layout_) |
| 2630 return false; | 2621 return false; |
| 2631 | 2622 |
| 2632 int pinned_tab_count = GetPinnedTabCount(); | 2623 int pinned_tab_count = GetPinnedTabCount(); |
| 2633 int normal_count = tab_count() - pinned_tab_count; | 2624 int normal_count = tab_count() - pinned_tab_count; |
| 2634 if (normal_count <= 1 || normal_count == pinned_tab_count) | 2625 if (normal_count <= 1 || normal_count == pinned_tab_count) |
| 2635 return false; | 2626 return false; |
| 2636 const int overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 2627 return (Tab::GetTouchWidth() * normal_count - |
| 2637 return (Tab::GetTouchWidth() * normal_count - overlap * (normal_count - 1)) > | 2628 Tab::kOverlap * (normal_count - 1)) > |
| 2638 GetTabAreaWidth() - GetStartXForNormalTabs(); | 2629 GetTabAreaWidth() - GetStartXForNormalTabs(); |
| 2639 } | 2630 } |
| 2640 | 2631 |
| 2641 void TabStrip::SetResetToShrinkOnExit(bool value) { | 2632 void TabStrip::SetResetToShrinkOnExit(bool value) { |
| 2642 if (!adjust_layout_) | 2633 if (!adjust_layout_) |
| 2643 return; | 2634 return; |
| 2644 | 2635 |
| 2645 if (value && !stacked_layout_) | 2636 if (value && !stacked_layout_) |
| 2646 value = false; // We're already using shrink (not stacked) layout. | 2637 value = false; // We're already using shrink (not stacked) layout. |
| 2647 | 2638 |
| 2648 if (value == reset_to_shrink_on_exit_) | 2639 if (value == reset_to_shrink_on_exit_) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2804 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2795 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
| 2805 if (view) | 2796 if (view) |
| 2806 return view; | 2797 return view; |
| 2807 } | 2798 } |
| 2808 Tab* tab = FindTabForEvent(point); | 2799 Tab* tab = FindTabForEvent(point); |
| 2809 if (tab) | 2800 if (tab) |
| 2810 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2801 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
| 2811 } | 2802 } |
| 2812 return this; | 2803 return this; |
| 2813 } | 2804 } |
| OLD | NEW |