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

Unified Diff: chrome/browser/ui/views/location_bar/bubble_icon_view.cc

Issue 1518543002: Adds MD ink ripple animations to buttons within location bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds MD ink ripple animations to buttons within location bar (missing member init) Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/bubble_icon_view.cc
diff --git a/chrome/browser/ui/views/location_bar/bubble_icon_view.cc b/chrome/browser/ui/views/location_bar/bubble_icon_view.cc
index 0ec8d52c568fe6653a8416a84a087cb597cee255..6ce238ac0762bea9b2f68a0ebabf2e2c4cb7939c 100644
--- a/chrome/browser/ui/views/location_bar/bubble_icon_view.cc
+++ b/chrome/browser/ui/views/location_bar/bubble_icon_view.cc
@@ -12,14 +12,29 @@
#include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
+#include "ui/views/animation/button_ink_drop_delegate.h"
#include "ui/views/bubble/bubble_delegate.h"
BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id)
- : command_updater_(command_updater),
+ : image_(new views::ImageView()),
+ command_updater_(command_updater),
command_id_(command_id),
active_(false),
- suppress_mouse_released_action_(false) {
- SetAccessibilityFocusable(true);
+ suppress_mouse_released_action_(false),
+ ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) {
+ AddChildView(image_);
+ image_->set_interactive(false);
+ image_->EnableCanvasFlippingForRTLUI(true);
+ image_->SetAccessibilityFocusable(true);
+
+ // TODO(varkha): Provide standard ink drop dimensions in LayoutConstants.
+ const int kInkDropLargeSize = 32;
+ const int kInkDropLargeCornerRadius = 5;
+ const int kInkDropSmallSize = 24;
+ const int kInkDropSmallCornerRadius = 2;
+ ink_drop_delegate_->SetInkDropSize(
+ kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
+ kInkDropSmallCornerRadius);
}
BubbleIconView::~BubbleIconView() {
@@ -31,22 +46,43 @@ bool BubbleIconView::IsBubbleShowing() const {
return GetBubble() != NULL;
}
+void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) {
+ image_->SetImage(image_skia);
+}
+
+const gfx::ImageSkia& BubbleIconView::GetImage() const {
+ return image_->GetImage();
+}
+
+void BubbleIconView::SetTooltipText(const base::string16& tooltip) {
+ image_->SetTooltipText(tooltip);
+}
+
void BubbleIconView::GetAccessibleState(ui::AXViewState* state) {
- views::ImageView::GetAccessibleState(state);
+ image_->GetAccessibleState(state);
state->role = ui::AX_ROLE_BUTTON;
}
bool BubbleIconView::GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const {
- if (IsBubbleShowing())
- return false;
+ return !IsBubbleShowing() && image_->GetTooltipText(p, tooltip);
+}
- return views::ImageView::GetTooltipText(p, tooltip);
+gfx::Size BubbleIconView::GetPreferredSize() const {
+ return image_->GetPreferredSize();
+}
+
+void BubbleIconView::Layout() {
+ View::Layout();
+ image_->SetBoundsRect(GetLocalBounds());
+ ink_drop_delegate_->OnLayout();
}
bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) {
// If the bubble is showing then don't reshow it when the mouse is released.
suppress_mouse_released_action_ = IsBubbleShowing();
+ if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton())
+ ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING);
// We want to show the bubble on mouse release; that is the standard behavior
// for buttons.
@@ -61,8 +97,13 @@ void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
suppress_mouse_released_action_ = false;
return;
}
+ if (!event.IsLeftMouseButton())
+ return;
- if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
+ const bool activated = HitTestPoint(event.location());
+ ink_drop_delegate_->OnAction(
+ activated ? views::InkDropState::ACTIVATED : views::InkDropState::HIDDEN);
+ if (activated)
ExecuteCommand(EXECUTE_SOURCE_MOUSE);
}
@@ -77,7 +118,7 @@ bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
void BubbleIconView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
- ImageView::ViewHierarchyChanged(details);
+ View::ViewHierarchyChanged(details);
if (details.is_add && GetNativeTheme())
UpdateIcon();
}
@@ -88,17 +129,50 @@ void BubbleIconView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) {
+ ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
ExecuteCommand(EXECUTE_SOURCE_GESTURE);
event->SetHandled();
}
}
+void BubbleIconView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
+ image_->SetPaintToLayer(true);
+ image_->SetFillsBoundsOpaquely(false);
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
+ layer()->Add(ink_drop_layer);
+ layer()->StackAtBottom(ink_drop_layer);
+}
+
+void BubbleIconView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
+ layer()->Remove(ink_drop_layer);
+ SetFillsBoundsOpaquely(true);
+ SetPaintToLayer(false);
+ image_->SetFillsBoundsOpaquely(true);
+ image_->SetPaintToLayer(false);
+}
+
+void BubbleIconView::OnWidgetDestroying(views::Widget* widget) {
+ widget->RemoveObserver(this);
+}
+
+void BubbleIconView::OnWidgetVisibilityChanged(views::Widget* widget,
+ bool visible) {
+ // |widget| is a bubble that has just got shown / hidden.
+ if (!visible)
+ ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
+}
+
void BubbleIconView::ExecuteCommand(ExecuteSource source) {
OnExecuting(source);
if (command_updater_)
command_updater_->ExecuteCommand(command_id_);
}
+gfx::VectorIconId BubbleIconView::GetVectorIcon() const {
+ return gfx::VectorIconId::VECTOR_ICON_NONE;
+}
+
bool BubbleIconView::SetRasterIcon() {
return false;
}
@@ -107,6 +181,16 @@ void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
views::BubbleDelegateView* bubble = GetBubble();
if (bubble)
bubble->OnAnchorBoundsChanged();
+ ink_drop_delegate_->OnLayout();
+}
+
+gfx::Point BubbleIconView::CalculateInkDropCenter() const {
+ return GetLocalBounds().CenterPoint();
+}
+
+bool BubbleIconView::ShouldShowInkDropHover() const {
+ // BubbleIconView views don't show hover effect.
+ return false;
}
void BubbleIconView::UpdateIcon() {
@@ -121,7 +205,8 @@ void BubbleIconView::UpdateIcon() {
? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor)
: color_utils::DeriveDefaultIconColor(theme->GetSystemColor(
ui::NativeTheme::kColorId_TextfieldDefaultColor));
- SetImage(gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color));
+ image_->SetImage(
+ gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color));
}
void BubbleIconView::SetActiveInternal(bool active) {

Powered by Google App Engine
This is Rietveld 408576698