Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Unified Diff: Source/core/editing/markup.cpp

Issue 24278008: [oilpan] Handlify Nodes in htmlediting (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/markup.cpp
diff --git a/Source/core/editing/markup.cpp b/Source/core/editing/markup.cpp
index 784a1ef3d002273fe22d28a48c09181e1ed13f01..6ef14aa6b68a58111d57693ca2ae39020765e46b 100644
--- a/Source/core/editing/markup.cpp
+++ b/Source/core/editing/markup.cpp
@@ -169,7 +169,7 @@ void StyledMarkupAccumulator::wrapWithNode(Node* node, bool convertBlocksToInlin
{
StringBuilder markup;
if (node->isElementNode())
- appendElement(markup, adoptRawResult(toElement(node)), convertBlocksToInlines && isBlock(const_cast<Node*>(node)), rangeFullySelectsNode);
+ appendElement(markup, adoptRawResult(toElement(node)), convertBlocksToInlines && isBlock(adoptRawResult(const_cast<Node*>(node))), rangeFullySelectsNode);
else
appendStartMarkup(markup, node, 0);
m_reversedPrecedingMarkup.append(markup.toString());
@@ -367,11 +367,11 @@ Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No
next = NodeTraversal::next(n);
bool openedTag = false;
- if (isBlock(n.raw()) && canHaveChildrenForEditing(n.raw()) && next == pastEnd)
+ if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
// Don't write out empty block containers that aren't fully selected.
continue;
- if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode(n.raw()), selectTag)) {
+ if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode(n), selectTag)) {
next = NodeTraversal::nextSkippingChildren(n);
// Don't skip over pastEnd.
if (pastEnd && pastEnd->isDescendantOf(n.raw()))
@@ -428,40 +428,42 @@ Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No
return lastClosed.raw();
}
-static bool isHTMLBlockElement(const Node* node)
+static bool isHTMLBlockElement(const Handle<const Node>& node)
{
return node->hasTagName(tdTag)
|| node->hasTagName(thTag)
|| isNonTableCellHTMLBlockElement(node);
}
-static Node* ancestorToRetainStructureAndAppearanceForBlock(Node* commonAncestorBlock)
+static Result<Node> ancestorToRetainStructureAndAppearanceForBlock(const Handle<Node>& commonAncestorBlock)
{
if (!commonAncestorBlock)
- return 0;
+ return nullptr;
if (commonAncestorBlock->hasTagName(tbodyTag) || commonAncestorBlock->hasTagName(trTag)) {
Handle<ContainerNode> table = commonAncestorBlock->parentNode();
- while (table && !table->hasTagName(tableTag))
+ while (table && !table->hasTagName(tableTag)) {
+ NoHandleScope scope;
table = table->parentNode();
+ }
- return table.raw();
+ return table;
}
if (isNonTableCellHTMLBlockElement(commonAncestorBlock))
return commonAncestorBlock;
- return 0;
+ return nullptr;
}
-static inline Node* ancestorToRetainStructureAndAppearance(Node* commonAncestor)
+static inline Result<Node> ancestorToRetainStructureAndAppearance(const Handle<Node>& commonAncestor)
{
- return ancestorToRetainStructureAndAppearanceForBlock(enclosingBlock(commonAncestor).handle().raw());
+ return ancestorToRetainStructureAndAppearanceForBlock(enclosingBlock(commonAncestor));
}
-static inline Node* ancestorToRetainStructureAndAppearanceWithNoRenderer(Node* commonAncestor)
+static inline Result<Node> ancestorToRetainStructureAndAppearanceWithNoRenderer(const Handle<Node>& commonAncestor)
{
- Node* commonAncestorBlock = enclosingNodeOfType(firstPositionInOrBeforeNode(commonAncestor), isHTMLBlockElement);
+ Handle<Node> commonAncestorBlock = enclosingNodeOfType(firstPositionInOrBeforeNode(commonAncestor), isHTMLBlockElement);
return ancestorToRetainStructureAndAppearanceForBlock(commonAncestorBlock);
}
@@ -499,7 +501,7 @@ static PassRefPtr<EditingStyle> styleFromMatchedRulesAndInlineDecl(const Node* n
return style.release();
}
-static bool isElementPresentational(const Node* node)
+static bool isElementPresentational(const Handle<const Node>& node)
{
return node->hasTagName(uTag) || node->hasTagName(sTag) || node->hasTagName(strikeTag)
|| node->hasTagName(iTag) || node->hasTagName(emTag) || node->hasTagName(bTag) || node->hasTagName(strongTag);
@@ -513,12 +515,12 @@ static Node* highestAncestorToWrapMarkup(const Handle<const Range>& range, EAnno
if (shouldAnnotate == AnnotateForInterchange) {
// Include ancestors that aren't completely inside the range but are required to retain
// the structure and appearance of the copied markup.
- specialCommonAncestor = adoptRawResult(ancestorToRetainStructureAndAppearance(commonAncestor.raw()));
+ specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAncestor);
- if (Node* parentListNode = enclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode().handle().raw()), isListItem)) {
- if (WebCore::areRangesEqual(VisibleSelection::selectionFromContentsOfNode(parentListNode).toNormalizedRange(), range)) {
+ if (Handle<Node> parentListNode = enclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode()), isListItem)) {
+ if (WebCore::areRangesEqual(VisibleSelection::selectionFromContentsOfNode(parentListNode.raw()).toNormalizedRange(), range)) {
specialCommonAncestor = parentListNode->parentNode();
- while (specialCommonAncestor && !isListElement(specialCommonAncestor.raw())) {
+ while (specialCommonAncestor && !isListElement(specialCommonAncestor)) {
NoHandleScope scope;
specialCommonAncestor = specialCommonAncestor->parentNode();
}
@@ -526,13 +528,13 @@ static Node* highestAncestorToWrapMarkup(const Handle<const Range>& range, EAnno
}
// Retain the Mail quote level by including all ancestor mail block quotes.
- if (Handle<Node> highestMailBlockquote = adoptRawResult(highestEnclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode().handle().raw()), isMailBlockquote, CanCrossEditingBoundary)))
+ if (Handle<Node> highestMailBlockquote = highestEnclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode()), isMailBlockquote, CanCrossEditingBoundary))
specialCommonAncestor = highestMailBlockquote;
}
Handle<Node> checkAncestor = specialCommonAncestor ? specialCommonAncestor : commonAncestor;
if (checkAncestor->renderer()) {
- Handle<Node> newSpecialCommonAncestor = adoptRawResult(highestEnclosingNodeOfType(firstPositionInNode(checkAncestor), &isElementPresentational, CanCrossEditingBoundary, constrainingAncestor));
+ Handle<Node> newSpecialCommonAncestor = highestEnclosingNodeOfType(firstPositionInNode(checkAncestor), &isElementPresentational, CanCrossEditingBoundary, adoptRawResult(constrainingAncestor));
if (newSpecialCommonAncestor)
specialCommonAncestor = newSpecialCommonAncestor;
}
@@ -541,12 +543,12 @@ static Node* highestAncestorToWrapMarkup(const Handle<const Range>& range, EAnno
// If two or more tabs are selected, commonAncestor will be the tab span.
// In either case, if there is a specialCommonAncestor already, it will necessarily be above
// any tab span that needs to be included.
- if (!specialCommonAncestor && isTabSpanTextNode(commonAncestor.raw()))
+ if (!specialCommonAncestor && isTabSpanTextNode(commonAncestor))
specialCommonAncestor = commonAncestor->parentNode();
- if (!specialCommonAncestor && isTabSpanNode(commonAncestor.raw()))
+ if (!specialCommonAncestor && isTabSpanNode(commonAncestor))
specialCommonAncestor = commonAncestor;
- if (Handle<Node> enclosingAnchor = adoptRawResult(enclosingNodeWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag)))
+ if (Handle<Node> enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag))
specialCommonAncestor = enclosingAnchor;
return specialCommonAncestor.raw();
@@ -571,13 +573,13 @@ static String createMarkupInternal(const Handle<Document>& document, const Handl
document->updateLayoutIgnorePendingStylesheets();
- Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyTag);
- Node* fullySelectedRoot = 0;
+ Handle<Node> body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyTag);
+ Handle<Node> fullySelectedRoot;
// FIXME: Do this for all fully selected blocks, not just the body.
- if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(body).toNormalizedRange(), range))
+ if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(body.raw()).toNormalizedRange(), range))
fullySelectedRoot = body;
- Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shouldAnnotate, constrainingAncestor);
- StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange, specialCommonAncestor);
+ Handle<Node> specialCommonAncestor = adoptRawResult(highestAncestorToWrapMarkup(updatedRange, shouldAnnotate, constrainingAncestor));
+ StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange, specialCommonAncestor.raw());
Handle<Node> pastEnd = updatedRange->pastLastNode();
Handle<Node> startNode = updatedRange->firstNode();
@@ -602,7 +604,7 @@ static String createMarkupInternal(const Handle<Document>& document, const Handl
for (Handle<ContainerNode> ancestor = lastClosed->parentNode(); ancestor; ancestor = ancestor->parentNode()) {
HandleScope scope;
if (ancestor == fullySelectedRoot && !convertBlocksToInlines) {
- RefPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRulesAndInlineDecl(fullySelectedRoot);
+ RefPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRulesAndInlineDecl(fullySelectedRoot.raw());
// Bring the background attribute over, but not as an attribute because a background attribute on a div
// appears to have no effect.
@@ -737,14 +739,14 @@ Result<DocumentFragment> createFragmentFromMarkupWithContext(const Handle<Docume
positionBeforeNode(adoptRawResult(nodeAfterContext.get())).parentAnchoredEquivalent());
Handle<Node> commonAncestor = range->commonAncestorContainer(ASSERT_NO_EXCEPTION);
- Node* specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRenderer(commonAncestor.raw());
+ Handle<Node> specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRenderer(commonAncestor);
// When there's a special common ancestor outside of the fragment, we must include it as well to
// preserve the structure and appearance of the fragment. For example, if the fragment contains
// TD, we need to include the enclosing TABLE tag as well.
Handle<DocumentFragment> fragment = DocumentFragment::create(document);
if (specialCommonAncestor)
- fragment->appendChild(adoptRawResult(specialCommonAncestor), ASSERT_NO_EXCEPTION);
+ fragment->appendChild(specialCommonAncestor, ASSERT_NO_EXCEPTION);
else
fragment->takeAllChildrenFrom(toContainerNode(commonAncestor));
@@ -811,7 +813,7 @@ bool isPlainTextMarkup(Node *node)
if (node->childNodeCount() == 1 && (node->firstChild()->isTextNode() || (node->firstChild()->firstChild())))
return true;
- return (node->childNodeCount() == 2 && isTabSpanTextNode(node->firstChild()->firstChild().handle().raw()) && node->firstChild()->nextSibling()->isTextNode());
+ return (node->childNodeCount() == 2 && isTabSpanTextNode(node->firstChild()->firstChild()) && node->firstChild()->nextSibling()->isTextNode());
}
Result<DocumentFragment> createFragmentFromText(const Handle<Range>& context, const String& text)
@@ -854,7 +856,7 @@ Result<DocumentFragment> createFragmentFromText(const Handle<Range>& context, co
}
// Break string into paragraphs. Extra line breaks turn into empty paragraphs.
- Handle<Node> blockNode = enclosingBlock(context->firstNode().handle().raw());
+ Handle<Node> blockNode = enclosingBlock(context->firstNode());
Handle<Element> block = toElement(blockNode);
bool useClonesOfEnclosingBlock = blockNode
&& blockNode->isElementNode()

Powered by Google App Engine
This is Rietveld 408576698