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

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

Issue 196743002: Parse the link element's size attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
OLDNEW
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
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) {
abarth-chromium 2014/03/17 18:15:50 We usually put a space after ;
Inactive 2014/03/17 18:17:49 ahah, I complained about this on the last patch it
michaelbai 2014/03/17 18:51:03 Oh, right, it should be after; On 2014/03/17 18:1
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
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 const AtomicString& HTMLLinkElement::type() const 413 const AtomicString& HTMLLinkElement::type() const
341 { 414 {
342 return getAttribute(typeAttr); 415 return getAttribute(typeAttr);
343 } 416 }
344 417
345 IconType HTMLLinkElement::iconType() const 418 IconType HTMLLinkElement::iconType() const
346 { 419 {
347 return m_relAttribute.iconType(); 420 return m_relAttribute.iconType();
348 } 421 }
349 422
350 const AtomicString& HTMLLinkElement::iconSizes() const 423 const Vector<IntSize>& HTMLLinkElement::iconSizes() const
351 { 424 {
352 return m_sizes->toString(); 425 return m_iconSizes;
353 } 426 }
354 427
355 DOMSettableTokenList* HTMLLinkElement::sizes() const 428 DOMSettableTokenList* HTMLLinkElement::sizes() const
356 { 429 {
357 return m_sizes.get(); 430 return m_sizes.get();
358 } 431 }
359 432
360 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) 433 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner)
361 { 434 {
362 return adoptPtr(new LinkStyle(owner)); 435 return adoptPtr(new LinkStyle(owner));
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 void LinkStyle::ownerRemoved() 699 void LinkStyle::ownerRemoved()
627 { 700 {
628 if (m_sheet) 701 if (m_sheet)
629 clearSheet(); 702 clearSheet();
630 703
631 if (styleSheetIsLoading()) 704 if (styleSheetIsLoading())
632 removePendingSheet(RemovePendingSheetNotifyLater); 705 removePendingSheet(RemovePendingSheetNotifyLater);
633 } 706 }
634 707
635 } // namespace WebCore 708 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | Source/core/html/HTMLLinkElementSizesAttributeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698