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 "chrome/browser/ui/layout_constants.h" | 7 #include "chrome/browser/ui/layout_constants.h" |
| 8 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 8 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 10 #include "ui/accessibility/ax_node_data.h" | 10 #include "ui/accessibility/ax_node_data.h" |
| 11 #include "ui/compositor/layer_animator.h" | |
| 12 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 11 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/gfx/scoped_canvas.h" | 15 #include "ui/gfx/scoped_canvas.h" |
| 14 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 15 #include "ui/views/animation/ink_drop_highlight.h" | 18 #include "ui/views/animation/ink_drop_highlight.h" |
| 19 #include "ui/views/animation/ink_drop_impl.h" | |
| 20 #include "ui/views/animation/ink_drop_mask.h" | |
| 21 #include "ui/views/animation/ink_drop_ripple.h" | |
| 16 #include "ui/views/border.h" | 22 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
| 18 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 19 | 25 |
| 20 namespace { | 26 namespace { |
| 21 | 27 |
| 22 // Amount of space on either side of the separator that appears after the label. | 28 // Amount of space on either side of the separator that appears after the label. |
| 23 constexpr int kSpaceBesideSeparator = 8; | 29 constexpr int kSpaceBesideSeparator = 8; |
| 24 | 30 |
| 31 // Radius of the ink drop mask's rounded rectangle shape. | |
| 32 constexpr int kInkDropMaskRadius = 2; | |
| 33 | |
| 34 // The length of the separator's fade animation. | |
| 35 constexpr int kFadeInDurationMs = 250; | |
| 36 constexpr int kFadeOutDurationMs = 175; | |
| 37 | |
| 25 } // namespace | 38 } // namespace |
| 26 | 39 |
| 40 ////////////////////////////////////////////////////////////////// | |
| 41 // SeparatorView class | |
| 42 | |
| 43 IconLabelBubbleView::SeparatorView::SeparatorView(IconLabelBubbleView* owner) { | |
| 44 DCHECK(owner); | |
| 45 owner_ = owner; | |
| 46 SetPaintToLayer(); | |
| 47 layer()->SetFillsBoundsOpaquely(false); | |
| 48 } | |
| 49 | |
| 50 void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) { | |
| 51 if (!owner_->ShouldShowLabel()) | |
| 52 return; | |
| 53 | |
| 54 const SkColor plain_text_color = owner_->GetNativeTheme()->GetSystemColor( | |
| 55 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 56 const SkColor separator_color = SkColorSetA( | |
| 57 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); | |
| 58 | |
| 59 gfx::Rect bounds(owner_->label()->bounds()); | |
| 60 const int kSeparatorHeight = 16; | |
| 61 bounds.Inset(0, (bounds.height() - kSeparatorHeight) / 2); | |
| 62 bounds.set_width(bounds.width() + kSpaceBesideSeparator); | |
| 63 canvas->Draw1pxLine(gfx::PointF(bounds.top_right()), | |
| 64 gfx::PointF(bounds.bottom_right()), separator_color); | |
| 65 } | |
| 66 | |
| 67 bool IconLabelBubbleView::SeparatorView::CanProcessEventsWithinSubtree() const { | |
| 68 return false; | |
| 69 } | |
| 70 | |
| 71 void IconLabelBubbleView::SeparatorView::UpdateOpacity() { | |
| 72 views::InkDrop* ink_drop = owner_->GetInkDrop(); | |
| 73 DCHECK(ink_drop); | |
| 74 | |
| 75 // If an inkdrop highlight or ripple is animating in or visible, the | |
| 76 // separator should fade out. | |
| 77 views::InkDropState state = ink_drop->GetTargetInkDropState(); | |
| 78 float opacity = 0.0f; | |
| 79 float duration = kFadeOutDurationMs; | |
| 80 if (!ink_drop->IsHighlightFadingInOrVisible() && | |
| 81 (state == views::InkDropState::HIDDEN || | |
| 82 state == views::InkDropState::ACTION_TRIGGERED || | |
| 83 state == views::InkDropState::DEACTIVATED)) { | |
| 84 opacity = 1.0f; | |
| 85 duration = kFadeInDurationMs; | |
| 86 } | |
| 87 | |
| 88 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
| 89 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(duration)); | |
| 90 animation.SetTweenType(gfx::Tween::Type::EASE_IN); | |
| 91 layer()->SetOpacity(opacity); | |
| 92 } | |
| 93 | |
| 94 ////////////////////////////////////////////////////////////////// | |
| 95 // IconLabelBubbleView class | |
| 96 | |
| 27 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, | 97 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, |
| 28 bool elide_in_middle) | 98 bool elide_in_middle) |
| 29 : image_(new views::ImageView()), | 99 : CustomButton(this), |
| 30 label_(new views::Label(base::string16(), {font_list})) { | 100 image_(new views::ImageView()), |
| 101 label_(new views::Label(base::string16(), {font_list})), | |
| 102 ink_drop_container_(new views::InkDropContainerView()), | |
| 103 suppress_button_release_(false) { | |
| 31 // Disable separate hit testing for |image_|. This prevents views treating | 104 // Disable separate hit testing for |image_|. This prevents views treating |
| 32 // |image_| as a separate mouse hover region from |this|. | 105 // |image_| as a separate mouse hover region from |this|. |
| 33 image_->set_can_process_events_within_subtree(false); | 106 image_->set_can_process_events_within_subtree(false); |
| 34 image_->SetBorder(views::CreateEmptyBorder( | 107 image_->SetBorder(views::CreateEmptyBorder( |
| 35 gfx::Insets(LocationBarView::kIconInteriorPadding))); | 108 gfx::Insets(LocationBarView::kIconInteriorPadding))); |
| 36 AddChildView(image_); | 109 AddChildView(image_); |
| 37 | 110 |
| 38 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 111 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 39 | 112 |
| 40 if (elide_in_middle) | 113 if (elide_in_middle) |
| 41 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); | 114 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 42 AddChildView(label_); | 115 AddChildView(label_); |
| 43 | 116 |
| 117 separator_view_.reset(new SeparatorView(this)); | |
| 118 AddChildView(separator_view_.get()); | |
| 119 | |
| 120 AddChildView(ink_drop_container_); | |
| 121 ink_drop_container_->SetVisible(false); | |
| 122 | |
| 44 // Bubbles are given the full internal height of the location bar so that all | 123 // Bubbles are given the full internal height of the location bar so that all |
| 45 // child views in the location bar have the same height. The visible height of | 124 // child views in the location bar have the same height. The visible height of |
| 46 // the bubble should be smaller, so use an empty border to shrink down the | 125 // the bubble should be smaller, so use an empty border to shrink down the |
| 47 // content bounds so the background gets painted correctly. | 126 // content bounds so the background gets painted correctly. |
| 48 SetBorder(views::CreateEmptyBorder( | 127 SetBorder(views::CreateEmptyBorder( |
| 49 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); | 128 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); |
| 50 | 129 |
| 51 // Flip the canvas in RTL so the separator is drawn on the correct side. | 130 // Flip the canvas in RTL so the separator is drawn on the correct side. |
| 52 EnableCanvasFlippingForRTLUI(true); | 131 separator_view_->EnableCanvasFlippingForRTLUI(true); |
| 53 } | 132 } |
| 54 | 133 |
| 55 IconLabelBubbleView::~IconLabelBubbleView() { | 134 IconLabelBubbleView::~IconLabelBubbleView() { |
| 56 } | 135 } |
| 57 | 136 |
| 137 void IconLabelBubbleView::ButtonPressed(Button* sender, | |
| 138 const ui::Event& event) { | |
| 139 OnActivate(event); | |
| 140 } | |
| 141 | |
| 142 void IconLabelBubbleView::InkDropAnimationStarted() { | |
| 143 separator_view_->UpdateOpacity(); | |
| 144 } | |
| 145 | |
| 58 void IconLabelBubbleView::SetLabel(const base::string16& label) { | 146 void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| 59 label_->SetText(label); | 147 label_->SetText(label); |
| 60 } | 148 } |
| 61 | 149 |
| 62 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { | 150 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| 63 image_->SetImage(image_skia); | 151 image_->SetImage(image_skia); |
| 64 } | 152 } |
| 65 | 153 |
| 66 bool IconLabelBubbleView::ShouldShowLabel() const { | 154 bool IconLabelBubbleView::ShouldShowLabel() const { |
| 67 return label_->visible() && !label_->text().empty(); | 155 return label_->visible() && !label_->text().empty(); |
| 68 } | 156 } |
| 69 | 157 |
| 70 double IconLabelBubbleView::WidthMultiplier() const { | 158 double IconLabelBubbleView::WidthMultiplier() const { |
| 71 return 1.0; | 159 return 1.0; |
| 72 } | 160 } |
| 73 | 161 |
| 74 bool IconLabelBubbleView::IsShrinking() const { | 162 bool IconLabelBubbleView::IsShrinking() const { |
| 75 return false; | 163 return false; |
| 76 } | 164 } |
| 77 | 165 |
| 78 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { | 166 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { |
| 79 return false; | 167 return false; |
| 80 } | 168 } |
| 81 | 169 |
| 170 bool IconLabelBubbleView::IsBubbleShown() const { | |
| 171 return false; | |
| 172 } | |
| 173 | |
| 82 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 174 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
| 83 // Height will be ignored by the LocationBarView. | 175 // Height will be ignored by the LocationBarView. |
| 84 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 176 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
| 85 } | 177 } |
| 86 | 178 |
| 87 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { | 179 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { |
| 88 if (event.key_code() == ui::VKEY_RETURN) | 180 if (event.key_code() == ui::VKEY_RETURN) |
| 89 return OnActivate(event); | 181 return OnActivate(event); |
| 90 return false; | 182 return false; |
| 91 } | 183 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 113 image_->SetBounds(0, 0, image_width, height()); | 205 image_->SetBounds(0, 0, image_width, height()); |
| 114 | 206 |
| 115 // Compute the label bounds. The label gets whatever size is left over after | 207 // Compute the label bounds. The label gets whatever size is left over after |
| 116 // accounting for the preferred image width and padding amounts. Note that if | 208 // accounting for the preferred image width and padding amounts. Note that if |
| 117 // the label has zero size it doesn't actually matter what we compute its X | 209 // the label has zero size it doesn't actually matter what we compute its X |
| 118 // value to be, since it won't be visible. | 210 // value to be, since it won't be visible. |
| 119 const int label_x = image_->bounds().right() + GetInternalSpacing(); | 211 const int label_x = image_->bounds().right() + GetInternalSpacing(); |
| 120 const int label_width = std::max( | 212 const int label_width = std::max( |
| 121 0, width() - label_x - bubble_trailing_padding - kSpaceBesideSeparator); | 213 0, width() - label_x - bubble_trailing_padding - kSpaceBesideSeparator); |
| 122 label_->SetBounds(label_x, 0, label_width, height()); | 214 label_->SetBounds(label_x, 0, label_width, height()); |
| 215 separator_view_->SetBoundsRect(GetLocalBounds()); | |
| 216 | |
| 217 gfx::Rect ink_drop_bounds = GetLocalBounds(); | |
| 218 if (ShouldShowLabel()) { | |
| 219 ink_drop_bounds.set_width(ink_drop_bounds.width() - | |
| 220 GetPostSeparatorPadding()); | |
| 221 } | |
| 222 | |
| 223 ink_drop_container_->SetBoundsRect(ink_drop_bounds); | |
| 224 } | |
| 225 | |
| 226 void IconLabelBubbleView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | |
| 227 if (ink_drop_mask_) | |
| 228 ink_drop_mask_->UpdateLayerSize(size()); | |
| 229 | |
| 230 InkDropHostView::OnBoundsChanged(previous_bounds); | |
| 231 } | |
| 232 | |
| 233 bool IconLabelBubbleView::OnMousePressed(const ui::MouseEvent& event) { | |
| 234 suppress_button_release_ = IsBubbleShown(); | |
|
bruthig
2017/03/28 21:33:34
Correct me if I'm wrong but I think the IconLabelB
| |
| 235 return CustomButton::OnMousePressed(event); | |
| 123 } | 236 } |
| 124 | 237 |
| 125 void IconLabelBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 238 void IconLabelBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 126 label_->GetAccessibleNodeData(node_data); | 239 label_->GetAccessibleNodeData(node_data); |
| 127 } | 240 } |
| 128 | 241 |
| 129 void IconLabelBubbleView::OnNativeThemeChanged( | 242 void IconLabelBubbleView::OnNativeThemeChanged( |
| 130 const ui::NativeTheme* native_theme) { | 243 const ui::NativeTheme* native_theme) { |
| 131 label_->SetEnabledColor(GetTextColor()); | 244 label_->SetEnabledColor(GetTextColor()); |
| 132 label_->SetBackgroundColor(GetParentBackgroundColor()); | 245 label_->SetBackgroundColor(GetParentBackgroundColor()); |
| 133 SchedulePaint(); | 246 SchedulePaint(); |
| 134 } | 247 } |
| 135 | 248 |
| 136 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 249 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 137 image()->SetPaintToLayer(); | 250 ink_drop_mask_ = CreateInkDropMask(); |
| 138 image()->layer()->SetFillsBoundsOpaquely(false); | 251 if (ink_drop_mask_) |
| 139 InkDropHostView::AddInkDropLayer(ink_drop_layer); | 252 ink_drop_layer->SetMaskLayer(ink_drop_mask_->layer()); |
| 253 ink_drop_container_->AddInkDropLayer(ink_drop_layer); | |
| 140 } | 254 } |
| 141 | 255 |
| 142 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 256 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 143 InkDropHostView::RemoveInkDropLayer(ink_drop_layer); | 257 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); |
| 144 image()->DestroyLayer(); | 258 ink_drop_mask_.reset(); |
| 259 } | |
| 260 | |
| 261 std::unique_ptr<views::InkDrop> IconLabelBubbleView::CreateInkDrop() { | |
| 262 std::unique_ptr<views::InkDropImpl> ink_drop = | |
| 263 CreateDefaultFloodFillInkDropImpl(); | |
| 264 ink_drop->SetShowHighlightOnFocus(true); | |
| 265 ink_drop->AddObserver(this); | |
| 266 return std::move(ink_drop); | |
| 145 } | 267 } |
| 146 | 268 |
| 147 std::unique_ptr<views::InkDropHighlight> | 269 std::unique_ptr<views::InkDropHighlight> |
| 148 IconLabelBubbleView::CreateInkDropHighlight() const { | 270 IconLabelBubbleView::CreateInkDropHighlight() const { |
| 149 // Only show a highlight effect when the label is empty/invisible. | 271 return InkDropHostView::CreateDefaultInkDropHighlight( |
| 150 return label()->visible() ? nullptr | 272 gfx::RectF(ink_drop_container_->bounds()).CenterPoint(), |
| 151 : InkDropHostView::CreateInkDropHighlight(); | 273 ink_drop_container_->size()); |
| 274 } | |
| 275 | |
| 276 std::unique_ptr<views::InkDropRipple> IconLabelBubbleView::CreateInkDropRipple() | |
| 277 const { | |
| 278 return base::MakeUnique<views::FloodFillInkDropRipple>( | |
| 279 ink_drop_container_->size(), ink_drop_container_->bounds().CenterPoint(), | |
| 280 GetInkDropBaseColor(), ink_drop_visible_opacity()); | |
| 281 } | |
| 282 | |
| 283 std::unique_ptr<views::InkDropMask> IconLabelBubbleView::CreateInkDropMask() | |
| 284 const { | |
| 285 return base::MakeUnique<views::RoundRectInkDropMask>(size(), gfx::Insets(), | |
| 286 kInkDropMaskRadius); | |
| 152 } | 287 } |
| 153 | 288 |
| 154 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { | 289 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { |
| 155 return color_utils::DeriveDefaultIconColor(GetTextColor()); | 290 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( |
| 291 ui::NativeTheme::kColorId_TextfieldDefaultColor)); | |
| 292 } | |
| 293 | |
| 294 bool IconLabelBubbleView::IsTriggerableEvent(const ui::Event& event) { | |
| 295 return !IsBubbleShown() && !suppress_button_release_; | |
| 296 } | |
| 297 | |
| 298 void IconLabelBubbleView::OnClickCanceled(const ui::Event& event) { | |
| 299 // Overriden to prevent CustomButton from hiding the ink drop when the click | |
| 300 // is cancelled. The click might be cancelled because the bubble is still | |
| 301 // opened. In this case, the ink drop state should still be active. | |
| 302 } | |
| 303 | |
| 304 void IconLabelBubbleView::OnWidgetDestroying(views::Widget* widget) { | |
| 305 widget->RemoveObserver(this); | |
| 306 } | |
| 307 | |
| 308 void IconLabelBubbleView::OnWidgetVisibilityChanged(views::Widget* widget, | |
| 309 bool visible) { | |
| 310 // |widget| is a bubble that has just got shown / hidden. | |
| 311 if (!visible) | |
| 312 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); | |
| 156 } | 313 } |
| 157 | 314 |
| 158 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { | 315 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { |
| 159 return GetNativeTheme()->GetSystemColor( | 316 return GetNativeTheme()->GetSystemColor( |
| 160 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 317 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 161 } | 318 } |
| 162 | 319 |
| 163 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { | 320 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| 164 gfx::Size size(image_->GetPreferredSize()); | 321 gfx::Size size(image_->GetPreferredSize()); |
| 165 const bool shrinking = IsShrinking(); | 322 const bool shrinking = IsShrinking(); |
| 166 // Animation continues for the last few pixels even after the label is not | 323 // Animation continues for the last few pixels even after the label is not |
| 167 // visible in order to slide the icon into its final position. Therefore it | 324 // visible in order to slide the icon into its final position. Therefore it |
| 168 // is necessary to animate |total_width| even when the background is hidden | 325 // is necessary to animate |total_width| even when the background is hidden |
| 169 // as long as the animation is still shrinking. | 326 // as long as the animation is still shrinking. |
| 170 if (ShouldShowLabel() || shrinking) { | 327 if (ShouldShowLabel() || shrinking) { |
| 328 // |multiplier| grows from zero to one, stays equal to one and then shrinks | |
| 329 // to zero again. The view width should correspondingly grow from zero to | |
| 330 // fully showing both label and icon, stay there, then shrink to just large | |
| 331 // enough to show the icon. We don't want to shrink all the way back to | |
| 332 // zero, since this would mean the view would completely disappear and then | |
| 333 // pop back to an icon after the animation finishes. | |
| 334 const int current_width = | |
| 335 WidthMultiplier() * GetMaxSizeForLabelWidth(label_width).width(); | |
| 336 size.set_width(shrinking ? std::max(current_width, size.width()) | |
| 337 : current_width); | |
| 338 } | |
| 339 return size; | |
| 340 } | |
| 341 | |
| 342 gfx::Size IconLabelBubbleView::GetMaxSizeForLabelWidth(int label_width) const { | |
| 343 gfx::Size size(image_->GetPreferredSize()); | |
| 344 if (ShouldShowLabel() || IsShrinking()) { | |
| 171 // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For | 345 // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For |
| 172 // higher scale factors, we simply take the separator px out of the | 346 // higher scale factors, we simply take the separator px out of the |
| 173 // kSpaceBesideSeparator region before the separator, as that results in a | 347 // kSpaceBesideSeparator region before the separator, as that results in a |
| 174 // width closer to the desired gap than if we added a whole DIP for the | 348 // width closer to the desired gap than if we added a whole DIP for the |
| 175 // separator px. (For scale 2, the two methods have equal error: 1 px.) | 349 // separator px. (For scale 2, the two methods have equal error: 1 px.) |
| 176 const int separator_width = (GetScaleFactor() >= 2) ? 0 : 1; | 350 const int separator_width = (GetScaleFactor() >= 2) ? 0 : 1; |
| 177 const int post_label_width = | 351 const int post_label_width = |
| 178 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()); | 352 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()); |
| 179 | 353 size.Enlarge(GetInternalSpacing() + label_width + post_label_width, 0); |
| 180 // |multiplier| grows from zero to one, stays equal to one and then shrinks | |
| 181 // to zero again. The view width should correspondingly grow from zero to | |
| 182 // fully showing both label and icon, stay there, then shrink to just large | |
| 183 // enough to show the icon. We don't want to shrink all the way back to | |
| 184 // zero, since this would mean the view would completely disappear and then | |
| 185 // pop back to an icon after the animation finishes. | |
| 186 const int max_width = | |
| 187 size.width() + GetInternalSpacing() + label_width + post_label_width; | |
| 188 const int current_width = WidthMultiplier() * max_width; | |
| 189 size.set_width(shrinking ? std::max(current_width, size.width()) | |
| 190 : current_width); | |
| 191 } | 354 } |
| 192 return size; | 355 return size; |
| 193 } | 356 } |
| 194 | 357 |
| 195 int IconLabelBubbleView::GetInternalSpacing() const { | 358 int IconLabelBubbleView::GetInternalSpacing() const { |
| 196 return image_->GetPreferredSize().IsEmpty() | 359 return image_->GetPreferredSize().IsEmpty() |
| 197 ? 0 | 360 ? 0 |
| 198 : GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); | 361 : GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); |
| 199 } | 362 } |
| 200 | 363 |
| 201 int IconLabelBubbleView::GetPostSeparatorPadding() const { | 364 int IconLabelBubbleView::GetPostSeparatorPadding() const { |
| 202 // The location bar will add LOCATION_BAR_ELEMENT_PADDING after us. | 365 // The location bar will add LOCATION_BAR_ELEMENT_PADDING after us. |
| 203 return kSpaceBesideSeparator - | 366 return kSpaceBesideSeparator - |
| 204 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) - | 367 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) - |
| 205 next_element_interior_padding_; | 368 next_element_interior_padding_; |
| 206 } | 369 } |
| 207 | 370 |
| 208 float IconLabelBubbleView::GetScaleFactor() const { | 371 float IconLabelBubbleView::GetScaleFactor() const { |
| 209 const views::Widget* widget = GetWidget(); | 372 const views::Widget* widget = GetWidget(); |
| 210 // There may be no widget in tests, and in ash there may be no compositor if | 373 // There may be no widget in tests, and in ash there may be no compositor if |
| 211 // the native view of the Widget doesn't have a parent. | 374 // the native view of the Widget doesn't have a parent. |
| 212 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr; | 375 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr; |
| 213 return compositor ? compositor->device_scale_factor() : 1.0f; | 376 return compositor ? compositor->device_scale_factor() : 1.0f; |
| 214 } | 377 } |
| 215 | 378 |
| 216 const char* IconLabelBubbleView::GetClassName() const { | 379 const char* IconLabelBubbleView::GetClassName() const { |
| 217 return "IconLabelBubbleView"; | 380 return "IconLabelBubbleView"; |
| 218 } | 381 } |
| 219 | |
| 220 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | |
| 221 if (!ShouldShowLabel()) | |
| 222 return; | |
| 223 | |
| 224 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( | |
| 225 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 226 const SkColor separator_color = SkColorSetA( | |
| 227 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); | |
| 228 | |
| 229 gfx::Rect bounds(label_->bounds()); | |
| 230 const int kSeparatorHeight = 16; | |
| 231 bounds.Inset(0, (bounds.height() - kSeparatorHeight) / 2); | |
| 232 bounds.set_width(bounds.width() + kSpaceBesideSeparator); | |
| 233 canvas->Draw1pxLine(gfx::PointF(bounds.top_right()), | |
| 234 gfx::PointF(bounds.bottom_right()), separator_color); | |
| 235 } | |
| OLD | NEW |