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

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

Issue 1402453002: Parametrize some more constants that will be changing in MD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Created 5 years, 2 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Amount of time we delay before resizing after a close from a touch. 113 // Amount of time we delay before resizing after a close from a touch.
114 const int kTouchResizeLayoutTimeMS = 2000; 114 const int kTouchResizeLayoutTimeMS = 2000;
115 115
116 // Amount to adjust the clip by when the tab is stacked before the active index. 116 // Amount to adjust the clip by when the tab is stacked before the active index.
117 const int kStackedTabLeftClip = 20; 117 const int kStackedTabLeftClip = 20;
118 118
119 // Amount to adjust the clip by when the tab is stacked after the active index. 119 // Amount to adjust the clip by when the tab is stacked after the active index.
120 const int kStackedTabRightClip = 20; 120 const int kStackedTabRightClip = 20;
121 121
122 #if defined(OS_MACOSX) 122 #if defined(OS_MACOSX)
123 const int kNewTabButtonHorizontalOffset = -8;
124 const int kPinnedToNonPinnedOffset = 2; 123 const int kPinnedToNonPinnedOffset = 2;
125 #else 124 #else
126 const int kNewTabButtonHorizontalOffset = -11;
127 const int kPinnedToNonPinnedOffset = 3; 125 const int kPinnedToNonPinnedOffset = 3;
128 #endif 126 #endif
129 127
130 // Returns the width needed for the new tab button (and padding). 128 // Returns the width needed for the new tab button (and padding).
131 int GetNewTabButtonWidth() { 129 int GetNewTabButtonWidth() {
132 return TabStrip::kNewTabButtonAssetWidth + kNewTabButtonHorizontalOffset; 130 return GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) -
131 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP);
133 } 132 }
134 133
135 // Animation delegate used for any automatic tab movement. Hides the tab if it 134 // Animation delegate used for any automatic tab movement. Hides the tab if it
136 // is not fully visible within the tabstrip area, to prevent overflow clipping. 135 // is not fully visible within the tabstrip area, to prevent overflow clipping.
137 class TabAnimationDelegate : public gfx::AnimationDelegate { 136 class TabAnimationDelegate : public gfx::AnimationDelegate {
138 public: 137 public:
139 TabAnimationDelegate(TabStrip* tab_strip, Tab* tab); 138 TabAnimationDelegate(TabStrip* tab_strip, Tab* tab);
140 ~TabAnimationDelegate() override; 139 ~TabAnimationDelegate() override;
141 140
142 void AnimationProgressed(const gfx::Animation* animation) override; 141 void AnimationProgressed(const gfx::Animation* animation) override;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 void TabStrip::RemoveTabDelegate::AnimationCanceled( 528 void TabStrip::RemoveTabDelegate::AnimationCanceled(
530 const gfx::Animation* animation) { 529 const gfx::Animation* animation) {
531 AnimationEnded(animation); 530 AnimationEnded(animation);
532 } 531 }
533 532
534 /////////////////////////////////////////////////////////////////////////////// 533 ///////////////////////////////////////////////////////////////////////////////
535 // TabStrip, public: 534 // TabStrip, public:
536 535
537 // static 536 // static
538 const int TabStrip::kNewTabButtonVerticalOffset = 7; 537 const int TabStrip::kNewTabButtonVerticalOffset = 7;
539 const int TabStrip::kNewTabButtonAssetWidth = 34;
540 538
541 TabStrip::TabStrip(TabStripController* controller) 539 TabStrip::TabStrip(TabStripController* controller)
542 : controller_(controller), 540 : controller_(controller),
543 newtab_button_(NULL), 541 newtab_button_(NULL),
544 current_inactive_width_(Tab::GetStandardSize().width()), 542 current_inactive_width_(Tab::GetStandardSize().width()),
545 current_active_width_(Tab::GetStandardSize().width()), 543 current_active_width_(Tab::GetStandardSize().width()),
546 available_width_for_tabs_(-1), 544 available_width_for_tabs_(-1),
547 in_tab_close_(false), 545 in_tab_close_(false),
548 animation_container_(new gfx::AnimationContainer()), 546 animation_container_(new gfx::AnimationContainer()),
549 bounds_animator_(this), 547 bounds_animator_(this),
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 } 1504 }
1507 1505
1508 /////////////////////////////////////////////////////////////////////////////// 1506 ///////////////////////////////////////////////////////////////////////////////
1509 // TabStrip, private: 1507 // TabStrip, private:
1510 1508
1511 void TabStrip::Init() { 1509 void TabStrip::Init() {
1512 set_id(VIEW_ID_TAB_STRIP); 1510 set_id(VIEW_ID_TAB_STRIP);
1513 // So we get enter/exit on children to switch stacked layout on and off. 1511 // So we get enter/exit on children to switch stacked layout on and off.
1514 set_notify_enter_exit_on_child(true); 1512 set_notify_enter_exit_on_child(true);
1515 newtab_button_bounds_.SetRect( 1513 newtab_button_bounds_.SetRect(
1516 0, 0, kNewTabButtonAssetWidth, 1514 0, 0, GetLayoutConstant(NEW_TAB_BUTTON_WIDTH),
1517 kNewTabButtonHeight + kNewTabButtonVerticalOffset); 1515 kNewTabButtonHeight + kNewTabButtonVerticalOffset);
1518 newtab_button_ = new NewTabButton(this, this); 1516 newtab_button_ = new NewTabButton(this, this);
1519 newtab_button_->SetTooltipText( 1517 newtab_button_->SetTooltipText(
1520 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); 1518 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB));
1521 newtab_button_->SetAccessibleName( 1519 newtab_button_->SetAccessibleName(
1522 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); 1520 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB));
1523 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1521 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1524 views::ImageButton::ALIGN_BOTTOM); 1522 views::ImageButton::ALIGN_BOTTOM);
1525 newtab_button_->SetEventTargeter( 1523 newtab_button_->SetEventTargeter(
1526 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_))); 1524 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_)));
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 const std::vector<gfx::Rect> tabs_bounds = 2308 const std::vector<gfx::Rect> tabs_bounds =
2311 CalculateBounds(GetTabSizeInfo(), GetPinnedTabCount(), tab_count(), 2309 CalculateBounds(GetTabSizeInfo(), GetPinnedTabCount(), tab_count(),
2312 controller_->GetActiveIndex(), available_width, 2310 controller_->GetActiveIndex(), available_width,
2313 &current_active_width_, &current_inactive_width_); 2311 &current_active_width_, &current_inactive_width_);
2314 DCHECK_EQ(static_cast<size_t>(tab_count()), tabs_bounds.size()); 2312 DCHECK_EQ(static_cast<size_t>(tab_count()), tabs_bounds.size());
2315 2313
2316 for (size_t i = 0; i < tabs_bounds.size(); ++i) 2314 for (size_t i = 0; i < tabs_bounds.size(); ++i)
2317 tabs_.set_ideal_bounds(i, tabs_bounds[i]); 2315 tabs_.set_ideal_bounds(i, tabs_bounds[i]);
2318 } 2316 }
2319 2317
2320 const int new_tab_x = tabs_.ideal_bounds(tabs_.view_size() - 1).right() + 2318 const int new_tab_x = tabs_.ideal_bounds(tabs_.view_size() - 1).right() -
2321 kNewTabButtonHorizontalOffset; 2319 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP);
2322 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0)); 2320 newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, 0));
2323 } 2321 }
2324 2322
2325 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) { 2323 int TabStrip::GenerateIdealBoundsForPinnedTabs(int* first_non_pinned_index) {
2326 const int num_pinned_tabs = GetPinnedTabCount(); 2324 const int num_pinned_tabs = GetPinnedTabCount();
2327 2325
2328 if (first_non_pinned_index) 2326 if (first_non_pinned_index)
2329 *first_non_pinned_index = num_pinned_tabs; 2327 *first_non_pinned_index = num_pinned_tabs;
2330 2328
2331 if (num_pinned_tabs == 0) 2329 if (num_pinned_tabs == 0)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2377 gfx::Rect bounds = ideal_bounds(i); 2375 gfx::Rect bounds = ideal_bounds(i);
2378 bounds.set_x(bounds.x() - delta); 2376 bounds.set_x(bounds.x() - delta);
2379 tabs_.set_ideal_bounds(i, bounds); 2377 tabs_.set_ideal_bounds(i, bounds);
2380 } 2378 }
2381 2379
2382 // Don't just subtract |delta| from the New Tab x-coordinate, as we might have 2380 // Don't just subtract |delta| from the New Tab x-coordinate, as we might have
2383 // overflow tabs that will be able to animate into the strip, in which case 2381 // overflow tabs that will be able to animate into the strip, in which case
2384 // the new tab button should stay where it is. 2382 // the new tab button should stay where it is.
2385 newtab_button_bounds_.set_x(std::min( 2383 newtab_button_bounds_.set_x(std::min(
2386 width() - newtab_button_bounds_.width(), 2384 width() - newtab_button_bounds_.width(),
2387 ideal_bounds(tab_count() - 1).right() + kNewTabButtonHorizontalOffset)); 2385 ideal_bounds(tab_count() - 1).right() -
2386 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP)));
2388 2387
2389 PrepareForAnimation(); 2388 PrepareForAnimation();
2390 2389
2391 tab_closing->set_closing(true); 2390 tab_closing->set_closing(true);
2392 2391
2393 // We still need to paint the tab until we actually remove it. Put it in 2392 // We still need to paint the tab until we actually remove it. Put it in
2394 // tabs_closing_map_ so we can find it. 2393 // tabs_closing_map_ so we can find it.
2395 RemoveTabFromViewModel(model_index); 2394 RemoveTabFromViewModel(model_index);
2396 2395
2397 AnimateToIdealBounds(); 2396 AnimateToIdealBounds();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2691 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2693 if (view) 2692 if (view)
2694 return view; 2693 return view;
2695 } 2694 }
2696 Tab* tab = FindTabForEvent(point); 2695 Tab* tab = FindTabForEvent(point);
2697 if (tab) 2696 if (tab)
2698 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2697 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2699 } 2698 }
2700 return this; 2699 return this;
2701 } 2700 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698