| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "HTMLNames.h" | 27 #include "HTMLNames.h" |
| 28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
| 29 #include "core/dom/Element.h" | 29 #include "core/dom/Element.h" |
| 30 #include "core/dom/ExceptionCodePlaceholder.h" | 30 #include "core/dom/ExceptionCodePlaceholder.h" |
| 31 #include "core/dom/Range.h" | 31 #include "core/dom/Range.h" |
| 32 #include "core/editing/FormatBlockCommand.h" | 32 #include "core/editing/FormatBlockCommand.h" |
| 33 #include "core/editing/VisibleUnits.h" | 33 #include "core/editing/VisibleUnits.h" |
| 34 #include "core/editing/htmlediting.h" | 34 #include "core/editing/htmlediting.h" |
| 35 #include "core/html/HTMLElement.h" | 35 #include "core/html/HTMLElement.h" |
| 36 #include "wtf/TableSet.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 using namespace HTMLNames; | 40 using namespace HTMLNames; |
| 40 | 41 |
| 41 static Node* enclosingBlockToSplitTreeTo(Node* startNode); | 42 static Node* enclosingBlockToSplitTreeTo(Node* startNode); |
| 42 static bool isElementForFormatBlock(const QualifiedName& tagName); | 43 static bool isElementForFormatBlock(const QualifiedName& tagName); |
| 43 static inline bool isElementForFormatBlock(Node* node) | 44 static inline bool isElementForFormatBlock(Node* node) |
| 44 { | 45 { |
| 45 return node->isElementNode() && isElementForFormatBlock(toElement(node)->tag
QName()); | 46 return node->isElementNode() && isElementForFormatBlock(toElement(node)->tag
QName()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 Element* rootEditableElement = range->startContainer()->rootEditableElement(
); | 112 Element* rootEditableElement = range->startContainer()->rootEditableElement(
); |
| 112 if (!rootEditableElement || commonAncestor->contains(rootEditableElement)) | 113 if (!rootEditableElement || commonAncestor->contains(rootEditableElement)) |
| 113 return 0; | 114 return 0; |
| 114 | 115 |
| 115 return commonAncestor->isElementNode() ? toElement(commonAncestor) : 0; | 116 return commonAncestor->isElementNode() ? toElement(commonAncestor) : 0; |
| 116 } | 117 } |
| 117 | 118 |
| 118 bool isElementForFormatBlock(const QualifiedName& tagName) | 119 bool isElementForFormatBlock(const QualifiedName& tagName) |
| 119 { | 120 { |
| 120 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, blockTags, ()); | 121 DEFINE_STATIC_LOCAL(TableSet<const QualifiedName*>, blockTags, (lessThanByIm
plAddress)); |
| 121 if (blockTags.isEmpty()) { | 122 if (blockTags.isEmpty()) { |
| 122 blockTags.add(addressTag); | 123 static const QualifiedName* blockTagNames[] = { |
| 123 blockTags.add(articleTag); | 124 &addressTag, |
| 124 blockTags.add(asideTag); | 125 &articleTag, |
| 125 blockTags.add(blockquoteTag); | 126 &asideTag, |
| 126 blockTags.add(ddTag); | 127 &blockquoteTag, |
| 127 blockTags.add(divTag); | 128 &ddTag, |
| 128 blockTags.add(dlTag); | 129 &divTag, |
| 129 blockTags.add(dtTag); | 130 &dlTag, |
| 130 blockTags.add(footerTag); | 131 &dtTag, |
| 131 blockTags.add(h1Tag); | 132 &footerTag, |
| 132 blockTags.add(h2Tag); | 133 &h1Tag, |
| 133 blockTags.add(h3Tag); | 134 &h2Tag, |
| 134 blockTags.add(h4Tag); | 135 &h3Tag, |
| 135 blockTags.add(h5Tag); | 136 &h4Tag, |
| 136 blockTags.add(h6Tag); | 137 &h5Tag, |
| 137 blockTags.add(headerTag); | 138 &h6Tag, |
| 138 blockTags.add(hgroupTag); | 139 &headerTag, |
| 139 blockTags.add(mainTag); | 140 &hgroupTag, |
| 140 blockTags.add(navTag); | 141 &mainTag, |
| 141 blockTags.add(pTag); | 142 &navTag, |
| 142 blockTags.add(preTag); | 143 &pTag, |
| 143 blockTags.add(sectionTag); | 144 &preTag, |
| 145 §ionTag, |
| 146 }; |
| 147 blockTags.init(blockTagNames, WTF_ARRAY_LENGTH(blockTagNames)); |
| 144 } | 148 } |
| 145 return blockTags.contains(tagName); | 149 return blockTags.contains(&tagName); |
| 146 } | 150 } |
| 147 | 151 |
| 148 Node* enclosingBlockToSplitTreeTo(Node* startNode) | 152 Node* enclosingBlockToSplitTreeTo(Node* startNode) |
| 149 { | 153 { |
| 150 Node* lastBlock = startNode; | 154 Node* lastBlock = startNode; |
| 151 for (Node* n = startNode; n; n = n->parentNode()) { | 155 for (Node* n = startNode; n; n = n->parentNode()) { |
| 152 if (!n->rendererIsEditable()) | 156 if (!n->rendererIsEditable()) |
| 153 return lastBlock; | 157 return lastBlock; |
| 154 if (isTableCell(n) || n->hasTagName(bodyTag) || !n->parentNode() || !n->
parentNode()->rendererIsEditable() || isElementForFormatBlock(n)) | 158 if (isTableCell(n) || n->hasTagName(bodyTag) || !n->parentNode() || !n->
parentNode()->rendererIsEditable() || isElementForFormatBlock(n)) |
| 155 return n; | 159 return n; |
| 156 if (isBlock(n)) | 160 if (isBlock(n)) |
| 157 lastBlock = n; | 161 lastBlock = n; |
| 158 if (isListElement(n)) | 162 if (isListElement(n)) |
| 159 return n->parentNode()->rendererIsEditable() ? n->parentNode() : n; | 163 return n->parentNode()->rendererIsEditable() ? n->parentNode() : n; |
| 160 } | 164 } |
| 161 return lastBlock; | 165 return lastBlock; |
| 162 } | 166 } |
| 163 | 167 |
| 164 } | 168 } |
| OLD | NEW |