| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008, 2009, 2010 Apple 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 body->parserAppendChild(div); | 79 body->parserAppendChild(div); |
| 80 | 80 |
| 81 RefPtrWillBeRawPtr<HTMLTableElement> table = HTMLTableElement::create(*this)
; | 81 RefPtrWillBeRawPtr<HTMLTableElement> table = HTMLTableElement::create(*this)
; |
| 82 body->parserAppendChild(table); | 82 body->parserAppendChild(table); |
| 83 m_tbody = HTMLTableSectionElement::create(tbodyTag, *this); | 83 m_tbody = HTMLTableSectionElement::create(tbodyTag, *this); |
| 84 table->parserAppendChild(m_tbody); | 84 table->parserAppendChild(m_tbody); |
| 85 m_current = m_tbody; | 85 m_current = m_tbody; |
| 86 m_lineNumber = 0; | 86 m_lineNumber = 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void HTMLViewSourceDocument::addSource(const String& source, HTMLToken& token) | 89 void HTMLViewSourceDocument::addSource(const String& source, HTMLToken& token, b
ool highlight) |
| 90 { | 90 { |
| 91 if (!m_current) | 91 if (!m_current) |
| 92 createContainingTable(); | 92 createContainingTable(); |
| 93 | 93 |
| 94 switch (token.type()) { | 94 switch (token.type()) { |
| 95 case HTMLToken::Uninitialized: | 95 case HTMLToken::Uninitialized: |
| 96 ASSERT_NOT_REACHED(); | 96 ASSERT_NOT_REACHED(); |
| 97 break; | 97 break; |
| 98 case HTMLToken::DOCTYPE: | 98 case HTMLToken::DOCTYPE: |
| 99 processDoctypeToken(source, token); | 99 processDoctypeToken(source, token); |
| 100 break; | 100 break; |
| 101 case HTMLToken::EndOfFile: | 101 case HTMLToken::EndOfFile: |
| 102 processEndOfFileToken(source, token); | 102 processEndOfFileToken(source, token); |
| 103 break; | 103 break; |
| 104 case HTMLToken::StartTag: | 104 case HTMLToken::StartTag: |
| 105 case HTMLToken::EndTag: | 105 case HTMLToken::EndTag: |
| 106 processTagToken(source, token); | 106 processTagToken(source, token, highlight); |
| 107 break; | 107 break; |
| 108 case HTMLToken::Comment: | 108 case HTMLToken::Comment: |
| 109 processCommentToken(source, token); | 109 processCommentToken(source, token); |
| 110 break; | 110 break; |
| 111 case HTMLToken::Character: | 111 case HTMLToken::Character: |
| 112 processCharacterToken(source, token); | 112 processCharacterToken(source, token, highlight); |
| 113 break; | 113 break; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 void HTMLViewSourceDocument::processDoctypeToken(const String& source, HTMLToken
&) | 117 void HTMLViewSourceDocument::processDoctypeToken(const String& source, HTMLToken
&) |
| 118 { | 118 { |
| 119 m_current = addSpanWithClassName("webkit-html-doctype"); | 119 m_current = addSpanWithClassName("webkit-html-doctype"); |
| 120 addText(source, "webkit-html-doctype"); | 120 addText(source, "webkit-html-doctype"); |
| 121 m_current = m_td; | 121 m_current = m_td; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void HTMLViewSourceDocument::processEndOfFileToken(const String& source, HTMLTok
en&) | 124 void HTMLViewSourceDocument::processEndOfFileToken(const String& source, HTMLTok
en&) |
| 125 { | 125 { |
| 126 m_current = addSpanWithClassName("webkit-html-end-of-file"); | 126 m_current = addSpanWithClassName("webkit-html-end-of-file"); |
| 127 addText(source, "webkit-html-end-of-file"); | 127 addText(source, "webkit-html-end-of-file"); |
| 128 m_current = m_td; | 128 m_current = m_td; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void HTMLViewSourceDocument::processTagToken(const String& source, HTMLToken& to
ken) | 131 void HTMLViewSourceDocument::processTagToken(const String& source, HTMLToken& to
ken, bool highlight) |
| 132 { | 132 { |
| 133 m_current = addSpanWithClassName("webkit-html-tag"); | 133 m_current = addSpanWithClassName(highlight ? "webkit-html-tag-highlight" : "
webkit-html-tag"); |
| 134 | 134 |
| 135 AtomicString tagName(token.name()); | 135 AtomicString tagName(token.name()); |
| 136 | 136 |
| 137 unsigned index = 0; | 137 unsigned index = 0; |
| 138 HTMLToken::AttributeList::const_iterator iter = token.attributes().begin(); | 138 HTMLToken::AttributeList::const_iterator iter = token.attributes().begin(); |
| 139 while (index < source.length()) { | 139 while (index < source.length()) { |
| 140 if (iter == token.attributes().end()) { | 140 if (iter == token.attributes().end()) { |
| 141 // We want to show the remaining characters in the token. | 141 // We want to show the remaining characters in the token. |
| 142 index = addRange(source, index, source.length(), emptyAtom); | 142 index = addRange(source, index, source.length(), emptyAtom); |
| 143 ASSERT(index == source.length()); | 143 ASSERT(index == source.length()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 163 m_current = m_td; | 163 m_current = m_td; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void HTMLViewSourceDocument::processCommentToken(const String& source, HTMLToken
&) | 166 void HTMLViewSourceDocument::processCommentToken(const String& source, HTMLToken
&) |
| 167 { | 167 { |
| 168 m_current = addSpanWithClassName("webkit-html-comment"); | 168 m_current = addSpanWithClassName("webkit-html-comment"); |
| 169 addText(source, "webkit-html-comment"); | 169 addText(source, "webkit-html-comment"); |
| 170 m_current = m_td; | 170 m_current = m_td; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void HTMLViewSourceDocument::processCharacterToken(const String& source, HTMLTok
en&) | 173 void HTMLViewSourceDocument::processCharacterToken(const String& source, HTMLTok
en&, bool highlight) |
| 174 { | 174 { |
| 175 addText(source, ""); | 175 addText(source, "", highlight); |
| 176 } | 176 } |
| 177 | 177 |
| 178 PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const AtomicStr
ing& className) | 178 PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const AtomicStr
ing& className) |
| 179 { | 179 { |
| 180 if (m_current == m_tbody) { | 180 if (m_current == m_tbody) { |
| 181 addLine(className); | 181 addLine(className); |
| 182 return m_current; | 182 return m_current; |
| 183 } | 183 } |
| 184 | 184 |
| 185 RefPtrWillBeRawPtr<HTMLSpanElement> span = HTMLSpanElement::create(*this); | 185 RefPtrWillBeRawPtr<HTMLSpanElement> span = HTMLSpanElement::create(*this); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 216 | 216 |
| 217 void HTMLViewSourceDocument::finishLine() | 217 void HTMLViewSourceDocument::finishLine() |
| 218 { | 218 { |
| 219 if (!m_current->hasChildren()) { | 219 if (!m_current->hasChildren()) { |
| 220 RefPtrWillBeRawPtr<HTMLBRElement> br = HTMLBRElement::create(*this); | 220 RefPtrWillBeRawPtr<HTMLBRElement> br = HTMLBRElement::create(*this); |
| 221 m_current->parserAppendChild(br); | 221 m_current->parserAppendChild(br); |
| 222 } | 222 } |
| 223 m_current = m_tbody; | 223 m_current = m_tbody; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void HTMLViewSourceDocument::addText(const String& text, const AtomicString& cla
ssName) | 226 void HTMLViewSourceDocument::addText(const String& text, const AtomicString& cla
ssName, bool highlight) |
| 227 { | 227 { |
| 228 if (text.isEmpty()) | 228 if (text.isEmpty()) |
| 229 return; | 229 return; |
| 230 | 230 |
| 231 // Add in the content, splitting on newlines. | 231 // Add in the content, splitting on newlines. |
| 232 Vector<String> lines; | 232 Vector<String> lines; |
| 233 text.split('\n', true, lines); | 233 text.split('\n', true, lines); |
| 234 unsigned size = lines.size(); | 234 unsigned size = lines.size(); |
| 235 for (unsigned i = 0; i < size; i++) { | 235 for (unsigned i = 0; i < size; i++) { |
| 236 String substring = lines[i]; | 236 String substring = lines[i]; |
| 237 if (m_current == m_tbody) | 237 if (m_current == m_tbody) |
| 238 addLine(className); | 238 addLine(className); |
| 239 if (substring.isEmpty()) { | 239 if (substring.isEmpty()) { |
| 240 if (i == size - 1) | 240 if (i == size - 1) |
| 241 break; | 241 break; |
| 242 finishLine(); | 242 finishLine(); |
| 243 continue; | 243 continue; |
| 244 } | 244 } |
| 245 RefPtrWillBeRawPtr<Element> oldElement; |
| 246 if (highlight) { |
| 247 oldElement = m_current; |
| 248 m_current = addSpanWithClassName("webkit-highlight"); |
| 249 } |
| 245 m_current->parserAppendChild(Text::create(*this, substring)); | 250 m_current->parserAppendChild(Text::create(*this, substring)); |
| 251 if (highlight) |
| 252 m_current = oldElement; |
| 246 if (i < size - 1) | 253 if (i < size - 1) |
| 247 finishLine(); | 254 finishLine(); |
| 248 } | 255 } |
| 249 } | 256 } |
| 250 | 257 |
| 251 int HTMLViewSourceDocument::addRange(const String& source, int start, int end, c
onst AtomicString& className, bool isLink, bool isAnchor, const AtomicString& li
nk) | 258 int HTMLViewSourceDocument::addRange(const String& source, int start, int end, c
onst AtomicString& className, bool isLink, bool isAnchor, const AtomicString& li
nk) |
| 252 { | 259 { |
| 253 ASSERT(start <= end); | 260 ASSERT(start <= end); |
| 254 if (start == end) | 261 if (start == end) |
| 255 return start; | 262 return start; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 303 |
| 297 void HTMLViewSourceDocument::trace(Visitor* visitor) | 304 void HTMLViewSourceDocument::trace(Visitor* visitor) |
| 298 { | 305 { |
| 299 visitor->trace(m_current); | 306 visitor->trace(m_current); |
| 300 visitor->trace(m_tbody); | 307 visitor->trace(m_tbody); |
| 301 visitor->trace(m_td); | 308 visitor->trace(m_td); |
| 302 HTMLDocument::trace(visitor); | 309 HTMLDocument::trace(visitor); |
| 303 } | 310 } |
| 304 | 311 |
| 305 } | 312 } |
| OLD | NEW |