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

Side by Side Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc

Issue 1419673017: [MD] Twiddle padding of omnibox chips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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/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
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 const bool trailing = image_->GetPreferredSize().IsEmpty() || !leading;
155 return GetLayoutConstant(trailing ? ICON_LABEL_VIEW_TRAILING_PADDING
156 : ICON_LABEL_VIEW_LEADING_PADDING);
152 } 157 }
153 158
154 void IconLabelBubbleView::SetLabelBackgroundColor( 159 void IconLabelBubbleView::SetLabelBackgroundColor(
155 SkColor background_image_color) { 160 SkColor background_image_color) {
156 // The background images are painted atop |parent_background_color_|. 161 // The background images are painted atop |parent_background_color_|.
157 // Alpha-blend |background_image_color| with |parent_background_color_| to 162 // Alpha-blend |background_image_color| with |parent_background_color_| to
158 // determine the actual color the label text will sit atop. 163 // determine the actual color the label text will sit atop.
159 // Tricky bit: We alpha blend an opaque version of |background_image_color| 164 // Tricky bit: We alpha blend an opaque version of |background_image_color|
160 // against |parent_background_color_| using the original image grid color's 165 // against |parent_background_color_| using the original image grid color's
161 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged 166 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
162 // even if |a| is a color with non-255 alpha. 167 // even if |a| is a color with non-255 alpha.
163 label_->SetBackgroundColor(color_utils::AlphaBlend( 168 label_->SetBackgroundColor(color_utils::AlphaBlend(
164 SkColorSetA(background_image_color, 255), parent_background_color_, 169 SkColorSetA(background_image_color, 255), parent_background_color_,
165 SkColorGetA(background_image_color))); 170 SkColorGetA(background_image_color)));
166 } 171 }
167 172
168 const char* IconLabelBubbleView::GetClassName() const { 173 const char* IconLabelBubbleView::GetClassName() const {
169 return "IconLabelBubbleView"; 174 return "IconLabelBubbleView";
170 } 175 }
171 176
172 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { 177 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
173 if (!ShouldShowBackground()) 178 if (!ShouldShowBackground())
174 return; 179 return;
175 if (background_painter_) 180 if (background_painter_)
176 background_painter_->Paint(canvas, size()); 181 background_painter_->Paint(canvas, size());
177 if (background()) 182 if (background())
178 background()->Paint(canvas, this); 183 background()->Paint(canvas, this);
179 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698