From c339c4dbccf42526840cf5c0664781a409ea583f Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 12 Jun 2015 13:59:53 -0700 Subject: [PATCH 1/2] Fixes #1668 Fixes #1807 Fixes #1809 --- src/lib/style-properties.html | 13 +++-- src/lib/style-transformer.html | 6 +- test/unit/custom-style.html | 79 ++++++++++++++++++++++---- test/unit/styling-cross-scope-var.html | 42 +++++++++++++- 4 files changed, 120 insertions(+), 20 deletions(-) diff --git a/src/lib/style-properties.html b/src/lib/style-properties.html index 01d5ab6faa..2003695f20 100644 --- a/src/lib/style-properties.html +++ b/src/lib/style-properties.html @@ -239,12 +239,17 @@ transformStyles: function(element, properties, scopeSelector) { var self = this; - var hostRx = new RegExp(this.rx.HOST_PREFIX + element.is + + var hostSelector = styleTransformer + ._calcHostScope(element.is, element.extends); + var rxHostSelector = element.extends ? + '\\' + hostSelector.slice(0, -1) + '\\]' : + hostSelector; + var hostRx = new RegExp(this.rx.HOST_PREFIX + rxHostSelector + this.rx.HOST_SUFFIX); return styleTransformer.elementStyles(element, function(rule) { self.applyProperties(rule, properties); if (rule.cssText && !nativeShadow) { - self._scopeSelector(rule, hostRx, element.is, + self._scopeSelector(rule, hostRx, hostSelector, element._scopeCssViaAttr, scopeSelector); } }); @@ -253,7 +258,7 @@ // Strategy: x scope shim a selector e.g. to scope `.x-foo-42` (via classes): // non-host selector: .a.x-foo -> .x-foo-42 .a.x-foo // host selector: x-foo.wide -> x-foo.x-foo-42.wide - _scopeSelector: function(rule, hostRx, is, viaAttr, scopeId) { + _scopeSelector: function(rule, hostRx, hostSelector, viaAttr, scopeId) { rule.transformedSelector = rule.transformedSelector || rule.selector; var selector = rule.transformedSelector; var scope = viaAttr ? '[' + styleTransformer.SCOPE_NAME + '~=' + @@ -262,7 +267,7 @@ var parts = selector.split(','); for (var i=0, l=parts.length, p; (i @@ -86,22 +109,18 @@ - +

+
+ + + @@ -113,6 +132,27 @@ +
+ + + + @@ -122,6 +162,10 @@ suiteSetup(function() { + Polymer({ + is: 'x-baz' + }); + Polymer({ is: 'x-bar' }); @@ -145,6 +189,12 @@ test('::shadow styles applied', function() { assertComputed(xFoo.$.bar2, '2px'); + assertComputed(xFoo.$.bar2.$.baz, '3px'); + }); + + test('/deep/ styles applied', function() { + assertComputed(xFoo.$.bar3, '4px'); + assertComputed(xFoo.$.bar3.$.baz, '5px'); }); test('custom properties registered as defaults', function() { @@ -187,11 +237,16 @@ assertComputed(e, '1px'); }); + test('custom-styles apply to pseudo elements', function() { + var e = document.querySelector('#after'); + assertComputed(e, '11px', null, '::after'); + }); + }); - function assertComputed(element, value, property) { - var computed = getComputedStyle(element); + function assertComputed(element, value, property, pseudo) { + var computed = getComputedStyle(element, pseudo); property = property || 'border-top-width'; assert.equal(computed[property], value, 'computed style incorrect for ' + property); } diff --git a/test/unit/styling-cross-scope-var.html b/test/unit/styling-cross-scope-var.html index ee831d0763..d97d6ee626 100644 --- a/test/unit/styling-cross-scope-var.html +++ b/test/unit/styling-cross-scope-var.html @@ -222,6 +222,26 @@ }); + + + + + +