michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDOMCaretPosition_h michael@0: #define nsDOMCaretPosition_h michael@0: michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsINode.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class DOMRect; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Implementation of a DOM Caret Position, which is a node and offset within michael@0: * that node, in the DOM tree. michael@0: * michael@0: * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint michael@0: * michael@0: * @see Document::caretPositionFromPoint(float x, float y) michael@0: */ michael@0: class nsDOMCaretPosition : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: typedef mozilla::dom::DOMRect DOMRect; michael@0: michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition) michael@0: michael@0: nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset); michael@0: michael@0: /** michael@0: * Retrieve the offset (character position within the DOM node) of the michael@0: * CaretPosition. michael@0: * michael@0: * @returns The offset within the DOM node. michael@0: */ michael@0: uint32_t Offset() const { return mOffset; } michael@0: michael@0: /** michael@0: * Retrieve the DOM node with which this CaretPosition was established. michael@0: * Normally, this will be created from a point, so it will be the DOM michael@0: * node that lies at the point specified. michael@0: * michael@0: * @returns The DOM node of the CaretPosition. michael@0: * michael@0: * @see Document::caretPositionFromPoint(float x, float y) michael@0: */ michael@0: nsINode* GetOffsetNode() const; michael@0: michael@0: /** michael@0: * Retrieve the bounding rectangle of this CaretPosition object. michael@0: * michael@0: * @returns An nsClientRect representing the bounding rectangle of this michael@0: * CaretPosition, if one can be successfully determined, otherwise michael@0: * nullptr. michael@0: */ michael@0: already_AddRefed GetClientRect() const; michael@0: michael@0: /** michael@0: * Set the anonymous content node that is the actual parent of this michael@0: * CaretPosition object. In situations where the DOM node for a CaretPosition michael@0: * actually lies within an anonymous content node (e.g. a textarea), the michael@0: * actual parent is not set as the offset node. This is used to get the michael@0: * correct bounding box of a CaretPosition object that lies within a textarea michael@0: * or input element. michael@0: * michael@0: * @param aNode A pointer to an nsINode object that is the actual element michael@0: * within which this CaretPosition lies, but is an anonymous content michael@0: * node. michael@0: */ michael@0: void SetAnonymousContentNode(nsINode* aNode) michael@0: { michael@0: mAnonymousContentNode = aNode; michael@0: } michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return GetOffsetNode(); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext *aCx) michael@0: MOZ_OVERRIDE MOZ_FINAL; michael@0: michael@0: protected: michael@0: virtual ~nsDOMCaretPosition(); michael@0: michael@0: uint32_t mOffset; michael@0: nsCOMPtr mOffsetNode; michael@0: nsCOMPtr mAnonymousContentNode; michael@0: }; michael@0: #endif michael@0: