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

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 (fixed test build) 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..b72e4b78a06e7d9a227c7cba22c24eddf97cc041 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,31 @@
#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"
+// static
+const char BubbleIconView::kViewClassName[] = "BubbleIconView";
+
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);
+
+ 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,8 +48,20 @@ bool BubbleIconView::IsBubbleShowing() const {
return GetBubble() != NULL;
}
+void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) {
+ image_->SetImage(image_skia);
+}
+
+const gfx::ImageSkia& BubbleIconView::GetImage() {
+ 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;
}
@@ -40,13 +69,25 @@ bool BubbleIconView::GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const {
if (IsBubbleShowing())
return false;
+ return image_->GetTooltipText(p, tooltip);
Peter Kasting 2016/01/26 16:59:35 Nit: Simpler: return IsBubbleShowing() && image
varkha 2016/01/26 17:45:45 Done.
+}
+
+gfx::Size BubbleIconView::GetPreferredSize() const {
+ return image_->GetPreferredSize();
+}
- return views::ImageView::GetTooltipText(p, tooltip);
+void BubbleIconView::Layout() {
+ View::Layout();
+ image_->SetBoundsRect(GetLocalBounds());
+ if (ink_drop_delegate_)
+ 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.
@@ -62,8 +103,14 @@ void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
return;
}
- if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
- ExecuteCommand(EXECUTE_SOURCE_MOUSE);
+ if (event.IsLeftMouseButton()) {
+ if (HitTestPoint(event.location())) {
+ ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
+ ExecuteCommand(EXECUTE_SOURCE_MOUSE);
+ } else {
+ ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN);
+ }
Peter Kasting 2016/01/26 16:59:35 Nit: Shorter: const bool activated = HitTestP
varkha 2016/01/26 17:45:45 Done.
+ }
}
bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
@@ -75,9 +122,13 @@ bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
return false;
}
+void BubbleIconView::OnBubbleClosing() {
+ ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
+}
+
void BubbleIconView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
- ImageView::ViewHierarchyChanged(details);
+ View::ViewHierarchyChanged(details);
if (details.is_add && GetNativeTheme())
UpdateIcon();
}
@@ -88,25 +139,57 @@ 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::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;
}
+const char* BubbleIconView::GetClassName() const {
+ return kViewClassName;
+}
+
void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
views::BubbleDelegateView* bubble = GetBubble();
if (bubble)
bubble->OnAnchorBoundsChanged();
+ if (ink_drop_delegate_)
+ ink_drop_delegate_->OnLayout();
+}
+
+gfx::Point BubbleIconView::CalculateInkDropCenter() const {
+ return GetLocalBounds().CenterPoint();
}
void BubbleIconView::UpdateIcon() {
@@ -121,7 +204,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