|
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/. */ |
|
4 |
|
5 #ifndef nsDOMCaretPosition_h |
|
6 #define nsDOMCaretPosition_h |
|
7 |
|
8 #include "nsCycleCollectionParticipant.h" |
|
9 #include "nsCOMPtr.h" |
|
10 #include "nsINode.h" |
|
11 #include "nsWrapperCache.h" |
|
12 |
|
13 namespace mozilla { |
|
14 namespace dom { |
|
15 class DOMRect; |
|
16 } |
|
17 } |
|
18 |
|
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; |
|
31 |
|
32 public: |
|
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
34 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition) |
|
35 |
|
36 nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset); |
|
37 |
|
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; } |
|
45 |
|
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; |
|
56 |
|
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; |
|
65 |
|
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 } |
|
82 |
|
83 nsISupports* GetParentObject() const |
|
84 { |
|
85 return GetOffsetNode(); |
|
86 } |
|
87 |
|
88 virtual JSObject* WrapObject(JSContext *aCx) |
|
89 MOZ_OVERRIDE MOZ_FINAL; |
|
90 |
|
91 protected: |
|
92 virtual ~nsDOMCaretPosition(); |
|
93 |
|
94 uint32_t mOffset; |
|
95 nsCOMPtr<nsINode> mOffsetNode; |
|
96 nsCOMPtr<nsINode> mAnonymousContentNode; |
|
97 }; |
|
98 #endif |
|
99 |