Bug 1562876: use `GetDocument()` instead of `GetParentObject` in Selection.cpp. r=smaug
authorMirko Brodesser <mbrodesser@mozilla.com>
Tue, 02 Jul 2019 13:50:06 +0200
changeset 540784 403c620d36f717bf85518ae24d8762d03e8beb65
parent 540737 3619d80d3bce3fa94c9887cf86774010b4a6544c
child 540785 616a94e9044404032b59f981e7f6a4c5ad32adc8
push id11529
push userarchaeopteryx@coole-files.de
push dateThu, 04 Jul 2019 15:22:33 +0000
treeherdermozilla-beta@ebb510a784b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1562876
milestone69.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 1562876: use `GetDocument()` instead of `GetParentObject` in Selection.cpp. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D36600
dom/base/Selection.cpp
dom/base/Selection.h
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -933,17 +933,17 @@ nsresult Selection::AddItem(nsRange* aIt
   if (!aItem->IsPositioned()) return NS_ERROR_UNEXPECTED;
 
   NS_ASSERTION(aOutIndex, "aOutIndex can't be null");
 
   if (mUserInitiated) {
     AutoTArray<RefPtr<nsRange>, 4> rangesToAdd;
     *aOutIndex = int32_t(mRanges.Length()) - 1;
 
-    Document* doc = GetParentObject();
+    Document* doc = GetDocument();
     bool selectEventsEnabled =
         StaticPrefs::dom_select_events_enabled() ||
         (doc && nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()));
 
     if (!aNoStartSelect && mSelectionType == SelectionType::eNormal &&
         selectEventsEnabled && IsCollapsed() &&
         !IsBlockingSelectionChangeEvents()) {
       // First, we generate the ranges to add with a scratch range, which is a
@@ -979,17 +979,17 @@ nsresult Selection::AddItem(nsRange* aIt
             // This is a selection under a text control, so don't dispatch the
             // event.
             dispatchEvent = false;
           }
         }
 
         if (dispatchEvent) {
           nsContentUtils::DispatchTrustedEvent(
-              GetParentObject(), target, NS_LITERAL_STRING("selectstart"),
+              GetDocument(), target, NS_LITERAL_STRING("selectstart"),
               CanBubble::eYes, Cancelable::eYes, &defaultAction);
 
           if (!defaultAction) {
             return NS_OK;
           }
 
           // As we just dispatched an event to the DOM, something could have
           // changed under our feet. Re-generate the rangesToAdd array, and
@@ -1977,17 +1977,17 @@ nsresult Selection::RemoveAllRangesTempo
 
 void Selection::AddRangeJS(nsRange& aRange, ErrorResult& aRv) {
   AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
   mCalledByJS = true;
   AddRange(aRange, aRv);
 }
 
 void Selection::AddRange(nsRange& aRange, ErrorResult& aRv) {
-  RefPtr<Document> document(GetParentObject());
+  RefPtr<Document> document(GetDocument());
   return AddRangeInternal(aRange, document, aRv);
 }
 
 void Selection::AddRangeInternal(nsRange& aRange, Document* aDocument,
                                  ErrorResult& aRv) {
   // If the given range is part of another Selection, we need to clone the
   // range first.
   RefPtr<nsRange> range;
@@ -3667,11 +3667,11 @@ JSObject* Selection::WrapObject(JSContex
 // AutoHideSelectionChanges
 AutoHideSelectionChanges::AutoHideSelectionChanges(
     const nsFrameSelection* aFrame)
     : AutoHideSelectionChanges(
           aFrame ? aFrame->GetSelection(SelectionType::eNormal) : nullptr) {}
 
 bool Selection::HasSameRootOrSameComposedDoc(const nsINode& aNode) {
   nsINode* root = aNode.SubtreeRoot();
-  Document* doc = GetParentObject();
+  Document* doc = GetDocument();
   return doc == root || (root && doc == root->GetComposedDoc());
 }
--- a/dom/base/Selection.h
+++ b/dom/base/Selection.h
@@ -112,17 +112,20 @@ class Selection final : public nsSupport
    * selectionchange event at every selection change.
    */
   void EnableSelectionChangeEvent() {
     if (!mSelectionChangeEventDispatcher) {
       mSelectionChangeEventDispatcher = new SelectionChangeEventDispatcher();
     }
   }
 
+  // Required for WebIDL bindings, see
+  // https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings#Adding_WebIDL_bindings_to_a_class.
   Document* GetParentObject() const;
+
   DocGroup* GetDocGroup() const;
 
   // utility methods for scrolling the selection into view
   nsPresContext* GetPresContext() const;
   PresShell* GetPresShell() const;
   nsFrameSelection* GetFrameSelection() const { return mFrameSelection; }
   // Returns a rect containing the selection region, and frame that that
   // position is relative to. For SELECTION_ANCHOR_REGION or