Title: [180631] trunk/Source/WebCore
Revision
180631
Author
rn...@webkit.org
Date
2015-02-25 10:42:04 -0800 (Wed, 25 Feb 2015)

Log Message

HTMLElement::collectStyleForPresentationAttribute duplicates a lot of code for contentEditableAttr
https://bugs.webkit.org/show_bug.cgi?id=142003

Reviewed by Sam Weinig.

Utilized contentEditableType to reduce the code duplication.

* html/HTMLElement.cpp:
(WebCore::contentEditableType): Moved and added a version that takes AtomicString.
(WebCore::HTMLElement::collectStyleForPresentationAttribute):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (180630 => 180631)


--- trunk/Source/WebCore/ChangeLog	2015-02-25 17:43:40 UTC (rev 180630)
+++ trunk/Source/WebCore/ChangeLog	2015-02-25 18:42:04 UTC (rev 180631)
@@ -1,3 +1,16 @@
+2015-02-25  Ryosuke Niwa  <rn...@webkit.org>
+
+        HTMLElement::collectStyleForPresentationAttribute duplicates a lot of code for contentEditableAttr
+        https://bugs.webkit.org/show_bug.cgi?id=142003
+
+        Reviewed by Sam Weinig.
+
+        Utilized contentEditableType to reduce the code duplication.
+
+        * html/HTMLElement.cpp:
+        (WebCore::contentEditableType): Moved and added a version that takes AtomicString.
+        (WebCore::HTMLElement::collectStyleForPresentationAttribute):
+
 2015-02-25  Sergio Villar Senin  <svil...@igalia.com>
 
         [CSS Grid Layout] Tracks growing beyond limits when they should not

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (180630 => 180631)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2015-02-25 17:43:40 UTC (rev 180630)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2015-02-25 18:42:04 UTC (rev 180631)
@@ -167,6 +167,32 @@
     return equalIgnoringCase(dirAttributeValue, "rtl") || equalIgnoringCase(dirAttributeValue, "ltr");
 }
 
+enum class ContentEditableType {
+    Inherit,
+    True,
+    False,
+    PlaintextOnly
+};
+
+static inline ContentEditableType contentEditableType(const AtomicString& value)
+{
+    if (value.isNull())
+        return ContentEditableType::Inherit;
+    if (value.isEmpty() || equalIgnoringCase(value, "true"))
+        return ContentEditableType::True;
+    if (equalIgnoringCase(value, "false"))
+        return ContentEditableType::False;
+    if (equalIgnoringCase(value, "plaintext-only"))
+        return ContentEditableType::PlaintextOnly;
+
+    return ContentEditableType::Inherit;
+}
+
+static ContentEditableType contentEditableType(const HTMLElement& element)
+{
+    return contentEditableType(element.fastGetAttribute(contenteditableAttr));
+}
+
 void HTMLElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style)
 {
     if (name == alignAttr) {
@@ -175,24 +201,26 @@
         else
             addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, value);
     } else if (name == contenteditableAttr) {
-        if (value.isEmpty() || equalIgnoringCase(value, "true")) {
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, CSSValueReadWrite);
+        CSSValueID userModifyValue = CSSValueReadWrite;
+        switch (contentEditableType(value)) {
+        case ContentEditableType::Inherit:
+            return;
+        case ContentEditableType::False:
+            userModifyValue = CSSValueReadOnly;
+            break;
+        case ContentEditableType::PlaintextOnly:
+            userModifyValue = CSSValueReadWritePlaintextOnly;
+            FALLTHROUGH;
+        case ContentEditableType::True:
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWordWrap, CSSValueBreakWord);
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitNbspMode, CSSValueSpace);
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLineBreak, CSSValueAfterWhiteSpace);
 #if PLATFORM(IOS)
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitTextSizeAdjust, CSSValueNone);
 #endif
-        } else if (equalIgnoringCase(value, "plaintext-only")) {
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, CSSValueReadWritePlaintextOnly);
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWordWrap, CSSValueBreakWord);
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitNbspMode, CSSValueSpace);
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLineBreak, CSSValueAfterWhiteSpace);
-#if PLATFORM(IOS)
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitTextSizeAdjust, CSSValueNone);
-#endif
-        } else if (equalIgnoringCase(value, "false"))
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, CSSValueReadOnly);
+            break;
+        }
+        addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, userModifyValue);
     } else if (name == hiddenAttr) {
         addPropertyToPresentationAttributeStyle(style, CSSPropertyDisplay, CSSValueNone);
     } else if (name == draggableAttr) {
@@ -339,29 +367,6 @@
         map.add(customTable[i].attributeName.localName().impl(), customTable[i].eventName);
 }
 
-enum class ContentEditableType {
-    Inherit,
-    True,
-    False,
-    PlaintextOnly
-};
-
-static ContentEditableType contentEditableType(const HTMLElement& element)
-{
-    const AtomicString& value = element.fastGetAttribute(contenteditableAttr);
-
-    if (value.isNull())
-        return ContentEditableType::Inherit;
-    if (value.isEmpty() || equalIgnoringCase(value, "true"))
-        return ContentEditableType::True;
-    if (equalIgnoringCase(value, "false"))
-        return ContentEditableType::False;
-    if (equalIgnoringCase(value, "plaintext-only"))
-        return ContentEditableType::PlaintextOnly;
-
-    return ContentEditableType::Inherit;
-}
-
 bool HTMLElement::matchesReadWritePseudoClass() const
 {
     const Element* currentElement = this;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to