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

Unified 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: address comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | Source/core/html/HTMLLinkElementSizesAttributeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLLinkElement.cpp
diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp
index 9025639b7fae91cba4e8635db5337f4b3d32c78f..9dbccda180d394e2a99ed0628d05848616f57f28 100644
--- a/Source/core/html/HTMLLinkElement.cpp
+++ b/Source/core/html/HTMLLinkElement.cpp
@@ -52,12 +52,84 @@ namespace WebCore {
using namespace HTMLNames;
+template <typename CharacterType>
+static void parseSizes(const CharacterType* value, unsigned length, Vector<IntSize>& iconSizes)
+{
+ enum State {
+ ParseStart,
+ ParseWidth,
+ ParseHeight
+ };
+ int width = 0;
+ unsigned start = 0;
+ unsigned i = 0;
+ State state = ParseStart;
+ bool invalid = false;
+ for (;i < length; ++i) {
Inactive 2014/03/14 20:53:51 "; i" <- missing space
michaelbai 2014/03/14 20:58:16 Done.
+ if (state == ParseWidth) {
+ if (value[i] == 'x' || value[i] == 'X') {
+ if (i == start) {
+ invalid = true;
+ break;
+ }
+ width = charactersToInt(value + start, i - start);
+ start = i + 1;
+ state = ParseHeight;
+ } else if (value[i] < '0' || value[i] > '9') {
+ invalid = true;
+ break;
+ }
+ } else if (state == ParseHeight) {
+ if (value[i] == ' ') {
+ if (i == start) {
+ invalid = true;
+ break;
+ }
+ int height = charactersToInt(value + start, i - start);
+ iconSizes.append(IntSize(width, height));
+ start = i + 1;
+ state = ParseStart;
+ } else if (value[i] < '0' || value[i] > '9') {
+ invalid = true;
+ break;
+ }
+ } else if (state == ParseStart) {
+ if (value[i] >= '0' && value[i] <= '9') {
+ start = i;
+ state = ParseWidth;
+ } else if (value[i] != ' ') {
+ invalid = true;
+ break;
+ }
+ }
+ }
+ if (invalid || state == ParseWidth || (state == ParseHeight && start == i)) {
+ iconSizes.clear();
+ return;
+ }
+ if (state == ParseHeight && i > start) {
+ int height = charactersToInt(value + start, i - start);
+ iconSizes.append(IntSize(width, height));
+ }
+}
+
static LinkEventSender& linkLoadEventSender()
{
DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames::load));
return sharedLoadEventSender;
}
+void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntSize>& iconSizes)
+{
+ ASSERT(iconSizes.isEmpty());
+ if (value.isEmpty())
+ return;
+ if (value.is8Bit())
+ parseSizes(value.characters8(), value.length(), iconSizes);
+ else
+ parseSizes(value.characters16(), value.length(), iconSizes);
+}
+
inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser)
: HTMLElement(linkTag, document)
, m_linkLoader(this)
@@ -96,6 +168,7 @@ void HTMLLinkElement::parseAttribute(const QualifiedName& name, const AtomicStri
process();
} else if (name == sizesAttr) {
m_sizes->setValue(value);
+ parseSizesAttribute(value, m_iconSizes);
process();
} else if (name == mediaAttr) {
m_media = value.string().lower();
@@ -347,9 +420,9 @@ IconType HTMLLinkElement::iconType() const
return m_relAttribute.iconType();
}
-const AtomicString& HTMLLinkElement::iconSizes() const
+const Vector<IntSize>& HTMLLinkElement::iconSizes() const
{
- return m_sizes->toString();
+ return m_iconSizes;
}
DOMSettableTokenList* HTMLLinkElement::sizes() const
« 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