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

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

Issue 1763713004: Adjusts content bubble animation with respect to icon size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjusts content bubble animation with respect to icon size (fix for a regression in growth stage) Created 4 years, 9 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/location_bar/icon_label_bubble_view.h ('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/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/layout_constants.h" 8 #include "chrome/browser/ui/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/material_design/material_design_controller.h" 10 #include "ui/base/material_design/material_design_controller.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 bool IconLabelBubbleView::ShouldShowBackground() const { 100 bool IconLabelBubbleView::ShouldShowBackground() const {
101 return should_show_background_; 101 return should_show_background_;
102 } 102 }
103 103
104 double IconLabelBubbleView::WidthMultiplier() const { 104 double IconLabelBubbleView::WidthMultiplier() const {
105 return 1.0; 105 return 1.0;
106 } 106 }
107 107
108 bool IconLabelBubbleView::IsShrinking() const {
109 return false;
110 }
111
108 int IconLabelBubbleView::GetImageAndPaddingWidth() const { 112 int IconLabelBubbleView::GetImageAndPaddingWidth() const {
109 const int image_width = image_->GetPreferredSize().width(); 113 const int image_width = image_->GetPreferredSize().width();
110 return image_width 114 return image_width
111 ? image_width + GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING) 115 ? image_width + GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING)
112 : 0; 116 : 0;
113 } 117 }
114 118
115 gfx::Size IconLabelBubbleView::GetPreferredSize() const { 119 gfx::Size IconLabelBubbleView::GetPreferredSize() const {
116 // Height will be ignored by the LocationBarView. 120 // Height will be ignored by the LocationBarView.
117 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); 121 return GetSizeForLabelWidth(label_->GetPreferredSize().width());
118 } 122 }
119 123
120 void IconLabelBubbleView::Layout() { 124 void IconLabelBubbleView::Layout() {
121 // In MD mode, both extension icons and Chrome-provided icons are 16px, 125 // In MD mode, both extension icons and Chrome-provided icons are 16px,
122 // so it's not necessary to handle them differently. TODO(estade): clean 126 // so it's not necessary to handle them differently. TODO(estade): clean
123 // this up when MD is on by default. 127 // this up when MD is on by default.
124 bool icon_has_enough_padding = 128 bool icon_has_enough_padding =
125 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); 129 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial();
126 const int image_width = image_->GetPreferredSize().width(); 130 const int image_preferred_width = image_->GetPreferredSize().width();
127 image_->SetBounds(std::min((width() - image_width) / 2, 131 // image is positioned at a constant offset when the bubble is growing or when
128 GetBubbleOuterPadding(icon_has_enough_padding)), 132 // there is enough room to fit the whole image. This is done so that the image
129 0, image_->GetPreferredSize().width(), height()); 133 // slides in as a part of the sliding surface and doesn't shift relative to
134 // the background.
135 const bool shrinking = IsShrinking();
136 int image_trailing_padding = GetBubbleOuterPadding(false);
137 int image_x = GetBubbleOuterPadding(icon_has_enough_padding);
138 if (shrinking &&
139 (!label_->visible() || image_x + image_preferred_width > width())) {
Peter Kasting 2016/03/11 07:15:08 Hmm. Doesn't this mean that once we get to the po
varkha 2016/03/11 10:16:20 No. This code was getting triggered only once imag
140 image_trailing_padding = 0;
141 image_x = std::min(image_x, std::max(0, width() - image_preferred_width));
142 }
143 const int image_width = std::min(image_preferred_width,
144 width() - image_x - image_trailing_padding);
145 image_->SetBounds(image_x, 0, image_width, height());
130 146
131 int pre_label_width = GetBubbleOuterPadding(true) + GetImageAndPaddingWidth(); 147 int label_x = GetBubbleOuterPadding(true) + GetImageAndPaddingWidth();
132 label_->SetBounds(pre_label_width, 0, 148 const int label_width =
133 width() - pre_label_width - GetBubbleOuterPadding(false), 149 std::max(0, width() - label_x - GetBubbleOuterPadding(false));
134 height()); 150
151 // Hiding the label when the leading edge of the image plus padding crosses
152 // the right edge of the bubble allows the final frames of the animation to
153 // smoothly transition from showing a bubble to showing just the image.
154 if (shrinking && label_->visible() &&
155 (image_x + image_preferred_width + image_trailing_padding >=
156 bounds().width())) {
157 label_->SetVisible(false);
158 }
159
160 label_->SetBounds(label_x, 0, label_width, height());
135 } 161 }
136 162
137 void IconLabelBubbleView::OnNativeThemeChanged( 163 void IconLabelBubbleView::OnNativeThemeChanged(
138 const ui::NativeTheme* native_theme) { 164 const ui::NativeTheme* native_theme) {
139 label_->SetEnabledColor(GetTextColor()); 165 label_->SetEnabledColor(GetTextColor());
140 166
141 if (!ui::MaterialDesignController::IsModeMaterial()) 167 if (!ui::MaterialDesignController::IsModeMaterial())
142 return; 168 return;
143 169
144 bool inverted = color_utils::IsDark(GetParentBackgroundColor()); 170 bool inverted = color_utils::IsDark(GetParentBackgroundColor());
(...skipping 25 matching lines...) Expand all
170 return color_utils::DeriveDefaultIconColor(GetTextColor()); 196 return color_utils::DeriveDefaultIconColor(GetTextColor());
171 } 197 }
172 198
173 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { 199 SkColor IconLabelBubbleView::GetParentBackgroundColor() const {
174 return ui::MaterialDesignController::IsModeMaterial() 200 return ui::MaterialDesignController::IsModeMaterial()
175 ? GetNativeTheme()->GetSystemColor( 201 ? GetNativeTheme()->GetSystemColor(
176 ui::NativeTheme::kColorId_TextfieldDefaultBackground) 202 ui::NativeTheme::kColorId_TextfieldDefaultBackground)
177 : parent_background_color_; 203 : parent_background_color_;
178 } 204 }
179 205
180 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { 206 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const {
181 gfx::Size size(image_->GetPreferredSize()); 207 gfx::Size size(image_->GetPreferredSize());
182 if (ShouldShowBackground()) { 208 bool shrinking = IsShrinking();
183 const int non_label_width = GetBubbleOuterPadding(true) + 209 // Animation continues for the last few pixels even after the label is not
184 GetImageAndPaddingWidth() + 210 // visible in order to slide the icon into its final position. Therefore it
185 GetBubbleOuterPadding(false); 211 // is necessary to animate |total_width| even when the background is hidden
186 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); 212 // as long as the animation is still shrinking.
187 if (!ui::MaterialDesignController::IsModeMaterial()) 213 if (ShouldShowBackground() || shrinking) {
188 size.SetToMax(background_painter_->GetMinimumSize()); 214 const int image_width = size.width();
215 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING) +
216 GetBubbleOuterPadding(true) + GetBubbleOuterPadding(false);
217 // |multiplier| grows from zero to one, stays equal to one and then shrinks
218 // to zero again. The view width should correspondingly grow from zero to
219 // fully showing both label and icon, stay there, then shrink to just large
220 // enough to show the icon. We don't want to shrink all the way back to
221 // zero, since this would mean the view would completely disappear and then
222 // pop back to an icon after the animation finishes.
223 int total_width = WidthMultiplier() * (label_width + image_width + padding);
224 if (shrinking)
225 total_width = std::max(total_width, image_width);
226 size.set_width(total_width);
189 } 227 }
228 return size;
229 }
190 230
191 return size; 231 int IconLabelBubbleView::GetBubbleOuterPadding(bool leading) const {
232 if (ui::MaterialDesignController::IsModeMaterial())
233 return GetBubbleOuterPaddingMd(leading);
234
235 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) -
236 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
237 (leading ? 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING));
192 } 238 }
193 239
194 void IconLabelBubbleView::SetLabelBackgroundColor( 240 void IconLabelBubbleView::SetLabelBackgroundColor(
195 SkColor chip_background_color) { 241 SkColor chip_background_color) {
196 // The background images are painted atop |parent_background_color_|. 242 // The background images are painted atop |parent_background_color_|.
197 // Alpha-blend |chip_background_color| with |parent_background_color_| to 243 // Alpha-blend |chip_background_color| with |parent_background_color_| to
198 // determine the actual color the label text will sit atop. 244 // determine the actual color the label text will sit atop.
199 // Tricky bit: We alpha blend an opaque version of |chip_background_color| 245 // Tricky bit: We alpha blend an opaque version of |chip_background_color|
200 // against |parent_background_color_| using the original image grid color's 246 // against |parent_background_color_| using the original image grid color's
201 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged 247 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
202 // even if |a| is a color with non-255 alpha. 248 // even if |a| is a color with non-255 alpha.
203 label_->SetBackgroundColor(color_utils::AlphaBlend( 249 label_->SetBackgroundColor(color_utils::AlphaBlend(
204 SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(), 250 SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(),
205 SkColorGetA(chip_background_color))); 251 SkColorGetA(chip_background_color)));
206 } 252 }
207 253
208 int IconLabelBubbleView::GetBubbleOuterPadding(bool leading) const {
209 if (ui::MaterialDesignController::IsModeMaterial())
210 return GetBubbleOuterPaddingMd(leading);
211
212 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) -
213 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
214 (leading ? 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING));
215 }
216
217 int IconLabelBubbleView::GetBubbleOuterPaddingMd(bool leading) const { 254 int IconLabelBubbleView::GetBubbleOuterPaddingMd(bool leading) const {
218 // When the image is empty, leading and trailing padding are equal. 255 // When the image is empty, leading and trailing padding are equal.
219 if (image_->GetPreferredSize().IsEmpty() || !leading) 256 if (image_->GetPreferredSize().IsEmpty() || !leading)
220 return GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING); 257 return GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING);
221 258
222 // Leading padding is 2dp. 259 // Leading padding is 2dp.
223 return 2; 260 return 2;
224 } 261 }
225 262
226 const char* IconLabelBubbleView::GetClassName() const { 263 const char* IconLabelBubbleView::GetClassName() const {
227 return "IconLabelBubbleView"; 264 return "IconLabelBubbleView";
228 } 265 }
229 266
230 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { 267 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
231 if (!ShouldShowBackground()) 268 if (!ShouldShowBackground())
232 return; 269 return;
233 if (background_painter_) { 270 if (background_painter_) {
234 views::Painter::PaintPainterAt(canvas, background_painter_.get(), 271 views::Painter::PaintPainterAt(canvas, background_painter_.get(),
235 GetContentsBounds()); 272 GetContentsBounds());
236 } 273 }
237 if (background()) 274 if (background())
238 background()->Paint(canvas, this); 275 background()->Paint(canvas, this);
239 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/icon_label_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698