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

Side by Side Diff: sky/engine/core/html/HTMLLinkElement.cpp

Issue 696413002: Remove HTMLLinkElement (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/core/html/HTMLLinkElement.h ('k') | sky/engine/core/html/HTMLLinkElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com)
7 * Copyright (C) 2011 Google Inc. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #include "config.h"
26 #include "core/html/HTMLLinkElement.h"
27
28 #include "core/HTMLNames.h"
29 #include "core/css/MediaList.h"
30 #include "core/css/MediaQueryEvaluator.h"
31 #include "core/css/StyleSheetContents.h"
32 #include "core/css/resolver/StyleResolver.h"
33 #include "core/dom/Attribute.h"
34 #include "core/dom/Document.h"
35 #include "core/dom/StyleEngine.h"
36 #include "core/events/Event.h"
37 #include "core/events/EventSender.h"
38 #include "core/fetch/FetchRequest.h"
39 #include "core/fetch/ResourceFetcher.h"
40 #include "core/frame/FrameView.h"
41 #include "core/frame/LocalFrame.h"
42 #include "core/html/imports/LinkImport.h"
43 #include "core/html/parser/HTMLParserIdioms.h"
44 #include "core/loader/FrameLoaderClient.h"
45 #include "core/rendering/style/RenderStyle.h"
46 #include "core/rendering/style/StyleInheritedData.h"
47 #include "platform/RuntimeEnabledFeatures.h"
48 #include "wtf/StdLibExtras.h"
49
50 namespace blink {
51
52 template <typename CharacterType>
53 static void parseSizes(const CharacterType* value, unsigned length, Vector<IntSi ze>& iconSizes)
54 {
55 enum State {
56 ParseStart,
57 ParseWidth,
58 ParseHeight
59 };
60 int width = 0;
61 unsigned start = 0;
62 unsigned i = 0;
63 State state = ParseStart;
64 bool invalid = false;
65 for (; i < length; ++i) {
66 if (state == ParseWidth) {
67 if (value[i] == 'x' || value[i] == 'X') {
68 if (i == start) {
69 invalid = true;
70 break;
71 }
72 width = charactersToInt(value + start, i - start);
73 start = i + 1;
74 state = ParseHeight;
75 } else if (value[i] < '0' || value[i] > '9') {
76 invalid = true;
77 break;
78 }
79 } else if (state == ParseHeight) {
80 if (value[i] == ' ') {
81 if (i == start) {
82 invalid = true;
83 break;
84 }
85 int height = charactersToInt(value + start, i - start);
86 iconSizes.append(IntSize(width, height));
87 start = i + 1;
88 state = ParseStart;
89 } else if (value[i] < '0' || value[i] > '9') {
90 invalid = true;
91 break;
92 }
93 } else if (state == ParseStart) {
94 if (value[i] >= '0' && value[i] <= '9') {
95 start = i;
96 state = ParseWidth;
97 } else if (value[i] != ' ') {
98 invalid = true;
99 break;
100 }
101 }
102 }
103 if (invalid || state == ParseWidth || (state == ParseHeight && start == i)) {
104 iconSizes.clear();
105 return;
106 }
107 if (state == ParseHeight && i > start) {
108 int height = charactersToInt(value + start, i - start);
109 iconSizes.append(IntSize(width, height));
110 }
111 }
112
113 static LinkEventSender& linkLoadEventSender()
114 {
115 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames: :load));
116 return sharedLoadEventSender;
117 }
118
119 void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntS ize>& iconSizes)
120 {
121 ASSERT(iconSizes.isEmpty());
122 if (value.isEmpty())
123 return;
124 if (value.is8Bit())
125 parseSizes(value.characters8(), value.length(), iconSizes);
126 else
127 parseSizes(value.characters16(), value.length(), iconSizes);
128 }
129
130 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser )
131 : HTMLElement(HTMLNames::linkTag, document)
132 , m_sizes(DOMSettableTokenList::create())
133 , m_createdByParser(createdByParser)
134 , m_isInShadowTree(false)
135 {
136 ScriptWrappable::init(this);
137 }
138
139 PassRefPtr<HTMLLinkElement> HTMLLinkElement::create(Document& document, bool cre atedByParser)
140 {
141 return adoptRef(new HTMLLinkElement(document, createdByParser));
142 }
143
144 HTMLLinkElement::~HTMLLinkElement()
145 {
146 #if !ENABLE(OILPAN)
147 m_link.clear();
148
149 if (inDocument())
150 document().styleEngine()->removeStyleSheetCandidateNode(this);
151 #endif
152
153 linkLoadEventSender().cancelEvent(this);
154 }
155
156 void HTMLLinkElement::parseAttribute(const QualifiedName& name, const AtomicStri ng& value)
157 {
158 if (name == HTMLNames::relAttr) {
159 m_relAttribute = LinkRelAttribute(value);
160 process();
161 } else if (name == HTMLNames::hrefAttr) {
162 process();
163 } else if (name == HTMLNames::typeAttr) {
164 m_type = value;
165 process();
166 } else if (name == HTMLNames::sizesAttr) {
167 m_sizes->setValue(value);
168 parseSizesAttribute(value, m_iconSizes);
169 process();
170 } else if (name == HTMLNames::mediaAttr) {
171 m_media = value.string().lower();
172 process();
173 } else {
174 HTMLElement::parseAttribute(name, value);
175 }
176 }
177
178 LinkResource* HTMLLinkElement::linkResourceToProcess()
179 {
180 bool visible = inDocument() && !m_isInShadowTree;
181 if (!visible)
182 return 0;
183
184 if (!m_link && m_relAttribute.isImport())
185 m_link = LinkImport::create(this);
186
187 return m_link.get();
188 }
189
190 LinkImport* HTMLLinkElement::linkImport() const
191 {
192 if (!m_link || m_link->type() != LinkResource::Import)
193 return 0;
194 return static_cast<LinkImport*>(m_link.get());
195 }
196
197 Document* HTMLLinkElement::import() const
198 {
199 if (LinkImport* link = linkImport())
200 return link->importedDocument();
201 return 0;
202 }
203
204 void HTMLLinkElement::process()
205 {
206 if (LinkResource* link = linkResourceToProcess())
207 link->process();
208 }
209
210 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode* insertionPoint)
211 {
212 HTMLElement::insertedInto(insertionPoint);
213 if (!insertionPoint->inDocument())
214 return InsertionDone;
215
216 m_isInShadowTree = isInShadowTree();
217 if (m_isInShadowTree)
218 return InsertionDone;
219
220 document().styleEngine()->addStyleSheetCandidateNode(this, m_createdByParser );
221
222 process();
223
224 if (m_link)
225 m_link->ownerInserted();
226
227 return InsertionDone;
228 }
229
230 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint)
231 {
232 HTMLElement::removedFrom(insertionPoint);
233 if (!insertionPoint->inDocument())
234 return;
235
236 if (m_isInShadowTree)
237 return;
238 document().styleEngine()->removeStyleSheetCandidateNode(this);
239
240 RefPtr<StyleSheet> removedSheet = sheet();
241
242 if (m_link)
243 m_link->ownerRemoved();
244
245 document().removedStyleSheet(removedSheet.get());
246 }
247
248 void HTMLLinkElement::finishParsingChildren()
249 {
250 m_createdByParser = false;
251 HTMLElement::finishParsingChildren();
252 }
253
254 void HTMLLinkElement::dispatchPendingLoadEvents()
255 {
256 linkLoadEventSender().dispatchPendingEvents();
257 }
258
259 void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender)
260 {
261 ASSERT_UNUSED(eventSender, eventSender == &linkLoadEventSender());
262 ASSERT(m_link);
263 // FIXME(sky): Remove
264 }
265
266 void HTMLLinkElement::scheduleEvent()
267 {
268 linkLoadEventSender().dispatchEventSoon(this);
269 }
270
271 bool HTMLLinkElement::isURLAttribute(const Attribute& attribute) const
272 {
273 return attribute.name().localName() == HTMLNames::hrefAttr || HTMLElement::i sURLAttribute(attribute);
274 }
275
276 bool HTMLLinkElement::hasLegalLinkAttribute(const QualifiedName& name) const
277 {
278 return name == HTMLNames::hrefAttr || HTMLElement::hasLegalLinkAttribute(nam e);
279 }
280
281 const QualifiedName& HTMLLinkElement::subResourceAttributeName() const
282 {
283 // If the link element is not css, ignore it.
284 if (equalIgnoringCase(getAttribute(HTMLNames::typeAttr), "text/css")) {
285 // FIXME: Add support for extracting links of sub-resources which
286 // are inside style-sheet such as @import, @font-face, url(), etc.
287 return HTMLNames::hrefAttr;
288 }
289 return HTMLElement::subResourceAttributeName();
290 }
291
292 KURL HTMLLinkElement::href() const
293 {
294 return document().completeURL(getAttribute(HTMLNames::hrefAttr));
295 }
296
297 const AtomicString& HTMLLinkElement::rel() const
298 {
299 return getAttribute(HTMLNames::relAttr);
300 }
301
302 const AtomicString& HTMLLinkElement::type() const
303 {
304 return getAttribute(HTMLNames::typeAttr);
305 }
306
307 bool HTMLLinkElement::async() const
308 {
309 return hasAttribute(HTMLNames::asyncAttr);
310 }
311
312 String HTMLLinkElement::as() const
313 {
314 return stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames::asAttr));
315 }
316
317 const Vector<IntSize>& HTMLLinkElement::iconSizes() const
318 {
319 return m_iconSizes;
320 }
321
322 DOMSettableTokenList* HTMLLinkElement::sizes() const
323 {
324 return m_sizes.get();
325 }
326
327 void HTMLLinkElement::trace(Visitor* visitor)
328 {
329 visitor->trace(m_link);
330 visitor->trace(m_sizes);
331 HTMLElement::trace(visitor);
332 }
333
334 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/html/HTMLLinkElement.h ('k') | sky/engine/core/html/HTMLLinkElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698