Chromium Code Reviews| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 245 } |
| 246 | 246 |
| 247 TabDragController::EventSource EventSourceFromEvent( | 247 TabDragController::EventSource EventSourceFromEvent( |
| 248 const ui::LocatedEvent& event) { | 248 const ui::LocatedEvent& event) { |
| 249 return event.IsGestureEvent() ? TabDragController::EVENT_SOURCE_TOUCH : | 249 return event.IsGestureEvent() ? TabDragController::EVENT_SOURCE_TOUCH : |
| 250 TabDragController::EVENT_SOURCE_MOUSE; | 250 TabDragController::EVENT_SOURCE_MOUSE; |
| 251 } | 251 } |
| 252 | 252 |
| 253 const TabSizeInfo& GetTabSizeInfo() { | 253 const TabSizeInfo& GetTabSizeInfo() { |
| 254 static TabSizeInfo* tab_size_info = nullptr; | 254 static TabSizeInfo* tab_size_info = nullptr; |
| 255 if (tab_size_info) | 255 |
| 256 return *tab_size_info; | 256 // if (tab_size_info) |
| 257 // return *tab_size_info; | |
|
tdanderson
2016/05/02 18:55:44
Turns out the source of the incorrect drawing was
| |
| 257 | 258 |
| 258 tab_size_info = new TabSizeInfo; | 259 tab_size_info = new TabSizeInfo; |
| 259 tab_size_info->pinned_tab_width = Tab::GetPinnedWidth(); | 260 tab_size_info->pinned_tab_width = Tab::GetPinnedWidth(); |
| 260 tab_size_info->min_active_width = Tab::GetMinimumActiveSize().width(); | 261 tab_size_info->min_active_width = Tab::GetMinimumActiveSize().width(); |
| 261 tab_size_info->min_inactive_width = Tab::GetMinimumInactiveSize().width(); | 262 tab_size_info->min_inactive_width = Tab::GetMinimumInactiveSize().width(); |
| 262 tab_size_info->max_size = Tab::GetStandardSize(); | 263 tab_size_info->max_size = Tab::GetStandardSize(); |
| 263 tab_size_info->tab_overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); | 264 tab_size_info->tab_overlap = GetLayoutConstant(TABSTRIP_TAB_OVERLAP); |
| 264 tab_size_info->pinned_to_normal_offset = kPinnedToNonPinnedOffset; | 265 tab_size_info->pinned_to_normal_offset = kPinnedToNonPinnedOffset; |
| 265 return *tab_size_info; | 266 return *tab_size_info; |
| 266 } | 267 } |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1705 } | 1706 } |
| 1706 | 1707 |
| 1707 /////////////////////////////////////////////////////////////////////////////// | 1708 /////////////////////////////////////////////////////////////////////////////// |
| 1708 // TabStrip, private: | 1709 // TabStrip, private: |
| 1709 | 1710 |
| 1710 void TabStrip::Init() { | 1711 void TabStrip::Init() { |
| 1711 set_id(VIEW_ID_TAB_STRIP); | 1712 set_id(VIEW_ID_TAB_STRIP); |
| 1712 // So we get enter/exit on children to switch stacked layout on and off. | 1713 // So we get enter/exit on children to switch stacked layout on and off. |
| 1713 set_notify_enter_exit_on_child(true); | 1714 set_notify_enter_exit_on_child(true); |
| 1714 | 1715 |
| 1715 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); | 1716 CalculateNewTabButtonSize(); |
| 1716 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); | |
| 1717 newtab_button_ = new NewTabButton(this, this); | 1717 newtab_button_ = new NewTabButton(this, this); |
| 1718 newtab_button_->SetTooltipText( | 1718 newtab_button_->SetTooltipText( |
| 1719 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); | 1719 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); |
| 1720 newtab_button_->SetAccessibleName( | 1720 newtab_button_->SetAccessibleName( |
| 1721 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); | 1721 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); |
| 1722 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 1722 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
| 1723 views::ImageButton::ALIGN_BOTTOM); | 1723 views::ImageButton::ALIGN_BOTTOM); |
| 1724 newtab_button_->SetEventTargeter(std::unique_ptr<views::ViewTargeter>( | 1724 newtab_button_->SetEventTargeter(std::unique_ptr<views::ViewTargeter>( |
| 1725 new views::ViewTargeter(newtab_button_))); | 1725 new views::ViewTargeter(newtab_button_))); |
| 1726 AddChildView(newtab_button_); | 1726 AddChildView(newtab_button_); |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2501 const std::vector<gfx::Rect> tabs_bounds = | 2501 const std::vector<gfx::Rect> tabs_bounds = |
| 2502 CalculateBounds(GetTabSizeInfo(), GetPinnedTabCount(), tab_count(), | 2502 CalculateBounds(GetTabSizeInfo(), GetPinnedTabCount(), tab_count(), |
| 2503 controller_->GetActiveIndex(), available_width, | 2503 controller_->GetActiveIndex(), available_width, |
| 2504 ¤t_active_width_, ¤t_inactive_width_); | 2504 ¤t_active_width_, ¤t_inactive_width_); |
| 2505 DCHECK_EQ(static_cast<size_t>(tab_count()), tabs_bounds.size()); | 2505 DCHECK_EQ(static_cast<size_t>(tab_count()), tabs_bounds.size()); |
| 2506 | 2506 |
| 2507 for (size_t i = 0; i < tabs_bounds.size(); ++i) | 2507 for (size_t i = 0; i < tabs_bounds.size(); ++i) |
| 2508 tabs_.set_ideal_bounds(i, tabs_bounds[i]); | 2508 tabs_.set_ideal_bounds(i, tabs_bounds[i]); |
| 2509 } | 2509 } |
| 2510 | 2510 |
| 2511 CalculateNewTabButtonSize(); | |
|
tdanderson
2016/05/02 18:55:44
Same problem: the new tab button dimensions are ca
| |
| 2511 const int max_new_tab_x = width() - newtab_button_bounds_.width(); | 2512 const int max_new_tab_x = width() - newtab_button_bounds_.width(); |
| 2512 // For non-stacked tabs the ideal bounds may go outside the bounds of the | 2513 // For non-stacked tabs the ideal bounds may go outside the bounds of the |
| 2513 // tabstrip. Constrain the x-coordinate of the new tab button so that it is | 2514 // tabstrip. Constrain the x-coordinate of the new tab button so that it is |
| 2514 // always visible. | 2515 // always visible. |
| 2515 const int new_tab_x = std::min( | 2516 const int new_tab_x = std::min( |
| 2516 max_new_tab_x, tabs_.ideal_bounds(tabs_.view_size() - 1).right() - | 2517 max_new_tab_x, tabs_.ideal_bounds(tabs_.view_size() - 1).right() - |
| 2517 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP)); | 2518 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP)); |
| 2518 const int old_max_x = newtab_button_bounds_.right(); | 2519 const int old_max_x = newtab_button_bounds_.right(); |
| 2519 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0)); | 2520 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0)); |
| 2520 if (newtab_button_bounds_.right() != old_max_x) | 2521 if (newtab_button_bounds_.right() != old_max_x) |
| 2521 FOR_EACH_OBSERVER(TabStripObserver, observers_, TabStripMaxXChanged(this)); | 2522 FOR_EACH_OBSERVER(TabStripObserver, observers_, TabStripMaxXChanged(this)); |
| 2522 } | 2523 } |
| 2523 | 2524 |
| 2525 void TabStrip::CalculateNewTabButtonSize() { | |
| 2526 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); | |
| 2527 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); | |
| 2528 } | |
| 2529 | |
| 2524 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { | 2530 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { |
| 2525 const int num_pinned_tabs = GetPinnedTabCount(); | 2531 const int num_pinned_tabs = GetPinnedTabCount(); |
| 2526 | 2532 |
| 2527 if (first_non_pinned_index) | 2533 if (first_non_pinned_index) |
| 2528 *first_non_pinned_index = num_pinned_tabs; | 2534 *first_non_pinned_index = num_pinned_tabs; |
| 2529 | 2535 |
| 2530 if (num_pinned_tabs == 0) | 2536 if (num_pinned_tabs == 0) |
| 2531 return 0; | 2537 return 0; |
| 2532 | 2538 |
| 2533 std::vector<gfx::Rect> tab_bounds(tab_count()); | 2539 std::vector<gfx::Rect> tab_bounds(tab_count()); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2891 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2897 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
| 2892 if (view) | 2898 if (view) |
| 2893 return view; | 2899 return view; |
| 2894 } | 2900 } |
| 2895 Tab* tab = FindTabForEvent(point); | 2901 Tab* tab = FindTabForEvent(point); |
| 2896 if (tab) | 2902 if (tab) |
| 2897 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2903 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
| 2898 } | 2904 } |
| 2899 return this; | 2905 return this; |
| 2900 } | 2906 } |
| OLD | NEW |