2009-08-18 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Aug 2009 08:11:01 +0000 (08:11 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Aug 2009 08:11:01 +0000 (08:11 +0000)
        Reviewed by Oliver Hunt.

        convert FormatBlock candidate tag list from if chain to hash lookup
        https://bugs.webkit.org/show_bug.cgi?id=28448

        No behavior change, just cleanup.

        * editing/htmlediting.cpp:
        (WebCore::validBlockTag):
        * editing/htmlediting.h:

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

LayoutTests/fast/html/nav-element.html
WebCore/ChangeLog
WebCore/editing/htmlediting.cpp
WebCore/editing/htmlediting.h

index 573e416472fb68ee834641e38c144d2cbab41575..8aa74ba59a1cb9f6117198e60ca0e975a3476f06 100644 (file)
@@ -49,7 +49,7 @@ Test of FormatBlock behavior. This text should have a green border.
 var ed = document.getElementById("editable");
 var selection = window.getSelection();
 selection.selectAllChildren(ed);
-document.execCommand("FormatBlock", false, "nav");
+document.execCommand("FormatBlock", false, null);
 selection.collapse();
 ed.blur();
 
index 24bd291cb676e7b893054e97a8be442afed0320d..f3589f38efb6215ed9aaccaa9dbc225de3dc2f0a 100644 (file)
@@ -1,3 +1,16 @@
+2009-08-18  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        convert FormatBlock candidate tag list from if chain to hash lookup
+        https://bugs.webkit.org/show_bug.cgi?id=28448
+
+        No behavior change, just cleanup.
+
+        * editing/htmlediting.cpp:
+        (WebCore::validBlockTag):
+        * editing/htmlediting.h:
+
 2009-08-19  Mike Fenton  <mike.fenton@torchmobile.com>
 
         Reviewed by Eric Seidel.
index da1b1fe669276f4d495919ffccff4f937280bb16..09b28af0386b8fe2620034100f2107a419fd7602 100644 (file)
@@ -459,26 +459,30 @@ bool isSpecialElement(const Node *n)
 }
 
 // Checks if a string is a valid tag for the FormatBlockCommand function of execCommand. Expects lower case strings.
-bool validBlockTag(const String& blockTag)
-{
-    // FIXME: convert this to a HashSet
-    if (blockTag == "address" ||
-        blockTag == "blockquote" ||
-        blockTag == "dd" ||
-        blockTag == "div" ||
-        blockTag == "dl" ||
-        blockTag == "dt" ||
-        blockTag == "h1" ||
-        blockTag == "h2" ||
-        blockTag == "h3" ||
-        blockTag == "h4" ||
-        blockTag == "h5" ||
-        blockTag == "h6" ||
-        blockTag == "nav" ||
-        blockTag == "p" ||
-        blockTag == "pre")
-        return true;
-    return false;
+bool validBlockTag(const AtomicString& blockTag)
+{
+    if (blockTag.isEmpty())
+        return false;
+
+    DEFINE_STATIC_LOCAL(HashSet<AtomicString>, blockTags, ());
+    if (blockTags.isEmpty()) {
+        blockTags.add(addressTag.localName());
+        blockTags.add(blockquoteTag.localName());
+        blockTags.add(ddTag.localName());
+        blockTags.add(divTag.localName());
+        blockTags.add(dlTag.localName());
+        blockTags.add(dtTag.localName());
+        blockTags.add(h1Tag.localName());
+        blockTags.add(h2Tag.localName());
+        blockTags.add(h3Tag.localName());
+        blockTags.add(h4Tag.localName());
+        blockTags.add(h5Tag.localName());
+        blockTags.add(h6Tag.localName());
+        blockTags.add(navTag.localName());
+        blockTags.add(pTag.localName());
+        blockTags.add(preTag.localName());
+    }
+    return blockTags.contains(blockTag);
 }
 
 static Node* firstInSpecialElement(const Position& pos)
index f98b14911f88e2891b65817e9aa6c655d789d46a..55002e18cadec0db97ec81f724308b7279f1f5b9 100644 (file)
@@ -81,7 +81,7 @@ PassRefPtr<Range> avoidIntersectionWithNode(const Range*, Node*);
 VisibleSelection avoidIntersectionWithNode(const VisibleSelection&, Node*);
 
 bool isSpecialElement(const Node*);
-bool validBlockTag(const String&);
+bool validBlockTag(const AtomicString&);
 
 PassRefPtr<HTMLElement> createDefaultParagraphElement(Document*);
 PassRefPtr<HTMLElement> createBreakElement(Document*);