1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDOMCaretPosition_h
8 #define nsDOMCaretPosition_h
10 #include "nsCycleCollectionParticipant.h"
13 #include "nsWrapperCache.h"
19 } // namespace mozilla
22 * Implementation of a DOM Caret Position, which is a node and offset within
23 * that node, in the DOM tree.
25 * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint
27 * @see Document::caretPositionFromPoint(float x, float y)
29 class nsDOMCaretPosition
: public nsISupports
, public nsWrapperCache
{
30 typedef mozilla::dom::DOMRect DOMRect
;
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition
)
36 nsDOMCaretPosition(nsINode
* aNode
, uint32_t aOffset
);
39 * Retrieve the offset (character position within the DOM node) of the
42 * @returns The offset within the DOM node.
44 uint32_t Offset() const { return mOffset
; }
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.
51 * @returns The DOM node of the CaretPosition.
53 * @see Document::caretPositionFromPoint(float x, float y)
55 nsINode
* GetOffsetNode() const;
58 * Retrieve the bounding rectangle of this CaretPosition object.
60 * @returns An nsClientRect representing the bounding rectangle of this
61 * CaretPosition, if one can be successfully determined, otherwise
64 already_AddRefed
<DOMRect
> GetClientRect() const;
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
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
78 void SetAnonymousContentNode(nsINode
* aNode
) {
79 mAnonymousContentNode
= aNode
;
82 nsISupports
* GetParentObject() const { return GetOffsetNode(); }
84 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) final
;
87 virtual ~nsDOMCaretPosition();
90 nsCOMPtr
<nsINode
> mOffsetNode
;
91 nsCOMPtr
<nsINode
> mAnonymousContentNode
;