Bug 1516258 - Part 2 - Remove XULScrollElement. r=NeilDeakin
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 10 Jan 2019 11:50:31 +0000
changeset 511650 2b59993a9659cd432afe453dcb4d3cc75aca7ba5
parent 511649 364d6aef9d05f15eab16b24468e48b7442d045c4
child 511651 a9783042dc4491dc9af417f4c91b00215178666f
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1516258
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516258 - Part 2 - Remove XULScrollElement. r=NeilDeakin There is still styling associated with the "scrollbox" element, but eventually those instances can be replaced with simple boxes. Differential Revision: https://phabricator.services.mozilla.com/D15298
dom/bindings/BindingUtils.cpp
dom/chrome-webidl/XULScrollElement.webidl
dom/chrome-webidl/moz.build
dom/tests/mochitest/general/test_interfaces.js
dom/xul/XULScrollElement.cpp
dom/xul/XULScrollElement.h
dom/xul/moz.build
dom/xul/nsXULElement.cpp
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -62,17 +62,16 @@
 #include "mozilla/dom/XULTextElementBinding.h"
 #include "mozilla/dom/XULTreeElementBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerScope.h"
 #include "mozilla/dom/XrayExpandoClass.h"
 #include "mozilla/dom/WindowProxyHolder.h"
-#include "mozilla/dom/XULScrollElementBinding.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "ipc/ErrorIPCUtils.h"
 #include "mozilla/UseCounter.h"
 #include "mozilla/dom/DocGroup.h"
 #include "nsXULElement.h"
 
 namespace mozilla {
 namespace dom {
@@ -3614,18 +3613,16 @@ bool HTMLConstructor(JSContext* aCx, uns
       cb = XULPopupElement_Binding::GetConstructorObject;
     } else if (definition->mLocalName == nsGkAtoms::iframe ||
                definition->mLocalName == nsGkAtoms::browser ||
                definition->mLocalName == nsGkAtoms::editor) {
       cb = XULFrameElement_Binding::GetConstructorObject;
     } else if (definition->mLocalName == nsGkAtoms::menu ||
                definition->mLocalName == nsGkAtoms::menulist) {
       cb = XULMenuElement_Binding::GetConstructorObject;
-    } else if (definition->mLocalName == nsGkAtoms::scrollbox) {
-      cb = XULScrollElement_Binding::GetConstructorObject;
     } else if (definition->mLocalName == nsGkAtoms::tree) {
       cb = XULTreeElement_Binding::GetConstructorObject;
     } else {
       cb = XULElement_Binding::GetConstructorObject;
     }
   }
 
   int32_t tag = eHTMLTag_userdefined;
deleted file mode 100644
--- a/dom/chrome-webidl/XULScrollElement.webidl
+++ /dev/null
@@ -1,15 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-[HTMLConstructor, Func="IsChromeOrXBL"]
-interface XULScrollElement : XULElement {
-  [Throws]
-  void scrollToElement(Element child);
-  [Throws]
-  void scrollByIndex(long aIndexes);
-  [Throws]
-  void ensureElementIsVisible(Element child);
-};
--- a/dom/chrome-webidl/moz.build
+++ b/dom/chrome-webidl/moz.build
@@ -53,17 +53,16 @@ WEBIDL_FILES = [
     'SessionStoreUtils.webidl',
     'StructuredCloneHolder.webidl',
     'TelemetryStopwatch.webidl',
     'WebExtensionContentScript.webidl',
     'WebExtensionPolicy.webidl',
     'WindowGlobalActors.webidl',
     'XULFrameElement.webidl',
     'XULMenuElement.webidl',
-    'XULScrollElement.webidl',
     'XULTextElement.webidl',
     'XULTreeElement.webidl'
 ]
 
 if CONFIG['MOZ_PLACES']:
     WEBIDL_FILES += [
         'PlacesEvent.webidl',
         'PlacesObservers.webidl',
--- a/dom/tests/mochitest/general/test_interfaces.js
+++ b/dom/tests/mochitest/general/test_interfaces.js
@@ -1275,18 +1275,16 @@ var interfaceNamesInGlobalScope =
     {name: "XULElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "XULFrameElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "XULMenuElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "XULPopupElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    {name: "XULScrollElement", insecureContext: true, xbl: true},
-// IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "XULTextElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "XULTreeElement", insecureContext: true, xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
   ];
 // IMPORTANT: Do not change the list above without review from a DOM peer!
 
 function createInterfaceMap(isXBLScope) {
deleted file mode 100644
--- a/dom/xul/XULScrollElement.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/dom/Element.h"
-#include "mozilla/dom/ToJSValue.h"
-#include "nsCOMPtr.h"
-#include "nsIPresShell.h"
-#include "nsIContent.h"
-#include "nsPresContext.h"
-#include "nsBox.h"
-#include "nsIScrollableFrame.h"
-#include "mozilla/dom/XULScrollElement.h"
-#include "mozilla/dom/XULScrollElementBinding.h"
-
-namespace mozilla {
-namespace dom {
-
-JSObject* XULScrollElement::WrapNode(JSContext* aCx,
-                                     JS::Handle<JSObject*> aGivenProto) {
-  return XULScrollElement_Binding::Wrap(aCx, this, aGivenProto);
-}
-
-void XULScrollElement::ScrollByIndex(int32_t aIndex, ErrorResult& aRv) {
-  nsIScrollableFrame* sf = GetScrollFrame();
-  if (!sf) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
-
-  nsIFrame* scrolledFrame = sf->GetScrolledFrame();
-  if (!scrolledFrame) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
-
-  nsRect rect;
-
-  // now get the element's first child
-  nsIFrame* child = nsBox::GetChildXULBox(scrolledFrame);
-
-  bool horiz = scrolledFrame->IsXULHorizontal();
-  nsPoint cp = sf->GetScrollPosition();
-  nscoord diff = 0;
-  int32_t curIndex = 0;
-  bool isLTR = scrolledFrame->IsXULNormalDirection();
-
-  nscoord frameWidth = 0;
-  if (!isLTR && horiz) {
-    nsCOMPtr<Document> doc = GetComposedDoc();
-
-    nsCOMPtr<nsIPresShell> shell = doc->GetShell();
-    if (!shell) {
-      aRv.Throw(NS_ERROR_UNEXPECTED);
-      return;
-    }
-    nsRect rcFrame = nsLayoutUtils::GetAllInFlowRectsUnion(
-        GetPrimaryFrame(), shell->GetRootFrame());
-    frameWidth = rcFrame.width;
-  }
-
-  // first find out what index we are currently at
-  while (child) {
-    rect = child->GetRect();
-    if (horiz) {
-      // In the left-to-right case we break from the loop when the center of
-      // the current child rect is greater than the scrolled position of
-      // the left edge of the scrollbox
-      // In the right-to-left case we break when the center of the current
-      // child rect is less than the scrolled position of the right edge of
-      // the scrollelement.
-      diff =
-          rect.x + rect.width / 2;  // use the center, to avoid rounding errors
-      if ((isLTR && diff > cp.x) || (!isLTR && diff < cp.x + frameWidth)) {
-        break;
-      }
-    } else {
-      diff =
-          rect.y + rect.height / 2;  // use the center, to avoid rounding errors
-      if (diff > cp.y) {
-        break;
-      }
-    }
-    child = nsBox::GetNextXULBox(child);
-    curIndex++;
-  }
-
-  int32_t count = 0;
-
-  if (aIndex == 0) return;
-
-  if (aIndex > 0) {
-    while (child) {
-      child = nsBox::GetNextXULBox(child);
-      if (child) {
-        rect = child->GetRect();
-      }
-      count++;
-      if (count >= aIndex) {
-        break;
-      }
-    }
-
-  } else if (aIndex < 0) {
-    child = nsBox::GetChildXULBox(scrolledFrame);
-    while (child) {
-      rect = child->GetRect();
-      if (count >= curIndex + aIndex) {
-        break;
-      }
-      count++;
-      child = nsBox::GetNextXULBox(child);
-    }
-  }
-
-  nscoord csspixel = nsPresContext::CSSPixelsToAppUnits(1);
-  if (horiz) {
-    // In the left-to-right case we scroll so that the left edge of the
-    // selected child is scrolled to the left edge of the scrollbox.
-    // In the right-to-left case we scroll so that the right edge of the
-    // selected child is scrolled to the right edge of the scrollbox.
-
-    nsPoint pt(isLTR ? rect.x : rect.x + rect.width - frameWidth, cp.y);
-
-    // Use a destination range that ensures the left edge (or right edge,
-    // for RTL) will indeed be visible. Also ensure that the top edge
-    // is visible.
-    nsRect range(pt.x, pt.y, csspixel, 0);
-    if (isLTR) {
-      range.x -= csspixel;
-    }
-    sf->ScrollTo(pt, nsIScrollableFrame::INSTANT, &range);
-  } else {
-    // Use a destination range that ensures the top edge will be visible.
-    nsRect range(cp.x, rect.y - csspixel, 0, csspixel);
-    sf->ScrollTo(nsPoint(cp.x, rect.y), nsIScrollableFrame::INSTANT, &range);
-  }
-}
-
-void XULScrollElement::ScrollToElement(Element& child, ErrorResult& aRv) {
-  nsCOMPtr<Document> doc = GetComposedDoc();
-  if (!doc) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
-
-  nsCOMPtr<nsIPresShell> shell = doc->GetShell();
-  if (!shell) {
-    aRv.Throw(NS_ERROR_UNEXPECTED);
-    return;
-  }
-
-  shell->ScrollContentIntoView(
-      &child,
-      nsIPresShell::ScrollAxis(nsIPresShell::SCROLL_TOP,
-                               nsIPresShell::SCROLL_ALWAYS),
-      nsIPresShell::ScrollAxis(nsIPresShell::SCROLL_LEFT,
-                               nsIPresShell::SCROLL_ALWAYS),
-      nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY |
-          nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
-}
-
-void XULScrollElement::EnsureElementIsVisible(Element& aChild,
-                                              ErrorResult& aRv) {
-  nsCOMPtr<Document> doc = GetComposedDoc();
-  if (!doc) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
-
-  nsCOMPtr<nsIPresShell> shell = doc->GetShell();
-  if (!shell) {
-    aRv.Throw(NS_ERROR_UNEXPECTED);
-    return;
-  }
-
-  shell->ScrollContentIntoView(&aChild, nsIPresShell::ScrollAxis(),
-                               nsIPresShell::ScrollAxis(),
-                               nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY |
-                                   nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
-}
-
-}  // namespace dom
-}  // namespace mozilla
deleted file mode 100644
--- a/dom/xul/XULScrollElement.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef XULScrollElement_h__
-#define XULScrollElement_h__
-
-#include "nsXULElement.h"
-#include "Units.h"
-
-namespace mozilla {
-namespace dom {
-
-class XULScrollElement final : public nsXULElement {
- public:
-  explicit XULScrollElement(
-      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
-      : nsXULElement(std::move(aNodeInfo)) {}
-
-  MOZ_CAN_RUN_SCRIPT void ScrollByIndex(int32_t aIndex, ErrorResult& aRv);
-  MOZ_CAN_RUN_SCRIPT void EnsureElementIsVisible(Element& aChild,
-                                                 ErrorResult& aRv);
-  MOZ_CAN_RUN_SCRIPT void ScrollToElement(Element& child, ErrorResult& aRv);
-
- protected:
-  virtual ~XULScrollElement() {}
-  JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
-};
-
-}  // namespace dom
-}  // namespace mozilla
-
-#endif  // XULScrollElement_h
--- a/dom/xul/moz.build
+++ b/dom/xul/moz.build
@@ -22,17 +22,16 @@ if CONFIG['MOZ_XUL']:
     ]
 
     EXPORTS.mozilla.dom += [
         'XULBroadcastManager.h',
         'XULFrameElement.h',
         'XULMenuElement.h',
         'XULPersist.h',
         'XULPopupElement.h',
-        'XULScrollElement.h',
         'XULTextElement.h',
         'XULTooltipElement.h',
         'XULTreeElement.h',
     ]
 
     UNIFIED_SOURCES += [
         'nsXULCommandDispatcher.cpp',
         'nsXULContentSink.cpp',
@@ -43,17 +42,16 @@ if CONFIG['MOZ_XUL']:
         'nsXULPrototypeDocument.cpp',
         'nsXULSortService.cpp',
         'XULBroadcastManager.cpp',
         'XULDocument.cpp',
         'XULFrameElement.cpp',
         'XULMenuElement.cpp',
         'XULPersist.cpp',
         'XULPopupElement.cpp',
-        'XULScrollElement.cpp',
         'XULTextElement.cpp',
         'XULTooltipElement.cpp',
         'XULTreeElement.cpp',
     ]
 
 XPIDL_SOURCES += [
     'nsIController.idl',
     'nsIControllers.idl',
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -72,17 +72,16 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozAutoDocUpdate.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsICSSDeclaration.h"
 #include "nsLayoutUtils.h"
 #include "XULFrameElement.h"
 #include "XULMenuElement.h"
 #include "XULPopupElement.h"
-#include "XULScrollElement.h"
 #include "XULTreeElement.h"
 
 #include "mozilla/dom/XULElementBinding.h"
 #include "mozilla/dom/BoxObject.h"
 #include "mozilla/dom/XULBroadcastManager.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/MutationEventBinding.h"
 #include "mozilla/dom/XULCommandEvent.h"
@@ -162,20 +161,16 @@ nsXULElement* nsXULElement::Construct(
     return new XULFrameElement(nodeInfo.forget());
   }
 
   if (nodeInfo->Equals(nsGkAtoms::menu) ||
       nodeInfo->Equals(nsGkAtoms::menulist)) {
     return new XULMenuElement(nodeInfo.forget());
   }
 
-  if (nodeInfo->Equals(nsGkAtoms::scrollbox)) {
-    return new XULScrollElement(nodeInfo.forget());
-  }
-
   if (nodeInfo->Equals(nsGkAtoms::tree)) {
     return new XULTreeElement(nodeInfo.forget());
   }
 
   return NS_NewBasicXULElement(nodeInfo.forget());
 }
 
 /* static */