Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / nsDOMCaretPosition.h
blob936e94f82e733dce5fdb75ec1a0cdd66734fb95b
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"
11 #include "nsCOMPtr.h"
12 #include "nsINode.h"
13 #include "nsWrapperCache.h"
15 namespace mozilla {
16 namespace dom {
17 class DOMRect;
18 } // namespace dom
19 } // namespace mozilla
21 /**
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;
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.
42 * @returns The offset within the DOM node.
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.
51 * @returns The DOM node of the CaretPosition.
53 * @see Document::caretPositionFromPoint(float x, float y)
55 nsINode* GetOffsetNode() const;
57 /**
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
62 * nullptr.
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.
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.
78 void SetAnonymousContentNode(nsINode* aNode) {
79 mAnonymousContentNode = aNode;
82 nsISupports* GetParentObject() const { return GetOffsetNode(); }
84 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
86 protected:
87 virtual ~nsDOMCaretPosition();
89 uint32_t mOffset;
90 nsCOMPtr<nsINode> mOffsetNode;
91 nsCOMPtr<nsINode> mAnonymousContentNode;
93 #endif