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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 // Amount to adjust the clip by when the tab is stacked after the active index. | 113 // Amount to adjust the clip by when the tab is stacked after the active index. |
114 const int kStackedTabRightClip = 20; | 114 const int kStackedTabRightClip = 20; |
115 | 115 |
116 #if defined(OS_MACOSX) | 116 #if defined(OS_MACOSX) |
117 const int kPinnedToNonPinnedOffset = 2; | 117 const int kPinnedToNonPinnedOffset = 2; |
118 #else | 118 #else |
119 const int kPinnedToNonPinnedOffset = 3; | 119 const int kPinnedToNonPinnedOffset = 3; |
120 #endif | 120 #endif |
121 | 121 |
| 122 // The vertical offset of the tab strip button. |
| 123 const int kNewTabButtonVerticalOffset = 7; |
| 124 |
122 // Returns the size of the new tab button, not including any bounds extension to | 125 // Returns the size of the new tab button, not including any bounds extension to |
123 // enlarge the clickable area. | 126 // enlarge the clickable area. |
124 gfx::Size GetNewTabButtonSize() { | 127 gfx::Size GetNewTabButtonSize() { |
125 return gfx::Size(GetLayoutConstant(NEW_TAB_BUTTON_WIDTH), | 128 return gfx::Size(GetLayoutConstant(NEW_TAB_BUTTON_WIDTH), |
126 kNewTabButtonHeight); | 129 kNewTabButtonHeight); |
127 } | 130 } |
128 | 131 |
129 // Returns the width needed for the new tab button (and padding). | 132 // Returns the width needed for the new tab button (and padding). |
130 int GetNewTabButtonWidth() { | 133 int GetNewTabButtonWidth() { |
131 return GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) - | 134 return GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) - |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 0, alpha); | 441 0, alpha); |
439 } | 442 } |
440 } | 443 } |
441 | 444 |
442 bool NewTabButton::GetHitTestMask(gfx::Path* mask) const { | 445 bool NewTabButton::GetHitTestMask(gfx::Path* mask) const { |
443 DCHECK(mask); | 446 DCHECK(mask); |
444 | 447 |
445 if (ui::MaterialDesignController::IsModeMaterial()) { | 448 if (ui::MaterialDesignController::IsModeMaterial()) { |
446 SkPath border; | 449 SkPath border; |
447 const float scale = GetWidget()->GetCompositor()->device_scale_factor(); | 450 const float scale = GetWidget()->GetCompositor()->device_scale_factor(); |
448 GetBorderPath(TabStrip::kNewTabButtonVerticalOffset * scale, scale, | 451 GetBorderPath(kNewTabButtonVerticalOffset * scale, scale, |
449 tab_strip_->SizeTabButtonToTopOfTabStrip(), &border); | 452 tab_strip_->SizeTabButtonToTopOfTabStrip(), &border); |
450 mask->addPath(border, SkMatrix::MakeScale(1 / scale)); | 453 mask->addPath(border, SkMatrix::MakeScale(1 / scale)); |
451 } else if (tab_strip_->SizeTabButtonToTopOfTabStrip()) { | 454 } else if (tab_strip_->SizeTabButtonToTopOfTabStrip()) { |
452 // When the button is sized to the top of the tab strip, we want the hit | 455 // When the button is sized to the top of the tab strip, we want the hit |
453 // test mask to be defined as the complete (rectangular) bounds of the | 456 // test mask to be defined as the complete (rectangular) bounds of the |
454 // button. | 457 // button. |
455 gfx::Rect button_bounds(GetContentsBounds()); | 458 gfx::Rect button_bounds(GetContentsBounds()); |
456 button_bounds.set_x(GetMirroredXForRect(button_bounds)); | 459 button_bounds.set_x(GetMirroredXForRect(button_bounds)); |
457 mask->addRect(RectToSkRect(button_bounds)); | 460 mask->addRect(RectToSkRect(button_bounds)); |
458 } else { | 461 } else { |
459 SkScalar w = SkIntToScalar(width()); | 462 SkScalar w = SkIntToScalar(width()); |
460 SkScalar v_offset = SkIntToScalar(TabStrip::kNewTabButtonVerticalOffset); | 463 SkScalar v_offset = SkIntToScalar(kNewTabButtonVerticalOffset); |
461 | 464 |
462 // These values are defined by the shape of the new tab image. Should that | 465 // These values are defined by the shape of the new tab image. Should that |
463 // image ever change, these values will need to be updated. They're so | 466 // image ever change, these values will need to be updated. They're so |
464 // custom it's not really worth defining constants for. | 467 // custom it's not really worth defining constants for. |
465 // These values are correct for regular and USE_ASH versions of the image. | 468 // These values are correct for regular and USE_ASH versions of the image. |
466 mask->moveTo(0, v_offset + 1); | 469 mask->moveTo(0, v_offset + 1); |
467 mask->lineTo(w - 7, v_offset + 1); | 470 mask->lineTo(w - 7, v_offset + 1); |
468 mask->lineTo(w - 4, v_offset + 4); | 471 mask->lineTo(w - 4, v_offset + 4); |
469 mask->lineTo(w, v_offset + 16); | 472 mask->lineTo(w, v_offset + 16); |
470 mask->lineTo(w - 1, v_offset + 17); | 473 mask->lineTo(w - 1, v_offset + 17); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 // The new tab background is mirrored in RTL mode, but the theme background | 564 // The new tab background is mirrored in RTL mode, but the theme background |
562 // should never be mirrored. Mirror it here to compensate. | 565 // should never be mirrored. Mirror it here to compensate. |
563 float x_scale = 1.0f; | 566 float x_scale = 1.0f; |
564 int x = GetMirroredX() + background_offset_.x(); | 567 int x = GetMirroredX() + background_offset_.x(); |
565 if (base::i18n::IsRTL()) { | 568 if (base::i18n::IsRTL()) { |
566 x_scale = -1.0f; | 569 x_scale = -1.0f; |
567 // Offset by |width| such that the same region is painted as if there was | 570 // Offset by |width| such that the same region is painted as if there was |
568 // no flip. | 571 // no flip. |
569 x += size.width(); | 572 x += size.width(); |
570 } | 573 } |
571 canvas->TileImageInt(*background, x, | 574 canvas->TileImageInt(*background, x, kNewTabButtonVerticalOffset + offset_y, |
572 TabStrip::kNewTabButtonVerticalOffset + offset_y, | |
573 x_scale, 1.0f, 0, 0, size.width(), size.height()); | 575 x_scale, 1.0f, 0, 0, size.width(), size.height()); |
574 | 576 |
575 // For non-MD, adjust the alpha of the fill to match that of inactive tabs | 577 // For non-MD, adjust the alpha of the fill to match that of inactive tabs |
576 // (except for pressed buttons, which get a different value). For MD, we do | 578 // (except for pressed buttons, which get a different value). For MD, we do |
577 // this with an opacity recorder in TabStrip::PaintChildren() so the fill | 579 // this with an opacity recorder in TabStrip::PaintChildren() so the fill |
578 // and stroke are both affected, to better match how tabs are handled, but | 580 // and stroke are both affected, to better match how tabs are handled, but |
579 // in non-MD, the button stroke is already lighter than the tab stroke, and | 581 // in non-MD, the button stroke is already lighter than the tab stroke, and |
580 // using the opacity recorder washes it out too much. | 582 // using the opacity recorder washes it out too much. |
581 static const SkAlpha kPressedAlpha = 145; | 583 static const SkAlpha kPressedAlpha = 145; |
582 const SkAlpha alpha = | 584 const SkAlpha alpha = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 650 } |
649 | 651 |
650 void TabStrip::RemoveTabDelegate::AnimationCanceled( | 652 void TabStrip::RemoveTabDelegate::AnimationCanceled( |
651 const gfx::Animation* animation) { | 653 const gfx::Animation* animation) { |
652 AnimationEnded(animation); | 654 AnimationEnded(animation); |
653 } | 655 } |
654 | 656 |
655 /////////////////////////////////////////////////////////////////////////////// | 657 /////////////////////////////////////////////////////////////////////////////// |
656 // TabStrip, public: | 658 // TabStrip, public: |
657 | 659 |
658 // static | |
659 const int TabStrip::kNewTabButtonVerticalOffset = 7; | |
660 | |
661 TabStrip::TabStrip(TabStripController* controller) | 660 TabStrip::TabStrip(TabStripController* controller) |
662 : controller_(controller), | 661 : controller_(controller), |
663 newtab_button_(NULL), | 662 newtab_button_(NULL), |
664 current_inactive_width_(Tab::GetStandardSize().width()), | 663 current_inactive_width_(Tab::GetStandardSize().width()), |
665 current_active_width_(Tab::GetStandardSize().width()), | 664 current_active_width_(Tab::GetStandardSize().width()), |
666 available_width_for_tabs_(-1), | 665 available_width_for_tabs_(-1), |
667 in_tab_close_(false), | 666 in_tab_close_(false), |
668 animation_container_(new gfx::AnimationContainer()), | 667 animation_container_(new gfx::AnimationContainer()), |
669 bounds_animator_(this), | 668 bounds_animator_(this), |
670 stacked_layout_(false), | 669 stacked_layout_(false), |
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2852 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2851 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
2853 if (view) | 2852 if (view) |
2854 return view; | 2853 return view; |
2855 } | 2854 } |
2856 Tab* tab = FindTabForEvent(point); | 2855 Tab* tab = FindTabForEvent(point); |
2857 if (tab) | 2856 if (tab) |
2858 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2857 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
2859 } | 2858 } |
2860 return this; | 2859 return this; |
2861 } | 2860 } |
OLD | NEW |