Skip to content

Commit b98d174

Browse files
author
Steve Orvell
authored
Merge pull request #63 from PolymerLabs/fix-css-safari
Styling fixes
2 parents f60c957 + c88973e commit b98d174

9 files changed

+41
-36
lines changed

polymer-core.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
<!-- BREAKME(kschaaf): Remove and make opt-in, eventually -->
2+
<link rel="import" href="src/shady/shady.html">
3+
14
<!-- BREAKME(kschaaf): Remove and make opt-in, eventually? -->
25
<link rel="import" href="src/compat/polymer-fn.html">
36
<link rel="import" href="src/compat/class.html">
47

58
<link rel="import" href="src/elements/element.html">
69

7-
<!-- BREAKME(kschaaf): Remove and make opt-in, eventually -->
8-
<link rel="import" href="src/shady/shady.html">
9-
<link rel="import" href="src/styling/style-lib.html">
10-
1110
<link rel="import" href="src/compat/dom-module.html">

src/elements/compat-element.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
function nyi() {
2323
var stack = new Error().stack.split('\n');
2424
var fn = stack.reduce(function(prev, val) {
25-
return prev == true ? val : (prev ? prev :
25+
return prev == true ? val : (prev ? prev :
2626
val.indexOf('compat-element.html') > 0);
2727
}, false);
2828
console.warn('Not yet implemented:', fn);
@@ -60,7 +60,7 @@
6060

6161
disconnectedCallback() {
6262
super.disconnectedCallback();
63-
this.detached();
63+
this.detached();
6464
}
6565

6666
attributeChangedCallback(name, old, value) {
@@ -85,13 +85,13 @@
8585
}
8686

8787
reflectPropertyToAttribute(property, attribute, value) {
88-
this.constructor.attributes.propertyToAttribute(this, property,
88+
this.constructor.attributes.propertyToAttribute(this, property,
8989
attribute, value);
9090
}
9191

9292
serializeValueToAttribute(value, attribute, node) {
9393
node = node || this;
94-
this.constructor.attributes.valueToAttribute(node, value,
94+
this.constructor.attributes.valueToAttribute(node, value,
9595
attribute, value);
9696
}
9797

src/elements/element.html

+12-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<link rel="import" href="../template/template-stamp.html">
1818
<link rel="import" href="../attributes/attribute-to-from-property.html">
1919
<link rel="import" href="../properties/meta-effects.html">
20+
<link rel="import" href="../styling/style-lib.html">
2021

2122
<script>
2223
(function() {
@@ -64,6 +65,9 @@
6465
this._observedAttributes = this.addPropertiesToAttributes(
6566
this._flattenedProperties, []);
6667
}
68+
if (!Polymer.StyleLib.nativeShadow) {
69+
this.__placeholder = Polymer.StyleLib.applyStylePlaceHolder(this.is);
70+
}
6771
return this._observedAttributes;
6872
}
6973

@@ -112,7 +116,7 @@
112116
this.createMethodObservers(config.observers);
113117
if (this.template) {
114118
var template = this.prepareTemplate(this.template);
115-
// TODO(dfreedm): remove when style stuff is refactored
119+
// TODO(dfreedm): remove when style stuff is refactored
116120
// away from using element as input.
117121
proto.__notStyleScopeCacheable = template.__notStyleScopeCacheable;
118122
this.data.clearPropagateEffects(proto);
@@ -125,12 +129,12 @@
125129
static get template() {
126130
if (!this.hasOwnProperty('_template')) {
127131
// TODO(sorvell): `__importDoc` may not be set if super class
128-
// has not run defined... falling back to document here is
132+
// has not run defined... falling back to document here is
129133
// incorrect. This gambit cannot work as is since if the superclass
130134
// document cannot be discovered via the subclass.
131135
// TODO(sorvell): support more ways to acquire template.
132136
// this requires `is` on constructor...
133-
this._template = Polymer.DomModule.import(this.is,
137+
this._template = Polymer.DomModule.import(this.is,
134138
'template', this.__importDoc || document);
135139
}
136140
return this._template;
@@ -141,13 +145,14 @@
141145
Polymer.CompatStyleUtil.normalizeForBC(template.content);
142146
// TODO(sorvell): cannot use `this` here, refactor this to only do
143147
// template preparation and take a name.
144-
// TODO(dfreedm): factor so that we do not need an object/element
148+
// TODO(dfreedm): factor so that we do not need an object/element
145149
// argument
146150
var info = {
147151
localName: this.is,
148152
is: this.is,
149153
extends: this.extends,
150-
__cssBuild: this.__cssBuild
154+
__cssBuild: this.__cssBuild,
155+
__placeholder: this.__placeholder,
151156
}
152157
Polymer.StyleLib.prepareTemplate(info, template);
153158
template.__notStyleScopeCacheable = info.__notStyleScopeCacheable;
@@ -168,7 +173,7 @@
168173
// add self to host's pending client list
169174
hostStack.registerHost(this);
170175
// apply defaults first.
171-
this.constructor.data.setPropertyDefaults(this,
176+
this.constructor.data.setPropertyDefaults(this,
172177
this.constructor._flattenedProperties);
173178
}
174179

@@ -216,7 +221,7 @@
216221
var property = caseMap.dashToCamelCase(name);
217222
var type = this.constructor._flattenedProperties[property].type;
218223
if (!this.constructor.data.hasReadOnlyEffect(this, property)) {
219-
this.constructor.attributes.attributeToProperty(this,
224+
this.constructor.attributes.attributeToProperty(this,
220225
name, value, type);
221226
}
222227
}

src/styling/style-lib.html

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@
3030
var id = this.scopeCounter[name] = (this.scopeCounter[name] || 0) + 1;
3131
return name + '-' + id;
3232
},
33+
applyStylePlaceHolder(name) {
34+
return Polymer.StyleUtil.applyStylePlaceHolder(name);
35+
},
3336
prepareTemplate(host, template) {
3437
if (template._prepared) {
3538
return;
3639
}
3740
template._prepared = true;
3841
var cssText = Polymer.StyleGather.cssFromElement(template);
3942
if (!this.nativeShadow) {
40-
template._placeholder = Polymer.StyleUtil.applyStylePlaceHolder(
41-
host.localName);
42-
Polymer.StyleTransformer.dom(template.content, host.localName);
43+
Polymer.StyleTransformer.dom(template.content, host.is);
4344
}
4445
var ast = Polymer.CssParse.parse(cssText);
4546
if (this.nativeCss && !this.nativeCssApply) {
@@ -52,10 +53,10 @@
5253
ownPropertyNames = Polymer.StyleProperties.decorateStyles(template._styleAst, host);
5354
}
5455
if (!ownPropertyNames.length || this.nativeCss) {
55-
var cssText = Polymer.StyleTransformer.elementStyles(host, template._styleAst);
56+
cssText = Polymer.StyleTransformer.elementStyles(host, template._styleAst);
5657
if (cssText.length) {
5758
var target = this.nativeShadow ? template.content : null;
58-
Polymer.StyleUtil.applyCss(cssText, host.localName, target, template._placeholder)
59+
Polymer.StyleUtil.applyCss(cssText, host.is, target, host.__placeholder);
5960
}
6061
}
6162
template._ownPropertyNames = ownPropertyNames;
@@ -64,8 +65,8 @@
6465
prepareHost(host, template) {
6566
if (template) {
6667
host.__styleRules = template._styleAst;
67-
host.__placeholder = template._placeholder;
6868
}
69+
host.__placeholder = host.constructor.__placeholder;
6970
host.__overrideStyleProperties = {};
7071
if (!this.nativeCss) {
7172
host.__styleProperties = null;
@@ -142,7 +143,7 @@
142143
var root = Polymer.Utils.ownerRootForNode(node);
143144
var host = root.host;
144145
if (host) {
145-
if (Polymer.isInstance(host)) {
146+
if (host instanceof Polymer.Element) {
146147
return host;
147148
} else {
148149
return this._styleOwnerForNode(host);
@@ -155,7 +156,7 @@
155156
},
156157
_applyStyleProperties(host) {
157158
var oldScopeSelector = host.__scopeSelector;
158-
host.__scopeSelector = this._generateScopeSelector(host.localName);
159+
host.__scopeSelector = this._generateScopeSelector(host.is);
159160
var style = Polymer.StyleProperties.applyElementStyle(host, host.__styleProperties, host.__scopeSelector, null);
160161
if (!this.nativeShadow) {
161162
Polymer.StyleProperties.applyElementScopeSelector(host, host.__scopeSelector, oldScopeSelector);

src/styling/style-properties.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// property names
3333
decorateStyles: function(rules, scope) {
3434
var self = this, props = {}, keyframes = [], ruleIndex = 0;
35-
var scopeSelector = styleTransformer._calcHostScope(scope.localName, scope.extends);
35+
var scopeSelector = styleTransformer._calcHostScope(scope.is, scope.extends);
3636
var cssBuild = rules.__cssBuild;
3737
styleUtil.forEachRule(rules, function(rule) {
3838
self.decorateRule(rule);
@@ -296,12 +296,12 @@
296296
if (!rule.propertyInfo.properties) {
297297
return;
298298
}
299-
var hostScope = scope.localName ?
300-
styleTransformer._calcHostScope(scope.localName, scope.extends) :
299+
var hostScope = scope.is ?
300+
styleTransformer._calcHostScope(scope.is, scope.extends) :
301301
'html';
302302
var parsedSelector = rule.parsedSelector;
303-
var isRoot = parsedSelector === ':root';
304-
var isHost = parsedSelector.indexOf(':host') === 0;
303+
var isRoot = (parsedSelector === ':host > *' || parsedSelector === 'html');
304+
var isHost = parsedSelector.indexOf(':host') === 0 && !isRoot;
305305
// build info is either in scope (when scope is an element) or in the style
306306
// when scope is the default scope; note: this allows default scope to have
307307
// mixed mode built and unbuilt styles.
@@ -363,7 +363,7 @@
363363
transformStyles: function(element, properties, scopeSelector) {
364364
var self = this;
365365
var hostSelector = styleTransformer
366-
._calcHostScope(element.localName);
366+
._calcHostScope(element.is, element.extends);
367367
var rxHostSelector = element.extends ?
368368
'\\' + hostSelector.slice(0, -1) + '\\]' :
369369
hostSelector;
@@ -388,7 +388,7 @@
388388
_elementKeyframeTransforms: function(element, rules, scopeSelector) {
389389
var keyframesRules = rules._keyframes;
390390
var keyframeTransforms = {};
391-
if (nativeShadow && keyframesRules) {
391+
if (!nativeShadow && keyframesRules) {
392392
// For non-ShadowDOM, we transform all known keyframes rules in
393393
// advance for the current scope. This allows us to catch keyframes
394394
// rules that appear anywhere in the stylesheet:

src/styling/style-transformer.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
if (node.classList) {
5656
this.element(node, selector, shouldRemoveScope);
5757
}
58-
var c$ = (node.localName === 'template') ?
58+
var c$ = (node.localName === 'template') ?
5959
(node.content || node._content).childNodes :
6060
node.children;
6161
if (c$) {
@@ -104,7 +104,7 @@
104104
// static shimming work when a proper build exists.
105105
var cssText = (nativeShadow || cssBuildType === 'shady') ?
106106
styleUtil.toCssText(styleRules, callback) :
107-
this.css(styleRules, element.localName, null, callback) + '\n\n';
107+
this.css(styleRules, element.is, element.extends, callback) + '\n\n';
108108
return cssText.trim();
109109
},
110110

test/unit/shady-v1-dynamic.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@
13761376
re.appendChild(child);
13771377
ShadyDom.flush();
13781378
child.addEventListener('child-event', function(e){
1379-
var path = e.path;
1379+
var path = e.composedPath();
13801380
assert.isTrue(path.indexOf(p) !== -1, 'path contains p');
13811381
assert.isTrue(path.indexOf(re) !== -1, 'path contains re');
13821382
done();

test/unit/styling-cross-scope-apply.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@
513513
propName = propName + Polymer.ApplyShim._separator + 'background';
514514
}
515515
assert.include(e.__styleProperties[propName], url);
516-
assert.include(e._customStyle.textContent, url);
516+
assert.include(e.__customStyle.textContent, url);
517517
}
518518
});
519519

@@ -557,7 +557,7 @@
557557
[xKeyframes1, xKeyframes2].forEach(function(xKeyframes, index) {
558558
var target = index === 0 ? '10px' : '20px';
559559
var onAnimationEnd = function() {
560-
assert.include(xKeyframes.getComputedStyleValue('left'), target);
560+
assert.include(xKeyframes.getComputedStyleValue('left'), target, xKeyframes.id);
561561

562562
xKeyframes.removeEventListener('animationend', onAnimationEnd);
563563
xKeyframes.removeEventListener('webkitAnimationEnd', onAnimationEnd);

test/unit/styling-cross-scope-var.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@
11001100
var d = document.createElement('x-var-produce-via-consume');
11011101
document.body.appendChild(d);
11021102
CustomElements.takeRecords();
1103-
var styleRoot = d.shadowRoot ? d.shadowRoot : document.head;
1103+
var styleRoot = Polymer.StyleLib.nativeShadow ? d.shadowRoot : document.head;
11041104
var staticStyle = styleRoot.querySelector('style[scope=x-var-produce-via-consume]');
11051105
assert.ok(staticStyle);
11061106
assert.match(staticStyle.textContent, /display/, 'static style does not contain style content');

0 commit comments

Comments
 (0)