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

Use tighter typing in editing: DeleteSelectionCommand

Use tighter typing in editing to increase code readability.
This CL focuses on DeleteSelectionCommand.

R=leviw@chromium.org

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

git-svn-id: svn://svn.chromium.org/blink/trunk@179072 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d06347df
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include "core/events/ScopedEventQueue.h" #include "core/events/ScopedEventQueue.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/html/HTMLBRElement.h" #include "core/html/HTMLBRElement.h"
#include "core/html/HTMLDivElement.h"
#include "core/html/HTMLElement.h" #include "core/html/HTMLElement.h"
#include "core/html/HTMLSpanElement.h" #include "core/html/HTMLSpanElement.h"
#include "core/rendering/InlineTextBox.h" #include "core/rendering/InlineTextBox.h"
...@@ -293,11 +294,12 @@ bool CompositeEditCommand::isRemovableBlock(const Node* node) ...@@ -293,11 +294,12 @@ bool CompositeEditCommand::isRemovableBlock(const Node* node)
if (!isHTMLDivElement(*node)) if (!isHTMLDivElement(*node))
return false; return false;
ContainerNode* parentNode = node->parentNode(); const HTMLDivElement& element = toHTMLDivElement(*node);
ContainerNode* parentNode = element.parentNode();
if (parentNode && parentNode->firstChild() != parentNode->lastChild()) if (parentNode && parentNode->firstChild() != parentNode->lastChild())
return false; return false;
if (!toElement(node)->hasAttributes()) if (!element.hasAttributes())
return true; return true;
return false; return false;
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/html/HTMLBRElement.h" #include "core/html/HTMLBRElement.h"
#include "core/html/HTMLInputElement.h" #include "core/html/HTMLInputElement.h"
#include "core/html/HTMLStyleElement.h"
#include "core/html/HTMLTableRowElement.h"
#include "core/rendering/RenderTableCell.h" #include "core/rendering/RenderTableCell.h"
#include "core/rendering/RenderText.h" #include "core/rendering/RenderText.h"
...@@ -178,8 +180,8 @@ void DeleteSelectionCommand::initializePositionData() ...@@ -178,8 +180,8 @@ void DeleteSelectionCommand::initializePositionData()
m_startRoot = editableRootForPosition(start); m_startRoot = editableRootForPosition(start);
m_endRoot = editableRootForPosition(end); m_endRoot = editableRootForPosition(end);
m_startTableRow = enclosingNodeOfType(start, &isHTMLTableRowElement); m_startTableRow = toHTMLTableRowElement(enclosingNodeOfType(start, &isHTMLTableRowElement));
m_endTableRow = enclosingNodeOfType(end, &isHTMLTableRowElement); m_endTableRow = toHTMLTableRowElement(enclosingNodeOfType(end, &isHTMLTableRowElement));
// Don't move content out of a table cell. // Don't move content out of a table cell.
// If the cell is non-editable, enclosingNodeOfType won't return it by default, so // If the cell is non-editable, enclosingNodeOfType won't return it by default, so
...@@ -400,7 +402,7 @@ void DeleteSelectionCommand::removeNode(PassRefPtrWillBeRawPtr<Node> node, Shoul ...@@ -400,7 +402,7 @@ void DeleteSelectionCommand::removeNode(PassRefPtrWillBeRawPtr<Node> node, Shoul
CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable); CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable);
} }
static void updatePositionForTextRemoval(Node* node, int offset, int count, Position& position) static void updatePositionForTextRemoval(Text* node, int offset, int count, Position& position)
{ {
if (position.anchorType() != Position::PositionIsOffsetInAnchor || position.containerNode() != node) if (position.anchorType() != Position::PositionIsOffsetInAnchor || position.containerNode() != node)
return; return;
...@@ -428,9 +430,10 @@ void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr ...@@ -428,9 +430,10 @@ void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPr
RefPtrWillBeRawPtr<Node> node = range->firstNode(); RefPtrWillBeRawPtr<Node> node = range->firstNode();
while (node && node != range->pastLastNode()) { while (node && node != range->pastLastNode()) {
RefPtrWillBeRawPtr<Node> nextNode = NodeTraversal::next(*node); RefPtrWillBeRawPtr<Node> nextNode = NodeTraversal::next(*node);
if ((isHTMLStyleElement(*node) && !(toElement(node)->hasAttribute(scopedAttr))) || isHTMLLinkElement(*node)) { if ((isHTMLStyleElement(*node) && !toHTMLStyleElement(node)->hasAttribute(scopedAttr))
|| isHTMLLinkElement(*node)) {
nextNode = NodeTraversal::nextSkippingChildren(*node); nextNode = NodeTraversal::nextSkippingChildren(*node);
RefPtrWillBeRawPtr<ContainerNode> rootEditableElement = node->rootEditableElement(); RefPtrWillBeRawPtr<Element> rootEditableElement = node->rootEditableElement();
if (rootEditableElement.get()) { if (rootEditableElement.get()) {
removeNode(node); removeNode(node);
appendNode(node, rootEditableElement); appendNode(node, rootEditableElement);
...@@ -758,9 +761,9 @@ void DeleteSelectionCommand::clearTransientState() ...@@ -758,9 +761,9 @@ void DeleteSelectionCommand::clearTransientState()
void DeleteSelectionCommand::removeRedundantBlocks() void DeleteSelectionCommand::removeRedundantBlocks()
{ {
Node* node = m_endingPosition.containerNode(); Node* node = m_endingPosition.containerNode();
Node* rootNode = node->rootEditableElement(); Element* rootElement = node->rootEditableElement();
while (node != rootNode) { while (node != rootElement) {
if (isRemovableBlock(node)) { if (isRemovableBlock(node)) {
if (node == m_endingPosition.anchorNode()) if (node == m_endingPosition.anchorNode())
updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node); updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
namespace blink { namespace blink {
class EditingStyle; class EditingStyle;
class HTMLTableRowElement;
class DeleteSelectionCommand FINAL : public CompositeEditCommand { class DeleteSelectionCommand FINAL : public CompositeEditCommand {
public: public:
...@@ -92,10 +93,10 @@ private: ...@@ -92,10 +93,10 @@ private:
RefPtrWillBeMember<Node> m_endBlock; RefPtrWillBeMember<Node> m_endBlock;
RefPtrWillBeMember<EditingStyle> m_typingStyle; RefPtrWillBeMember<EditingStyle> m_typingStyle;
RefPtrWillBeMember<EditingStyle> m_deleteIntoBlockquoteStyle; RefPtrWillBeMember<EditingStyle> m_deleteIntoBlockquoteStyle;
RefPtrWillBeMember<Node> m_startRoot; RefPtrWillBeMember<Element> m_startRoot;
RefPtrWillBeMember<Node> m_endRoot; RefPtrWillBeMember<Element> m_endRoot;
RefPtrWillBeMember<Node> m_startTableRow; RefPtrWillBeMember<HTMLTableRowElement> m_startTableRow;
RefPtrWillBeMember<Node> m_endTableRow; RefPtrWillBeMember<HTMLTableRowElement> m_endTableRow;
RefPtrWillBeMember<Node> m_temporaryPlaceholder; RefPtrWillBeMember<Node> m_temporaryPlaceholder;
}; };
......
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