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) {
// pasting does not inherit local inline styles
nsCOMPtr<nsIDOMNode> tmpNode =
do_QueryInterface(selection->GetAnchorNode());
nsCOMPtr<nsINode> tmpNode = selection->GetAnchorNode();
int32_t tmpOffset = static_cast<int32_t>(selection->AnchorOffset());
rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);

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

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

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

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

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

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