Android: Edge glow effect for history navigation

Shows the edge glow effect when further forward navigation is not
possible. There are three cases to consider: native pages, rendered
pages, and tab switcher:

- Native pages: uses android.widget.EdgeEffect (GlowView)
- Rendered pages: uses ui::OverscrollGlow on cc::Layer of WebContents'
  native view
- Tab switcher: also ui::OverscrollGlow on cc::Layer of StackLayout's
  SceneLayer

All the logic is behind a new class NavigationGlow.

Bug: 937946
Change-Id: I7771a23ae861188a40388659baa784111e58140d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1583169
Reviewed-by: Matthew Jones <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Commit-Queue: Jinsuk Kim <[email protected]>
Cr-Commit-Position: refs/heads/master@{#657496}
diff --git a/ui/android/java/src/org/chromium/ui/OverscrollRefreshHandler.java b/ui/android/java/src/org/chromium/ui/OverscrollRefreshHandler.java
index 525874b..185aff6b 100644
--- a/ui/android/java/src/org/chromium/ui/OverscrollRefreshHandler.java
+++ b/ui/android/java/src/org/chromium/ui/OverscrollRefreshHandler.java
@@ -13,12 +13,15 @@
     /**
      * Signals the start of an overscrolling pull.
      * @param type Type of the overscroll action.
+     * @param startX X position of touch event at the beginning of overscroll.
+     * @param startY Y position of touch event at the beginning of overscroll.
      * @param navigateForward {@code true} for forward navigation, {@code false} for back.
      *        Used only for {@link OverscrollAction.HISTORY_NAVIGATION}.
      * @return Whether the handler will consume the overscroll sequence.
      */
     @CalledByNative
-    public boolean start(@OverscrollAction int type, boolean navigateForward);
+    public boolean start(
+            @OverscrollAction int type, float startX, float startY, boolean navigateForward);
 
     /**
      * Signals a pull update.
diff --git a/ui/android/overscroll_refresh.cc b/ui/android/overscroll_refresh.cc
index 0026a4a..13d546ef 100644
--- a/ui/android/overscroll_refresh.cc
+++ b/ui/android/overscroll_refresh.cc
@@ -56,6 +56,7 @@
 
 void OverscrollRefresh::OnScrollBegin(const gfx::PointF& pos) {
   scroll_begin_x_ = pos.x();
+  scroll_begin_y_ = pos.y();
   top_at_scroll_start_ = scrolled_to_top_;
   ReleaseWithoutActivation();
   scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK;
@@ -98,7 +99,10 @@
 
   if (type != OverscrollAction::NONE) {
     scroll_consumption_state_ =
-        handler_->PullStart(type, navigate_forward) ? ENABLED : DISABLED;
+        handler_->PullStart(type, scroll_begin_x_, scroll_begin_y_,
+                            navigate_forward)
+            ? ENABLED
+            : DISABLED;
   }
 }
 
diff --git a/ui/android/overscroll_refresh.h b/ui/android/overscroll_refresh.h
index ec32e7ee..b650d46 100644
--- a/ui/android/overscroll_refresh.h
+++ b/ui/android/overscroll_refresh.h
@@ -104,6 +104,7 @@
 
   float viewport_width_;
   float scroll_begin_x_;
+  float scroll_begin_y_;
   const float edge_width_;
   gfx::Vector2dF cumulative_scroll_;
   OverscrollRefreshHandler* const handler_;
diff --git a/ui/android/overscroll_refresh_handler.cc b/ui/android/overscroll_refresh_handler.cc
index 34e610fc..ca1fcd7 100644
--- a/ui/android/overscroll_refresh_handler.cc
+++ b/ui/android/overscroll_refresh_handler.cc
@@ -20,10 +20,12 @@
 OverscrollRefreshHandler::~OverscrollRefreshHandler() {}
 
 bool OverscrollRefreshHandler::PullStart(OverscrollAction type,
+                                         float startx,
+                                         float starty,
                                          bool navigate_forward) {
-  return Java_OverscrollRefreshHandler_start(AttachCurrentThread(),
-                                             j_overscroll_refresh_handler_,
-                                             type, navigate_forward);
+  return Java_OverscrollRefreshHandler_start(
+      AttachCurrentThread(), j_overscroll_refresh_handler_, type, startx,
+      starty, navigate_forward);
 }
 
 void OverscrollRefreshHandler::PullUpdate(float x_delta, float y_delta) {
diff --git a/ui/android/overscroll_refresh_handler.h b/ui/android/overscroll_refresh_handler.h
index 3471c2f..3322458 100644
--- a/ui/android/overscroll_refresh_handler.h
+++ b/ui/android/overscroll_refresh_handler.h
@@ -24,7 +24,10 @@
   // Signals the start of an overscrolling pull. Returns whether the handler
   // will consume the overscroll gesture, in which case it will receive the
   // remaining pull updates.
-  virtual bool PullStart(OverscrollAction type, bool navigate_forward);
+  virtual bool PullStart(OverscrollAction type,
+                         float startx,
+                         float starty,
+                         bool navigate_forward);
 
   // Signals a pull update, where |x_delta| and |y_delta| are in device pixels.
   virtual void PullUpdate(float x_delta, float y_delta);
diff --git a/ui/android/overscroll_refresh_unittest.cc b/ui/android/overscroll_refresh_unittest.cc
index d15557e6..fb44686 100644
--- a/ui/android/overscroll_refresh_unittest.cc
+++ b/ui/android/overscroll_refresh_unittest.cc
@@ -20,7 +20,10 @@
   OverscrollRefreshTest() : OverscrollRefreshHandler(nullptr) {}
 
   // OverscrollRefreshHandler implementation.
-  bool PullStart(OverscrollAction type, bool navigateForward) override {
+  bool PullStart(OverscrollAction type,
+                 float startx,
+                 float starty,
+                 bool navigateForward) override {
     started_ = true;
     return true;
   }