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