Title: [92891] trunk
- Revision
- 92891
- Author
- [email protected]
- Date
- 2011-08-11 16:43:11 -0700 (Thu, 11 Aug 2011)
Log Message
Share code between isStyleSpanOrSpanWithOnlyStyleAttribute, isUnstyledStyleSpan,
isSpanWithoutAttributesOrUnstyleStyleSpan and replaceWithSpanOrRemoveIfWithoutAttributes
https://bugs.webkit.org/show_bug.cgi?id=66091
Reviewed by Tony Chang.
Source/WebCore:
Extracted common code as hasNoAttributeOrOnlyStyleAttribute. The only behavioral difference is that
replaceWithSpanOrRemoveIfWithoutAttributes will now remove elements with class="Apple-style-span",
for which I'm adding a test.
Test: editing/style/remove-styled-element-with-style-span.html
* editing/ApplyStyleCommand.cpp:
(WebCore::hasNoAttributeOrOnlyStyleAttribute):
(WebCore::isStyleSpanOrSpanWithOnlyStyleAttribute):
(WebCore::isUnstyledStyleSpan):
(WebCore::isSpanWithoutAttributesOrUnstyleStyleSpan):
(WebCore::ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes):
LayoutTests:
Added a test to ensure WebKit removes implicitly styled elements such as em, b, etc...
with class="Apple-style-span" when they're not necessary.
* editing/style/remove-styled-element-with-style-span-expected.txt: Added.
* editing/style/remove-styled-element-with-style-span.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (92890 => 92891)
--- trunk/LayoutTests/ChangeLog 2011-08-11 23:35:29 UTC (rev 92890)
+++ trunk/LayoutTests/ChangeLog 2011-08-11 23:43:11 UTC (rev 92891)
@@ -1,3 +1,17 @@
+2011-08-11 Ryosuke Niwa <[email protected]>
+
+ Share code between isStyleSpanOrSpanWithOnlyStyleAttribute, isUnstyledStyleSpan,
+ isSpanWithoutAttributesOrUnstyleStyleSpan and replaceWithSpanOrRemoveIfWithoutAttributes
+ https://bugs.webkit.org/show_bug.cgi?id=66091
+
+ Reviewed by Tony Chang.
+
+ Added a test to ensure WebKit removes implicitly styled elements such as em, b, etc...
+ with class="Apple-style-span" when they're not necessary.
+
+ * editing/style/remove-styled-element-with-style-span-expected.txt: Added.
+ * editing/style/remove-styled-element-with-style-span.html: Added.
+
2011-08-11 Tom Zakrajsek <[email protected]>
Created tests for HTMLUnknownElement interface.
Added: trunk/LayoutTests/editing/style/remove-styled-element-with-style-span-expected.txt (0 => 92891)
--- trunk/LayoutTests/editing/style/remove-styled-element-with-style-span-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/style/remove-styled-element-with-style-span-expected.txt 2011-08-11 23:43:11 UTC (rev 92891)
@@ -0,0 +1,5 @@
+This test ensures WebKit removes implicitly styled elements even if they had class="Apple-style-span". There should be no span below.
+| <i>
+| "<#selection-anchor>hello "
+| "world"
+| " WebKit<#selection-focus>"
Added: trunk/LayoutTests/editing/style/remove-styled-element-with-style-span.html (0 => 92891)
--- trunk/LayoutTests/editing/style/remove-styled-element-with-style-span.html (rev 0)
+++ trunk/LayoutTests/editing/style/remove-styled-element-with-style-span.html 2011-08-11 23:43:11 UTC (rev 92891)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="test" contenteditable>hello <em class="Apple-style-span">world</em> WebKit</div>
+<script src=""
+<script>
+
+Markup.description('This test ensures WebKit removes implicitly styled elements even if they had class="Apple-style-span".'
++ ' There should be no span below.');
+
+var test = document.getElementById('test');
+test.focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('Italic', false, null);
+
+Markup.dump(test);
+
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (92890 => 92891)
--- trunk/Source/WebCore/ChangeLog 2011-08-11 23:35:29 UTC (rev 92890)
+++ trunk/Source/WebCore/ChangeLog 2011-08-11 23:43:11 UTC (rev 92891)
@@ -1,3 +1,24 @@
+2011-08-11 Ryosuke Niwa <[email protected]>
+
+ Share code between isStyleSpanOrSpanWithOnlyStyleAttribute, isUnstyledStyleSpan,
+ isSpanWithoutAttributesOrUnstyleStyleSpan and replaceWithSpanOrRemoveIfWithoutAttributes
+ https://bugs.webkit.org/show_bug.cgi?id=66091
+
+ Reviewed by Tony Chang.
+
+ Extracted common code as hasNoAttributeOrOnlyStyleAttribute. The only behavioral difference is that
+ replaceWithSpanOrRemoveIfWithoutAttributes will now remove elements with class="Apple-style-span",
+ for which I'm adding a test.
+
+ Test: editing/style/remove-styled-element-with-style-span.html
+
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::hasNoAttributeOrOnlyStyleAttribute):
+ (WebCore::isStyleSpanOrSpanWithOnlyStyleAttribute):
+ (WebCore::isUnstyledStyleSpan):
+ (WebCore::isSpanWithoutAttributesOrUnstyleStyleSpan):
+ (WebCore::ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes):
+
2011-08-11 Tom Zakrajsek <[email protected]>
Add HTMLUnknownElement interface as defined in
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (92890 => 92891)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2011-08-11 23:35:29 UTC (rev 92890)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2011-08-11 23:43:11 UTC (rev 92891)
@@ -70,11 +70,9 @@
return elem->hasLocalName(spanAttr) && elem->getAttribute(classAttr) == styleSpanClassString();
}
-bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element)
+enum ShouldStyleAttributeBeEmpty { AllowNonEmptyStyleAttribute, StyleAttributeShouldBeEmpty };
+static bool hasNoAttributeOrOnlyStyleAttribute(const StyledElement* element, ShouldStyleAttributeBeEmpty shouldStyleAttributeBeEmpty)
{
- if (!element || !element->hasTagName(spanTag))
- return false;
-
const bool readonly = true;
NamedNodeMap* map = element->attributes(readonly);
if (!map || map->isEmpty())
@@ -83,34 +81,31 @@
unsigned matchedAttributes = 0;
if (element->fastGetAttribute(classAttr) == styleSpanClassString())
matchedAttributes++;
- if (element->hasAttribute(styleAttr))
+ if (element->hasAttribute(styleAttr) && (shouldStyleAttributeBeEmpty == AllowNonEmptyStyleAttribute
+ || !element->inlineStyleDecl() || element->inlineStyleDecl()->isEmpty()))
matchedAttributes++;
ASSERT(matchedAttributes <= map->length());
return matchedAttributes == map->length();
}
-static bool isUnstyledStyleSpan(const Node* node)
+bool isStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element)
{
- if (!node || !node->isHTMLElement() || !node->hasTagName(spanTag))
+ if (!element || !element->hasTagName(spanTag))
return false;
+ return hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(element), AllowNonEmptyStyleAttribute);
+}
- const HTMLElement* elem = static_cast<const HTMLElement*>(node);
- CSSMutableStyleDeclaration* inlineStyleDecl = elem->inlineStyleDecl();
- return (!inlineStyleDecl || inlineStyleDecl->isEmpty()) && elem->getAttribute(classAttr) == styleSpanClassString();
+static inline bool isUnstyledStyleSpan(const Node* node)
+{
+ return isStyleSpan(node) && hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(node), StyleAttributeShouldBeEmpty);
}
-static bool isSpanWithoutAttributesOrUnstyleStyleSpan(const Node* node)
+static inline bool isSpanWithoutAttributesOrUnstyleStyleSpan(const Node* node)
{
if (!node || !node->isHTMLElement() || !node->hasTagName(spanTag))
return false;
-
- const HTMLElement* elem = static_cast<const HTMLElement*>(node);
- NamedNodeMap* attributes = elem->attributes(true); // readonly
- if (attributes->isEmpty())
- return true;
-
- return isUnstyledStyleSpan(node);
+ return hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(node), StyleAttributeShouldBeEmpty);
}
static bool isEmptyFontTag(const Node *node)
@@ -855,20 +850,7 @@
void ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*& elem)
{
- bool removeNode = false;
-
- // Similar to isSpanWithoutAttributesOrUnstyleStyleSpan, but does not look for Apple-style-span.
- NamedNodeMap* attributes = elem->attributes(true); // readonly
- if (!attributes || attributes->isEmpty())
- removeNode = true;
- else if (attributes->length() == 1 && elem->hasAttribute(styleAttr)) {
- // Remove the element even if it has just style='' (this might be redundantly checked later too)
- CSSMutableStyleDeclaration* inlineStyleDecl = elem->inlineStyleDecl();
- if (!inlineStyleDecl || inlineStyleDecl->isEmpty())
- removeNode = true;
- }
-
- if (removeNode)
+ if (hasNoAttributeOrOnlyStyleAttribute(elem, StyleAttributeShouldBeEmpty))
removeNodePreservingChildren(elem);
else {
HTMLElement* newSpanElement = replaceElementWithSpanPreservingChildrenAndAttributes(elem);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes