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

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

Issue 1543963002: Refactor layout constants in preparation for adding support for Material Hybrid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab_drag_height
Patch Set: Created 4 years, 12 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.cc ('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 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #include "ui/gfx/win/hwnd_util.h" 72 #include "ui/gfx/win/hwnd_util.h"
73 #include "ui/views/widget/monitor_win.h" 73 #include "ui/views/widget/monitor_win.h"
74 #include "ui/views/win/hwnd_util.h" 74 #include "ui/views/win/hwnd_util.h"
75 #endif 75 #endif
76 76
77 using base::UserMetricsAction; 77 using base::UserMetricsAction;
78 using ui::DropTargetEvent; 78 using ui::DropTargetEvent;
79 79
80 namespace { 80 namespace {
81 81
82 const int kNewTabButtonHeight = 18;
83
84 const int kTabStripAnimationVSlop = 40; 82 const int kTabStripAnimationVSlop = 40;
85 83
86 // Inverse ratio of the width of a tab edge to the width of the tab. When 84 // Inverse ratio of the width of a tab edge to the width of the tab. When
87 // hovering over the left or right edge of a tab, the drop indicator will 85 // hovering over the left or right edge of a tab, the drop indicator will
88 // point between tabs. 86 // point between tabs.
89 const int kTabEdgeRatioInverse = 4; 87 const int kTabEdgeRatioInverse = 4;
90 88
91 // Size of the drop indicator. 89 // Size of the drop indicator.
92 int drop_indicator_width; 90 int drop_indicator_width;
93 int drop_indicator_height; 91 int drop_indicator_height;
(...skipping 21 matching lines...) Expand all
115 113
116 #if defined(OS_MACOSX) 114 #if defined(OS_MACOSX)
117 const int kPinnedToNonPinnedOffset = 2; 115 const int kPinnedToNonPinnedOffset = 2;
118 #else 116 #else
119 const int kPinnedToNonPinnedOffset = 3; 117 const int kPinnedToNonPinnedOffset = 3;
120 #endif 118 #endif
121 119
122 // The vertical offset of the tab strip button. 120 // The vertical offset of the tab strip button.
123 const int kNewTabButtonVerticalOffset = 7; 121 const int kNewTabButtonVerticalOffset = 7;
124 122
125 // Returns the size of the new tab button, not including any bounds extension to
126 // enlarge the clickable area.
127 gfx::Size GetNewTabButtonSize() {
128 return gfx::Size(GetLayoutConstant(NEW_TAB_BUTTON_WIDTH),
129 kNewTabButtonHeight);
130 }
131
132 // Returns the width needed for the new tab button (and padding). 123 // Returns the width needed for the new tab button (and padding).
133 int GetNewTabButtonWidth() { 124 int GetNewTabButtonWidth() {
134 return GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) - 125 return GetLayoutSize(NEW_TAB_BUTTON).width() -
135 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP); 126 GetLayoutConstant(TABSTRIP_NEW_TAB_BUTTON_OVERLAP);
136 } 127 }
137 128
138 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper(SkAlpha alpha) { 129 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper(SkAlpha alpha) {
139 SkLayerDrawLooper::Builder looper_builder; 130 SkLayerDrawLooper::Builder looper_builder;
140 looper_builder.addLayer(); 131 looper_builder.addLayer();
141 132
142 SkLayerDrawLooper::LayerInfo layer_info; 133 SkLayerDrawLooper::LayerInfo layer_info;
143 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; 134 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
144 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 135 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 356
366 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { 357 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) {
367 // Consume all gesture events here so that the parent (Tab) does not 358 // Consume all gesture events here so that the parent (Tab) does not
368 // start consuming gestures. 359 // start consuming gestures.
369 views::ImageButton::OnGestureEvent(event); 360 views::ImageButton::OnGestureEvent(event);
370 event->SetHandled(); 361 event->SetHandled();
371 } 362 }
372 363
373 void NewTabButton::OnPaint(gfx::Canvas* canvas) { 364 void NewTabButton::OnPaint(gfx::Canvas* canvas) {
374 gfx::ScopedCanvas scoped_canvas(canvas); 365 gfx::ScopedCanvas scoped_canvas(canvas);
375 canvas->Translate(gfx::Vector2d(0, height() - kNewTabButtonHeight)); 366 const int visible_height = GetLayoutSize(NEW_TAB_BUTTON).height();
367 canvas->Translate(gfx::Vector2d(0, height() - visible_height));
376 368
377 const bool pressed = state() == views::CustomButton::STATE_PRESSED; 369 const bool pressed = state() == views::CustomButton::STATE_PRESSED;
378 double hover_value = 370 double hover_value =
379 (state() == views::CustomButton::STATE_HOVERED) ? 1 : 0; 371 (state() == views::CustomButton::STATE_HOVERED) ? 1 : 0;
380 if (hover_animation_->is_animating()) 372 if (hover_animation_->is_animating())
381 hover_value = hover_animation_->GetCurrentValue(); 373 hover_value = hover_animation_->GetCurrentValue();
382 const float scale = canvas->image_scale(); 374 const float scale = canvas->image_scale();
383 375
384 SkPath fill; 376 SkPath fill;
385 if (ui::MaterialDesignController::IsModeMaterial()) { 377 if (ui::MaterialDesignController::IsModeMaterial()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 paint.setLooper(stroke_looper.get()); 410 paint.setLooper(stroke_looper.get());
419 paint.setColor(SkColorSetA(SK_ColorBLACK, pressed ? 0x38 : 0x27)); 411 paint.setColor(SkColorSetA(SK_ColorBLACK, pressed ? 0x38 : 0x27));
420 canvas->DrawPath(stroke, paint); 412 canvas->DrawPath(stroke, paint);
421 } else { 413 } else {
422 // Fill. 414 // Fill.
423 gfx::ImageSkia* mask = 415 gfx::ImageSkia* mask =
424 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); 416 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
425 // The canvas and mask have to use the same scale factor. 417 // The canvas and mask have to use the same scale factor.
426 const float fill_canvas_scale = mask->HasRepresentation(scale) ? 418 const float fill_canvas_scale = mask->HasRepresentation(scale) ?
427 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P); 419 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
428 gfx::Canvas fill_canvas(GetNewTabButtonSize(), fill_canvas_scale, false); 420 gfx::Canvas fill_canvas(GetLayoutSize(NEW_TAB_BUTTON), fill_canvas_scale,
421 false);
429 PaintFill(pressed, hover_value, fill_canvas_scale, fill, &fill_canvas); 422 PaintFill(pressed, hover_value, fill_canvas_scale, fill, &fill_canvas);
430 gfx::ImageSkia image(fill_canvas.ExtractImageRep()); 423 gfx::ImageSkia image(fill_canvas.ExtractImageRep());
431 canvas->DrawImageInt( 424 canvas->DrawImageInt(
432 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0); 425 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0);
433 426
434 // Stroke. Draw the button border with a slight alpha. 427 // Stroke. Draw the button border with a slight alpha.
435 static const SkAlpha kGlassFrameOverlayAlpha = 178; 428 static const SkAlpha kGlassFrameOverlayAlpha = 178;
436 static const SkAlpha kOpaqueFrameOverlayAlpha = 230; 429 static const SkAlpha kOpaqueFrameOverlayAlpha = 230;
437 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? 430 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ?
438 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; 431 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 538 }
546 539
547 // Clip to just the fill region for any theme drawing and hover/pressed 540 // Clip to just the fill region for any theme drawing and hover/pressed
548 // state overlay drawing below. In non-MD mode, this is done on the caller 541 // state overlay drawing below. In non-MD mode, this is done on the caller
549 // side using image masking operations. 542 // side using image masking operations.
550 canvas->ClipPath(fill, true); 543 canvas->ClipPath(fill, true);
551 canvas->sk_canvas()->scale(scale, scale); 544 canvas->sk_canvas()->scale(scale, scale);
552 } 545 }
553 546
554 // Draw the fill background image. 547 // Draw the fill background image.
555 const gfx::Size size(GetNewTabButtonSize()); 548 const gfx::Size size(GetLayoutSize(NEW_TAB_BUTTON));
556 if (custom_image || !md) { 549 if (custom_image || !md) {
557 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 550 const ui::ThemeProvider* theme_provider = GetThemeProvider();
558 gfx::ImageSkia* background = theme_provider->GetImageSkiaNamed(bg_id); 551 gfx::ImageSkia* background = theme_provider->GetImageSkiaNamed(bg_id);
559 // For custom tab backgrounds the background starts at the top of the tab 552 // For custom tab backgrounds the background starts at the top of the tab
560 // strip. Otherwise the background starts at the top of the frame. 553 // strip. Otherwise the background starts at the top of the frame.
561 const int offset_y = theme_provider->HasCustomImage(bg_id) ? 554 const int offset_y = theme_provider->HasCustomImage(bg_id) ?
562 -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) : background_offset_.y(); 555 -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) : background_offset_.y();
563 556
564 // The new tab background is mirrored in RTL mode, but the theme background 557 // The new tab background is mirrored in RTL mode, but the theme background
565 // should never be mirrored. Mirror it here to compensate. 558 // should never be mirrored. Mirror it here to compensate.
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 } 1654 }
1662 1655
1663 /////////////////////////////////////////////////////////////////////////////// 1656 ///////////////////////////////////////////////////////////////////////////////
1664 // TabStrip, private: 1657 // TabStrip, private:
1665 1658
1666 void TabStrip::Init() { 1659 void TabStrip::Init() {
1667 set_id(VIEW_ID_TAB_STRIP); 1660 set_id(VIEW_ID_TAB_STRIP);
1668 // So we get enter/exit on children to switch stacked layout on and off. 1661 // So we get enter/exit on children to switch stacked layout on and off.
1669 set_notify_enter_exit_on_child(true); 1662 set_notify_enter_exit_on_child(true);
1670 1663
1671 newtab_button_bounds_.set_size(GetNewTabButtonSize()); 1664 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON));
1672 newtab_button_bounds_.Inset(0, 0, 0, -kNewTabButtonVerticalOffset); 1665 newtab_button_bounds_.Inset(0, 0, 0, -kNewTabButtonVerticalOffset);
1673 newtab_button_ = new NewTabButton(this, this); 1666 newtab_button_ = new NewTabButton(this, this);
1674 newtab_button_->SetTooltipText( 1667 newtab_button_->SetTooltipText(
1675 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); 1668 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB));
1676 newtab_button_->SetAccessibleName( 1669 newtab_button_->SetAccessibleName(
1677 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); 1670 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB));
1678 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1671 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1679 views::ImageButton::ALIGN_BOTTOM); 1672 views::ImageButton::ALIGN_BOTTOM);
1680 newtab_button_->SetEventTargeter( 1673 newtab_button_->SetEventTargeter(
1681 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_))); 1674 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_)));
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2851 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2844 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2852 if (view) 2845 if (view)
2853 return view; 2846 return view;
2854 } 2847 }
2855 Tab* tab = FindTabForEvent(point); 2848 Tab* tab = FindTabForEvent(point);
2856 if (tab) 2849 if (tab)
2857 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2850 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2858 } 2851 }
2859 return this; 2852 return this;
2860 } 2853 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698