content/base/src/nsDOMCaretPosition.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 #include "nsDOMCaretPosition.h"
michael@0 6
michael@0 7 #include "mozilla/dom/CaretPositionBinding.h"
michael@0 8 #include "mozilla/dom/DOMRect.h"
michael@0 9 #include "nsRange.h"
michael@0 10
michael@0 11 using namespace mozilla::dom;
michael@0 12
michael@0 13 nsDOMCaretPosition::nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset)
michael@0 14 : mOffset(aOffset), mOffsetNode(aNode), mAnonymousContentNode(nullptr)
michael@0 15 {
michael@0 16 SetIsDOMBinding();
michael@0 17 }
michael@0 18
michael@0 19 nsDOMCaretPosition::~nsDOMCaretPosition()
michael@0 20 {
michael@0 21 }
michael@0 22
michael@0 23 nsINode* nsDOMCaretPosition::GetOffsetNode() const
michael@0 24 {
michael@0 25 return mOffsetNode;
michael@0 26 }
michael@0 27
michael@0 28 already_AddRefed<DOMRect>
michael@0 29 nsDOMCaretPosition::GetClientRect() const
michael@0 30 {
michael@0 31 if (!mOffsetNode) {
michael@0 32 return nullptr;
michael@0 33 }
michael@0 34
michael@0 35 nsRefPtr<DOMRect> rect;
michael@0 36 nsRefPtr<nsRange> domRange;
michael@0 37 nsCOMPtr<nsINode> node;
michael@0 38
michael@0 39 if (mAnonymousContentNode) {
michael@0 40 node = mAnonymousContentNode;
michael@0 41 } else {
michael@0 42 node = mOffsetNode;
michael@0 43 }
michael@0 44
michael@0 45 nsresult creationRv = nsRange::CreateRange(node, mOffset, node,
michael@0 46 mOffset,
michael@0 47 getter_AddRefs<nsRange>(domRange));
michael@0 48 if (!NS_SUCCEEDED(creationRv)) {
michael@0 49 return nullptr;
michael@0 50 }
michael@0 51
michael@0 52 NS_ASSERTION(domRange, "unable to retrieve valid dom range from CaretPosition");
michael@0 53
michael@0 54 rect = domRange->GetBoundingClientRect();
michael@0 55
michael@0 56 return rect.forget();
michael@0 57 }
michael@0 58
michael@0 59 JSObject*
michael@0 60 nsDOMCaretPosition::WrapObject(JSContext *aCx)
michael@0 61 {
michael@0 62 return mozilla::dom::CaretPositionBinding::Wrap(aCx, this);
michael@0 63 }
michael@0 64
michael@0 65 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(nsDOMCaretPosition,
michael@0 66 mOffsetNode, mAnonymousContentNode)
michael@0 67
michael@0 68 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCaretPosition)
michael@0 69 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCaretPosition)
michael@0 70
michael@0 71 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCaretPosition)
michael@0 72 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 73 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 74 NS_INTERFACE_MAP_END
michael@0 75

mercurial