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 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add polyfill support for /shadow/ and /shadow-deep/ combinators. Fixes …
…#12
- Loading branch information
Showing
6 changed files
with
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
x-foo /shadow/ .foo2 { | ||
background: green; | ||
} |
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 @@ | ||
<link rel="stylesheet" href="combinators-shadow-import.css" shim-shadowdom> |
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,3 @@ | ||
body /shadow-deep/ x-zot /shadow/ .zot-inner { | ||
background: blue; | ||
} |
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,109 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Copyright 2013 The Polymer Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style | ||
license that can be found in the LICENSE file. | ||
--> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="initial-scale=1.0"> | ||
<title>Using combinators styling</title> | ||
<script src="../../../platform.js"></script> | ||
<script src="register.js"></script> | ||
<script src="../../../../tools/test/htmltest.js"></script> | ||
<script src="../../../../tools/test/chai/chai.js"></script> | ||
<style shim-shadowdom> | ||
x-foo /shadow/ .foo { | ||
background: orange; | ||
} | ||
</style> | ||
<link rel="stylesheet" href="combinators-shadow.css" shim-shadowdom> | ||
<link rel="import" href="combinators-shadow-import.html"> | ||
</head> | ||
<body> | ||
|
||
<template id="x-foo"> | ||
<style> | ||
x-bar /shadow/ .bar { | ||
background: red; | ||
} | ||
|
||
x-bar /shadow/ .noogy { | ||
background: blue; | ||
} | ||
|
||
x-bar /shadow-deep/ .zot { | ||
color: white; | ||
} | ||
</style> | ||
<div class="foo">orange</div> | ||
<div class="foo2">green</div> | ||
<x-bar></x-bar> | ||
</template> | ||
<template id="x-bar"> | ||
<style> | ||
x-zot /shadow/ .zot { | ||
background: green; | ||
} | ||
</style> | ||
<div class="bar">Bar</div> | ||
<div class="noogy">Noogy</div> | ||
<x-zot></x-zot> | ||
</template> | ||
|
||
<template id="x-zot"> | ||
<div class="zot">Zot</div> | ||
<div class="zot-inner">inner</div> | ||
</template> | ||
|
||
|
||
<script> | ||
XZot = register('x-zot', '', HTMLElement.prototype, ['x-zot']); | ||
XBar = register('x-bar', '', HTMLElement.prototype, ['x-bar']); | ||
XFoo = register('x-foo', '', HTMLElement.prototype, ['x-foo']); | ||
</script> | ||
|
||
<x-foo></x-foo> | ||
|
||
<script> | ||
document.addEventListener('WebComponentsReady', function() { | ||
var foo = document.querySelector('x-foo'); | ||
var xBarRoot = foo.shadowRoot.querySelector('x-bar').shadowRoot; | ||
var bar = xBarRoot.querySelector('.bar'); | ||
chai.assert.equal(getComputedStyle(bar).backgroundColor, 'rgb(255, 0, 0)', | ||
'^ styles are applied (backgroundColor)'); | ||
|
||
var noogy = xBarRoot.querySelector('.noogy'); | ||
chai.assert.equal(getComputedStyle(noogy).backgroundColor, 'rgb(0, 0, 255)', | ||
'^ styles are applied (backgroundColor)'); | ||
var xZot = foo.shadowRoot.querySelector('x-bar').shadowRoot | ||
.querySelector('x-zot'); | ||
var zot = xZot.shadowRoot.querySelector('.zot'); | ||
|
||
chai.assert.equal(getComputedStyle(zot).backgroundColor, 'rgb(0, 128, 0)', | ||
'^ styles are applied (backgroundColor)'); | ||
chai.assert.equal(getComputedStyle(zot).color, 'rgb(255, 255, 255)', | ||
'^^ styles are applied (color)'); | ||
|
||
// NOTE: native import styles not shimmed under SD polyfill | ||
var unsupported = window.ShadowDOMPolyfill && HTMLImports.useNative; | ||
if (!unsupported) { | ||
var fooDiv = foo.shadowRoot.querySelector('.foo'); | ||
var zotDiv = xZot.shadowRoot.querySelector('.zot-inner'); | ||
var fooDiv2 = foo.shadowRoot.querySelector('.foo2'); | ||
|
||
// TODO(sorvell): test blocked on | ||
// https://code.google.com/p/chromium/issues/detail?id=339657 | ||
//chai.assert.equal(getComputedStyle(fooDiv2).backgroundColor, 'rgb(0, 128, 0)', | ||
// 'combinators applied via stylesheet in import'); | ||
|
||
chai.assert.equal(getComputedStyle(fooDiv).backgroundColor, 'rgb(255, 165, 0)', | ||
'combinators applied via style in main document'); | ||
chai.assert.equal(getComputedStyle(zotDiv).backgroundColor, 'rgb(0, 0, 255)', | ||
'combinators applied via stylesheet in main document'); | ||
} | ||
done(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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