content/base/src/nsDOMCaretPosition.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsDOMCaretPosition_h
     6 #define nsDOMCaretPosition_h
     8 #include "nsCycleCollectionParticipant.h"
     9 #include "nsCOMPtr.h"
    10 #include "nsINode.h"
    11 #include "nsWrapperCache.h"
    13 namespace mozilla {
    14 namespace dom {
    15 class DOMRect;
    16 }
    17 }
    19 /**
    20  * Implementation of a DOM Caret Position, which is a node and offset within
    21  * that node, in the DOM tree.
    22  *
    23  * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint
    24  *
    25  * @see Document::caretPositionFromPoint(float x, float y)
    26  */
    27 class nsDOMCaretPosition : public nsISupports,
    28                            public nsWrapperCache
    29 {
    30   typedef mozilla::dom::DOMRect DOMRect;
    32 public:
    33   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    34   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition)
    36   nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset);
    38   /**
    39    * Retrieve the offset (character position within the DOM node) of the
    40    * CaretPosition.
    41    *
    42    * @returns The offset within the DOM node.
    43    */
    44   uint32_t Offset() const { return mOffset; }
    46   /**
    47    * Retrieve the DOM node with which this CaretPosition was established.
    48    * Normally, this will be created from a point, so it will be the DOM
    49    * node that lies at the point specified.
    50    *
    51    * @returns The DOM node of the CaretPosition.
    52    *
    53    * @see Document::caretPositionFromPoint(float x, float y)
    54    */
    55   nsINode* GetOffsetNode() const;
    57   /**
    58    * Retrieve the bounding rectangle of this CaretPosition object.
    59    *
    60    * @returns An nsClientRect representing the bounding rectangle of this
    61    *          CaretPosition, if one can be successfully determined, otherwise
    62    *          nullptr.
    63    */
    64   already_AddRefed<DOMRect> GetClientRect() const;
    66   /**
    67    * Set the anonymous content node that is the actual parent of this
    68    * CaretPosition object. In situations where the DOM node for a CaretPosition
    69    * actually lies within an anonymous content node (e.g. a textarea), the
    70    * actual parent is not set as the offset node. This is used to get the
    71    * correct bounding box of a CaretPosition object that lies within a textarea
    72    * or input element.
    73    *
    74    * @param aNode A pointer to an nsINode object that is the actual element
    75    *        within which this CaretPosition lies, but is an anonymous content
    76    *        node.
    77    */
    78   void SetAnonymousContentNode(nsINode* aNode)
    79   {
    80     mAnonymousContentNode = aNode;
    81   }
    83   nsISupports* GetParentObject() const
    84   {
    85     return GetOffsetNode();
    86   }
    88   virtual JSObject* WrapObject(JSContext *aCx)
    89     MOZ_OVERRIDE MOZ_FINAL;
    91 protected:
    92   virtual ~nsDOMCaretPosition();
    94   uint32_t mOffset;
    95   nsCOMPtr<nsINode> mOffsetNode;
    96   nsCOMPtr<nsINode> mAnonymousContentNode;
    97 };
    98 #endif

mercurial