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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 50 |
51 namespace WebCore { | 51 namespace WebCore { |
52 | 52 |
53 using namespace HTMLNames; | 53 using namespace HTMLNames; |
54 | 54 |
| 55 template <typename CharacterType> |
| 56 static void parseSizes(const CharacterType* value, unsigned length, Vector<IntSi
ze>& iconSizes) |
| 57 { |
| 58 enum State { |
| 59 ParseStart, |
| 60 ParseWidth, |
| 61 ParseHeight |
| 62 }; |
| 63 int width = 0; |
| 64 unsigned start = 0; |
| 65 unsigned i = 0; |
| 66 State state = ParseStart; |
| 67 bool invalid = false; |
| 68 for (; i < length; ++i) { |
| 69 if (state == ParseWidth) { |
| 70 if (value[i] == 'x' || value[i] == 'X') { |
| 71 if (i == start) { |
| 72 invalid = true; |
| 73 break; |
| 74 } |
| 75 width = charactersToInt(value + start, i - start); |
| 76 start = i + 1; |
| 77 state = ParseHeight; |
| 78 } else if (value[i] < '0' || value[i] > '9') { |
| 79 invalid = true; |
| 80 break; |
| 81 } |
| 82 } else if (state == ParseHeight) { |
| 83 if (value[i] == ' ') { |
| 84 if (i == start) { |
| 85 invalid = true; |
| 86 break; |
| 87 } |
| 88 int height = charactersToInt(value + start, i - start); |
| 89 iconSizes.append(IntSize(width, height)); |
| 90 start = i + 1; |
| 91 state = ParseStart; |
| 92 } else if (value[i] < '0' || value[i] > '9') { |
| 93 invalid = true; |
| 94 break; |
| 95 } |
| 96 } else if (state == ParseStart) { |
| 97 if (value[i] >= '0' && value[i] <= '9') { |
| 98 start = i; |
| 99 state = ParseWidth; |
| 100 } else if (value[i] != ' ') { |
| 101 invalid = true; |
| 102 break; |
| 103 } |
| 104 } |
| 105 } |
| 106 if (invalid || state == ParseWidth || (state == ParseHeight && start == i))
{ |
| 107 iconSizes.clear(); |
| 108 return; |
| 109 } |
| 110 if (state == ParseHeight && i > start) { |
| 111 int height = charactersToInt(value + start, i - start); |
| 112 iconSizes.append(IntSize(width, height)); |
| 113 } |
| 114 } |
| 115 |
55 static LinkEventSender& linkLoadEventSender() | 116 static LinkEventSender& linkLoadEventSender() |
56 { | 117 { |
57 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames:
:load)); | 118 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames:
:load)); |
58 return sharedLoadEventSender; | 119 return sharedLoadEventSender; |
59 } | 120 } |
60 | 121 |
| 122 void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntS
ize>& iconSizes) |
| 123 { |
| 124 ASSERT(iconSizes.isEmpty()); |
| 125 if (value.isEmpty()) |
| 126 return; |
| 127 if (value.is8Bit()) |
| 128 parseSizes(value.characters8(), value.length(), iconSizes); |
| 129 else |
| 130 parseSizes(value.characters16(), value.length(), iconSizes); |
| 131 } |
| 132 |
61 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser
) | 133 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser
) |
62 : HTMLElement(linkTag, document) | 134 : HTMLElement(linkTag, document) |
63 , m_linkLoader(this) | 135 , m_linkLoader(this) |
64 , m_sizes(DOMSettableTokenList::create()) | 136 , m_sizes(DOMSettableTokenList::create()) |
65 , m_createdByParser(createdByParser) | 137 , m_createdByParser(createdByParser) |
66 , m_isInShadowTree(false) | 138 , m_isInShadowTree(false) |
67 , m_beforeLoadRecurseCount(0) | 139 , m_beforeLoadRecurseCount(0) |
68 { | 140 { |
69 ScriptWrappable::init(this); | 141 ScriptWrappable::init(this); |
70 } | 142 } |
(...skipping 18 matching lines...) Expand all Loading... |
89 if (name == relAttr) { | 161 if (name == relAttr) { |
90 m_relAttribute = LinkRelAttribute(value); | 162 m_relAttribute = LinkRelAttribute(value); |
91 process(); | 163 process(); |
92 } else if (name == hrefAttr) { | 164 } else if (name == hrefAttr) { |
93 process(); | 165 process(); |
94 } else if (name == typeAttr) { | 166 } else if (name == typeAttr) { |
95 m_type = value; | 167 m_type = value; |
96 process(); | 168 process(); |
97 } else if (name == sizesAttr) { | 169 } else if (name == sizesAttr) { |
98 m_sizes->setValue(value); | 170 m_sizes->setValue(value); |
| 171 parseSizesAttribute(value, m_iconSizes); |
99 process(); | 172 process(); |
100 } else if (name == mediaAttr) { | 173 } else if (name == mediaAttr) { |
101 m_media = value.string().lower(); | 174 m_media = value.string().lower(); |
102 process(); | 175 process(); |
103 } else if (name == disabledAttr) { | 176 } else if (name == disabledAttr) { |
104 if (LinkStyle* link = linkStyle()) | 177 if (LinkStyle* link = linkStyle()) |
105 link->setDisabledState(!value.isNull()); | 178 link->setDisabledState(!value.isNull()); |
106 } else if (name == onbeforeloadAttr) | 179 } else if (name == onbeforeloadAttr) |
107 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve
ntListener(this, name, value)); | 180 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve
ntListener(this, name, value)); |
108 else { | 181 else { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 bool HTMLLinkElement::async() const | 418 bool HTMLLinkElement::async() const |
346 { | 419 { |
347 return fastHasAttribute(HTMLNames::asyncAttr); | 420 return fastHasAttribute(HTMLNames::asyncAttr); |
348 } | 421 } |
349 | 422 |
350 IconType HTMLLinkElement::iconType() const | 423 IconType HTMLLinkElement::iconType() const |
351 { | 424 { |
352 return m_relAttribute.iconType(); | 425 return m_relAttribute.iconType(); |
353 } | 426 } |
354 | 427 |
355 const AtomicString& HTMLLinkElement::iconSizes() const | 428 const Vector<IntSize>& HTMLLinkElement::iconSizes() const |
356 { | 429 { |
357 return m_sizes->toString(); | 430 return m_iconSizes; |
358 } | 431 } |
359 | 432 |
360 DOMSettableTokenList* HTMLLinkElement::sizes() const | 433 DOMSettableTokenList* HTMLLinkElement::sizes() const |
361 { | 434 { |
362 return m_sizes.get(); | 435 return m_sizes.get(); |
363 } | 436 } |
364 | 437 |
365 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) | 438 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
366 { | 439 { |
367 return adoptPtr(new LinkStyle(owner)); | 440 return adoptPtr(new LinkStyle(owner)); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 void LinkStyle::ownerRemoved() | 704 void LinkStyle::ownerRemoved() |
632 { | 705 { |
633 if (m_sheet) | 706 if (m_sheet) |
634 clearSheet(); | 707 clearSheet(); |
635 | 708 |
636 if (styleSheetIsLoading()) | 709 if (styleSheetIsLoading()) |
637 removePendingSheet(RemovePendingSheetNotifyLater); | 710 removePendingSheet(RemovePendingSheetNotifyLater); |
638 } | 711 } |
639 | 712 |
640 } // namespace WebCore | 713 } // namespace WebCore |
OLD | NEW |