Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/core/html/HTMLViewSourceDocument.cpp

Issue 23886003: Have HTMLElements / SVGElements constructors take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Another Android build fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLVideoElement.cpp ('k') | Source/core/html/ImageDocument.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 lockCompatibilityMode(); 56 lockCompatibilityMode();
57 } 57 }
58 58
59 PassRefPtr<DocumentParser> HTMLViewSourceDocument::createParser() 59 PassRefPtr<DocumentParser> HTMLViewSourceDocument::createParser()
60 { 60 {
61 return HTMLViewSourceParser::create(this, m_type); 61 return HTMLViewSourceParser::create(this, m_type);
62 } 62 }
63 63
64 void HTMLViewSourceDocument::createContainingTable() 64 void HTMLViewSourceDocument::createContainingTable()
65 { 65 {
66 RefPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(this); 66 RefPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*this);
67 parserAppendChild(html); 67 parserAppendChild(html);
68 html->lazyAttach(); 68 html->lazyAttach();
69 RefPtr<HTMLBodyElement> body = HTMLBodyElement::create(this); 69 RefPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this);
70 html->parserAppendChild(body); 70 html->parserAppendChild(body);
71 71
72 // Create a line gutter div that can be used to make sure the gutter extends down the height of the whole 72 // Create a line gutter div that can be used to make sure the gutter extends down the height of the whole
73 // document. 73 // document.
74 RefPtr<HTMLDivElement> div = HTMLDivElement::create(this); 74 RefPtr<HTMLDivElement> div = HTMLDivElement::create(*this);
75 div->setAttribute(classAttr, "webkit-line-gutter-backdrop"); 75 div->setAttribute(classAttr, "webkit-line-gutter-backdrop");
76 body->parserAppendChild(div); 76 body->parserAppendChild(div);
77 77
78 RefPtr<HTMLTableElement> table = HTMLTableElement::create(this); 78 RefPtr<HTMLTableElement> table = HTMLTableElement::create(*this);
79 body->parserAppendChild(table); 79 body->parserAppendChild(table);
80 m_tbody = HTMLTableSectionElement::create(tbodyTag, this); 80 m_tbody = HTMLTableSectionElement::create(tbodyTag, *this);
81 table->parserAppendChild(m_tbody); 81 table->parserAppendChild(m_tbody);
82 m_current = m_tbody; 82 m_current = m_tbody;
83 m_lineNumber = 0; 83 m_lineNumber = 0;
84 } 84 }
85 85
86 void HTMLViewSourceDocument::addSource(const String& source, HTMLToken& token) 86 void HTMLViewSourceDocument::addSource(const String& source, HTMLToken& token)
87 { 87 {
88 if (!m_current) 88 if (!m_current)
89 createContainingTable(); 89 createContainingTable();
90 90
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 addText(source, ""); 166 addText(source, "");
167 } 167 }
168 168
169 PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const AtomicStr ing& className) 169 PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const AtomicStr ing& className)
170 { 170 {
171 if (m_current == m_tbody) { 171 if (m_current == m_tbody) {
172 addLine(className); 172 addLine(className);
173 return m_current; 173 return m_current;
174 } 174 }
175 175
176 RefPtr<HTMLElement> span = HTMLElement::create(spanTag, this); 176 RefPtr<HTMLElement> span = HTMLElement::create(spanTag, *this);
177 span->setAttribute(classAttr, className); 177 span->setAttribute(classAttr, className);
178 m_current->parserAppendChild(span); 178 m_current->parserAppendChild(span);
179 return span.release(); 179 return span.release();
180 } 180 }
181 181
182 void HTMLViewSourceDocument::addLine(const AtomicString& className) 182 void HTMLViewSourceDocument::addLine(const AtomicString& className)
183 { 183 {
184 // Create a table row. 184 // Create a table row.
185 RefPtr<HTMLTableRowElement> trow = HTMLTableRowElement::create(this); 185 RefPtr<HTMLTableRowElement> trow = HTMLTableRowElement::create(*this);
186 m_tbody->parserAppendChild(trow); 186 m_tbody->parserAppendChild(trow);
187 187
188 // Create a cell that will hold the line number (it is generated in the styl esheet using counters). 188 // Create a cell that will hold the line number (it is generated in the styl esheet using counters).
189 RefPtr<HTMLTableCellElement> td = HTMLTableCellElement::create(tdTag, this); 189 RefPtr<HTMLTableCellElement> td = HTMLTableCellElement::create(tdTag, *this) ;
190 td->setAttribute(classAttr, "webkit-line-number"); 190 td->setAttribute(classAttr, "webkit-line-number");
191 td->setAttribute(valueAttr, String::number(++m_lineNumber)); 191 td->setAttribute(valueAttr, String::number(++m_lineNumber));
192 trow->parserAppendChild(td); 192 trow->parserAppendChild(td);
193 193
194 // Create a second cell for the line contents 194 // Create a second cell for the line contents
195 td = HTMLTableCellElement::create(tdTag, this); 195 td = HTMLTableCellElement::create(tdTag, *this);
196 td->setAttribute(classAttr, "webkit-line-content"); 196 td->setAttribute(classAttr, "webkit-line-content");
197 trow->parserAppendChild(td); 197 trow->parserAppendChild(td);
198 m_current = m_td = td; 198 m_current = m_td = td;
199 199
200 #ifdef DEBUG_LINE_NUMBERS 200 #ifdef DEBUG_LINE_NUMBERS
201 RefPtr<Text> lineNumberText = Text::create(this, String::number(parser()->li neNumber() + 1) + " "); 201 RefPtr<Text> lineNumberText = Text::create(this, String::number(parser()->li neNumber() + 1) + " ");
202 td->addChild(lineNumberText); 202 td->addChild(lineNumberText);
203 lineNumberText->lazyAttach(); 203 lineNumberText->lazyAttach();
204 #endif 204 #endif
205 205
206 // Open up the needed spans. 206 // Open up the needed spans.
207 if (!className.isEmpty()) { 207 if (!className.isEmpty()) {
208 if (className == "webkit-html-attribute-name" || className == "webkit-ht ml-attribute-value") 208 if (className == "webkit-html-attribute-name" || className == "webkit-ht ml-attribute-value")
209 m_current = addSpanWithClassName("webkit-html-tag"); 209 m_current = addSpanWithClassName("webkit-html-tag");
210 m_current = addSpanWithClassName(className); 210 m_current = addSpanWithClassName(className);
211 } 211 }
212 } 212 }
213 213
214 void HTMLViewSourceDocument::finishLine() 214 void HTMLViewSourceDocument::finishLine()
215 { 215 {
216 if (!m_current->hasChildNodes()) { 216 if (!m_current->hasChildNodes()) {
217 RefPtr<HTMLBRElement> br = HTMLBRElement::create(this); 217 RefPtr<HTMLBRElement> br = HTMLBRElement::create(*this);
218 m_current->parserAppendChild(br); 218 m_current->parserAppendChild(br);
219 } 219 }
220 m_current = m_tbody; 220 m_current = m_tbody;
221 } 221 }
222 222
223 void HTMLViewSourceDocument::addText(const String& text, const AtomicString& cla ssName) 223 void HTMLViewSourceDocument::addText(const String& text, const AtomicString& cla ssName)
224 { 224 {
225 if (text.isEmpty()) 225 if (text.isEmpty())
226 return; 226 return;
227 227
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 m_current = addSpanWithClassName(className); 260 m_current = addSpanWithClassName(className);
261 } 261 }
262 addText(text, className); 262 addText(text, className);
263 if (!className.isEmpty() && m_current != m_tbody) 263 if (!className.isEmpty() && m_current != m_tbody)
264 m_current = toElement(m_current->parentNode()); 264 m_current = toElement(m_current->parentNode());
265 return end; 265 return end;
266 } 266 }
267 267
268 PassRefPtr<Element> HTMLViewSourceDocument::addBase(const AtomicString& href) 268 PassRefPtr<Element> HTMLViewSourceDocument::addBase(const AtomicString& href)
269 { 269 {
270 RefPtr<HTMLBaseElement> base = HTMLBaseElement::create(baseTag, this); 270 RefPtr<HTMLBaseElement> base = HTMLBaseElement::create(baseTag, *this);
271 base->setAttribute(hrefAttr, href); 271 base->setAttribute(hrefAttr, href);
272 m_current->parserAppendChild(base); 272 m_current->parserAppendChild(base);
273 return base.release(); 273 return base.release();
274 } 274 }
275 275
276 PassRefPtr<Element> HTMLViewSourceDocument::addLink(const AtomicString& url, boo l isAnchor) 276 PassRefPtr<Element> HTMLViewSourceDocument::addLink(const AtomicString& url, boo l isAnchor)
277 { 277 {
278 if (m_current == m_tbody) 278 if (m_current == m_tbody)
279 addLine("webkit-html-tag"); 279 addLine("webkit-html-tag");
280 280
281 // Now create a link for the attribute value instead of a span. 281 // Now create a link for the attribute value instead of a span.
282 RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(this); 282 RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(*this);
283 const char* classValue; 283 const char* classValue;
284 if (isAnchor) 284 if (isAnchor)
285 classValue = "webkit-html-attribute-value webkit-html-external-link"; 285 classValue = "webkit-html-attribute-value webkit-html-external-link";
286 else 286 else
287 classValue = "webkit-html-attribute-value webkit-html-resource-link"; 287 classValue = "webkit-html-attribute-value webkit-html-resource-link";
288 anchor->setAttribute(classAttr, classValue); 288 anchor->setAttribute(classAttr, classValue);
289 anchor->setAttribute(targetAttr, "_blank"); 289 anchor->setAttribute(targetAttr, "_blank");
290 anchor->setAttribute(hrefAttr, url); 290 anchor->setAttribute(hrefAttr, url);
291 m_current->parserAppendChild(anchor); 291 m_current->parserAppendChild(anchor);
292 return anchor.release(); 292 return anchor.release();
293 } 293 }
294 294
295 } 295 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLVideoElement.cpp ('k') | Source/core/html/ImageDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698