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/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/layout_constants.h" | 8 #include "chrome/browser/ui/views/layout_constants.h" |
| 9 #include "ui/base/resource/material_design/material_design_controller.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/painter.h" | 14 #include "ui/views/painter.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 SkColor CalculateImageColor(gfx::ImageSkia* image) { | 18 SkColor CalculateImageColor(gfx::ImageSkia* image) { |
| 18 // We grab the color of the middle pixel of the image, which we treat as | 19 // We grab the color of the middle pixel of the image, which we treat as |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 double IconLabelBubbleView::WidthMultiplier() const { | 94 double IconLabelBubbleView::WidthMultiplier() const { |
| 94 return 1.0; | 95 return 1.0; |
| 95 } | 96 } |
| 96 | 97 |
| 97 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 98 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
| 98 // Height will be ignored by the LocationBarView. | 99 // Height will be ignored by the LocationBarView. |
| 99 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 100 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void IconLabelBubbleView::Layout() { | 103 void IconLabelBubbleView::Layout() { |
| 104 // In MD mode, both extension icons and Chrome-provided icons are 16px, | |
| 105 // so it's not necessary to handle them differently. TODO(estade): clean | |
| 106 // this up when MD is on by default. | |
| 107 bool is_extension_icon = ui::MaterialDesignController::IsModeMaterial() ? | |
|
Peter Kasting
2015/10/23 23:44:09
Nit: Seems clearer?
bool is_extension_icon =
| |
| 108 false : is_extension_icon_; | |
|
Peter Kasting
2015/10/23 23:44:09
Nit: Seems clearer?
bool is_extension_icon =
Evan Stade
2015/10/26 19:29:19
done
| |
| 103 const int image_width = image()->GetPreferredSize().width(); | 109 const int image_width = image()->GetPreferredSize().width(); |
| 104 image_->SetBounds(std::min((width() - image_width) / 2, | 110 image_->SetBounds(std::min((width() - image_width) / 2, |
| 105 GetBubbleOuterPadding(!is_extension_icon_)), | 111 GetBubbleOuterPadding(!is_extension_icon)), |
| 106 0, image_->GetPreferredSize().width(), height()); | 112 0, image_->GetPreferredSize().width(), height()); |
| 107 | 113 |
| 108 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); | 114 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); |
| 109 int pre_label_width = | 115 int pre_label_width = |
| 110 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0); | 116 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0); |
| 111 label_->SetBounds(pre_label_width, 0, | 117 label_->SetBounds(pre_label_width, 0, |
| 112 width() - pre_label_width - GetBubbleOuterPadding(false), | 118 width() - pre_label_width - GetBubbleOuterPadding(false), |
| 113 height()); | 119 height()); |
| 114 } | 120 } |
| 115 | 121 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 const char* IconLabelBubbleView::GetClassName() const { | 158 const char* IconLabelBubbleView::GetClassName() const { |
| 153 return "IconLabelBubbleView"; | 159 return "IconLabelBubbleView"; |
| 154 } | 160 } |
| 155 | 161 |
| 156 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 162 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
| 157 if (!ShouldShowBackground()) | 163 if (!ShouldShowBackground()) |
| 158 return; | 164 return; |
| 159 if (background_painter_) | 165 if (background_painter_) |
| 160 background_painter_->Paint(canvas, size()); | 166 background_painter_->Paint(canvas, size()); |
| 161 } | 167 } |
| OLD | NEW |