This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2014 The Polymer Authors. All rights reserved. | ||
// Use of this source code is goverened by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
var registerObject = scope.registerObject; | ||
|
||
var SVG_NS = 'http://www.w3.org/2000/svg'; | ||
var svgTitleElement = document.createElementNS(SVG_NS, 'title'); | ||
var SVGTitleElement = registerObject(svgTitleElement); | ||
var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructor; | ||
|
||
scope.wrappers.SVGElement = SVGElement; | ||
})(window.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2014 The Polymer Authors. All rights reserved. | ||
// Use of this source code is goverened by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
var EventTarget = scope.wrappers.EventTarget; | ||
var mixin = scope.mixin; | ||
var registerWrapper = scope.registerWrapper; | ||
var wrap = scope.wrap; | ||
|
||
var OriginalSVGElementInstance = window.SVGElementInstance; | ||
if (!OriginalSVGElementInstance) | ||
return; | ||
|
||
function SVGElementInstance(impl) { | ||
EventTarget.call(this, impl); | ||
} | ||
|
||
SVGElementInstance.prototype = Object.create(EventTarget.prototype); | ||
mixin(SVGElementInstance.prototype, { | ||
/** @type {SVGElement} */ | ||
get correspondingElement() { | ||
return wrap(this.impl.correspondingElement); | ||
}, | ||
|
||
/** @type {SVGUseElement} */ | ||
get correspondingUseElement() { | ||
return wrap(this.impl.correspondingUseElement); | ||
}, | ||
|
||
/** @type {SVGElementInstance} */ | ||
get parentNode() { | ||
return wrap(this.impl.parentNode); | ||
}, | ||
|
||
/** @type {SVGElementInstanceList} */ | ||
get childNodes() { | ||
throw new Error('Not implemented'); | ||
}, | ||
|
||
/** @type {SVGElementInstance} */ | ||
get firstChild() { | ||
return wrap(this.impl.firstChild); | ||
}, | ||
|
||
/** @type {SVGElementInstance} */ | ||
get lastChild() { | ||
return wrap(this.impl.lastChild); | ||
}, | ||
|
||
/** @type {SVGElementInstance} */ | ||
get previousSibling() { | ||
return wrap(this.impl.previousSibling); | ||
}, | ||
|
||
/** @type {SVGElementInstance} */ | ||
get nextSibling() { | ||
return wrap(this.impl.nextSibling); | ||
} | ||
}); | ||
|
||
registerWrapper(OriginalSVGElementInstance, SVGElementInstance); | ||
|
||
scope.wrappers.SVGElementInstance = SVGElementInstance; | ||
})(window.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2014 The Polymer Authors. All rights reserved. | ||
// Use of this source code is goverened by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
var mixin = scope.mixin; | ||
var registerWrapper = scope.registerWrapper; | ||
var unwrap = scope.unwrap; | ||
var wrap = scope.wrap; | ||
|
||
var OriginalSVGUseElement = window.SVGUseElement; | ||
|
||
// IE uses SVGElement as parent interface, SVG2 (Blink & Gecko) uses | ||
// SVGGraphicsElement. Use the <g> element to get the right prototype. | ||
|
||
var SVG_NS = 'http://www.w3.org/2000/svg'; | ||
var gWrapper = wrap(document.createElementNS(SVG_NS, 'g')); | ||
var useElement = document.createElementNS(SVG_NS, 'use'); | ||
var SVGGElement = gWrapper.constructor; | ||
var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype); | ||
var parentInterface = parentInterfacePrototype.constructor; | ||
|
||
function SVGUseElement(impl) { | ||
parentInterface.call(this, impl); | ||
} | ||
|
||
SVGUseElement.prototype = Object.create(parentInterfacePrototype); | ||
|
||
// Firefox does not expose instanceRoot. | ||
if ('instanceRoot' in useElement) { | ||
mixin(SVGUseElement.prototype, { | ||
get instanceRoot() { | ||
return wrap(unwrap(this).instanceRoot); | ||
}, | ||
get animatedInstanceRoot() { | ||
return wrap(unwrap(this).animatedInstanceRoot); | ||
}, | ||
}); | ||
} | ||
|
||
registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement); | ||
|
||
scope.wrappers.SVGUseElement = SVGUseElement; | ||
})(window.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2014 The Polymer Authors. All rights reserved. | ||
* Use of this source code is goverened by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
suite('SVGElementInstance', function() { | ||
|
||
var div; | ||
|
||
teardown(function() { | ||
if (div) { | ||
if (div.parentNode) | ||
div.parentNode.removeChild(div); | ||
div = undefined; | ||
} | ||
}); | ||
|
||
var svgCode = '\ | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">\ | ||
<defs>\ | ||
<g id="g">\ | ||
<line/>\ | ||
</g>\ | ||
</defs>\ | ||
<use xlink:href="#g" />\ | ||
</svg>'; | ||
|
||
function getInstanceRoot() { | ||
div = document.body.appendChild(document.createElement('div')); | ||
div.innerHTML = svgCode; | ||
var svg = div.firstElementChild; | ||
var useElement = svg.firstElementChild.nextElementSibling; | ||
return useElement.instanceRoot; | ||
} | ||
|
||
test('instanceof SVGUseElement', function() { | ||
div = document.body.appendChild(document.createElement('div')); | ||
div.innerHTML = svgCode; | ||
var svg = div.firstElementChild; | ||
var useElement = svg.firstElementChild.nextElementSibling; | ||
assert.instanceOf(useElement, SVGUseElement); | ||
assert.instanceOf(useElement, SVGElement); | ||
assert.instanceOf(useElement, Element); | ||
assert.instanceOf(useElement, EventTarget); | ||
}); | ||
|
||
test('instanceof SVGElementInstance', function() { | ||
// Firefox does not implement SVGElementInstance. | ||
if (/Firefox/.test(navigator.userAgent)) | ||
return; | ||
|
||
var instanceRoot = getInstanceRoot(); | ||
assert.instanceOf(instanceRoot, SVGElementInstance); | ||
assert.instanceOf(instanceRoot, EventTarget); | ||
}); | ||
|
||
test('correspondingUseElement', function() { | ||
// Firefox does not implement SVGElementInstance. | ||
if (/Firefox/.test(navigator.userAgent)) | ||
return; | ||
|
||
div = document.body.appendChild(document.createElement('div')); | ||
div.innerHTML = svgCode; | ||
var svg = div.firstElementChild; | ||
var useElement = svg.firstElementChild.nextElementSibling; | ||
var instanceRoot = useElement.instanceRoot; | ||
assert.equal(useElement, instanceRoot.correspondingUseElement); | ||
}); | ||
|
||
test('correspondingElement', function() { | ||
// Firefox does not implement SVGElementInstance. | ||
if (/Firefox/.test(navigator.userAgent)) | ||
return; | ||
|
||
var instanceRoot = getInstanceRoot(); | ||
assert.equal('g', instanceRoot.correspondingElement.localName); | ||
}); | ||
|
||
test('tree', function() { | ||
// Firefox does not implement SVGElementInstance. | ||
if (/Firefox/.test(navigator.userAgent)) | ||
return; | ||
|
||
var instanceRoot = getInstanceRoot(); | ||
|
||
assert.equal('line', instanceRoot.firstChild.correspondingElement.localName); | ||
assert.equal('line', instanceRoot.lastChild.correspondingElement.localName); | ||
|
||
// IE always returns new wrappers for all the accessors. | ||
if (/Trident/.test(navigator.userAgent)) | ||
return; | ||
|
||
assert.equal(instanceRoot.firstChild, instanceRoot.lastChild); | ||
assert.equal(instanceRoot, instanceRoot.firstChild.parentNode); | ||
assert.isNull(instanceRoot.parentNode); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters