Bug 1190172 part 2 - Clean up nsHTMLEditor::ClearStyle; r=ehsan

This commit is contained in:
Aryeh Gregor 2016-05-01 16:11:40 +03:00
Родитель d0c325c933
Коммит b9ebf8a2e4
4 изменённых файлов: 18 добавлений и 28 удалений

Просмотреть файл

@ -344,8 +344,7 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
if (aClearStyle) { if (aClearStyle) {
// pasting does not inherit local inline styles // pasting does not inherit local inline styles
nsCOMPtr<nsIDOMNode> tmpNode = nsCOMPtr<nsINode> tmpNode = selection->GetAnchorNode();
do_QueryInterface(selection->GetAnchorNode());
int32_t tmpOffset = static_cast<int32_t>(selection->AnchorOffset()); int32_t tmpOffset = static_cast<int32_t>(selection->AnchorOffset());
rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr); rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -4425,14 +4425,11 @@ nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
{ {
MOZ_ASSERT(aSelection && aDoc && mHTMLEditor->mTypeInState); MOZ_ASSERT(aSelection && aDoc && mHTMLEditor->mTypeInState);
nsresult res;
bool weDidSomething = false; bool weDidSomething = false;
nsCOMPtr<nsIDOMNode> node, tmp; NS_ENSURE_STATE(aSelection->GetRangeAt(0));
int32_t offset; nsCOMPtr<nsINode> node = aSelection->GetRangeAt(0)->GetStartParent();
NS_ENSURE_STATE(mHTMLEditor); int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection,
getter_AddRefs(node),
&offset);
NS_ENSURE_SUCCESS(res, res);
// next examine our present style and make sure default styles are either // next examine our present style and make sure default styles are either
// present or explicitly overridden. If neither, add the default style to // present or explicitly overridden. If neither, add the default style to
@ -4471,7 +4468,7 @@ nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
// process clearing any styles first // process clearing any styles first
nsAutoPtr<PropItem> item(mHTMLEditor->mTypeInState->TakeClearProperty()); nsAutoPtr<PropItem> item(mHTMLEditor->mTypeInState->TakeClearProperty());
while (item && node != rootElement) { while (item && GetAsDOMNode(node) != rootElement) {
NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->ClearStyle(address_of(node), &offset, res = mHTMLEditor->ClearStyle(address_of(node), &offset,
item->tag, &item->attr); item->tag, &item->attr);
@ -4487,27 +4484,24 @@ nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
if (item || relFontSize) { if (item || relFontSize) {
// we have at least one style to add; make a new text node to insert style // we have at least one style to add; make a new text node to insert style
// nodes above. // nodes above.
if (mHTMLEditor->IsTextNode(node)) { if (RefPtr<Text> text = node->GetAsText()) {
// if we are in a text node, split it // if we are in a text node, split it
NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIContent> content = do_QueryInterface(node); offset = mHTMLEditor->SplitNodeDeep(*text, *text, offset);
NS_ENSURE_STATE(content || !node);
offset = mHTMLEditor->SplitNodeDeep(*content, *content, offset);
NS_ENSURE_STATE(offset != -1); NS_ENSURE_STATE(offset != -1);
node->GetParentNode(getter_AddRefs(tmp)); node = node->GetParentNode();
node = tmp;
} }
if (!mHTMLEditor->IsContainer(node)) { if (!mHTMLEditor->IsContainer(node)) {
return NS_OK; return NS_OK;
} }
nsCOMPtr<nsIDOMNode> newNode; nsCOMPtr<nsIContent> newNode;
nsCOMPtr<nsIDOMText> nodeAsText; nsCOMPtr<nsIDOMText> nodeAsText;
res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText)); res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
newNode = do_QueryInterface(nodeAsText); newNode = do_QueryInterface(nodeAsText);
NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->InsertNode(newNode, node, offset); res = mHTMLEditor->InsertNode(*newNode, *node, offset);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
node = newNode; node = newNode;
offset = 0; offset = 0;
@ -4526,10 +4520,9 @@ nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
while (item) { while (item) {
NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIContent> content = do_QueryInterface(node); res = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
NS_ENSURE_STATE(content || !node); *item->tag, &item->attr,
res = mHTMLEditor->SetInlinePropertyOnNode(*content, *item->tag, item->value);
&item->attr, item->value);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
item = mHTMLEditor->mTypeInState->TakeSetProperty(); item = mHTMLEditor->mTypeInState->TakeSetProperty();
} }

Просмотреть файл

@ -755,7 +755,7 @@ protected:
bool aTrustedInput, bool aTrustedInput,
bool aClearStyle = true); bool aClearStyle = true);
nsresult ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset, nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsIAtom* aProperty, const nsAString* aAttribute); nsIAtom* aProperty, const nsAString* aAttribute);
void SetElementPosition(mozilla::dom::Element& aElement, void SetElementPosition(mozilla::dom::Element& aElement,

Просмотреть файл

@ -605,15 +605,13 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
} }
nsresult nsresult
nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset, nsHTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsIAtom* aProperty, const nsAString* aAttribute) nsIAtom* aProperty, const nsAString* aAttribute)
{ {
nsCOMPtr<nsINode> node = do_QueryInterface(*aNode);
nsCOMPtr<nsIContent> leftNode, rightNode; nsCOMPtr<nsIContent> leftNode, rightNode;
nsresult res = SplitStyleAbovePoint(address_of(node), aOffset, aProperty, nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty,
aAttribute, getter_AddRefs(leftNode), aAttribute, getter_AddRefs(leftNode),
getter_AddRefs(rightNode)); getter_AddRefs(rightNode));
*aNode = GetAsDOMNode(node);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
if (leftNode) { if (leftNode) {
@ -679,7 +677,7 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
} }
// reset our node offset values to the resulting new sel point // reset our node offset values to the resulting new sel point
*aNode = GetAsDOMNode(newSelParent); *aNode = newSelParent;
*aOffset = newSelOffset; *aOffset = newSelOffset;
} }