content/base/src/nsDOMCaretPosition.cpp

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.)

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "nsDOMCaretPosition.h"
     7 #include "mozilla/dom/CaretPositionBinding.h"
     8 #include "mozilla/dom/DOMRect.h"
     9 #include "nsRange.h"
    11 using namespace mozilla::dom;
    13 nsDOMCaretPosition::nsDOMCaretPosition(nsINode* aNode, uint32_t aOffset)
    14   : mOffset(aOffset), mOffsetNode(aNode), mAnonymousContentNode(nullptr)
    15 {
    16   SetIsDOMBinding();
    17 }
    19 nsDOMCaretPosition::~nsDOMCaretPosition()
    20 {
    21 }
    23 nsINode* nsDOMCaretPosition::GetOffsetNode() const
    24 {
    25   return mOffsetNode;
    26 }
    28 already_AddRefed<DOMRect>
    29 nsDOMCaretPosition::GetClientRect() const
    30 {
    31   if (!mOffsetNode) {
    32     return nullptr;
    33   }
    35   nsRefPtr<DOMRect> rect;
    36   nsRefPtr<nsRange> domRange;
    37   nsCOMPtr<nsINode> node;
    39   if (mAnonymousContentNode) {
    40     node = mAnonymousContentNode;
    41   } else {
    42     node = mOffsetNode;
    43   }
    45   nsresult creationRv = nsRange::CreateRange(node, mOffset, node,
    46                                              mOffset,
    47                                              getter_AddRefs<nsRange>(domRange));
    48   if (!NS_SUCCEEDED(creationRv)) {
    49     return nullptr;
    50   }
    52   NS_ASSERTION(domRange, "unable to retrieve valid dom range from CaretPosition");
    54   rect = domRange->GetBoundingClientRect();
    56   return rect.forget();
    57 }
    59 JSObject*
    60 nsDOMCaretPosition::WrapObject(JSContext *aCx)
    61 {
    62   return mozilla::dom::CaretPositionBinding::Wrap(aCx, this);
    63 }
    65 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(nsDOMCaretPosition,
    66                                         mOffsetNode, mAnonymousContentNode)
    68 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCaretPosition)
    69 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCaretPosition)
    71 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCaretPosition)
    72   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    73   NS_INTERFACE_MAP_ENTRY(nsISupports)
    74 NS_INTERFACE_MAP_END

mercurial