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

Use tighter typing in editing: FormatBlockCommand / FrameSelection

Use tighter typing in editing/ to increase code readability. This CL focuses
on FormatBlockCommand / FrameSelection.

R=leviw@chromium.org

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

git-svn-id: svn://svn.chromium.org/blink/trunk@179170 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent afeb829a
......@@ -60,12 +60,12 @@ void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection
m_didApply = true;
}
void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockNode)
void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockElement)
{
Element* refNode = enclosingBlockFlowElement(VisiblePosition(end));
Element* refElement = enclosingBlockFlowElement(VisiblePosition(end));
Element* root = editableRootForPosition(start);
// Root is null for elements with contenteditable=false.
if (!root || !refNode)
if (!root || !refElement)
return;
Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.deprecatedNode());
......@@ -73,30 +73,30 @@ void FormatBlockCommand::formatRange(const Position& start, const Position& end,
RefPtrWillBeRawPtr<Node> nodeAfterInsertionPosition = outerBlock;
RefPtrWillBeRawPtr<Range> range = Range::create(document(), start, endOfSelection);
if (isElementForFormatBlock(refNode->tagQName()) && VisiblePosition(start) == startOfBlock(VisiblePosition(start))
&& (VisiblePosition(end) == endOfBlock(VisiblePosition(end)) || isNodeVisiblyContainedWithin(*refNode, *range))
&& refNode != root && !root->isDescendantOf(refNode)) {
if (isElementForFormatBlock(refElement->tagQName()) && VisiblePosition(start) == startOfBlock(VisiblePosition(start))
&& (VisiblePosition(end) == endOfBlock(VisiblePosition(end)) || isNodeVisiblyContainedWithin(*refElement, *range))
&& refElement != root && !root->isDescendantOf(refElement)) {
// Already in a block element that only contains the current paragraph
if (refNode->hasTagName(tagName()))
if (refElement->hasTagName(tagName()))
return;
nodeAfterInsertionPosition = refNode;
nodeAfterInsertionPosition = refElement;
}
if (!blockNode) {
if (!blockElement) {
// Create a new blockquote and insert it as a child of the root editable element. We accomplish
// this by splitting all parents of the current paragraph up to that point.
blockNode = createBlockElement();
insertNodeBefore(blockNode, nodeAfterInsertionPosition);
blockElement = createBlockElement();
insertNodeBefore(blockElement, nodeAfterInsertionPosition);
}
Position lastParagraphInBlockNode = blockNode->lastChild() ? positionAfterNode(blockNode->lastChild()) : Position();
Position lastParagraphInBlockNode = blockElement->lastChild() ? positionAfterNode(blockElement->lastChild()) : Position();
bool wasEndOfParagraph = isEndOfParagraph(VisiblePosition(lastParagraphInBlockNode));
moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), blockNode.get(), outerBlock.get());
moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), blockElement.get(), outerBlock.get());
// Copy the inline style of the original block element to the newly created block-style element.
if (outerBlock.get() != nodeAfterInsertionPosition.get() && toHTMLElement(nodeAfterInsertionPosition.get())->hasAttribute(styleAttr))
blockNode->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPosition.get())->getAttribute(styleAttr));
blockElement->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPosition.get())->getAttribute(styleAttr));
if (wasEndOfParagraph && !isEndOfParagraph(VisiblePosition(lastParagraphInBlockNode)) && !isStartOfParagraph(VisiblePosition(lastParagraphInBlockNode)))
insertBlockPlaceholder(lastParagraphInBlockNode);
......
......@@ -121,7 +121,7 @@ Element* FrameSelection::rootEditableElementOrDocumentElement() const
return selectionRoot ? selectionRoot : m_frame->document()->documentElement();
}
Node* FrameSelection::rootEditableElementOrTreeScopeRootNode() const
ContainerNode* FrameSelection::rootEditableElementOrTreeScopeRootNode() const
{
Element* selectionRoot = m_selection.rootEditableElement();
if (selectionRoot)
......@@ -1353,7 +1353,7 @@ void FrameSelection::selectFrameElementInParentIfFullySelected()
// Get to the <iframe> or <frame> (or even <object>) element in the parent frame.
// FIXME: Doesn't work for OOPI.
Element* ownerElement = m_frame->deprecatedLocalOwner();
HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
if (!ownerElement)
return;
ContainerNode* ownerElementParent = ownerElement->parentNode();
......@@ -1631,7 +1631,7 @@ bool FrameSelection::shouldBlinkCaret() const
if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled())
return false;
Node* root = rootEditableElement();
Element* root = rootEditableElement();
if (!root)
return false;
......@@ -1820,10 +1820,10 @@ void FrameSelection::setSelectionFromNone()
if (!isNone() || !(document->hasEditableStyle() || caretBrowsing))
return;
Node* node = document->documentElement();
if (!node)
Element* documentElement = document->documentElement();
if (!documentElement)
return;
Node* body = isHTMLBodyElement(*node) ? node : Traversal<HTMLBodyElement>::next(*node);
HTMLBodyElement* body = isHTMLBodyElement(*documentElement) ? toHTMLBodyElement(documentElement) : Traversal<HTMLBodyElement>::next(*documentElement);
if (body)
setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), DOWNSTREAM));
}
......
......@@ -92,7 +92,7 @@ public:
Element* rootEditableElement() const { return m_selection.rootEditableElement(); }
Element* rootEditableElementOrDocumentElement() const;
Node* rootEditableElementOrTreeScopeRootNode() const;
ContainerNode* rootEditableElementOrTreeScopeRootNode() const;
bool hasEditableStyle() const { return m_selection.hasEditableStyle(); }
bool isContentEditable() const { return m_selection.isContentEditable(); }
......
......@@ -367,7 +367,7 @@ PlainTextRange InputMethodController::getSelectionOffsets() const
RefPtrWillBeRawPtr<Range> range = m_frame.selection().selection().firstRange();
if (!range)
return PlainTextRange();
Node* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode();
ContainerNode* editable = m_frame.selection().rootEditableElementOrTreeScopeRootNode();
ASSERT(editable);
return PlainTextRange::create(*editable, *range.get());
}
......
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