Omnibox/Views: Circlify location bar decorations.

r534314 made the omnibox / LocationBarView pill-shaped without clipping the ink
drop highlight / ripples of the LocationBarView decorations (e.g. the security
chip / LocationIconView). This meant hovering / clicking on these decorations
would sometimes result in the corners of their backgrounds poking out. Fix by
making them pill-shaped as well.

Screenshots - https://drive.google.com/open?id=1gUMuVdCKa4fQH9M9t118dQC21GWRZGH8

Bug: 801583
Change-Id: I45b5c541753a203a96354dbe32b406dbf25ed259
Reviewed-on: https://chromium-review.googlesource.com/908170
Reviewed-by: Mohsen Izadi <mohsen@chromium.org>
Reviewed-by: Trent Apted <tapted@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Patti <patricialor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536296}
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 c7612c2..da46b4e 100644
--- a/chrome/browser/ui/views/location_bar/bubble_icon_view.cc
+++ b/chrome/browser/ui/views/location_bar/bubble_icon_view.cc
@@ -17,6 +17,7 @@
 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
 #include "ui/views/animation/ink_drop_highlight.h"
 #include "ui/views/animation/ink_drop_impl.h"
+#include "ui/views/animation/ink_drop_mask.h"
 #include "ui/views/bubble/bubble_dialog_delegate.h"
 
 void BubbleIconView::Init() {
@@ -166,17 +167,23 @@
   return std::move(ink_drop);
 }
 
+std::unique_ptr<views::InkDropRipple> BubbleIconView::CreateInkDropRipple()
+    const {
+  return std::make_unique<views::FloodFillInkDropRipple>(
+      size(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
+      ink_drop_visible_opacity());
+}
+
 SkColor BubbleIconView::GetInkDropBaseColor() const {
   return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor(
       ui::NativeTheme::kColorId_TextfieldDefaultColor));
 }
 
-std::unique_ptr<views::InkDropRipple> BubbleIconView::CreateInkDropRipple()
-    const {
-  return std::make_unique<views::FloodFillInkDropRipple>(
-      gfx::Size(kDefaultInkDropSize, kDefaultInkDropSize),
-      GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
-      ink_drop_visible_opacity());
+std::unique_ptr<views::InkDropMask> BubbleIconView::CreateInkDropMask() const {
+  if (!BackgroundWith1PxBorder::IsRounded())
+    return nullptr;
+  return std::make_unique<views::RoundRectInkDropMask>(size(), gfx::Insets(),
+                                                       height() / 2.f);
 }
 
 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
@@ -208,6 +215,7 @@
   views::BubbleDialogDelegateView* bubble = GetBubble();
   if (bubble)
     bubble->OnAnchorBoundsChanged();
+  InkDropHostView::OnBoundsChanged(previous_bounds);
 }
 
 void BubbleIconView::UpdateIcon() {
diff --git a/chrome/browser/ui/views/location_bar/bubble_icon_view.h b/chrome/browser/ui/views/location_bar/bubble_icon_view.h
index c0069945..cb9bfb3 100644
--- a/chrome/browser/ui/views/location_bar/bubble_icon_view.h
+++ b/chrome/browser/ui/views/location_bar/bubble_icon_view.h
@@ -66,7 +66,7 @@
   // Invoked after the icon is pressed.
   virtual void OnPressed(bool activated) {}
 
-  // views::View:
+  // views::InkDropHostView:
   void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
   bool GetTooltipText(const gfx::Point& p,
                       base::string16* tooltip) const override;
@@ -84,6 +84,7 @@
   std::unique_ptr<views::InkDrop> CreateInkDrop() override;
   std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
   SkColor GetInkDropBaseColor() const override;
+  std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
 
   // ui::EventHandler:
   void OnGestureEvent(ui::GestureEvent* event) override;
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
index ac42360..d30db3f6 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
@@ -19,6 +19,7 @@
 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
 #include "ui/views/animation/ink_drop_highlight.h"
 #include "ui/views/animation/ink_drop_impl.h"
+#include "ui/views/animation/ink_drop_mask.h"
 #include "ui/views/animation/ink_drop_ripple.h"
 #include "ui/views/border.h"
 #include "ui/views/controls/image_view.h"
@@ -248,11 +249,14 @@
 }
 
 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
+  ink_drop_layer->SetBounds(ink_drop_container_->bounds());
   ink_drop_container_->AddInkDropLayer(ink_drop_layer);
+  InstallInkDropMask(ink_drop_layer);
 }
 
 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
   ink_drop_container_->RemoveInkDropLayer(ink_drop_layer);
+  ResetInkDropMask();
   separator_view_->UpdateOpacity();
 }
 
@@ -264,13 +268,6 @@
   return std::move(ink_drop);
 }
 
-std::unique_ptr<views::InkDropHighlight>
-IconLabelBubbleView::CreateInkDropHighlight() const {
-  return InkDropHostView::CreateDefaultInkDropHighlight(
-      gfx::RectF(ink_drop_container_->bounds()).CenterPoint(),
-      ink_drop_container_->size());
-}
-
 std::unique_ptr<views::InkDropRipple> IconLabelBubbleView::CreateInkDropRipple()
     const {
   gfx::Point center_point = GetInkDropCenterBasedOnLastEvent();
@@ -283,11 +280,27 @@
       ink_drop_visible_opacity());
 }
 
+std::unique_ptr<views::InkDropHighlight>
+IconLabelBubbleView::CreateInkDropHighlight() const {
+  return InkDropHostView::CreateDefaultInkDropHighlight(
+      gfx::RectF(ink_drop_container_->bounds()).CenterPoint(),
+      ink_drop_container_->size());
+}
+
 SkColor IconLabelBubbleView::GetInkDropBaseColor() const {
   return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor(
       ui::NativeTheme::kColorId_TextfieldDefaultColor));
 }
 
+std::unique_ptr<views::InkDropMask> IconLabelBubbleView::CreateInkDropMask()
+    const {
+  if (!BackgroundWith1PxBorder::IsRounded())
+    return nullptr;
+  return std::make_unique<views::RoundRectInkDropMask>(
+      ink_drop_container_->size(), gfx::Insets(),
+      ink_drop_container_->height() / 2.f);
+}
+
 bool IconLabelBubbleView::IsTriggerableEvent(const ui::Event& event) {
   if (event.IsMouseEvent())
     return !IsBubbleShowing() && !suppress_button_release_;
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
index fe9f893..e658c78 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
@@ -127,10 +127,11 @@
   void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
   void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
   std::unique_ptr<views::InkDrop> CreateInkDrop() override;
+  std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
   std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
       const override;
-  std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
   SkColor GetInkDropBaseColor() const override;
+  std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
 
   // views::Button:
   bool IsTriggerableEvent(const ui::Event& event) override;
diff --git a/ui/views/animation/ink_drop_mask.cc b/ui/views/animation/ink_drop_mask.cc
index 05bd983..a2d2adb3 100644
--- a/ui/views/animation/ink_drop_mask.cc
+++ b/ui/views/animation/ink_drop_mask.cc
@@ -35,7 +35,7 @@
 
 RoundRectInkDropMask::RoundRectInkDropMask(const gfx::Size& layer_size,
                                            const gfx::InsetsF& mask_insets,
-                                           int corner_radius)
+                                           float corner_radius)
     : InkDropMask(layer_size),
       mask_insets_(mask_insets),
       corner_radius_(corner_radius) {}
@@ -52,10 +52,8 @@
   gfx::RectF masking_bound(layer()->bounds());
   masking_bound.Inset(mask_insets_);
 
-  const gfx::Rect masking_bound_scaled =
-      gfx::ScaleToRoundedRect(gfx::ToNearestRect(masking_bound), dsf);
-  recorder.canvas()->DrawRoundRect(masking_bound_scaled, corner_radius_ * dsf,
-                                   flags);
+  recorder.canvas()->DrawRoundRect(gfx::ScaleRect(masking_bound, dsf),
+                                   corner_radius_ * dsf, flags);
 }
 
 // CircleInkDropMask
diff --git a/ui/views/animation/ink_drop_mask.h b/ui/views/animation/ink_drop_mask.h
index 8899e5b..debfb16 100644
--- a/ui/views/animation/ink_drop_mask.h
+++ b/ui/views/animation/ink_drop_mask.h
@@ -47,14 +47,14 @@
  public:
   RoundRectInkDropMask(const gfx::Size& layer_size,
                        const gfx::InsetsF& mask_insets,
-                       int corner_radius);
+                       float corner_radius);
 
  private:
   // Overriden from InkDropMask:
   void OnPaintLayer(const ui::PaintContext& context) override;
 
   gfx::InsetsF mask_insets_;
-  int corner_radius_;
+  float corner_radius_;
 
   DISALLOW_COPY_AND_ASSIGN(RoundRectInkDropMask);
 };