OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@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. | 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. |
6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) | 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) |
7 * Copyright (C) 2011 Google Inc. All rights reserved. | 7 * Copyright (C) 2011 Google Inc. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 29 matching lines...) Expand all Loading... | |
40 #include "core/fetch/CSSStyleSheetResource.h" | 40 #include "core/fetch/CSSStyleSheetResource.h" |
41 #include "core/fetch/FetchRequest.h" | 41 #include "core/fetch/FetchRequest.h" |
42 #include "core/fetch/ResourceFetcher.h" | 42 #include "core/fetch/ResourceFetcher.h" |
43 #include "core/frame/FrameView.h" | 43 #include "core/frame/FrameView.h" |
44 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
45 #include "core/frame/csp/ContentSecurityPolicy.h" | 45 #include "core/frame/csp/ContentSecurityPolicy.h" |
46 #include "core/html/imports/LinkImport.h" | 46 #include "core/html/imports/LinkImport.h" |
47 #include "core/loader/FrameLoader.h" | 47 #include "core/loader/FrameLoader.h" |
48 #include "core/loader/FrameLoaderClient.h" | 48 #include "core/loader/FrameLoaderClient.h" |
49 #include "wtf/StdLibExtras.h" | 49 #include "wtf/StdLibExtras.h" |
50 #include "wtf/text/StringBuffer.h" | |
50 | 51 |
51 namespace WebCore { | 52 namespace WebCore { |
52 | 53 |
53 using namespace HTMLNames; | 54 using namespace HTMLNames; |
54 | 55 |
55 static LinkEventSender& linkLoadEventSender() | 56 static LinkEventSender& linkLoadEventSender() |
56 { | 57 { |
57 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames: :load)); | 58 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames: :load)); |
58 return sharedLoadEventSender; | 59 return sharedLoadEventSender; |
59 } | 60 } |
60 | 61 |
62 void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntS ize>* iconSizes) | |
63 { | |
64 ASSERT(!iconSizes->size()); | |
Inactive
2014/03/12 23:27:13
ASSERT(iconSizes.isEmpty()); would be more readabl
michaelbai
2014/03/13 05:50:11
Done.
| |
65 if (value.isNull() || value.isEmpty()) | |
Inactive
2014/03/12 23:27:13
if (value.isEmpty())
The isNull() check is superf
michaelbai
2014/03/13 05:50:11
Done.
| |
66 return; | |
67 | |
68 enum State { | |
69 ParseStart, | |
70 ParseWidth, | |
71 ParseHeight | |
72 }; | |
73 int width = 0; | |
74 StringBuffer<UChar> buff(value.length()); | |
Inactive
2014/03/12 23:27:13
We prefer not to use abbreviations. Why do we need
michaelbai
2014/03/13 05:50:11
Can we assume the passed in |value| is always 8bit
Inactive
2014/03/14 18:24:47
I don't think you can make this assumption althoug
| |
75 unsigned buffIndex = 0; | |
Inactive
2014/03/12 23:27:13
Ditto
| |
76 int i = 0; | |
77 UChar c = value[i++]; | |
78 State state = ParseStart; | |
79 bool invalid = false; | |
80 while (c) { | |
81 if (state == ParseWidth) { | |
82 if (c >= '0' && c <= '9') { | |
83 buff[buffIndex++] = c; | |
84 } else if (c == 'x' || c == 'X') { | |
85 buff[buffIndex] = 0; | |
86 width = String(buff.characters()).toInt(); | |
87 buffIndex = 0; | |
88 state = ParseHeight; | |
89 } else { | |
90 invalid = true; | |
91 break; | |
92 } | |
93 } else if (state == ParseHeight) { | |
94 if (c >= '0' && c <= '9') { | |
95 buff[buffIndex++] = c; | |
96 } else if (c == ' ') { | |
97 buff[buffIndex] = 0; | |
98 int height = String(buff.characters()).toInt(); | |
99 iconSizes->append(IntSize(width, height)); | |
100 buffIndex = 0; | |
101 state = ParseStart; | |
102 } else { | |
103 invalid = true; | |
104 break; | |
105 } | |
106 } else if (state == ParseStart) { | |
107 if (c >= '0' && c <= '9') { | |
108 buff[buffIndex++] = c; | |
109 state = ParseWidth; | |
110 } else if (c != ' ') { | |
111 invalid = true; | |
112 break; | |
113 } | |
114 } | |
115 c = value[i++]; | |
116 } | |
117 if (invalid || state == ParseWidth || (state == ParseHeight && !buffIndex)) { | |
118 iconSizes->clear(); | |
119 return; | |
120 } | |
121 if (state == ParseHeight && buffIndex > 0) { | |
122 buff[buffIndex] = 0; | |
123 int height = String(buff.characters()).toInt(); | |
124 iconSizes->append(IntSize(width, height)); | |
125 } | |
126 } | |
127 | |
61 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser ) | 128 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser ) |
62 : HTMLElement(linkTag, document) | 129 : HTMLElement(linkTag, document) |
63 , m_linkLoader(this) | 130 , m_linkLoader(this) |
64 , m_sizes(DOMSettableTokenList::create()) | 131 , m_sizes(DOMSettableTokenList::create()) |
65 , m_createdByParser(createdByParser) | 132 , m_createdByParser(createdByParser) |
66 , m_isInShadowTree(false) | 133 , m_isInShadowTree(false) |
67 , m_beforeLoadRecurseCount(0) | 134 , m_beforeLoadRecurseCount(0) |
68 { | 135 { |
69 ScriptWrappable::init(this); | 136 ScriptWrappable::init(this); |
70 } | 137 } |
(...skipping 18 matching lines...) Expand all Loading... | |
89 if (name == relAttr) { | 156 if (name == relAttr) { |
90 m_relAttribute = LinkRelAttribute(value); | 157 m_relAttribute = LinkRelAttribute(value); |
91 process(); | 158 process(); |
92 } else if (name == hrefAttr) { | 159 } else if (name == hrefAttr) { |
93 process(); | 160 process(); |
94 } else if (name == typeAttr) { | 161 } else if (name == typeAttr) { |
95 m_type = value; | 162 m_type = value; |
96 process(); | 163 process(); |
97 } else if (name == sizesAttr) { | 164 } else if (name == sizesAttr) { |
98 m_sizes->setValue(value); | 165 m_sizes->setValue(value); |
166 parseSizesAttribute(value, &m_iconSizes); | |
99 process(); | 167 process(); |
100 } else if (name == mediaAttr) { | 168 } else if (name == mediaAttr) { |
101 m_media = value.string().lower(); | 169 m_media = value.string().lower(); |
102 process(); | 170 process(); |
103 } else if (name == disabledAttr) { | 171 } else if (name == disabledAttr) { |
104 if (LinkStyle* link = linkStyle()) | 172 if (LinkStyle* link = linkStyle()) |
105 link->setDisabledState(!value.isNull()); | 173 link->setDisabledState(!value.isNull()); |
106 } else if (name == onbeforeloadAttr) | 174 } else if (name == onbeforeloadAttr) |
107 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value)); | 175 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value)); |
108 else { | 176 else { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 const AtomicString& HTMLLinkElement::type() const | 408 const AtomicString& HTMLLinkElement::type() const |
341 { | 409 { |
342 return getAttribute(typeAttr); | 410 return getAttribute(typeAttr); |
343 } | 411 } |
344 | 412 |
345 IconType HTMLLinkElement::iconType() const | 413 IconType HTMLLinkElement::iconType() const |
346 { | 414 { |
347 return m_relAttribute.iconType(); | 415 return m_relAttribute.iconType(); |
348 } | 416 } |
349 | 417 |
350 const AtomicString& HTMLLinkElement::iconSizes() const | 418 const Vector<IntSize>& HTMLLinkElement::iconSizes() const |
351 { | 419 { |
352 return m_sizes->toString(); | 420 return m_iconSizes; |
353 } | 421 } |
354 | 422 |
355 DOMSettableTokenList* HTMLLinkElement::sizes() const | 423 DOMSettableTokenList* HTMLLinkElement::sizes() const |
356 { | 424 { |
357 return m_sizes.get(); | 425 return m_sizes.get(); |
358 } | 426 } |
359 | 427 |
360 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) | 428 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
361 { | 429 { |
362 return adoptPtr(new LinkStyle(owner)); | 430 return adoptPtr(new LinkStyle(owner)); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 void LinkStyle::ownerRemoved() | 694 void LinkStyle::ownerRemoved() |
627 { | 695 { |
628 if (m_sheet) | 696 if (m_sheet) |
629 clearSheet(); | 697 clearSheet(); |
630 | 698 |
631 if (styleSheetIsLoading()) | 699 if (styleSheetIsLoading()) |
632 removePendingSheet(RemovePendingSheetNotifyLater); | 700 removePendingSheet(RemovePendingSheetNotifyLater); |
633 } | 701 } |
634 | 702 |
635 } // namespace WebCore | 703 } // namespace WebCore |
OLD | NEW |