[dart:html] Expose `scrollIntoViewIfNeeded`

`scrollIntoViewIfNeeded` is nested within `scrollIntoView`. The latter
method is outdated and the way to access the different ways to call
`scrollIntoViewIfNeeded`. Instead of using that method, this CL
directly exposes `scrollIntoViewIfNeeded`.

Change-Id: I38d7876a7923768ae165c29a98e514e90182b77e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231047
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Riley Porter <rileyporter@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 33e2611..0c9b5d0 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -13389,10 +13389,14 @@
     } else if (alignment == ScrollAlignment.BOTTOM) {
       this._scrollIntoView(false);
     } else if (hasScrollIntoViewIfNeeded) {
+      // TODO(srujzs): This method shouldn't be calling out to
+      // `scrollIntoViewIfNeeded`. Remove this and make `scrollIntoView` match
+      // the browser definition. If you intend to use `scrollIntoViewIfNeeded`,
+      // use the `Element.scrollIntoViewIfNeeded` method.
       if (alignment == ScrollAlignment.CENTER) {
-        this._scrollIntoViewIfNeeded(true);
+        this.scrollIntoViewIfNeeded(true);
       } else {
-        this._scrollIntoViewIfNeeded();
+        this.scrollIntoViewIfNeeded();
       }
     } else {
       this._scrollIntoView();
@@ -14896,8 +14900,18 @@
   @JSName('scrollIntoView')
   void _scrollIntoView([Object? arg]) native;
 
-  @JSName('scrollIntoViewIfNeeded')
-  void _scrollIntoViewIfNeeded([bool? centerIfNeeded]) native;
+  /**
+   * Nonstandard version of `scrollIntoView` that scrolls the current element
+   * into the visible area of the browser window if it's not already within the
+   * visible area of the browser window. If the element is already within the
+   * visible area of the browser window, then no scrolling takes place.
+   *
+   * ## Other resources
+   *
+   * * [Element.scrollIntoViewIfNeeded](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded)
+   *   from MDN.
+   */
+  void scrollIntoViewIfNeeded([bool? centerIfNeeded]) native;
 
   void scrollTo([options_OR_x, num? y]) {
     if (options_OR_x == null && y == null) {
diff --git a/tools/dom/docs.json b/tools/dom/docs.json
index e1a453b..2dfd29c 100644
--- a/tools/dom/docs.json
+++ b/tools/dom/docs.json
@@ -1270,6 +1270,19 @@
           "   * See [EventStreamProvider] for usage information.",
           "   */"
         ],
+        "scrollIntoViewIfNeeded": [
+          "/**",
+          "   * Nonstandard version of `scrollIntoView` that scrolls the current element",
+          "   * into the visible area of the browser window if it's not already within the",
+          "   * visible area of the browser window. If the element is already within the",
+          "   * visible area of the browser window, then no scrolling takes place.",
+          "   *",
+          "   * ## Other resources",
+          "   *",
+          "   * * [Element.scrollIntoViewIfNeeded](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded)",
+          "   *   from MDN.",
+          "   */"
+        ],
         "searchEvent": [
           "/**",
           "   * Static factory designed to expose `search` events to event",
diff --git a/tools/dom/scripts/htmlrenamer.py b/tools/dom/scripts/htmlrenamer.py
index 30fa1af..13f18fb 100644
--- a/tools/dom/scripts/htmlrenamer.py
+++ b/tools/dom/scripts/htmlrenamer.py
@@ -403,7 +403,6 @@
         'Element.getElementsByTagName',
         'Element.insertAdjacentHTML',
         'Element.scrollIntoView',
-        'Element.scrollIntoViewIfNeeded',
         'Element.getAttribute',
         'Element.getAttributeNS',
         'Element.hasAttribute',
diff --git a/tools/dom/templates/html/impl/impl_Element.darttemplate b/tools/dom/templates/html/impl/impl_Element.darttemplate
index a0ce567..3ff4bcc 100644
--- a/tools/dom/templates/html/impl/impl_Element.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Element.darttemplate
@@ -1007,10 +1007,14 @@
     } else if (alignment == ScrollAlignment.BOTTOM) {
       this._scrollIntoView(false);
     } else if (hasScrollIntoViewIfNeeded) {
+      // TODO(srujzs): This method shouldn't be calling out to
+      // `scrollIntoViewIfNeeded`. Remove this and make `scrollIntoView` match
+      // the browser definition. If you intend to use `scrollIntoViewIfNeeded`,
+      // use the `Element.scrollIntoViewIfNeeded` method.
       if (alignment == ScrollAlignment.CENTER) {
-        this._scrollIntoViewIfNeeded(true);
+        this.scrollIntoViewIfNeeded(true);
       } else {
-        this._scrollIntoViewIfNeeded();
+        this.scrollIntoViewIfNeeded();
       }
     } else {
       this._scrollIntoView();