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