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 "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
10 #include "ui/base/resource/material_design/material_design_controller.h" | 10 #include "ui/base/resource/material_design/material_design_controller.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 (image_width ? (image_width + padding) : 0) + | 133 (image_width ? (image_width + padding) : 0) + |
134 GetBubbleOuterPadding(false); | 134 GetBubbleOuterPadding(false); |
135 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); | 135 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); |
136 if (!ui::MaterialDesignController::IsModeMaterial()) | 136 if (!ui::MaterialDesignController::IsModeMaterial()) |
137 size.SetToMax(background_painter_->GetMinimumSize()); | 137 size.SetToMax(background_painter_->GetMinimumSize()); |
138 } | 138 } |
139 | 139 |
140 return size; | 140 return size; |
141 } | 141 } |
142 | 142 |
143 int IconLabelBubbleView::GetBubbleOuterPadding(bool start) const { | 143 int IconLabelBubbleView::GetBubbleOuterPadding(bool leading) const { |
144 // When the image is empty, leading and trailing padding are equal. | 144 if (ui::MaterialDesignController::IsModeMaterial()) |
145 const int extra_padding = | 145 return GetBubbleOuterPaddingMd(leading); |
146 image_->GetPreferredSize().IsEmpty() || !start | 146 |
147 ? GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING) | |
148 : 0; | |
149 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) - | 147 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) - |
150 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + | 148 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + |
151 extra_padding; | 149 (leading ? 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING)); |
| 150 } |
| 151 |
| 152 int IconLabelBubbleView::GetBubbleOuterPaddingMd(bool leading) const { |
| 153 // When the image is empty, leading and trailing padding are equal. |
| 154 if (image_->GetPreferredSize().IsEmpty() || !leading) |
| 155 return GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING); |
| 156 |
| 157 // Leading padding is 2dp. |
| 158 return 2; |
152 } | 159 } |
153 | 160 |
154 void IconLabelBubbleView::SetLabelBackgroundColor( | 161 void IconLabelBubbleView::SetLabelBackgroundColor( |
155 SkColor background_image_color) { | 162 SkColor background_image_color) { |
156 // The background images are painted atop |parent_background_color_|. | 163 // The background images are painted atop |parent_background_color_|. |
157 // Alpha-blend |background_image_color| with |parent_background_color_| to | 164 // Alpha-blend |background_image_color| with |parent_background_color_| to |
158 // determine the actual color the label text will sit atop. | 165 // determine the actual color the label text will sit atop. |
159 // Tricky bit: We alpha blend an opaque version of |background_image_color| | 166 // Tricky bit: We alpha blend an opaque version of |background_image_color| |
160 // against |parent_background_color_| using the original image grid color's | 167 // against |parent_background_color_| using the original image grid color's |
161 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged | 168 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
162 // even if |a| is a color with non-255 alpha. | 169 // even if |a| is a color with non-255 alpha. |
163 label_->SetBackgroundColor(color_utils::AlphaBlend( | 170 label_->SetBackgroundColor(color_utils::AlphaBlend( |
164 SkColorSetA(background_image_color, 255), parent_background_color_, | 171 SkColorSetA(background_image_color, 255), parent_background_color_, |
165 SkColorGetA(background_image_color))); | 172 SkColorGetA(background_image_color))); |
166 } | 173 } |
167 | 174 |
168 const char* IconLabelBubbleView::GetClassName() const { | 175 const char* IconLabelBubbleView::GetClassName() const { |
169 return "IconLabelBubbleView"; | 176 return "IconLabelBubbleView"; |
170 } | 177 } |
171 | 178 |
172 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 179 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
173 if (!ShouldShowBackground()) | 180 if (!ShouldShowBackground()) |
174 return; | 181 return; |
175 if (background_painter_) | 182 if (background_painter_) |
176 background_painter_->Paint(canvas, size()); | 183 background_painter_->Paint(canvas, size()); |
177 if (background()) | 184 if (background()) |
178 background()->Paint(canvas, this); | 185 background()->Paint(canvas, this); |
179 } | 186 } |
OLD | NEW |