Bug 1341137 - Backport nsISelection::AsSelection() to fix bustage. r=smaug, a=bustage FIREFOX_45_8_0esr_BUILD2 FIREFOX_45_8_0esr_RELEASE
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 17 Jun 2016 16:16:10 +0900
changeset 312738 e5083d8a855a12f5f35e824573748fad71fa6693
parent 312737 22546e2cee64585bae13e2560cc5d2d50c476c7b
child 312739 bd6db49931b1d02a265d0c62858f2d8db28515b1
child 312745 e9e229c7a377a209f7a852ff39e35eb7af0f7d9f
push id455
push userryanvm@gmail.com
push dateThu, 02 Mar 2017 02:16:44 +0000
treeherdermozilla-esr45@e5083d8a855a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, bustage
bugs1341137
milestone45.8.0
Bug 1341137 - Backport nsISelection::AsSelection() to fix bustage. r=smaug, a=bustage This patch adds nsISelection::AsSelection() for safer "upcast". MozReview-Commit-ID: LlxoMaU0oE
dom/base/nsISelection.idl
dom/base/nsISelectionPrivate.idl
layout/generic/Selection.h
--- a/dom/base/nsISelection.idl
+++ b/dom/base/nsISelection.idl
@@ -6,24 +6,32 @@
 #include "nsISupports.idl"
 
 /* THIS IS A PUBLIC INTERFACE */
 
 interface nsIDOMNode;
 interface nsIDOMRange;
 interface nsINode;
 
+%{C++
+namespace mozilla {
+namespace dom {
+class Selection;
+} // namespace dom
+} // namespace mozilla
+%}
+
 /**
  * Interface for manipulating and querying the current selected range
  * of nodes within the document.
  *
  * @version 1.0
  */
 
-[builtinclass, uuid(e0a4d4b3-f34e-44bd-b1f2-4e3bde9b6915)]
+[builtinclass, uuid(4844124d-3c00-47c8-abc0-afe4119e60ca)]
 interface nsISelection : nsISupports
 {
     /**
      * Returns the node in which the selection begins.
      */
     readonly attribute nsIDOMNode anchorNode;
 
     /**
@@ -145,9 +153,18 @@ interface nsISelection : nsISupports
      *
      * @returns NS_ERROR_NOT_IMPLEMENTED if the granularity is "sentence",
      * "sentenceboundary", "paragraph", "paragraphboundary", or
      * "documentboundary".  Returns NS_ERROR_INVALID_ARG if alter, direction,
      * or granularity has an unrecognized value.
      */
     void modify(in DOMString alter, in DOMString direction,
                 in DOMString granularity);
+
+%{C++
+    /**
+     * AsSelection() returns a pointer to Selection class if the instance is
+     * derived from it.  Otherwise, nullptr but it should never happen
+     * since Selection is the only class implementing nsISelection.
+     */
+    virtual mozilla::dom::Selection* AsSelection() = 0;
+%}
 };
--- a/dom/base/nsISelectionPrivate.idl
+++ b/dom/base/nsISelectionPrivate.idl
@@ -23,17 +23,17 @@ template<class T> class nsTArray;
 
 [ptr] native nsIFrame(nsIFrame);
 [ptr] native RangeArray(nsTArray<nsRange*>);
 [ref] native constTextRangeStyleRef(const mozilla::TextRangeStyle);
 [ref] native nsPointRef(nsPoint);
 native nsDirection(nsDirection);
 native ScrollAxis(nsIPresShell::ScrollAxis);
 
-[scriptable, builtinclass, uuid(0c9f4f74-ee7e-4fe9-be6b-0ba856368178)]
+[scriptable, builtinclass, uuid(4d3bb9d5-a259-47ca-b7b7-9b66c6f8b348)]
 interface nsISelectionPrivate : nsISelection
  {
     const short ENDOFPRECEDINGLINE=0;
     const short STARTOFNEXTLINE=1;
 
     attribute boolean interlinePosition;
     [noscript] attribute nsIContent ancestorLimiter;
 
--- a/layout/generic/Selection.h
+++ b/layout/generic/Selection.h
@@ -62,16 +62,18 @@ public:
   Selection();
   explicit Selection(nsFrameSelection *aList);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Selection, nsISelectionPrivate)
   NS_DECL_NSISELECTION
   NS_DECL_NSISELECTIONPRIVATE
 
+  virtual Selection* AsSelection() override { return this; }
+
   nsresult EndBatchChangesInternal(int16_t aReason = nsISelectionListener::NO_REASON);
 
   nsIDocument* GetParentObject() const;
 
   // utility methods for scrolling the selection into view
   nsPresContext* GetPresContext() const;
   nsIPresShell* GetPresShell() const;
   nsFrameSelection* GetFrameSelection() const { return mFrameSelection; }