Chromium Code Reviews| Index: chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc |
| index 4abe60c7c68684c4ea339439a1923b18e5df36a6..ba0a9251d1ccd1ec8466469cfa81aa1dce1e87ae 100644 |
| --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc |
| +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc |
| @@ -7,7 +7,6 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/ui/layout_constants.h" |
| #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| -#include "ui/base/material_design/material_design_controller.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/color_utils.h" |
| @@ -37,21 +36,10 @@ SkColor CalculateImageColor(gfx::ImageSkia* image) { |
| } // namespace |
| -IconLabelBubbleView::IconLabelBubbleView(int contained_image, |
| - const gfx::FontList& font_list, |
| - SkColor parent_background_color, |
| +IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, |
| bool elide_in_middle) |
| - : background_painter_(nullptr), |
| - image_(new views::ImageView()), |
| - label_(new views::Label(base::string16(), font_list)), |
| - is_extension_icon_(false), |
| - parent_background_color_(parent_background_color) { |
| - if (contained_image) { |
| - image_->SetImage( |
| - ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| - contained_image)); |
| - } |
| - |
| + : image_(new views::ImageView()), |
| + label_(new views::Label(base::string16(), font_list)) { |
| // Disable separate hit testing for |image_|. This prevents views treating |
| // |image_| as a separate mouse hover region from |this|. |
| image_->set_interactive(false); |
| @@ -70,34 +58,13 @@ IconLabelBubbleView::IconLabelBubbleView(int contained_image, |
| SetBorder(views::Border::CreateEmptyBorder( |
| gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); |
| - // Flip the canvas in MD RTL so the separator is drawn on the correct side. |
| - EnableCanvasFlippingForRTLUI(ui::MaterialDesignController::IsModeMaterial()); |
| + // Flip the canvas in RTL so the separator is drawn on the correct side. |
| + EnableCanvasFlippingForRTLUI(true); |
| } |
| IconLabelBubbleView::~IconLabelBubbleView() { |
| } |
| -void IconLabelBubbleView::SetBackgroundImageGrid( |
| - const int background_images[]) { |
| - should_show_background_ = true; |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - background_painter_.reset( |
| - views::Painter::CreateImageGridPainter(background_images)); |
| - // Use the middle image of the background to represent the color of the |
| - // entire background. |
| - gfx::ImageSkia* background_image = |
| - ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| - background_images[4]); |
| - SetLabelBackgroundColor(CalculateImageColor(background_image)); |
| - } |
| - OnNativeThemeChanged(GetNativeTheme()); |
| -} |
| - |
| -void IconLabelBubbleView::UnsetBackgroundImageGrid() { |
| - should_show_background_ = false; |
| - SetLabelBackgroundColor(SK_ColorTRANSPARENT); |
| -} |
| - |
| void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| label_->SetText(label); |
| } |
| @@ -106,8 +73,8 @@ void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| image_->SetImage(image_skia); |
| } |
| -bool IconLabelBubbleView::ShouldShowBackground() const { |
| - return should_show_background_; |
| +bool IconLabelBubbleView::ShouldShowLabel() const { |
| + return label_->visible() && !label_->text().empty(); |
|
Peter Kasting
2016/09/19 23:46:45
Is this logic synthesized from the cases when we c
Evan Stade
2016/09/20 17:37:03
In LocationBarView, it's only called on LocationIc
|
| } |
| double IconLabelBubbleView::WidthMultiplier() const { |
| @@ -144,12 +111,10 @@ void IconLabelBubbleView::Layout() { |
| // whether this is an extension icon, since extension icons and |
| // Chrome-provided icons are different sizes. In MD, these sizes are the |
| // same, so it's not necessary to handle the two types differently. |
|
Peter Kasting
2016/09/19 23:46:45
Nit: This comment needs updating
Evan Stade
2016/09/20 17:37:04
Done.
|
| - const bool icon_has_enough_padding = |
| - !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); |
| - int image_x = GetOuterPadding(icon_has_enough_padding); |
| - int bubble_trailing_padding = GetOuterPadding(false); |
| + int image_x = GetOuterPadding(); |
| + int bubble_trailing_padding = GetOuterPadding(); |
|
Peter Kasting
2016/09/19 23:46:45
Nit: I'd just do "bubble_trailing_padding = image_
Evan Stade
2016/09/20 17:37:04
Done.
|
| - // If ShouldShowBackground() is true, then either we show a background in the |
| + // If ShouldShowLabel() is true, then either we show a label in the |
| // steady state, or we're not yet in the last portion of the animation. In |
| // these cases, we leave the leading and trailing padding alone; we don't want |
| // to let the image overlap the edge of the background, as this looks glitchy. |
| @@ -159,7 +124,7 @@ void IconLabelBubbleView::Layout() { |
| // so the image slides all the way to the trailing edge before slowing or |
| // stopping; then we want to shrink the leading padding down to zero. |
| const int image_preferred_width = image_->GetPreferredSize().width(); |
| - if (!ShouldShowBackground()) { |
| + if (!ShouldShowLabel()) { |
| image_x = std::min(image_x, width() - image_preferred_width); |
| bubble_trailing_padding = std::min( |
| bubble_trailing_padding, width() - image_preferred_width - image_x); |
| @@ -187,11 +152,8 @@ void IconLabelBubbleView::Layout() { |
| void IconLabelBubbleView::OnNativeThemeChanged( |
| const ui::NativeTheme* native_theme) { |
| label_->SetEnabledColor(GetTextColor()); |
| - |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - label_->SetBackgroundColor(GetParentBackgroundColor()); |
| - SchedulePaint(); |
| - } |
| + label_->SetBackgroundColor(GetParentBackgroundColor()); |
| + SchedulePaint(); |
| } |
| void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| @@ -217,10 +179,8 @@ SkColor IconLabelBubbleView::GetInkDropBaseColor() const { |
| } |
| SkColor IconLabelBubbleView::GetParentBackgroundColor() const { |
| - return ui::MaterialDesignController::IsModeMaterial() |
| - ? GetNativeTheme()->GetSystemColor( |
| - ui::NativeTheme::kColorId_TextfieldDefaultBackground) |
| - : parent_background_color_; |
| + return GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| } |
| gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| @@ -230,7 +190,7 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| // visible in order to slide the icon into its final position. Therefore it |
| // is necessary to animate |total_width| even when the background is hidden |
| // as long as the animation is still shrinking. |
| - if (ShouldShowBackground() || shrinking) { |
| + if (ShouldShowLabel() || shrinking) { |
| // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For |
| // higher scale factors, we simply take the separator px out of the |
| // kSpaceBesideSeparator region before the separator, as that results in a |
| @@ -240,9 +200,8 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| // There may be no widget in tests. |
| const int separator_width = |
| (widget && widget->GetCompositor()->device_scale_factor() >= 2) ? 0 : 1; |
| - const int post_label_width = ui::MaterialDesignController::IsModeMaterial() |
| - ? (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()) |
| - : GetOuterPadding(false); |
| + const int post_label_width = |
| + (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()); |
| // |multiplier| grows from zero to one, stays equal to one and then shrinks |
| // to zero again. The view width should correspondingly grow from zero to |
| @@ -260,34 +219,15 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| } |
| int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const { |
| - return GetImageTrailingEdge() + GetOuterPadding(false); |
| + return GetImageTrailingEdge() + GetOuterPadding(); |
| } |
| -void IconLabelBubbleView::SetLabelBackgroundColor( |
| - SkColor chip_background_color) { |
| - // The background images are painted atop |parent_background_color_|. |
| - // Alpha-blend |chip_background_color| with |parent_background_color_| to |
| - // determine the actual color the label text will sit atop. |
| - // Tricky bit: We alpha blend an opaque version of |chip_background_color| |
| - // against |parent_background_color_| using the original image grid color's |
| - // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
| - // even if |a| is a color with non-255 alpha. |
| - label_->SetBackgroundColor(color_utils::AlphaBlend( |
| - SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(), |
| - SkColorGetA(chip_background_color))); |
| -} |
| - |
| -int IconLabelBubbleView::GetOuterPadding(bool leading) const { |
| - if (ui::MaterialDesignController::IsModeMaterial()) |
| - return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| - |
| - return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) - |
| - GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + |
| - (leading ? 0 : kTrailingPaddingPreMd); |
| +int IconLabelBubbleView::GetOuterPadding() const { |
| + return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
|
Peter Kasting
2016/09/19 23:46:45
Nit: Seems like we could just make this call direc
Evan Stade
2016/09/20 17:37:04
Done.
|
| } |
| int IconLabelBubbleView::GetImageTrailingEdge() const { |
| - return GetOuterPadding(true) + image_->GetPreferredSize().width(); |
| + return GetOuterPadding() + image_->GetPreferredSize().width(); |
| } |
| int IconLabelBubbleView::GetInternalSpacing() const { |
| @@ -307,32 +247,25 @@ const char* IconLabelBubbleView::GetClassName() const { |
| } |
| void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
| - if (!ShouldShowBackground()) |
| + if (!ShouldShowLabel()) |
| return; |
| - if (background_painter_) { |
| - views::Painter::PaintPainterAt(canvas, background_painter_.get(), |
| - GetContentsBounds()); |
| - } |
| - // In MD, draw a separator and not a background. |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( |
| - ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| - const SkColor separator_color = SkColorSetA( |
| - plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); |
| - |
| - gfx::Rect bounds(GetLocalBounds()); |
| - const int kSeparatorHeight = 16; |
| - bounds.Inset(GetPostSeparatorPadding(), |
| - (bounds.height() - kSeparatorHeight) / 2); |
| - |
| - // Draw the 1 px separator. |
| - gfx::ScopedCanvas scoped_canvas(canvas); |
| - const float scale = canvas->UndoDeviceScaleFactor(); |
| - // Keep the separator aligned on a pixel center. |
| - const gfx::RectF pixel_aligned_bounds = |
| - gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); |
| - canvas->DrawLine(pixel_aligned_bounds.top_right(), |
| - pixel_aligned_bounds.bottom_right(), separator_color); |
| - } |
| + const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| + const SkColor separator_color = SkColorSetA( |
| + plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); |
| + |
| + gfx::Rect bounds(GetLocalBounds()); |
| + const int kSeparatorHeight = 16; |
| + bounds.Inset(GetPostSeparatorPadding(), |
| + (bounds.height() - kSeparatorHeight) / 2); |
| + |
| + // Draw the 1 px separator. |
| + gfx::ScopedCanvas scoped_canvas(canvas); |
| + const float scale = canvas->UndoDeviceScaleFactor(); |
| + // Keep the separator aligned on a pixel center. |
| + const gfx::RectF pixel_aligned_bounds = |
| + gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); |
| + canvas->DrawLine(pixel_aligned_bounds.top_right(), |
| + pixel_aligned_bounds.bottom_right(), separator_color); |
| } |