1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsDOMCaretPosition.h"
9 #include "mozilla/dom/CaretPositionBinding.h"
10 #include "mozilla/dom/DOMRect.h"
11 #include "mozilla/ErrorResult.h"
14 using namespace mozilla::dom
;
16 nsDOMCaretPosition::nsDOMCaretPosition(nsINode
* aNode
, uint32_t aOffset
)
17 : mOffset(aOffset
), mOffsetNode(aNode
), mAnonymousContentNode(nullptr) {}
19 nsDOMCaretPosition::~nsDOMCaretPosition() = default;
21 nsINode
* nsDOMCaretPosition::GetOffsetNode() const { return mOffsetNode
; }
23 already_AddRefed
<DOMRect
> nsDOMCaretPosition::GetClientRect() const {
28 nsCOMPtr
<nsINode
> node
;
29 if (mAnonymousContentNode
) {
30 node
= mAnonymousContentNode
;
35 RefPtr
<nsRange
> range
=
36 nsRange::Create(node
, mOffset
, node
, mOffset
, mozilla::IgnoreErrors());
40 RefPtr
<DOMRect
> rect
= range
->GetBoundingClientRect(false);
44 JSObject
* nsDOMCaretPosition::WrapObject(JSContext
* aCx
,
45 JS::Handle
<JSObject
*> aGivenProto
) {
46 return mozilla::dom::CaretPosition_Binding::Wrap(aCx
, this, aGivenProto
);
49 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCaretPosition
, mOffsetNode
,
50 mAnonymousContentNode
)
52 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCaretPosition
)
53 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCaretPosition
)
55 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCaretPosition
)
56 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
57 NS_INTERFACE_MAP_ENTRY(nsISupports
)