Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / nsDOMCaretPosition.h
blob8ede967edda6f84dca89350032343116cf301637
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::dom {
16 class DOMRect;
17 } // namespace mozilla::dom
19 /**
20 * Implementation of a DOM Caret Position, which is a node and offset within
21 * that node, in the DOM tree.
23 * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint
25 * @see Document::caretPositionFromPoint(float x, float y)
27 class nsDOMCaretPosition : public nsISupports, public nsWrapperCache {
28 using DOMRect = mozilla::dom::DOMRect;
30 public:
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsDOMCaretPosition)
34 nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset);
36 /**
37 * Retrieve the offset (character position within the DOM node) of the
38 * CaretPosition.
40 * @returns The offset within the DOM node.
42 uint32_t Offset() const { return mOffset; }
44 /**
45 * Retrieve the DOM node with which this CaretPosition was established.
46 * Normally, this will be created from a point, so it will be the DOM
47 * node that lies at the point specified.
49 * @returns The DOM node of the CaretPosition.
51 * @see Document::caretPositionFromPoint(float x, float y)
53 nsINode* GetOffsetNode() const;
55 /**
56 * Retrieve the bounding rectangle of this CaretPosition object.
58 * @returns An nsClientRect representing the bounding rectangle of this
59 * CaretPosition, if one can be successfully determined, otherwise
60 * nullptr.
62 already_AddRefed<DOMRect> GetClientRect() const;
64 /**
65 * Set the anonymous content node that is the actual parent of this
66 * CaretPosition object. In situations where the DOM node for a CaretPosition
67 * actually lies within an anonymous content node (e.g. a textarea), the
68 * actual parent is not set as the offset node. This is used to get the
69 * correct bounding box of a CaretPosition object that lies within a textarea
70 * or input element.
72 * @param aNode A pointer to an nsINode object that is the actual element
73 * within which this CaretPosition lies, but is an anonymous content
74 * node.
76 void SetAnonymousContentNode(nsINode* aNode) {
77 mAnonymousContentNode = aNode;
80 nsISupports* GetParentObject() const { return GetOffsetNode(); }
82 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
84 protected:
85 virtual ~nsDOMCaretPosition();
87 uint32_t mOffset;
88 nsCOMPtr<nsINode> mOffsetNode;
89 nsCOMPtr<nsINode> mAnonymousContentNode;
91 #endif