2012-12-28 09:11:06 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsDOMCaretPosition.h"
|
2013-08-13 23:56:21 -07:00
|
|
|
|
2012-12-28 09:11:06 -08:00
|
|
|
#include "mozilla/dom/CaretPositionBinding.h"
|
2013-09-20 03:21:03 -07:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2013-08-13 23:56:21 -07:00
|
|
|
#include "nsRange.h"
|
2012-12-28 09:11:06 -08:00
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2012-12-28 09:11:06 -08:00
|
|
|
nsDOMCaretPosition::nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset)
|
2013-04-16 14:12:03 -07:00
|
|
|
: mOffset(aOffset), mOffsetNode(aNode), mAnonymousContentNode(nullptr)
|
2012-12-28 09:11:06 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCaretPosition::~nsDOMCaretPosition()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode* nsDOMCaretPosition::GetOffsetNode() const
|
|
|
|
{
|
|
|
|
return mOffsetNode;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
already_AddRefed<DOMRect>
|
2013-04-16 14:12:03 -07:00
|
|
|
nsDOMCaretPosition::GetClientRect() const
|
|
|
|
{
|
|
|
|
if (!mOffsetNode) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
nsRefPtr<DOMRect> rect;
|
2013-04-16 14:12:03 -07:00
|
|
|
nsRefPtr<nsRange> domRange;
|
|
|
|
nsCOMPtr<nsINode> node;
|
|
|
|
|
|
|
|
if (mAnonymousContentNode) {
|
|
|
|
node = mAnonymousContentNode;
|
|
|
|
} else {
|
|
|
|
node = mOffsetNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult creationRv = nsRange::CreateRange(node, mOffset, node,
|
|
|
|
mOffset,
|
|
|
|
getter_AddRefs<nsRange>(domRange));
|
|
|
|
if (!NS_SUCCEEDED(creationRv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(domRange, "unable to retrieve valid dom range from CaretPosition");
|
|
|
|
|
2014-06-27 13:58:57 -07:00
|
|
|
rect = domRange->GetBoundingClientRect(false);
|
2013-04-16 14:12:03 -07:00
|
|
|
|
|
|
|
return rect.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:11:06 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsDOMCaretPosition::WrapObject(JSContext *aCx)
|
2012-12-28 09:11:06 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return mozilla::dom::CaretPositionBinding::Wrap(aCx, this);
|
2012-12-28 09:11:06 -08:00
|
|
|
}
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCaretPosition,
|
|
|
|
mOffsetNode, mAnonymousContentNode)
|
2012-12-28 09:11:06 -08:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCaretPosition)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCaretPosition)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCaretPosition)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|