content/base/src/nsDOMCaretPosition.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsDOMCaretPosition_h
michael@0 6 #define nsDOMCaretPosition_h
michael@0 7
michael@0 8 #include "nsCycleCollectionParticipant.h"
michael@0 9 #include "nsCOMPtr.h"
michael@0 10 #include "nsINode.h"
michael@0 11 #include "nsWrapperCache.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14 namespace dom {
michael@0 15 class DOMRect;
michael@0 16 }
michael@0 17 }
michael@0 18
michael@0 19 /**
michael@0 20 * Implementation of a DOM Caret Position, which is a node and offset within
michael@0 21 * that node, in the DOM tree.
michael@0 22 *
michael@0 23 * http://www.w3.org/TR/cssom-view/#dom-documentview-caretrangefrompoint
michael@0 24 *
michael@0 25 * @see Document::caretPositionFromPoint(float x, float y)
michael@0 26 */
michael@0 27 class nsDOMCaretPosition : public nsISupports,
michael@0 28 public nsWrapperCache
michael@0 29 {
michael@0 30 typedef mozilla::dom::DOMRect DOMRect;
michael@0 31
michael@0 32 public:
michael@0 33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 34 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMCaretPosition)
michael@0 35
michael@0 36 nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset);
michael@0 37
michael@0 38 /**
michael@0 39 * Retrieve the offset (character position within the DOM node) of the
michael@0 40 * CaretPosition.
michael@0 41 *
michael@0 42 * @returns The offset within the DOM node.
michael@0 43 */
michael@0 44 uint32_t Offset() const { return mOffset; }
michael@0 45
michael@0 46 /**
michael@0 47 * Retrieve the DOM node with which this CaretPosition was established.
michael@0 48 * Normally, this will be created from a point, so it will be the DOM
michael@0 49 * node that lies at the point specified.
michael@0 50 *
michael@0 51 * @returns The DOM node of the CaretPosition.
michael@0 52 *
michael@0 53 * @see Document::caretPositionFromPoint(float x, float y)
michael@0 54 */
michael@0 55 nsINode* GetOffsetNode() const;
michael@0 56
michael@0 57 /**
michael@0 58 * Retrieve the bounding rectangle of this CaretPosition object.
michael@0 59 *
michael@0 60 * @returns An nsClientRect representing the bounding rectangle of this
michael@0 61 * CaretPosition, if one can be successfully determined, otherwise
michael@0 62 * nullptr.
michael@0 63 */
michael@0 64 already_AddRefed<DOMRect> GetClientRect() const;
michael@0 65
michael@0 66 /**
michael@0 67 * Set the anonymous content node that is the actual parent of this
michael@0 68 * CaretPosition object. In situations where the DOM node for a CaretPosition
michael@0 69 * actually lies within an anonymous content node (e.g. a textarea), the
michael@0 70 * actual parent is not set as the offset node. This is used to get the
michael@0 71 * correct bounding box of a CaretPosition object that lies within a textarea
michael@0 72 * or input element.
michael@0 73 *
michael@0 74 * @param aNode A pointer to an nsINode object that is the actual element
michael@0 75 * within which this CaretPosition lies, but is an anonymous content
michael@0 76 * node.
michael@0 77 */
michael@0 78 void SetAnonymousContentNode(nsINode* aNode)
michael@0 79 {
michael@0 80 mAnonymousContentNode = aNode;
michael@0 81 }
michael@0 82
michael@0 83 nsISupports* GetParentObject() const
michael@0 84 {
michael@0 85 return GetOffsetNode();
michael@0 86 }
michael@0 87
michael@0 88 virtual JSObject* WrapObject(JSContext *aCx)
michael@0 89 MOZ_OVERRIDE MOZ_FINAL;
michael@0 90
michael@0 91 protected:
michael@0 92 virtual ~nsDOMCaretPosition();
michael@0 93
michael@0 94 uint32_t mOffset;
michael@0 95 nsCOMPtr<nsINode> mOffsetNode;
michael@0 96 nsCOMPtr<nsINode> mAnonymousContentNode;
michael@0 97 };
michael@0 98 #endif
michael@0 99

mercurial