mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1368387 - Remove nsIDOMText usages from Editor. r=masayuki
nsIDOMText is old interface and it needs QI to access node etc. So we should use Text etc. MozReview-Commit-ID: 7VrTrE0p2Q9 --HG-- extra : rebase_source : baa6601708d4b71e624a4dc893cc413d7743dbeb
This commit is contained in:
parent
bbbd718f2c
commit
ecc0e24787
@ -70,7 +70,6 @@
|
||||
#include "nsIDOMMouseEvent.h" // for nsIDOMMouseEvent
|
||||
#include "nsIDOMNode.h" // for nsIDOMNode, etc.
|
||||
#include "nsIDOMNodeList.h" // for nsIDOMNodeList
|
||||
#include "nsIDOMText.h" // for nsIDOMText
|
||||
#include "nsIDocument.h" // for nsIDocument
|
||||
#include "nsIDocumentStateListener.h" // for nsIDocumentStateListener
|
||||
#include "nsIEditActionListener.h" // for nsIEditActionListener
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIHTMLAbsPosEditor.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
@ -5595,10 +5594,9 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
|
||||
bool isPRE;
|
||||
mHTMLEditor->IsPreformatted(nextNode->AsDOMNode(), &isPRE);
|
||||
if (isPRE) {
|
||||
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(nextNode);
|
||||
if (textNode) {
|
||||
if (EditorBase::IsTextNode(nextNode)) {
|
||||
nsAutoString tempString;
|
||||
textNode->GetData(tempString);
|
||||
nextNode->GetAsText()->GetData(tempString);
|
||||
int32_t newlinePos = tempString.FindChar(nsCRT::LF);
|
||||
if (newlinePos >= 0) {
|
||||
if (static_cast<uint32_t>(newlinePos) + 1 == tempString.Length()) {
|
||||
@ -6455,11 +6453,6 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
|
||||
// we are at the edges of the block, newBRneeded not needed!
|
||||
sibling = node->AsContent();
|
||||
} else if (EditorBase::IsTextNode(aNode)) {
|
||||
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(aNode);
|
||||
uint32_t strLength;
|
||||
nsresult rv = textNode->GetLength(&strLength);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// at beginning of text node?
|
||||
if (!aOffset) {
|
||||
// is there a BR prior to it?
|
||||
@ -6470,7 +6463,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
newBRneeded = true;
|
||||
}
|
||||
} else if (aOffset == (int32_t)strLength) {
|
||||
} else if (aOffset == static_cast<int32_t>(node->Length())) {
|
||||
// we're at the end of text node...
|
||||
// is there a BR after to it?
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
@ -6487,7 +6480,8 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
|
||||
if (NS_WARN_IF(!mHTMLEditor)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
rv = mHTMLEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
|
||||
nsresult rv =
|
||||
mHTMLEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
selNode = tmp;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "TextEditUtils.h"
|
||||
#include "TypeInState.h"
|
||||
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMMozNamedAttrMap.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMAttr.h"
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHTMLObjectResizer.h"
|
||||
@ -626,8 +625,6 @@ HTMLEditor::SetResizingInfoPosition(int32_t aX,
|
||||
int32_t aW,
|
||||
int32_t aH)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
|
||||
|
||||
// Determine the position of the resizing info box based upon the new
|
||||
// position and size of the element (aX, aY, aW, aH), and which
|
||||
// resizer is the "activated handle". For example, place the resizing
|
||||
@ -696,12 +693,15 @@ HTMLEditor::SetResizingInfoPosition(int32_t aX,
|
||||
NS_LITERAL_STRING(", ") + diffHeightStr +
|
||||
NS_LITERAL_STRING(")"));
|
||||
|
||||
nsCOMPtr<nsIDOMText> nodeAsText;
|
||||
nsresult rv = domdoc->CreateTextNode(info, getter_AddRefs(nodeAsText));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
textInfo = do_QueryInterface(nodeAsText);
|
||||
nsCOMPtr<nsIDocument> doc = GetDocument();
|
||||
textInfo = doc->CreateTextNode(info);
|
||||
if (NS_WARN_IF(!textInfo)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mResizingInfo->AppendChild(*textInfo, erv);
|
||||
NS_ENSURE_TRUE(!erv.Failed(), erv.StealNSResult());
|
||||
if (NS_WARN_IF(erv.Failed())) {
|
||||
return erv.StealNSResult();
|
||||
}
|
||||
|
||||
return mResizingInfo->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsIPlaintextEditor.h"
|
||||
@ -445,42 +444,42 @@ TextEditRules::CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection)
|
||||
// if we are at the end of the textarea, we need to set the
|
||||
// selection to stick to the mozBR at the end of the textarea.
|
||||
int32_t selOffset;
|
||||
nsCOMPtr<nsIDOMNode> selNode;
|
||||
nsCOMPtr<nsINode> selNode;
|
||||
nsresult rv =
|
||||
EditorBase::GetStartNodeAndOffset(aSelection,
|
||||
getter_AddRefs(selNode), &selOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(selNode);
|
||||
if (!nodeAsText) {
|
||||
if (!EditorBase::IsTextNode(selNode)) {
|
||||
return NS_OK; // Nothing to do if we're not at a text node.
|
||||
}
|
||||
|
||||
uint32_t length;
|
||||
rv = nodeAsText->GetLength(&length);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// nothing to do if we're not at the end of the text node
|
||||
if (selOffset != int32_t(length)) {
|
||||
if (selOffset != static_cast<int32_t>(selNode->Length())) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int32_t parentOffset;
|
||||
nsCOMPtr<nsIDOMNode> parentNode =
|
||||
nsINode* parentNode =
|
||||
EditorBase::GetNodeLocation(selNode, &parentOffset);
|
||||
|
||||
NS_ENSURE_STATE(mTextEditor);
|
||||
nsCOMPtr<nsIDOMNode> root = do_QueryInterface(mTextEditor->GetRoot());
|
||||
NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER);
|
||||
nsINode* root = mTextEditor->GetRoot();
|
||||
if (NS_WARN_IF(!root)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (parentNode != root) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> nextNode = mTextEditor->GetChildAt(parentNode,
|
||||
parentOffset + 1);
|
||||
nsINode* nextNode = parentNode->GetChildAt(parentOffset + 1);
|
||||
if (nextNode && TextEditUtils::IsMozBR(nextNode)) {
|
||||
rv = aSelection->Collapse(parentNode, parentOffset + 1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1045,26 +1044,27 @@ TextEditRules::DidDeleteSelection(Selection* aSelection,
|
||||
nsIEditor::EDirection aCollapsedAction,
|
||||
nsresult aResult)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> startNode;
|
||||
nsCOMPtr<nsINode> startNode;
|
||||
int32_t startOffset;
|
||||
nsresult rv =
|
||||
EditorBase::GetStartNodeAndOffset(aSelection,
|
||||
getter_AddRefs(startNode), &startOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
if (NS_WARN_IF(!startNode)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// delete empty text nodes at selection
|
||||
if (EditorBase::IsTextNode(startNode)) {
|
||||
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(startNode);
|
||||
uint32_t strLength;
|
||||
rv = textNode->GetLength(&strLength);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// are we in an empty text node?
|
||||
if (!strLength) {
|
||||
if (!startNode->Length()) {
|
||||
NS_ENSURE_STATE(mTextEditor);
|
||||
rv = mTextEditor->DeleteNode(startNode);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mDidExplicitlySetInterline) {
|
||||
|
Loading…
Reference in New Issue
Block a user