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

Use tighter typing in editing: InsertParagraphSeparatorCommand / InsertTextCommand

Use tighter typing in editing/ to increase code readability. This CL focuses on
InsertParagraphSeparatorCommand / InsertTextCommand.

R=leviw@chromium.org, yosin@chromium.org

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

git-svn-id: svn://svn.chromium.org/blink/trunk@179180 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b5319893
...@@ -61,10 +61,10 @@ static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock) ...@@ -61,10 +61,10 @@ static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock)
return curBlock; return curBlock;
} }
InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& document, bool mustUseDefaultParagraphElement, bool pasteBlockqutoeIntoUnquotedArea) InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& document, bool mustUseDefaultParagraphElement, bool pasteBlockquoteIntoUnquotedArea)
: CompositeEditCommand(document) : CompositeEditCommand(document)
, m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement) , m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement)
, m_pasteBlockqutoeIntoUnquotedArea(pasteBlockqutoeIntoUnquotedArea) , m_pasteBlockquoteIntoUnquotedArea(pasteBlockquoteIntoUnquotedArea)
{ {
} }
...@@ -87,7 +87,7 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi ...@@ -87,7 +87,7 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi
m_style->mergeTypingStyle(pos.document()); m_style->mergeTypingStyle(pos.document());
} }
void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Node* originalEnclosingBlock) void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Element* originalEnclosingBlock)
{ {
// Not only do we break out of header tags, but we also do not preserve the typing style, // Not only do we break out of header tags, but we also do not preserve the typing style,
// in order to match other browsers. // in order to match other browsers.
...@@ -106,7 +106,7 @@ void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Node* originalEnc ...@@ -106,7 +106,7 @@ void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Node* originalEnc
applyStyle(m_style.get()); applyStyle(m_style.get());
} }
bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Node* enclosingBlock) const bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element* enclosingBlock) const
{ {
if (m_mustUseDefaultParagraphElement) if (m_mustUseDefaultParagraphElement)
return true; return true;
...@@ -168,7 +168,7 @@ void InsertParagraphSeparatorCommand::doApply() ...@@ -168,7 +168,7 @@ void InsertParagraphSeparatorCommand::doApply()
// FIXME: The parentAnchoredEquivalent conversion needs to be moved into enclosingBlock. // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enclosingBlock.
RefPtrWillBeRawPtr<Element> startBlock = enclosingBlock(insertionPosition.parentAnchoredEquivalent().containerNode()); RefPtrWillBeRawPtr<Element> startBlock = enclosingBlock(insertionPosition.parentAnchoredEquivalent().containerNode());
Node* listChildNode = enclosingListChild(insertionPosition.parentAnchoredEquivalent().containerNode()); Node* listChildNode = enclosingListChild(insertionPosition.parentAnchoredEquivalent().containerNode());
RefPtrWillBeRawPtr<Element> listChild = listChildNode && listChildNode->isHTMLElement() ? toHTMLElement(listChildNode) : 0; RefPtrWillBeRawPtr<HTMLElement> listChild = listChildNode && listChildNode->isHTMLElement() ? toHTMLElement(listChildNode) : 0;
Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent();
if (!startBlock if (!startBlock
|| !startBlock->nonShadowBoundaryParentNode() || !startBlock->nonShadowBoundaryParentNode()
...@@ -222,7 +222,7 @@ void InsertParagraphSeparatorCommand::doApply() ...@@ -222,7 +222,7 @@ void InsertParagraphSeparatorCommand::doApply()
if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos)) { if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos)) {
// The block is empty. Create an empty block to // The block is empty. Create an empty block to
// represent the paragraph that we're leaving. // represent the paragraph that we're leaving.
RefPtrWillBeRawPtr<Element> extraBlock = createDefaultParagraphElement(document()); RefPtrWillBeRawPtr<HTMLElement> extraBlock = createDefaultParagraphElement(document());
appendNode(extraBlock, startBlock); appendNode(extraBlock, startBlock);
appendBlockPlaceholder(extraBlock); appendBlockPlaceholder(extraBlock);
} }
...@@ -230,7 +230,7 @@ void InsertParagraphSeparatorCommand::doApply() ...@@ -230,7 +230,7 @@ void InsertParagraphSeparatorCommand::doApply()
} else { } else {
// We can get here if we pasted a copied portion of a blockquote with a newline at the end and are trying to paste it // We can get here if we pasted a copied portion of a blockquote with a newline at the end and are trying to paste it
// into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted. // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted.
if (m_pasteBlockqutoeIntoUnquotedArea) { if (m_pasteBlockquoteIntoUnquotedArea) {
if (HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNodeOfType(canonicalPos, &isMailHTMLBlockquoteElement))) if (HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNodeOfType(canonicalPos, &isMailHTMLBlockquoteElement)))
startBlock = highestBlockquote; startBlock = highestBlockquote;
} }
...@@ -242,10 +242,10 @@ void InsertParagraphSeparatorCommand::doApply() ...@@ -242,10 +242,10 @@ void InsertParagraphSeparatorCommand::doApply()
} else { } else {
// Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists). However, // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists). However,
// for div nodes, this can result in nested div tags that are hard to break out of. // for div nodes, this can result in nested div tags that are hard to break out of.
Element* siblingNode = startBlock.get(); Element* siblingElement = startBlock.get();
if (isHTMLDivElement(*blockToInsert)) if (isHTMLDivElement(*blockToInsert))
siblingNode = highestVisuallyEquivalentDivBelowRoot(startBlock.get()); siblingElement = highestVisuallyEquivalentDivBelowRoot(startBlock.get());
insertNodeAfter(blockToInsert, siblingNode); insertNodeAfter(blockToInsert, siblingElement);
} }
} }
......
...@@ -34,31 +34,31 @@ class EditingStyle; ...@@ -34,31 +34,31 @@ class EditingStyle;
class InsertParagraphSeparatorCommand FINAL : public CompositeEditCommand { class InsertParagraphSeparatorCommand FINAL : public CompositeEditCommand {
public: public:
static PassRefPtrWillBeRawPtr<InsertParagraphSeparatorCommand> create(Document& document, bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false) static PassRefPtrWillBeRawPtr<InsertParagraphSeparatorCommand> create(Document& document, bool useDefaultParagraphElement = false, bool pasteBlockquoteIntoUnquotedArea = false)
{ {
return adoptRefWillBeNoop(new InsertParagraphSeparatorCommand(document, useDefaultParagraphElement, pasteBlockqutoeIntoUnquotedArea)); return adoptRefWillBeNoop(new InsertParagraphSeparatorCommand(document, useDefaultParagraphElement, pasteBlockquoteIntoUnquotedArea));
} }
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
private: private:
InsertParagraphSeparatorCommand(Document&, bool useDefaultParagraphElement, bool pasteBlockqutoeIntoUnquotedArea); InsertParagraphSeparatorCommand(Document&, bool useDefaultParagraphElement, bool pasteBlockquoteIntoUnquotedArea);
virtual void doApply() OVERRIDE; virtual void doApply() OVERRIDE;
void calculateStyleBeforeInsertion(const Position&); void calculateStyleBeforeInsertion(const Position&);
void applyStyleAfterInsertion(Node* originalEnclosingBlock); void applyStyleAfterInsertion(Element* originalEnclosingBlock);
void getAncestorsInsideBlock(const Node* insertionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element> >& ancestors); void getAncestorsInsideBlock(const Node* insertionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element> >& ancestors);
PassRefPtrWillBeRawPtr<Element> cloneHierarchyUnderNewBlock(const WillBeHeapVector<RefPtrWillBeMember<Element> >& ancestors, PassRefPtrWillBeRawPtr<Element> blockToInsert); PassRefPtrWillBeRawPtr<Element> cloneHierarchyUnderNewBlock(const WillBeHeapVector<RefPtrWillBeMember<Element> >& ancestors, PassRefPtrWillBeRawPtr<Element> blockToInsert);
bool shouldUseDefaultParagraphElement(Node*) const; bool shouldUseDefaultParagraphElement(Element*) const;
virtual bool preservesTypingStyle() const OVERRIDE; virtual bool preservesTypingStyle() const OVERRIDE;
RefPtrWillBeMember<EditingStyle> m_style; RefPtrWillBeMember<EditingStyle> m_style;
bool m_mustUseDefaultParagraphElement; bool m_mustUseDefaultParagraphElement;
bool m_pasteBlockqutoeIntoUnquotedArea; bool m_pasteBlockquoteIntoUnquotedArea;
}; };
} }
......
...@@ -49,7 +49,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p) ...@@ -49,7 +49,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p)
{ {
Position pos = p; Position pos = p;
if (isTabHTMLSpanElementTextNode(pos.anchorNode())) { if (isTabHTMLSpanElementTextNode(pos.anchorNode())) {
RefPtrWillBeRawPtr<Node> textNode = document().createEditingTextNode(""); RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("");
insertNodeAtTabSpanPosition(textNode.get(), pos); insertNodeAtTabSpanPosition(textNode.get(), pos);
return firstPositionInNode(textNode.get()); return firstPositionInNode(textNode.get());
} }
...@@ -57,7 +57,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p) ...@@ -57,7 +57,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p)
// Prepare for text input by looking at the specified position. // Prepare for text input by looking at the specified position.
// It may be necessary to insert a text node to receive characters. // It may be necessary to insert a text node to receive characters.
if (!pos.containerNode()->isTextNode()) { if (!pos.containerNode()->isTextNode()) {
RefPtrWillBeRawPtr<Node> textNode = document().createEditingTextNode(""); RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("");
insertNodeAt(textNode.get(), pos); insertNodeAt(textNode.get(), pos);
return firstPositionInNode(textNode.get()); return firstPositionInNode(textNode.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