1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsDOMCaretPosition.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsDOMCaretPosition_h 1.9 +#define nsDOMCaretPosition_h 1.10 + 1.11 +#include "nsCycleCollectionParticipant.h" 1.12 +#include "nsCOMPtr.h" 1.13 +#include "nsINode.h" 1.14 +#include "nsWrapperCache.h" 1.15 + 1.16 +namespace mozilla { 1.17 +namespace dom { 1.18 +class DOMRect; 1.19 +} 1.20 +} 1.21 + 1.22 +/** 1.23 + * Implementation of a DOM Caret Position, which is a node and offset within 1.24 + * that node, in the DOM tree. 1.25 + * 1.26 + * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint 1.27 + * 1.28 + * @see Document::caretPositionFromPoint(float x, float y) 1.29 + */ 1.30 +class nsDOMCaretPosition : public nsISupports, 1.31 + public nsWrapperCache 1.32 +{ 1.33 + typedef mozilla::dom::DOMRect DOMRect; 1.34 + 1.35 +public: 1.36 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.37 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition) 1.38 + 1.39 + nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset); 1.40 + 1.41 + /** 1.42 + * Retrieve the offset (character position within the DOM node) of the 1.43 + * CaretPosition. 1.44 + * 1.45 + * @returns The offset within the DOM node. 1.46 + */ 1.47 + uint32_t Offset() const { return mOffset; } 1.48 + 1.49 + /** 1.50 + * Retrieve the DOM node with which this CaretPosition was established. 1.51 + * Normally, this will be created from a point, so it will be the DOM 1.52 + * node that lies at the point specified. 1.53 + * 1.54 + * @returns The DOM node of the CaretPosition. 1.55 + * 1.56 + * @see Document::caretPositionFromPoint(float x, float y) 1.57 + */ 1.58 + nsINode* GetOffsetNode() const; 1.59 + 1.60 + /** 1.61 + * Retrieve the bounding rectangle of this CaretPosition object. 1.62 + * 1.63 + * @returns An nsClientRect representing the bounding rectangle of this 1.64 + * CaretPosition, if one can be successfully determined, otherwise 1.65 + * nullptr. 1.66 + */ 1.67 + already_AddRefed<DOMRect> GetClientRect() const; 1.68 + 1.69 + /** 1.70 + * Set the anonymous content node that is the actual parent of this 1.71 + * CaretPosition object. In situations where the DOM node for a CaretPosition 1.72 + * actually lies within an anonymous content node (e.g. a textarea), the 1.73 + * actual parent is not set as the offset node. This is used to get the 1.74 + * correct bounding box of a CaretPosition object that lies within a textarea 1.75 + * or input element. 1.76 + * 1.77 + * @param aNode A pointer to an nsINode object that is the actual element 1.78 + * within which this CaretPosition lies, but is an anonymous content 1.79 + * node. 1.80 + */ 1.81 + void SetAnonymousContentNode(nsINode* aNode) 1.82 + { 1.83 + mAnonymousContentNode = aNode; 1.84 + } 1.85 + 1.86 + nsISupports* GetParentObject() const 1.87 + { 1.88 + return GetOffsetNode(); 1.89 + } 1.90 + 1.91 + virtual JSObject* WrapObject(JSContext *aCx) 1.92 + MOZ_OVERRIDE MOZ_FINAL; 1.93 + 1.94 +protected: 1.95 + virtual ~nsDOMCaretPosition(); 1.96 + 1.97 + uint32_t mOffset; 1.98 + nsCOMPtr<nsINode> mOffsetNode; 1.99 + nsCOMPtr<nsINode> mAnonymousContentNode; 1.100 +}; 1.101 +#endif 1.102 +