Implement sizes attribute for link tag from HTML5
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jul 2011 03:00:54 +0000 (03:00 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jul 2011 03:00:54 +0000 (03:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=37674

Patch by Rachel Blum <groby@chromium.org> on 2011-07-27
Reviewed by Dimitri Glazkov.

Source/WebCore:

Test: fast/dom/icon-size-property.html

* WebCore.gypi:
* WebCore.pro:
* bindings/js/JSHTMLLinkElementCustom.cpp:
(WebCore::JSHTMLLinkElement::sizes):
(WebCore::JSHTMLLinkElement::setSizes):
* bindings/v8/custom/V8HTMLLinkElementCustom.cpp: Added.
(WebCore::V8HTMLLinkElement::sizesAccessorGetter):
(WebCore::V8HTMLLinkElement::sizesAccessorSetter):
* html/HTMLAttributeNames.in:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::HTMLLinkElement):
(WebCore::HTMLLinkElement::parseMappedAttribute):
(WebCore::HTMLLinkElement::sizes):
(WebCore::HTMLLinkElement::setSizes):
* html/HTMLLinkElement.h:
* html/HTMLLinkElement.idl:

LayoutTests:

* fast/dom/icon-size-property-expected.txt: Added.
* fast/dom/icon-size-property.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91893 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/icon-size-property-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/icon-size-property.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/bindings/js/JSHTMLLinkElementCustom.cpp
Source/WebCore/bindings/v8/custom/V8HTMLLinkElementCustom.cpp [new file with mode: 0644]
Source/WebCore/html/HTMLAttributeNames.in
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/HTMLLinkElement.idl

index 02b7788..4d8a2df 100644 (file)
@@ -1,3 +1,13 @@
+2011-07-27  Rachel Blum  <groby@chromium.org>
+
+        Implement sizes attribute for link tag from HTML5
+        https://bugs.webkit.org/show_bug.cgi?id=37674
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/icon-size-property-expected.txt: Added.
+        * fast/dom/icon-size-property.html: Added.
+
 2011-07-27  Ryosuke Niwa  <rniwa@webkit.org>
 
         Fix Chromium test expectations for http://crbug.com/88911
diff --git a/LayoutTests/fast/dom/icon-size-property-expected.txt b/LayoutTests/fast/dom/icon-size-property-expected.txt
new file mode 100644 (file)
index 0000000..5b680cc
--- /dev/null
@@ -0,0 +1,17 @@
+Tests for sizes attribute of the link element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS icon.sizes.length is 2
+PASS icon.sizes.value is "23x47 19x42"
+PASS icon.sizes.length is 3
+PASS icon.sizes.value is "10x10 20x20 30x30"
+PASS icon.sizes.length is 0
+PASS icon.sizes.value is ""
+PASS icon.sizes.length is 0
+PASS icon.sizes.value is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/icon-size-property.html b/LayoutTests/fast/dom/icon-size-property.html
new file mode 100644 (file)
index 0000000..32027a2
--- /dev/null
@@ -0,0 +1,38 @@
+<html>
+<head>
+  <link id="rel-icon" rel="icon" sizes="23x47 19x42" type="image/x-icon" href="http://test.com/oldfavicon.ico"/>
+  <link id="no-sizes" rel="icon" type="image/x-icon" href="http://test.com/oldfavicon.ico"/>
+  <link id="empty-sizes" rel="icon" sizes="" type="image/x-icon" href="http://test.com/oldfavicon.ico"/>
+  <link rel="stylesheet" href="../js/resources/js-test-style.css">
+
+  <script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+  <p id="description"></p>
+  <div id="console"></div>
+  
+  <script>
+      description('Tests for sizes attribute of the link element.');
+
+      var icon=document.getElementById("rel-icon");
+
+      shouldEvaluateTo('icon.sizes.length',2);
+      shouldBeEqualToString('icon.sizes.value',"23x47 19x42");
+      
+      icon.sizes="10x10 20x20 30x30";
+      shouldEvaluateTo('icon.sizes.length',3);
+      shouldBeEqualToString('icon.sizes.value',"10x10 20x20 30x30");
+
+      var icon=document.getElementById("no-sizes");
+      shouldEvaluateTo('icon.sizes.length',0);
+      shouldBeEqualToString('icon.sizes.value',"");
+
+      var icon=document.getElementById("empty-sizes");
+      shouldEvaluateTo('icon.sizes.length',0);
+      shouldBeEqualToString('icon.sizes.value',"");
+
+      var successfullyParsed = true;
+</script>  
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 9932a25..4179f3d 100644 (file)
@@ -1,3 +1,29 @@
+2011-07-27  Rachel Blum  <groby@chromium.org>
+
+        Implement sizes attribute for link tag from HTML5
+        https://bugs.webkit.org/show_bug.cgi?id=37674
+
+        Reviewed by Dimitri Glazkov.
+
+        Test: fast/dom/icon-size-property.html
+
+        * WebCore.gypi:
+        * WebCore.pro:
+        * bindings/js/JSHTMLLinkElementCustom.cpp:
+        (WebCore::JSHTMLLinkElement::sizes):
+        (WebCore::JSHTMLLinkElement::setSizes):
+        * bindings/v8/custom/V8HTMLLinkElementCustom.cpp: Added.
+        (WebCore::V8HTMLLinkElement::sizesAccessorGetter):
+        (WebCore::V8HTMLLinkElement::sizesAccessorSetter):
+        * html/HTMLAttributeNames.in:
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::HTMLLinkElement):
+        (WebCore::HTMLLinkElement::parseMappedAttribute):
+        (WebCore::HTMLLinkElement::sizes):
+        (WebCore::HTMLLinkElement::setSizes):
+        * html/HTMLLinkElement.h:
+        * html/HTMLLinkElement.idl:
+
 2011-07-27  Pratik Solanki  <psolanki@apple.com>
 
         Incorrect arguments passed to LOG statement
index 2afd876..db0ccd6 100644 (file)
             'bindings/v8/custom/V8HTMLImageElementConstructor.cpp',
             'bindings/v8/custom/V8HTMLImageElementConstructor.h',
             'bindings/v8/custom/V8HTMLInputElementCustom.cpp',
+            'bindings/v8/custom/V8HTMLLinkElementCustom.cpp',
             'bindings/v8/custom/V8HTMLOptionElementConstructor.cpp',
             'bindings/v8/custom/V8HTMLOptionElementConstructor.h',
             'bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp',
index 730bb0c..2538b1a 100644 (file)
@@ -184,6 +184,7 @@ v8 {
         bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp \
         bindings/v8/custom/V8HTMLImageElementConstructor.cpp \
         bindings/v8/custom/V8HTMLInputElementCustom.cpp \
+        bindings/v8/custom/V8HTMLLinkElementCustom.cpp \
         bindings/v8/custom/V8HTMLOptionElementConstructor.cpp \
         bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp \
         bindings/v8/custom/V8HTMLOutputElementCustom.cpp \
index 3cfc99d..bbd55a9 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "JSHTMLLinkElement.h"
 
 #include "HTMLLinkElement.h"
+#include "JSDOMBinding.h"
+#include "JSDOMSettableTokenList.h"
+#include <wtf/GetPtr.h>
 
 using namespace JSC;
 
 namespace WebCore {
 
+JSValue JSHTMLLinkElement::sizes(ExecState* exec) const
+{
+    HTMLLinkElement* output = static_cast<HTMLLinkElement*>(impl());
+    JSValue result = toJS(exec, globalObject(), WTF::getPtr(output->sizes()));
+    return result;
 }
+
+void JSHTMLLinkElement::setSizes(ExecState* exec, JSValue value)
+{
+    HTMLLinkElement* output = static_cast<HTMLLinkElement*>(impl());
+    output->setSizes(valueToStringWithNullCheck(exec, value));
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/bindings/v8/custom/V8HTMLLinkElementCustom.cpp b/Source/WebCore/bindings/v8/custom/V8HTMLLinkElementCustom.cpp
new file mode 100644 (file)
index 0000000..78a2264
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "V8HTMLLinkElement.h"
+
+#include "HTMLLinkElement.h"
+#include "V8Binding.h"
+#include "V8DOMSettableTokenList.h"
+#include "V8Proxy.h"
+
+namespace WebCore {
+
+v8::Handle<v8::Value> V8HTMLLinkElement::sizesAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.HTMLLinkElement.sizes._get");
+    HTMLLinkElement* imp = V8HTMLLinkElement::toNative(info.Holder());
+    return toV8(imp->sizes());
+}
+
+void V8HTMLLinkElement::sizesAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.HTMLLinkElement.sizes._set");
+    HTMLLinkElement* imp = V8HTMLLinkElement::toNative(info.Holder());
+    imp->setSizes(toWebCoreString(value));
+}
+
+} // namespace WebCore
index 8410de6..fa906e7 100644 (file)
@@ -272,6 +272,7 @@ scrolling
 selected
 shape
 size
+sizes
 sortable
 sortdirection
 span
index 4335329..c4d9431 100644 (file)
@@ -4,6 +4,7 @@
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
  * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com)
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -53,6 +54,7 @@ using namespace HTMLNames;
 inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document* document, bool createdByParser)
     : HTMLElement(tagName, document)
     , m_linkLoader(this)
+    , m_sizes(DOMSettableTokenList::create())
     , m_loading(false)
     , m_isEnabledViaScript(false)
     , m_createdByParser(createdByParser)
@@ -133,6 +135,9 @@ void HTMLLinkElement::parseMappedAttribute(Attribute* attr)
     } else if (attr->name() == typeAttr) {
         m_type = attr->value();
         process();
+    } else if (attr->name() == sizesAttr) {
+        setSizes(attr->value());
+        process();
     } else if (attr->name() == mediaAttr) {
         m_media = attr->value().string().lower();
         process();
@@ -440,4 +445,14 @@ bool HTMLLinkElement::disabled() const
     return m_sheet && m_sheet->disabled();
 }
 
+DOMSettableTokenList* HTMLLinkElement::sizes() const
+{
+    return m_sizes.get();
+}
+
+void HTMLLinkElement::setSizes(const String& value)
+{
+    m_sizes->setValue(value);
 }
+
+} // namespace WebCore
index ef3b0a6..8fede02 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -26,6 +27,7 @@
 #include "CSSStyleSheet.h"
 #include "CachedResourceClient.h"
 #include "CachedResourceHandle.h"
+#include "DOMSettableTokenList.h"
 #include "HTMLElement.h"
 #include "IconURL.h"
 #include "LinkLoader.h"
@@ -53,11 +55,13 @@ public:
 
     StyleSheet* sheet() const;
 
-    // FIXME: This should be remaned isStyleSheetLoading as this is only used for stylesheets.
+    // FIXME: This should be renamed isStyleSheetLoading as this is only used for stylesheets.
     bool isLoading() const;
     bool isEnabledViaScript() const { return m_isEnabledViaScript; }
     bool disabled() const;
     void setDisabled(bool);
+    void setSizes(const String&);
+    DOMSettableTokenList* sizes() const;
 
 private:
     virtual void parseMappedAttribute(Attribute*);
@@ -99,6 +103,7 @@ private:
     KURL m_url;
     String m_type;
     String m_media;
+    RefPtr<DOMSettableTokenList> m_sizes;
     LinkRelAttribute m_relAttribute;
     bool m_loading;
     bool m_isEnabledViaScript;
index 1f36232..7f48a72 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -28,6 +29,9 @@ module html {
         attribute [Reflect] DOMString media;
         attribute [Reflect] DOMString rel;
         attribute [Reflect] DOMString rev;
+#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
+        attribute [Custom] DOMSettableTokenList sizes;
+#endif
         attribute [Reflect] DOMString target;
         attribute [Reflect] DOMString type;