2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:34:41 +03:00
|
|
|
#include "mozilla/SelectionState.h"
|
2014-12-02 08:07:42 +03:00
|
|
|
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/EditorUtils.h" // for EditorUtils
|
2014-04-10 20:09:40 +04:00
|
|
|
#include "mozilla/dom/Selection.h" // for Selection
|
2017-03-10 05:17:23 +03:00
|
|
|
#include "nsAString.h" // for nsAString::Length
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc.
|
|
|
|
#include "nsError.h" // for NS_OK, etc.
|
2014-04-28 19:34:05 +04:00
|
|
|
#include "nsIContent.h" // for nsIContent
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMCharacterData.h" // for nsIDOMCharacterData
|
|
|
|
#include "nsIDOMNode.h" // for nsIDOMNode
|
|
|
|
#include "nsISupportsImpl.h" // for nsRange::Release
|
|
|
|
#include "nsRange.h" // for nsRange
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-07 12:15:53 +03:00
|
|
|
namespace mozilla {
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-07 12:15:53 +03:00
|
|
|
using namespace dom;
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SelectionState
|
|
|
|
*
|
|
|
|
* Class for recording selection info. Stores selection as collection of
|
2005-11-26 00:57:13 +03:00
|
|
|
* { {startnode, startoffset} , {endnode, endoffset} } tuples. Can't store
|
2001-01-28 23:13:07 +03:00
|
|
|
* ranges since dom gravity will possibly change the ranges.
|
2016-07-07 12:15:53 +03:00
|
|
|
******************************************************************************/
|
|
|
|
SelectionState::SelectionState()
|
|
|
|
{
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::~SelectionState()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
MakeEmpty();
|
|
|
|
}
|
|
|
|
|
2012-07-23 14:27:22 +04:00
|
|
|
void
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::SaveSelection(Selection* aSel)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2012-07-23 14:27:22 +04:00
|
|
|
MOZ_ASSERT(aSel);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t arrayCount = mArray.Length();
|
2015-02-25 19:08:00 +03:00
|
|
|
int32_t rangeCount = aSel->RangeCount();
|
2012-07-23 14:27:22 +04:00
|
|
|
|
2009-06-16 16:38:51 +04:00
|
|
|
// if we need more items in the array, new them
|
2012-07-23 14:27:22 +04:00
|
|
|
if (arrayCount < rangeCount) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = arrayCount; i < rangeCount; i++) {
|
2009-06-16 16:38:51 +04:00
|
|
|
mArray.AppendElement();
|
2016-06-24 08:44:14 +03:00
|
|
|
mArray[i] = new RangeItem();
|
2009-06-16 16:38:51 +04:00
|
|
|
}
|
2012-07-23 14:27:22 +04:00
|
|
|
} else if (arrayCount > rangeCount) {
|
|
|
|
// else if we have too many, delete them
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = arrayCount - 1; i >= rangeCount; i--) {
|
2009-06-16 16:38:51 +04:00
|
|
|
mArray.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 14:27:22 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// now store the selection ranges
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < rangeCount; i++) {
|
2012-07-23 14:27:22 +04:00
|
|
|
mArray[i]->StoreRange(aSel->GetRangeAt(i));
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::RestoreSelection(Selection* aSel)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
// clear out selection
|
|
|
|
aSel->RemoveAllRanges();
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// set the selection ranges anew
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t arrayCount = mArray.Length();
|
|
|
|
for (size_t i = 0; i < arrayCount; i++) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> range = mArray[i]->GetRange();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = aSel->AddRange(range);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::IsCollapsed()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mArray.Length() != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> range = mArray[0]->GetRange();
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(range, false);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bIsCollapsed = false;
|
2001-01-28 23:13:07 +03:00
|
|
|
range->GetCollapsed(&bIsCollapsed);
|
|
|
|
return bIsCollapsed;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::IsEqual(SelectionState* aSelState)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aSelState, false);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t myCount = mArray.Length(), itsCount = aSelState->mArray.Length();
|
|
|
|
if (myCount != itsCount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!myCount) {
|
|
|
|
return false;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < myCount; i++) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> myRange = mArray[i]->GetRange();
|
|
|
|
RefPtr<nsRange> itsRange = aSelState->mArray[i]->GetRange();
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(myRange && itsRange, false);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t compResult;
|
2010-08-06 06:13:07 +04:00
|
|
|
nsresult rv;
|
|
|
|
rv = myRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, itsRange, &compResult);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_FAILED(rv) || compResult) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-06 06:13:07 +04:00
|
|
|
rv = myRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, itsRange, &compResult);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_FAILED(rv) || compResult) {
|
|
|
|
return false;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
// if we got here, they are equal
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
void
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::MakeEmpty()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
// free any items in the array
|
2001-12-21 04:10:07 +03:00
|
|
|
mArray.Clear();
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
bool
|
2016-07-07 12:15:53 +03:00
|
|
|
SelectionState::IsEmpty()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2009-04-22 12:43:15 +04:00
|
|
|
return mArray.IsEmpty();
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 09:01:40 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::RangeUpdater
|
|
|
|
*
|
|
|
|
* Class for updating nsRanges in response to editor actions.
|
|
|
|
******************************************************************************/
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::RangeUpdater()
|
|
|
|
: mLock(false)
|
|
|
|
{
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::~RangeUpdater()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2002-11-10 18:11:08 +03:00
|
|
|
// nothing to do, we don't own the items in our array.
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::RegisterRangeItem(RangeItem* aRangeItem)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!aRangeItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mArray.Contains(aRangeItem)) {
|
2002-11-10 18:11:08 +03:00
|
|
|
NS_ERROR("tried to register an already registered range");
|
|
|
|
return; // don't register it again. It would get doubly adjusted.
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
mArray.AppendElement(aRangeItem);
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DropRangeItem(RangeItem* aRangeItem)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!aRangeItem) {
|
|
|
|
return;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
mArray.RemoveElement(aRangeItem);
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::RegisterSelectionState(SelectionState& aSelState)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t theCount = aSelState.mArray.Length();
|
|
|
|
if (theCount < 1) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < theCount; i++) {
|
2012-07-13 10:31:15 +04:00
|
|
|
RegisterRangeItem(aSelState.mArray[i]);
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2003-06-30 23:10:53 +04:00
|
|
|
return NS_OK;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DropSelectionState(SelectionState& aSelState)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t theCount = aSelState.mArray.Length();
|
|
|
|
if (theCount < 1) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < theCount; i++) {
|
2012-07-13 10:31:15 +04:00
|
|
|
DropRangeItem(aSelState.mArray[i]);
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2003-06-30 23:10:53 +04:00
|
|
|
return NS_OK;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// gravity methods:
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjCreateNode(nsINode* aParent,
|
|
|
|
int32_t aPosition)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 03:15:27 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
|
|
|
if (item->startNode == aParent && item->startOffset > aPosition) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset++;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
|
|
|
if (item->endNode == aParent && item->endOffset > aPosition) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset++;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjCreateNode(nsIDOMNode* aParent,
|
|
|
|
int32_t aPosition)
|
2014-04-28 19:34:05 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
|
|
|
|
return SelAdjCreateNode(parent, aPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjInsertNode(nsINode* aParent,
|
|
|
|
int32_t aPosition)
|
2014-04-28 19:34:05 +04:00
|
|
|
{
|
|
|
|
return SelAdjCreateNode(aParent, aPosition);
|
|
|
|
}
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjInsertNode(nsIDOMNode* aParent,
|
|
|
|
int32_t aPosition)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
return SelAdjCreateNode(aParent, aPosition);
|
|
|
|
}
|
|
|
|
|
2012-07-02 16:07:57 +04:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjDeleteNode(nsINode* aNode)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2012-07-02 16:07:57 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(aNode);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
2012-07-02 16:07:57 +04:00
|
|
|
return;
|
2010-06-29 22:14:54 +04:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
nsCOMPtr<nsINode> parent = aNode->GetParentNode();
|
|
|
|
int32_t offset = parent ? parent->IndexOf(aNode) : -1;
|
|
|
|
|
2002-12-22 04:51:14 +03:00
|
|
|
// check for range endpoints that are after aNode and in the same parent
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2012-07-02 16:07:57 +04:00
|
|
|
MOZ_ASSERT(item);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
|
|
|
if (item->startNode == parent && item->startOffset > offset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset--;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
|
|
|
if (item->endNode == parent && item->endOffset > offset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset--;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
|
|
|
|
2002-12-22 10:48:32 +03:00
|
|
|
// check for range endpoints that are in aNode
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startNode == aNode) {
|
2002-12-22 10:48:32 +03:00
|
|
|
item->startNode = parent;
|
|
|
|
item->startOffset = offset;
|
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endNode == aNode) {
|
2002-12-22 10:48:32 +03:00
|
|
|
item->endNode = parent;
|
|
|
|
item->endOffset = offset;
|
|
|
|
}
|
2002-12-22 04:51:14 +03:00
|
|
|
|
2002-12-22 10:48:32 +03:00
|
|
|
// check for range endpoints that are in descendants of aNode
|
2014-04-28 19:34:05 +04:00
|
|
|
nsCOMPtr<nsINode> oldStart;
|
2016-07-07 05:49:42 +03:00
|
|
|
if (EditorUtils::IsDescendantOf(item->startNode, aNode)) {
|
2002-12-22 10:48:32 +03:00
|
|
|
oldStart = item->startNode; // save for efficiency hack below.
|
|
|
|
item->startNode = parent;
|
|
|
|
item->startOffset = offset;
|
|
|
|
}
|
2002-12-22 04:51:14 +03:00
|
|
|
|
2002-12-22 10:48:32 +03:00
|
|
|
// avoid having to call IsDescendantOf() for common case of range startnode == range endnode.
|
2016-07-07 05:49:42 +03:00
|
|
|
if (item->endNode == oldStart ||
|
2016-10-24 05:27:45 +03:00
|
|
|
EditorUtils::IsDescendantOf(item->endNode, aNode)) {
|
2002-12-22 10:48:32 +03:00
|
|
|
item->endNode = parent;
|
|
|
|
item->endOffset = offset;
|
|
|
|
}
|
2002-12-22 04:51:14 +03:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjDeleteNode(nsIDOMNode* aNode)
|
2014-04-28 19:34:05 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
2016-10-24 05:27:45 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(node);
|
2014-04-28 19:34:05 +04:00
|
|
|
return SelAdjDeleteNode(node);
|
|
|
|
}
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
nsIContent* aNewLeftNode)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-11-02 15:04:13 +03:00
|
|
|
NS_ENSURE_TRUE(aNewLeftNode, NS_ERROR_NULL_POINTER);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
nsCOMPtr<nsINode> parent = aOldRightNode.GetParentNode();
|
|
|
|
int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// first part is same as inserting aNewLeftnode
|
2016-10-24 18:43:49 +03:00
|
|
|
nsresult rv = SelAdjInsertNode(parent, offset - 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
// next step is to check for range enpoints inside aOldRightNode
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
if (item->startNode == &aOldRightNode) {
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startOffset > aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset -= aOffset;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startNode = aNewLeftNode;
|
|
|
|
}
|
|
|
|
}
|
2014-11-02 15:04:13 +03:00
|
|
|
if (item->endNode == &aOldRightNode) {
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endOffset > aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset -= aOffset;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endNode = aNewLeftNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
|
|
|
|
nsINode& aRightNode,
|
|
|
|
nsINode& aParent,
|
|
|
|
int32_t aOffset,
|
|
|
|
int32_t aOldLeftNodeLength)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2014-11-02 15:04:12 +03:00
|
|
|
if (item->startNode == &aParent) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust start point in aParent
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startOffset > aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset--;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else if (item->startOffset == aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
// join keeps right hand node
|
2014-11-02 15:04:12 +03:00
|
|
|
item->startNode = &aRightNode;
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset = aOldLeftNodeLength;
|
|
|
|
}
|
2014-11-02 15:04:12 +03:00
|
|
|
} else if (item->startNode == &aRightNode) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust start point in aRightNode
|
|
|
|
item->startOffset += aOldLeftNodeLength;
|
2014-11-02 15:04:12 +03:00
|
|
|
} else if (item->startNode == &aLeftNode) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust start point in aLeftNode
|
2014-11-02 15:04:12 +03:00
|
|
|
item->startNode = &aRightNode;
|
2003-02-27 17:53:03 +03:00
|
|
|
}
|
|
|
|
|
2014-11-02 15:04:12 +03:00
|
|
|
if (item->endNode == &aParent) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust end point in aParent
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endOffset > aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset--;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else if (item->endOffset == aOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
// join keeps right hand node
|
2014-11-02 15:04:12 +03:00
|
|
|
item->endNode = &aRightNode;
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset = aOldLeftNodeLength;
|
|
|
|
}
|
2014-11-02 15:04:12 +03:00
|
|
|
} else if (item->endNode == &aRightNode) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust end point in aRightNode
|
|
|
|
item->endOffset += aOldLeftNodeLength;
|
2014-11-02 15:04:12 +03:00
|
|
|
} else if (item->endNode == &aLeftNode) {
|
2003-02-27 17:53:03 +03:00
|
|
|
// adjust end point in aLeftNode
|
2014-11-02 15:04:12 +03:00
|
|
|
item->endNode = &aRightNode;
|
2003-02-27 17:53:03 +03:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-29 15:43:23 +04:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjInsertText(Text& aTextNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
const nsAString& aString)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
2014-08-29 15:43:23 +04:00
|
|
|
return;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
2002-04-14 03:54:59 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
2014-08-29 15:43:23 +04:00
|
|
|
return;
|
2010-06-29 22:14:54 +04:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t len = aString.Length();
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2014-08-29 15:43:23 +04:00
|
|
|
MOZ_ASSERT(item);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
2014-08-29 15:43:23 +04:00
|
|
|
if (item->startNode == &aTextNode && item->startOffset > aOffset) {
|
2002-04-14 03:54:59 +04:00
|
|
|
item->startOffset += len;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
2014-08-29 15:43:23 +04:00
|
|
|
if (item->endNode == &aTextNode && item->endOffset > aOffset) {
|
2002-04-14 03:54:59 +04:00
|
|
|
item->endOffset += len;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
2002-04-14 03:54:59 +04:00
|
|
|
}
|
2014-08-29 15:43:23 +04:00
|
|
|
return;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjDeleteText(nsIContent* aTextNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
int32_t aLength)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
if (mLock) {
|
|
|
|
// lock set by Will/DidReplaceParent, etc...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-14 03:54:59 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
NS_ENSURE_TRUE(aTextNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2014-04-28 19:34:05 +04:00
|
|
|
|
|
|
|
if (item->startNode == aTextNode && item->startOffset > aOffset) {
|
2002-04-14 03:54:59 +04:00
|
|
|
item->startOffset -= aLength;
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startOffset < 0) {
|
|
|
|
item->startOffset = 0;
|
|
|
|
}
|
2002-04-14 03:54:59 +04:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endNode == aTextNode && item->endOffset > aOffset) {
|
2002-04-14 03:54:59 +04:00
|
|
|
item->endOffset -= aLength;
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endOffset < 0) {
|
|
|
|
item->endOffset = 0;
|
|
|
|
}
|
2002-04-14 03:54:59 +04:00
|
|
|
}
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::SelAdjDeleteText(nsIDOMCharacterData* aTextNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
int32_t aLength)
|
2014-04-28 19:34:05 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> textNode = do_QueryInterface(aTextNode);
|
|
|
|
return SelAdjDeleteText(textNode, aOffset, aLength);
|
|
|
|
}
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::WillReplaceContainer()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLock) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = true;
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DidReplaceContainer(Element* aOriginalNode,
|
|
|
|
Element* aNewNode)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = false;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aOriginalNode && aNewNode, NS_ERROR_NULL_POINTER);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startNode == aOriginalNode) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startNode = aNewNode;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
|
|
|
if (item->endNode == aOriginalNode) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endNode = aNewNode;
|
2014-04-28 19:34:05 +04:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::WillRemoveContainer()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLock) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = true;
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DidRemoveContainer(nsINode* aNode,
|
|
|
|
nsINode* aParent,
|
|
|
|
int32_t aOffset,
|
|
|
|
uint32_t aNodeOrigLen)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = false;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
|
2016-10-24 05:27:45 +03:00
|
|
|
size_t count = mArray.Length();
|
2010-06-29 22:14:54 +04:00
|
|
|
if (!count) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startNode == aNode) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startNode = aParent;
|
|
|
|
item->startOffset += aOffset;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else if (item->startNode == aParent && item->startOffset > aOffset) {
|
|
|
|
item->startOffset += (int32_t)aNodeOrigLen - 1;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endNode == aNode) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endNode = aParent;
|
|
|
|
item->endOffset += aOffset;
|
2014-04-28 19:34:05 +04:00
|
|
|
} else if (item->endNode == aParent && item->endOffset > aOffset) {
|
|
|
|
item->endOffset += (int32_t)aNodeOrigLen - 1;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DidRemoveContainer(nsIDOMNode* aNode,
|
|
|
|
nsIDOMNode* aParent,
|
|
|
|
int32_t aOffset,
|
|
|
|
uint32_t aNodeOrigLen)
|
2014-04-28 19:34:05 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
|
|
|
|
return DidRemoveContainer(node, parent, aOffset, aNodeOrigLen);
|
|
|
|
}
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::WillInsertContainer()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLock) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = true;
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DidInsertContainer()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = false;
|
2001-01-28 23:13:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:03:38 +04:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::WillMoveNode()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = true;
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:03:38 +04:00
|
|
|
void
|
2016-06-24 09:01:40 +03:00
|
|
|
RangeUpdater::DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
|
2013-07-10 14:03:38 +04:00
|
|
|
nsINode* aNewParent, int32_t aNewOffset)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2013-07-10 14:03:38 +04:00
|
|
|
MOZ_ASSERT(aOldParent);
|
|
|
|
MOZ_ASSERT(aNewParent);
|
|
|
|
NS_ENSURE_TRUE_VOID(mLock);
|
2011-10-17 18:59:28 +04:00
|
|
|
mLock = false;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0, count = mArray.Length(); i < count; ++i) {
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem* item = mArray[i];
|
2013-07-10 14:03:38 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(item);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// like a delete in aOldParent
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startNode == aOldParent && item->startOffset > aOldOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset--;
|
2013-07-10 14:03:38 +04:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endNode == aOldParent && item->endOffset > aOldOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset--;
|
2013-07-10 14:03:38 +04:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// and like an insert in aNewParent
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->startNode == aNewParent && item->startOffset > aNewOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->startOffset++;
|
2013-07-10 14:03:38 +04:00
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
if (item->endNode == aNewParent && item->endOffset > aNewOffset) {
|
2001-01-28 23:13:07 +03:00
|
|
|
item->endOffset++;
|
2013-07-10 14:03:38 +04:00
|
|
|
}
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:44:14 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::RangeItem
|
|
|
|
*
|
|
|
|
* Helper struct for SelectionState. This stores range endpoints.
|
|
|
|
******************************************************************************/
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem::RangeItem()
|
2015-05-28 18:58:42 +03:00
|
|
|
{
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
2016-06-24 08:44:14 +03:00
|
|
|
|
|
|
|
RangeItem::~RangeItem()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:44:14 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(RangeItem, startNode, endNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(RangeItem, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(RangeItem, Release)
|
2016-03-05 01:11:37 +03:00
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
void
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem::StoreRange(nsRange* aRange)
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2014-04-28 19:34:05 +04:00
|
|
|
MOZ_ASSERT(aRange);
|
|
|
|
startNode = aRange->GetStartParent();
|
|
|
|
startOffset = aRange->StartOffset();
|
|
|
|
endNode = aRange->GetEndParent();
|
|
|
|
endOffset = aRange->EndOffset();
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:34:05 +04:00
|
|
|
already_AddRefed<nsRange>
|
2016-06-24 08:44:14 +03:00
|
|
|
RangeItem::GetRange()
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> range = new nsRange(startNode);
|
2016-10-19 12:09:33 +03:00
|
|
|
if (NS_FAILED(range->Set(startNode, startOffset, endNode, endOffset))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-28 19:34:05 +04:00
|
|
|
return range.forget();
|
2001-01-28 23:13:07 +03:00
|
|
|
}
|
2016-06-24 08:44:14 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|