Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp

Issue 2102913002: Remove style spans to follow the styles of the block element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use of assert_selection() Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/deleting/merge-paragraph-from-p-with-style-3-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp b/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
index cfbeebd84a333bfa091068ee7b29239729958a04..65e1689266a3d1b9a015d149020c55068741c029 100644
--- a/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
@@ -35,6 +35,7 @@
#include "core/dom/Document.h"
#include "core/dom/DocumentFragment.h"
#include "core/dom/Element.h"
+#include "core/dom/NodeComputedStyle.h"
#include "core/dom/Text.h"
#include "core/editing/EditingUtilities.h"
#include "core/editing/FrameSelection.h"
@@ -794,6 +795,23 @@ static void removeHeadContents(ReplacementFragment& fragment)
}
}
+static bool followBlockElementStyle(const Node* node)
+{
+ if (!node->isHTMLElement())
+ return false;
+
+ const HTMLElement& element = toHTMLElement(*node);
+ return element.computedStyle()->display() == LIST_ITEM
+ || element.computedStyle()->display() == TABLE_CELL
+ || element.hasTagName(preTag)
+ || element.hasTagName(h1Tag)
+ || element.hasTagName(h2Tag)
+ || element.hasTagName(h3Tag)
+ || element.hasTagName(h4Tag)
+ || element.hasTagName(h5Tag)
+ || element.hasTagName(h6Tag);
+}
+
// Remove style spans before insertion if they are unnecessary. It's faster because we'll
// avoid doing a layout.
static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos)
@@ -807,10 +825,19 @@ static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
if (isMailPasteAsQuotationHTMLBlockQuoteElement(topNode) || enclosingNodeOfType(firstPositionInOrBeforeNode(topNode), isMailHTMLBlockquoteElement, CanCrossEditingBoundary))
return false;
- // Remove style spans to follow the styles of list item when |fragment| becomes a list item.
- // See bug http://crbug.com/335955.
+ // Remove style spans to follow the styles of parent block element when |fragment| becomes a part of it.
+ // See bugs http://crbug.com/226941 and http://crbug.com/335955.
HTMLSpanElement* wrappingStyleSpan = toHTMLSpanElement(topNode);
- if (isListItem(enclosingBlock(insertionPos.anchorNode()))) {
+ const Node* node = insertionPos.anchorNode();
+ // |node| can be an inline element like <br> under <li>
+ // e.g.) editing/execCommand/switch-list-type.html
+ // editing/deleting/backspace-merge-into-block.html
+ if (node->computedStyle()->display() == INLINE) {
+ if (!(node = enclosingBlock(insertionPos.anchorNode())))
+ return false;
+ }
+
+ if (followBlockElementStyle(node)) {
fragment.removeNodePreservingChildren(wrappingStyleSpan);
return true;
}
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/deleting/merge-paragraph-from-p-with-style-3-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698