Bug 1190172 - Back out for now, requested by Masayuki at bug 1191356 comment 23

This commit is contained in:
Aryeh Gregor 2016-04-20 20:44:48 +03:00
parent 52f4bc1e37
commit b75a20d5c8
3 changed files with 80 additions and 58 deletions

View File

@ -2710,14 +2710,22 @@ nsHTMLEditRules::JoinBlocks(nsIContent& aLeftNode, nsIContent& aRightNode,
nsCOMPtr<Element> editorRoot = mHTMLEditor->GetEditorRoot(); nsCOMPtr<Element> editorRoot = mHTMLEditor->GetEditorRoot();
if (!editorRoot || &aLeftNode != editorRoot) { if (!editorRoot || &aLeftNode != editorRoot) {
nsCOMPtr<nsIContent> splittedPreviousContent; nsCOMPtr<nsIDOMNode> previousContentParentDOM =
res = mHTMLEditor->SplitStyleAbovePoint(address_of(previousContentParent), GetAsDOMNode(previousContentParent);
nsCOMPtr<nsIDOMNode> splittedPreviousContentDOM;
res = mHTMLEditor->SplitStyleAbovePoint(address_of(previousContentParentDOM),
&previousContentOffset, &previousContentOffset,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
getter_AddRefs(splittedPreviousContent)); address_of(splittedPreviousContentDOM));
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
previousContentParent = do_QueryInterface(previousContentParentDOM);
NS_ENSURE_STATE(previousContentParent || !previousContentParentDOM);
if (splittedPreviousContent) { if (splittedPreviousContentDOM) {
nsCOMPtr<nsINode> splittedPreviousContent =
do_QueryInterface(splittedPreviousContentDOM);
NS_ENSURE_STATE(splittedPreviousContent ||
!splittedPreviousContentDOM);
previousContentParent = splittedPreviousContent->GetParentNode(); previousContentParent = splittedPreviousContent->GetParentNode();
previousContentOffset = previousContentParent ? previousContentOffset = previousContentParent ?
previousContentParent->IndexOf(splittedPreviousContent) : -1; previousContentParent->IndexOf(splittedPreviousContent) : -1;

View File

@ -664,11 +664,12 @@ protected:
nsresult SplitStyleAboveRange(nsRange* aRange, nsresult SplitStyleAboveRange(nsRange* aRange,
nsIAtom *aProperty, nsIAtom *aProperty,
const nsAString *aAttribute); const nsAString *aAttribute);
nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset, nsresult SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
nsIAtom* aProperty, int32_t *aOffset,
const nsAString* aAttribute, nsIAtom *aProperty,
nsIContent** aOutLeftNode = nullptr, const nsAString *aAttribute,
nsIContent** aOutRightNode = nullptr); nsCOMPtr<nsIDOMNode> *outLeftNode = nullptr,
nsCOMPtr<nsIDOMNode> *outRightNode = nullptr);
nsresult ApplyDefaultProperties(); nsresult ApplyDefaultProperties();
nsresult RemoveStyleInside(nsIDOMNode *aNode, nsresult RemoveStyleInside(nsIDOMNode *aNode,
nsIAtom *aProperty, nsIAtom *aProperty,

View File

@ -523,25 +523,29 @@ nsHTMLEditor::SplitStyleAboveRange(nsRange* inRange, nsIAtom* aProperty,
{ {
NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
nsresult res; nsresult res;
nsCOMPtr<nsIDOMNode> startNode, endNode, origStartNode;
int32_t startOffset, endOffset;
nsCOMPtr<nsINode> startNode = inRange->GetStartParent(); res = inRange->GetStartContainer(getter_AddRefs(startNode));
int32_t startOffset = inRange->StartOffset(); NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsINode> endNode = inRange->GetEndParent(); res = inRange->GetStartOffset(&startOffset);
int32_t endOffset = inRange->EndOffset(); NS_ENSURE_SUCCESS(res, res);
res = inRange->GetEndContainer(getter_AddRefs(endNode));
NS_ENSURE_SUCCESS(res, res);
res = inRange->GetEndOffset(&endOffset);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsINode> origStartNode = startNode; origStartNode = startNode;
// split any matching style nodes above the start of range // split any matching style nodes above the start of range
{ {
nsAutoTrackDOMPoint tracker(mRangeUpdater, address_of(endNode), &endOffset); nsAutoTrackDOMPoint tracker(mRangeUpdater, address_of(endNode), &endOffset);
res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty, res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty, aAttribute);
aAttribute);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
} }
// second verse, same as the first... // second verse, same as the first...
res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty, res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty, aAttribute);
aAttribute);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
// reset the range // reset the range
@ -551,32 +555,30 @@ nsHTMLEditor::SplitStyleAboveRange(nsRange* inRange, nsIAtom* aProperty,
return res; return res;
} }
nsresult nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t *aOffset,
int32_t* aOffset, nsIAtom *aProperty, // null here means we split all properties
// null here means we split all properties const nsAString *aAttribute,
nsIAtom* aProperty, nsCOMPtr<nsIDOMNode> *outLeftNode,
const nsAString* aAttribute, nsCOMPtr<nsIDOMNode> *outRightNode)
nsIContent** aOutLeftNode,
nsIContent** aOutRightNode)
{ {
MOZ_ASSERT(aNode && *aNode && aOffset); NS_ENSURE_TRUE(aNode && *aNode && aOffset, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE((*aNode)->IsContent(), NS_OK); if (outLeftNode) *outLeftNode = nullptr;
if (outRightNode) *outRightNode = nullptr;
// Split any matching style nodes above the node/offset // split any matching style nodes above the node/offset
OwningNonNull<nsIContent> node = *(*aNode)->AsContent(); nsCOMPtr<nsIContent> node = do_QueryInterface(*aNode);
NS_ENSURE_STATE(node);
int32_t offset;
bool useCSS = IsCSSEnabled(); bool useCSS = IsCSSEnabled();
bool isSet; bool isSet;
while (!IsBlockNode(node) && node->GetParent() && while (node && !IsBlockNode(node) && node->GetParentNode() &&
IsEditable(node->GetParent())) { IsEditable(node->GetParentNode())) {
isSet = false; isSet = false;
if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
aAttribute)) { // the HTML style defined by aProperty/aAttribute has a CSS equivalence
// The HTML style defined by aProperty/aAttribute has a CSS equivalence // in this implementation for the node; let's check if it carries those css styles
// in this implementation for the node; let's check if it carries those
// CSS styles
nsAutoString firstValue; nsAutoString firstValue;
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node), mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node),
aProperty, aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified); aProperty, aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified);
@ -589,18 +591,26 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
(!aProperty && NodeIsProperty(GetAsDOMNode(node))) || (!aProperty && NodeIsProperty(GetAsDOMNode(node))) ||
// or the style is specified in the style attribute // or the style is specified in the style attribute
isSet) { isSet) {
// Found a style node we need to split // found a style node we need to split
int32_t offset = SplitNodeDeep(*node, *(*aNode)->AsContent(), *aOffset, nsCOMPtr<nsIContent> outLeftContent, outRightContent;
EmptyContainers::yes, aOutLeftNode, nsCOMPtr<nsIContent> nodeParam = do_QueryInterface(*aNode);
aOutRightNode); NS_ENSURE_STATE(nodeParam || !*aNode);
offset = SplitNodeDeep(*node, *nodeParam, *aOffset, EmptyContainers::yes,
getter_AddRefs(outLeftContent),
getter_AddRefs(outRightContent));
NS_ENSURE_TRUE(offset != -1, NS_ERROR_FAILURE); NS_ENSURE_TRUE(offset != -1, NS_ERROR_FAILURE);
// reset startNode/startOffset // reset startNode/startOffset
*aNode = node->GetParent(); *aNode = GetAsDOMNode(node->GetParent());
*aOffset = offset; *aOffset = offset;
if (outLeftNode) {
*outLeftNode = GetAsDOMNode(outLeftContent);
}
if (outRightNode) {
*outRightNode = GetAsDOMNode(outRightContent);
}
} }
node = node->GetParent(); node = node->GetParent();
} }
return NS_OK; return NS_OK;
} }
@ -608,14 +618,11 @@ nsresult
nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset, nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
nsIAtom* aProperty, const nsAString* aAttribute) nsIAtom* aProperty, const nsAString* aAttribute)
{ {
nsCOMPtr<nsINode> node = do_QueryInterface(*aNode); nsCOMPtr<nsIDOMNode> leftNode, rightNode, tmp;
nsCOMPtr<nsIContent> leftNode, rightNode; nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty, aAttribute,
nsresult res = SplitStyleAbovePoint(address_of(node), aOffset, aProperty, address_of(leftNode),
aAttribute, getter_AddRefs(leftNode), address_of(rightNode));
getter_AddRefs(rightNode));
*aNode = GetAsDOMNode(node);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
if (leftNode) { if (leftNode) {
bool bIsEmptyNode; bool bIsEmptyNode;
IsEmptyNode(leftNode, &bIsEmptyNode, false, true); IsEmptyNode(leftNode, &bIsEmptyNode, false, true);
@ -626,7 +633,10 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
} }
} }
if (rightNode) { if (rightNode) {
nsCOMPtr<nsINode> secondSplitParent = GetLeftmostChild(rightNode); nsCOMPtr<nsINode> rightNode_ = do_QueryInterface(rightNode);
NS_ENSURE_STATE(rightNode_);
nsCOMPtr<nsIDOMNode> secondSplitParent =
GetAsDOMNode(GetLeftmostChild(rightNode_));
// don't try to split non-containers (br's, images, hr's, etc) // don't try to split non-containers (br's, images, hr's, etc)
if (!secondSplitParent) { if (!secondSplitParent) {
secondSplitParent = rightNode; secondSplitParent = rightNode;
@ -638,18 +648,21 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
NS_ENSURE_STATE(savedBR); NS_ENSURE_STATE(savedBR);
} }
secondSplitParent = secondSplitParent->GetParentNode(); secondSplitParent->GetParentNode(getter_AddRefs(tmp));
secondSplitParent = tmp;
} }
*aOffset = 0; *aOffset = 0;
res = SplitStyleAbovePoint(address_of(secondSplitParent), res = SplitStyleAbovePoint(address_of(secondSplitParent),
aOffset, aProperty, aAttribute, aOffset, aProperty, aAttribute,
getter_AddRefs(leftNode), address_of(leftNode), address_of(rightNode));
getter_AddRefs(rightNode));
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
// should be impossible to not get a new leftnode here // should be impossible to not get a new leftnode here
nsCOMPtr<nsINode> newSelParent = GetLeftmostChild(leftNode); nsCOMPtr<nsINode> leftNode_ = do_QueryInterface(leftNode);
NS_ENSURE_TRUE(leftNode_, NS_ERROR_FAILURE);
nsCOMPtr<nsINode> newSelParent = GetLeftmostChild(leftNode_);
if (!newSelParent) { if (!newSelParent) {
newSelParent = leftNode; newSelParent = do_QueryInterface(leftNode);
NS_ENSURE_STATE(newSelParent);
} }
// If rightNode starts with a br, suck it out of right node and into // If rightNode starts with a br, suck it out of right node and into
// leftNode. This is so we you don't revert back to the previous style // leftNode. This is so we you don't revert back to the previous style
@ -675,7 +688,7 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
// selection. // selection.
nsAutoTrackDOMPoint tracker(mRangeUpdater, nsAutoTrackDOMPoint tracker(mRangeUpdater,
address_of(newSelParent), &newSelOffset); address_of(newSelParent), &newSelOffset);
res = RemoveStyleInside(GetAsDOMNode(leftNode), aProperty, aAttribute); res = RemoveStyleInside(leftNode, aProperty, aAttribute);
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