Пример #1
0
nsresult
nsRangeUpdater::SelAdjSplitNode(nsIDOMNode *aOldRightNode, PRInt32 aOffset, nsIDOMNode *aNewLeftNode)
{
  if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
  NS_ENSURE_TRUE(aOldRightNode && aNewLeftNode, NS_ERROR_NULL_POINTER);
  PRUint32 i, count = mArray.Length();
  if (!count) {
    return NS_OK;
  }

  nsCOMPtr<nsIDOMNode> parent;
  PRInt32 offset;
  nsresult result = nsEditor::GetNodeLocation(aOldRightNode, address_of(parent), &offset);
  NS_ENSURE_SUCCESS(result, result);
  
  // first part is same as inserting aNewLeftnode
  result = SelAdjInsertNode(parent,offset-1);
  NS_ENSURE_SUCCESS(result, result);

  // next step is to check for range enpoints inside aOldRightNode
  nsRangeStore *item;
  
  for (i=0; i<count; i++)
  {
    item = mArray[i];
    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
    
    if (item->startNode.get() == aOldRightNode)
    {
      if (item->startOffset > aOffset)
      {
        item->startOffset -= aOffset;
      }
      else
      {
        item->startNode = aNewLeftNode;
      }
    }
    if (item->endNode.get() == aOldRightNode)
    {
      if (item->endOffset > aOffset)
      {
        item->endOffset -= aOffset;
      }
      else
      {
        item->endNode = aNewLeftNode;
      }
    }
  }
  return NS_OK;
}
Пример #2
0
nsresult
RangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode,
                              int32_t aOffset,
                              nsIContent* aNewLeftNode)
{
  if (mLock) {
    // lock set by Will/DidReplaceParent, etc...
    return NS_OK;
  }
  NS_ENSURE_TRUE(aNewLeftNode, NS_ERROR_NULL_POINTER);
  size_t count = mArray.Length();
  if (!count) {
    return NS_OK;
  }

  nsCOMPtr<nsINode> parent = aOldRightNode.GetParentNode();
  int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;

  // first part is same as inserting aNewLeftnode
  nsresult rv = SelAdjInsertNode(parent, offset - 1);
  NS_ENSURE_SUCCESS(rv, rv);

  // next step is to check for range enpoints inside aOldRightNode
  for (size_t i = 0; i < count; i++) {
    RangeItem* item = mArray[i];
    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);

    if (item->startNode == &aOldRightNode) {
      if (item->startOffset > aOffset) {
        item->startOffset -= aOffset;
      } else {
        item->startNode = aNewLeftNode;
      }
    }
    if (item->endNode == &aOldRightNode) {
      if (item->endOffset > aOffset) {
        item->endOffset -= aOffset;
      } else {
        item->endNode = aNewLeftNode;
      }
    }
  }
  return NS_OK;
}