Commit 94d5a8d9 authored by ed@opera.com's avatar ed@opera.com

[SVG2] Add onbegin, onend and onrepeat EventHandlers on SVGAnimationElement

These map to the eventnames 'beginEvent', 'endEvent' and 'repeatEvent'
respectively.

Spec:
https://svgwg.org/svg2-draft/animate.html#InterfaceSVGAnimationElement

BUG=338288
NOTRY=true

Review URL: https://codereview.chromium.org/201673003

git-svn-id: svn://svn.chromium.org/blink/trunk@169871 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 06f0b6be
......@@ -344,6 +344,9 @@ PASS 'onpaste' in pathelement is true
PASS 'onreset' in pathelement is true
PASS 'onsearch' in pathelement is true
PASS 'onselectstart' in pathelement is true
PASS 'onbegin' in pathelement is false
PASS 'onend' in pathelement is false
PASS 'onrepeat' in pathelement is false
Test SVGSVGElement
PASS 'onabort' in svgelement is true
......@@ -384,6 +387,52 @@ PASS 'onpaste' in svgelement is true
PASS 'onreset' in svgelement is true
PASS 'onsearch' in svgelement is true
PASS 'onselectstart' in svgelement is true
PASS 'onbegin' in svgelement is false
PASS 'onend' in svgelement is false
PASS 'onrepeat' in svgelement is false
Test SVGAnimationElement
PASS 'onabort' in animateelement is true
PASS 'onblur' in animateelement is true
PASS 'onchange' in animateelement is true
PASS 'onclick' in animateelement is true
PASS 'oncontextmenu' in animateelement is true
PASS 'ondblclick' in animateelement is true
PASS 'ondrag' in animateelement is true
PASS 'ondragend' in animateelement is true
PASS 'ondragenter' in animateelement is true
PASS 'ondragleave' in animateelement is true
PASS 'ondragover' in animateelement is true
PASS 'ondragstart' in animateelement is true
PASS 'ondrop' in animateelement is true
PASS 'onerror' in animateelement is true
PASS 'onfocus' in animateelement is true
PASS 'oninput' in animateelement is true
PASS 'onkeydown' in animateelement is true
PASS 'onkeypress' in animateelement is true
PASS 'onkeyup' in animateelement is true
PASS 'onload' in animateelement is true
PASS 'onmousedown' in animateelement is true
PASS 'onmousemove' in animateelement is true
PASS 'onmouseout' in animateelement is true
PASS 'onmouseover' in animateelement is true
PASS 'onmouseup' in animateelement is true
PASS 'onmousewheel' in animateelement is true
PASS 'onscroll' in animateelement is true
PASS 'onselect' in animateelement is true
PASS 'onsubmit' in animateelement is true
PASS 'onbeforecut' in animateelement is true
PASS 'oncut' in animateelement is true
PASS 'onbeforecopy' in animateelement is true
PASS 'oncopy' in animateelement is true
PASS 'onbeforepaste' in animateelement is true
PASS 'onpaste' in animateelement is true
PASS 'onreset' in animateelement is true
PASS 'onsearch' in animateelement is true
PASS 'onselectstart' in animateelement is true
PASS 'onbegin' in animateelement is true
PASS 'onend' in animateelement is true
PASS 'onrepeat' in animateelement is true
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -25,6 +25,10 @@ var bodyAndFrameSetProperties = [
// "onafterprint", "onbeforeprint", "onhashchange", "onpopstate", "onredo", "onundo"
];
var svgAnimationElementProperties = [
"onbegin", "onend", "onrepeat"
];
debug("Test Element");
var element = document.createElement("div");
......@@ -77,9 +81,24 @@ var pathelement = document.createElementNS("http://www.w3.org/2000/svg", "path")
for (var i = 0; i < elementAndDocumentProperties.length; ++i) {
shouldBeTrue("'" + elementAndDocumentProperties[i] + "' in pathelement");
}
for (var i = 0; i < svgAnimationElementProperties.length; ++i) {
shouldBeFalse("'" + svgAnimationElementProperties[i] + "' in pathelement");
}
debug("\nTest SVGSVGElement");
var svgelement = document.implementation.createDocument("http://www.w3.org/2000/svg", "svg").documentElement;
var svgelement = document.implementation.createDocument("http://www.w3.org/2000/svg", "svg", null).documentElement;
for (var i = 0; i < elementAndDocumentProperties.length; ++i) {
shouldBeTrue("'" + elementAndDocumentProperties[i] + "' in svgelement");
}
for (var i = 0; i < svgAnimationElementProperties.length; ++i) {
shouldBeFalse("'" + svgAnimationElementProperties[i] + "' in svgelement");
}
debug("\nTest SVGAnimationElement");
var animateelement = document.createElementNS("http://www.w3.org/2000/svg", "animate");
for (var i = 0; i < elementAndDocumentProperties.length; ++i) {
shouldBeTrue("'" + elementAndDocumentProperties[i] + "' in animateelement");
}
for (var i = 0; i < svgAnimationElementProperties.length; ++i) {
shouldBeTrue("'" + svgAnimationElementProperties[i] + "' in animateelement");
}
<!DOCTYPE html>
<title>EventHandlers on SVGAnimationElement test</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="script-tests/animation-events.js"></script>
<script>
var attributeToEventMap = {
"onbegin" : "beginEvent",
"onend" : "endEvent",
"onrepeat" : "repeatEvent"
};
for (var attribute in attributeToEventMap) {
[
"SVGAnimateElement",
"SVGAnimateMotionElement",
"SVGAnimateTransformElement",
"SVGSetElement"
].forEach(function(interface) {
testSet(interface, attribute);
testEnumerate(interface, attribute);
testReflect(interface, attribute);
});
testEventHandlerMapping(attribute, attributeToEventMap[attribute]);
};
</script>
<div id="log"></div>
function getObject(interface) {
switch(interface) {
case "SVGAnimateElement":
var e = document.createElementNS("http://www.w3.org/2000/svg", "animate");
assert_true(e instanceof SVGAnimateElement);
return e;
case "SVGAnimateMotionElement":
var e = document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");
assert_true(e instanceof SVGAnimateMotionElement);
return e;
case "SVGAnimateTransformElement":
var e = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
assert_true(e instanceof SVGAnimateTransformElement);
return e;
case "SVGSetElement":
var e = document.createElementNS("http://www.w3.org/2000/svg", "set");
assert_true(e instanceof SVGSetElement);
return e;
}
assert_unreached();
}
function testSet(interface, attribute) {
test(function() {
var object = getObject(interface);
function nop() {}
assert_equals(object[attribute], null, "Initially null");
object[attribute] = nop;
assert_equals(object[attribute], nop, "Return same function");
object[attribute] = "";
assert_equals(object[attribute], null, "Return null after setting string");
object[attribute] = null;
assert_equals(object[attribute], null, "Finally null");
}, "Set " + interface + "." + attribute);
}
function testReflect(interface, attribute) {
test(function() {
var element = getObject(interface);
assert_false(element.hasAttribute(attribute), "Initially missing");
element.setAttribute(attribute, "return");
assert_equals(element.getAttribute(attribute), "return", "Return same string");
assert_equals(typeof element[attribute], "function", "Convert to function");
element.removeAttribute(attribute);
}, "Reflect " + interface + "." + attribute);
}
// Object.propertyIsEnumerable cannot be used because it doesn't
// work with properties inherited through the prototype chain.
function getEnumerable(interface) {
var enumerable = {};
for (var attribute in getObject(interface)) {
enumerable[attribute] = true;
}
return enumerable;
}
function testEventHandlerMapping(attribute, eventname) {
async_test(function(t) {
var element = getObject("SVGAnimateElement");
assert_false(element.hasAttribute(attribute), "Initially missing");
element[attribute] = function() {
t.step(function (){assert_true(true); t.done();});
};
var event = new CustomEvent(eventname);
element.dispatchEvent(event);
}, "Event " + eventname + " maps to " + attribute);
}
var enumerableCache = {};
function testEnumerate(interface, attribute) {
if (!(interface in enumerableCache)) {
enumerableCache[interface] = getEnumerable(interface);
}
test(function() {
assert_true(enumerableCache[interface][attribute]);
}, "Enumerate " + interface + "." + attribute);
}
......@@ -74,6 +74,10 @@ public:
void endElement();
void endElementAt(float offset);
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(begin, beginEvent);
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(end, endEvent);
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(repeat, repeatEvent);
static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&);
virtual bool isAdditive() const;
......
......@@ -35,6 +35,10 @@ interface SVGAnimationElement : SVGElement {
void beginElementAt([Default=Undefined] optional float offset);
void endElement();
void endElementAt([Default=Undefined] optional float offset);
attribute EventHandler onbegin;
attribute EventHandler onend;
attribute EventHandler onrepeat;
};
SVGAnimationElement implements SVGTests;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment