HTMLElement::collectStyleForPresentationAttribute duplicates a lot of code for conten...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Feb 2015 18:42:04 +0000 (18:42 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Feb 2015 18:42:04 +0000 (18:42 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180631 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLElement.cpp

index 45c107c14dda71bc67abad6aeca94364129d9e8c..94dd8285cbdf2ca178de5923d3bf6e21054d2db9 100644 (file)
@@ -1,3 +1,16 @@
+2015-02-25  Ryosuke Niwa  <rniwa@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  <svillar@igalia.com>
 
         [CSS Grid Layout] Tracks growing beyond limits when they should not
index 5854bc98d5b0f9f580a8888e212aae08ee93c09d..8ef5fdd9a597a195f3e43938de235ef9dc4b5963 100644 (file)
@@ -167,6 +167,32 @@ static bool isLTROrRTLIgnoringCase(const AtomicString& dirAttributeValue)
     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 @@ void HTMLElement::collectStyleForPresentationAttribute(const QualifiedName& name
         else
             addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, value);
     } else if (name == contenteditableAttr) {
-        if (value.isEmpty() || equalIgnoringCase(value, "true")) {
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, CSSValueReadWrite);
-            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);
+        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, "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 @@ void HTMLElement::populateEventNameForAttributeLocalNameMap(HashMap<AtomicString
         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;