Bug 1185307 part.1 Add nsISelection::AsSelection() r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 17 Jun 2016 16:16:10 +0900
changeset 380006 ca8fdcf1473c7854bef16578a5f8cd09501ba093
parent 380005 df00a3e270cffe3546b5b90c13925bc46fa72eb0
child 380007 a86c0e7e9758b97dc2648afc0cff049daec61e77
push id21108
push usermasayuki@d-toybox.com
push dateMon, 20 Jun 2016 10:11:38 +0000
reviewerssmaug
bugs1185307
milestone50.0a1
Bug 1185307 part.1 Add nsISelection::AsSelection() r?smaug This patch adds nsISelection::AsSelection() for safer "upcast". MozReview-Commit-ID: LlxoMaU0oE
dom/base/nsISelection.idl
layout/generic/Selection.h
--- a/dom/base/nsISelection.idl
+++ b/dom/base/nsISelection.idl
@@ -6,16 +6,24 @@
 #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)]
@@ -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/layout/generic/Selection.h
+++ b/layout/generic/Selection.h
@@ -60,16 +60,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; }