Commit afeb829a authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Use tighter typing in editing: markup

Use tighter typing in editing to increase code readability and avoid
unnecessary type checks. This CL focuses on markup.

Review URL: https://codereview.chromium.org/428823002

git-svn-id: svn://svn.chromium.org/blink/trunk@179169 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 09b16003
...@@ -2239,10 +2239,10 @@ void Element::setOuterHTML(const String& html, ExceptionState& exceptionState) ...@@ -2239,10 +2239,10 @@ void Element::setOuterHTML(const String& html, ExceptionState& exceptionState)
parent->replaceChild(fragment.release(), this, exceptionState); parent->replaceChild(fragment.release(), this, exceptionState);
RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : 0; RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : 0;
if (!exceptionState.hadException() && node && node->isTextNode()) if (!exceptionState.hadException() && node && node->isTextNode())
mergeWithNextTextNode(node.release(), exceptionState); mergeWithNextTextNode(toText(node.get()), exceptionState);
if (!exceptionState.hadException() && prev && prev->isTextNode()) if (!exceptionState.hadException() && prev && prev->isTextNode())
mergeWithNextTextNode(prev.release(), exceptionState); mergeWithNextTextNode(toText(prev.get()), exceptionState);
} }
Node* Element::insertAdjacent(const String& where, Node* newChild, ExceptionState& exceptionState) Node* Element::insertAdjacent(const String& where, Node* newChild, ExceptionState& exceptionState)
......
...@@ -493,7 +493,7 @@ Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) ...@@ -493,7 +493,7 @@ Position CompositeEditCommand::replaceSelectedTextInNode(const String& text)
{ {
Position start = endingSelection().start(); Position start = endingSelection().start();
Position end = endingSelection().end(); Position end = endingSelection().end();
if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode() || isTabSpanTextNode(start.containerNode())) if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode() || isTabHTMLSpanElementTextNode(start.containerNode()))
return Position(); return Position();
RefPtrWillBeRawPtr<Text> textNode = start.containerText(); RefPtrWillBeRawPtr<Text> textNode = start.containerText();
...@@ -529,7 +529,7 @@ void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtrWillBeRa ...@@ -529,7 +529,7 @@ void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtrWillBeRa
Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos) Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos)
{ {
if (!isTabSpanTextNode(pos.anchorNode())) if (!isTabHTMLSpanElementTextNode(pos.anchorNode()))
return pos; return pos;
switch (pos.anchorType()) { switch (pos.anchorType()) {
...@@ -1326,9 +1326,9 @@ bool CompositeEditCommand::breakOutOfEmptyListItem() ...@@ -1326,9 +1326,9 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
RefPtrWillBeRawPtr<Node> previousListNode = emptyListItem->isElementNode() ? ElementTraversal::previousSibling(*emptyListItem): emptyListItem->previousSibling(); RefPtrWillBeRawPtr<Node> previousListNode = emptyListItem->isElementNode() ? ElementTraversal::previousSibling(*emptyListItem): emptyListItem->previousSibling();
RefPtrWillBeRawPtr<Node> nextListNode = emptyListItem->isElementNode() ? ElementTraversal::nextSibling(*emptyListItem): emptyListItem->nextSibling(); RefPtrWillBeRawPtr<Node> nextListNode = emptyListItem->isElementNode() ? ElementTraversal::nextSibling(*emptyListItem): emptyListItem->nextSibling();
if (isListItem(nextListNode.get()) || isListElement(nextListNode.get())) { if (isListItem(nextListNode.get()) || isHTMLListElement(nextListNode.get())) {
// If emptyListItem follows another list item or nested list, split the list node. // If emptyListItem follows another list item or nested list, split the list node.
if (isListItem(previousListNode.get()) || isListElement(previousListNode.get())) if (isListItem(previousListNode.get()) || isHTMLListElement(previousListNode.get()))
splitElement(toElement(listNode), emptyListItem); splitElement(toElement(listNode), emptyListItem);
// If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node. // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node.
...@@ -1340,7 +1340,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem() ...@@ -1340,7 +1340,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
// When emptyListItem does not follow any list item or nested list, insert newBlock after the enclosing list node. // When emptyListItem does not follow any list item or nested list, insert newBlock after the enclosing list node.
// Remove the enclosing node if emptyListItem is the only child; otherwise just remove emptyListItem. // Remove the enclosing node if emptyListItem is the only child; otherwise just remove emptyListItem.
insertNodeAfter(newBlock, listNode); insertNodeAfter(newBlock, listNode);
removeNode(isListItem(previousListNode.get()) || isListElement(previousListNode.get()) ? emptyListItem.get() : listNode.get()); removeNode(isListItem(previousListNode.get()) || isHTMLListElement(previousListNode.get()) ? emptyListItem.get() : listNode.get());
} }
appendBlockPlaceholder(newBlock); appendBlockPlaceholder(newBlock);
......
...@@ -455,9 +455,9 @@ static int textAlignResolvingStartAndEnd(T* style) ...@@ -455,9 +455,9 @@ static int textAlignResolvingStartAndEnd(T* style)
void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude)
{ {
if (isTabSpanTextNode(node)) if (isTabHTMLSpanElementTextNode(node))
node = tabSpanElement(node)->parentNode(); node = tabSpanElement(node)->parentNode();
else if (isTabSpanElement(node)) else if (isTabHTMLSpanElement(node))
node = node->parentNode(); node = node->parentNode();
RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedStyleDeclaration::create(node); RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedStyleDeclaration::create(node);
...@@ -746,7 +746,7 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(Element* element, EditingSt ...@@ -746,7 +746,7 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(Element* element, EditingSt
CSSPropertyID propertyID = m_mutableStyle->propertyAt(i).id(); CSSPropertyID propertyID = m_mutableStyle->propertyAt(i).id();
// We don't override whitespace property of a tab span because that would collapse the tab into a space. // We don't override whitespace property of a tab span because that would collapse the tab into a space.
if (propertyID == CSSPropertyWhiteSpace && isTabSpanElement(element)) if (propertyID == CSSPropertyWhiteSpace && isTabHTMLSpanElement(element))
continue; continue;
if (propertyID == CSSPropertyWebkitTextDecorationsInEffect && inlineStyle->getPropertyCSSValue(textDecorationPropertyForEditing())) { if (propertyID == CSSPropertyWebkitTextDecorationsInEffect && inlineStyle->getPropertyCSSValue(textDecorationPropertyForEditing())) {
...@@ -1434,7 +1434,7 @@ StyleChange::StyleChange(EditingStyle* style, const Position& position) ...@@ -1434,7 +1434,7 @@ StyleChange::StyleChange(EditingStyle* style, const Position& position)
extractTextStyles(document, mutableStyle.get(), computedStyle->fixedPitchFontType()); extractTextStyles(document, mutableStyle.get(), computedStyle->fixedPitchFontType());
// Changing the whitespace style in a tab span would collapse the tab into a space. // Changing the whitespace style in a tab span would collapse the tab into a space.
if (isTabSpanTextNode(position.deprecatedNode()) || isTabSpanElement((position.deprecatedNode()))) if (isTabHTMLSpanElementTextNode(position.deprecatedNode()) || isTabHTMLSpanElement((position.deprecatedNode())))
mutableStyle->removeProperty(CSSPropertyWhiteSpace); mutableStyle->removeProperty(CSSPropertyWhiteSpace);
// If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle.
......
...@@ -161,7 +161,7 @@ Node* enclosingBlockToSplitTreeTo(Node* startNode) ...@@ -161,7 +161,7 @@ Node* enclosingBlockToSplitTreeTo(Node* startNode)
return n; return n;
if (isBlock(n)) if (isBlock(n))
lastBlock = n; lastBlock = n;
if (isListElement(n)) if (isHTMLListElement(n))
return n->parentNode()->hasEditableStyle() ? n->parentNode() : n; return n->parentNode()->hasEditableStyle() ? n->parentNode() : n;
} }
return lastBlock; return lastBlock;
......
...@@ -48,7 +48,7 @@ InsertTextCommand::InsertTextCommand(Document& document, const String& text, boo ...@@ -48,7 +48,7 @@ InsertTextCommand::InsertTextCommand(Document& document, const String& text, boo
Position InsertTextCommand::positionInsideTextNode(const Position& p) Position InsertTextCommand::positionInsideTextNode(const Position& p)
{ {
Position pos = p; Position pos = p;
if (isTabSpanTextNode(pos.anchorNode())) { if (isTabHTMLSpanElementTextNode(pos.anchorNode())) {
RefPtrWillBeRawPtr<Node> textNode = document().createEditingTextNode(""); RefPtrWillBeRawPtr<Node> textNode = document().createEditingTextNode("");
insertNodeAtTabSpanPosition(textNode.get(), pos); insertNodeAtTabSpanPosition(textNode.get(), pos);
return firstPositionInNode(textNode.get()); return firstPositionInNode(textNode.get());
...@@ -237,7 +237,7 @@ Position InsertTextCommand::insertTab(const Position& pos) ...@@ -237,7 +237,7 @@ Position InsertTextCommand::insertTab(const Position& pos)
unsigned offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0; unsigned offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0;
// keep tabs coalesced in tab span // keep tabs coalesced in tab span
if (isTabSpanTextNode(node)) { if (isTabHTMLSpanElementTextNode(node)) {
RefPtrWillBeRawPtr<Text> textNode = toText(node); RefPtrWillBeRawPtr<Text> textNode = toText(node);
insertTextIntoNode(textNode, offset, "\t"); insertTextIntoNode(textNode, offset, "\t");
return Position(textNode.release(), offset + 1); return Position(textNode.release(), offset + 1);
......
...@@ -1096,7 +1096,7 @@ void ReplaceSelectionCommand::doApply() ...@@ -1096,7 +1096,7 @@ void ReplaceSelectionCommand::doApply()
fragment.removeNode(refNode); fragment.removeNode(refNode);
Node* blockStart = enclosingBlock(insertionPos.deprecatedNode()); Node* blockStart = enclosingBlock(insertionPos.deprecatedNode());
if ((isListElement(refNode.get()) || (isLegacyAppleStyleSpan(refNode.get()) && isListElement(refNode->firstChild()))) if ((isHTMLListElement(refNode.get()) || (isLegacyAppleStyleSpan(refNode.get()) && isHTMLListElement(refNode->firstChild())))
&& blockStart && blockStart->renderer()->isListItem()) && blockStart && blockStart->renderer()->isListItem())
refNode = insertAsListItems(toHTMLElement(refNode), blockStart, insertionPos, insertedNodes); refNode = insertAsListItems(toHTMLElement(refNode), blockStart, insertionPos, insertedNodes);
else { else {
...@@ -1441,7 +1441,7 @@ Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtrWillBeRawPtr<HTMLElem ...@@ -1441,7 +1441,7 @@ Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtrWillBeRawPtr<HTMLElem
{ {
RefPtrWillBeRawPtr<HTMLElement> listElement = prpListElement; RefPtrWillBeRawPtr<HTMLElement> listElement = prpListElement;
while (listElement->hasChildren() && isListElement(listElement->firstChild()) && listElement->hasOneChild()) while (listElement->hasOneChild() && isHTMLListElement(listElement->firstChild()))
listElement = toHTMLElement(listElement->firstChild()); listElement = toHTMLElement(listElement->firstChild());
bool isStart = isStartOfParagraph(VisiblePosition(insertPos)); bool isStart = isStartOfParagraph(VisiblePosition(insertPos));
......
...@@ -559,7 +559,7 @@ PassRefPtrWillBeRawPtr<Range> createRange(Document& document, const VisiblePosit ...@@ -559,7 +559,7 @@ PassRefPtrWillBeRawPtr<Range> createRange(Document& document, const VisiblePosit
return selectedRange.release(); return selectedRange.release();
} }
bool isListElement(Node* n) bool isHTMLListElement(Node* n)
{ {
return (n && (isHTMLUListElement(*n) || isHTMLOListElement(*n) || isHTMLDListElement(*n))); return (n && (isHTMLUListElement(*n) || isHTMLOListElement(*n) || isHTMLDListElement(*n)));
} }
...@@ -697,7 +697,7 @@ Node* enclosingListChild(Node *node) ...@@ -697,7 +697,7 @@ Node* enclosingListChild(Node *node)
// FIXME: This function is inappropriately named if it starts with node instead of node->parentNode() // FIXME: This function is inappropriately named if it starts with node instead of node->parentNode()
for (Node* n = node; n && n->parentNode(); n = n->parentNode()) { for (Node* n = node; n && n->parentNode(); n = n->parentNode()) {
if (isHTMLLIElement(*n) || (isListElement(n->parentNode()) && n != root)) if (isHTMLLIElement(*n) || (isHTMLListElement(n->parentNode()) && n != root))
return n; return n;
if (n == root || isTableCell(n)) if (n == root || isTableCell(n))
return 0; return 0;
...@@ -847,7 +847,7 @@ PassRefPtrWillBeRawPtr<HTMLElement> createHTMLElement(Document& document, const ...@@ -847,7 +847,7 @@ PassRefPtrWillBeRawPtr<HTMLElement> createHTMLElement(Document& document, const
return HTMLElementFactory::createHTMLElement(tagName, document, 0, false); return HTMLElementFactory::createHTMLElement(tagName, document, 0, false);
} }
bool isTabSpanElement(const Node* node) bool isTabHTMLSpanElement(const Node* node)
{ {
if (!isHTMLSpanElement(node) || toHTMLSpanElement(node)->getAttribute(classAttr) != AppleTabSpanClass) if (!isHTMLSpanElement(node) || toHTMLSpanElement(node)->getAttribute(classAttr) != AppleTabSpanClass)
return false; return false;
...@@ -855,14 +855,14 @@ bool isTabSpanElement(const Node* node) ...@@ -855,14 +855,14 @@ bool isTabSpanElement(const Node* node)
return true; return true;
} }
bool isTabSpanTextNode(const Node* node) bool isTabHTMLSpanElementTextNode(const Node* node)
{ {
return node && node->isTextNode() && node->parentNode() && isTabSpanElement(node->parentNode()); return node && node->isTextNode() && node->parentNode() && isTabHTMLSpanElement(node->parentNode());
} }
HTMLSpanElement* tabSpanElement(const Node* node) HTMLSpanElement* tabSpanElement(const Node* node)
{ {
return isTabSpanTextNode(node) ? toHTMLSpanElement(node->parentNode()) : 0; return isTabHTMLSpanElementTextNode(node) ? toHTMLSpanElement(node->parentNode()) : 0;
} }
PassRefPtrWillBeRawPtr<HTMLSpanElement> createTabSpanElement(Document& document, PassRefPtrWillBeRawPtr<Text> prpTabTextNode) PassRefPtrWillBeRawPtr<HTMLSpanElement> createTabSpanElement(Document& document, PassRefPtrWillBeRawPtr<Text> prpTabTextNode)
......
...@@ -103,15 +103,15 @@ bool isAtomicNode(const Node*); ...@@ -103,15 +103,15 @@ bool isAtomicNode(const Node*);
bool isBlock(const Node*); bool isBlock(const Node*);
bool isInline(const Node*); bool isInline(const Node*);
bool isSpecialHTMLElement(const Node*); bool isSpecialHTMLElement(const Node*);
bool isTabSpanElement(const Node*); bool isTabHTMLSpanElement(const Node*);
bool isTabSpanTextNode(const Node*); bool isTabHTMLSpanElementTextNode(const Node*);
bool isMailHTMLBlockquoteElement(const Node*); bool isMailHTMLBlockquoteElement(const Node*);
bool isRenderedTable(const Node*); bool isRenderedTable(const Node*);
bool isRenderedTableElement(const Node*); bool isRenderedTableElement(const Node*);
bool isTableCell(const Node*); bool isTableCell(const Node*);
bool isEmptyTableCell(const Node*); bool isEmptyTableCell(const Node*);
bool isTableStructureNode(const Node*); bool isTableStructureNode(const Node*);
bool isListElement(Node*); bool isHTMLListElement(Node*);
bool isListItem(const Node*); bool isListItem(const Node*);
bool isNodeRendered(const Node*); bool isNodeRendered(const Node*);
bool isNodeVisiblyContainedWithin(Node&, const Range&); bool isNodeVisiblyContainedWithin(Node&, const Range&);
......
...@@ -68,7 +68,7 @@ String createFullMarkup(const Node*); ...@@ -68,7 +68,7 @@ String createFullMarkup(const Node*);
String createStyledMarkupForNavigationTransition(Node*); String createStyledMarkupForNavigationTransition(Node*);
String urlToMarkup(const KURL&, const String& title); String urlToMarkup(const KURL&, const String& title);
void mergeWithNextTextNode(PassRefPtrWillBeRawPtr<Node>, ExceptionState&); void mergeWithNextTextNode(Text*, ExceptionState&);
} }
......
...@@ -447,10 +447,10 @@ void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionStat ...@@ -447,10 +447,10 @@ void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionStat
RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : nullptr; RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : nullptr;
if (!exceptionState.hadException() && node && node->isTextNode()) if (!exceptionState.hadException() && node && node->isTextNode())
mergeWithNextTextNode(node.release(), exceptionState); mergeWithNextTextNode(toText(node.get()), exceptionState);
if (!exceptionState.hadException() && prev && prev->isTextNode()) if (!exceptionState.hadException() && prev && prev->isTextNode())
mergeWithNextTextNode(prev.release(), exceptionState); mergeWithNextTextNode(toText(prev.get()), exceptionState);
} }
void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style) void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment