// @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
var view = document.defaultView;
- var parentNode = domNode.parentNode;
+ var parentNode = helpers._getParentNode(domNode);
var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
var hasCNode = isConstrainedValue(constrainedNode);
return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10);
};
+ /**
+ * @private
+ */
+ helpers._getParentNode = function(domNode) {
+ var parent = domNode.parentNode;
+ if (parent && parent.host) {
+ parent = parent.host;
+ }
+ return parent;
+ };
helpers.getMaximumWidth = function(domNode) {
- var container = domNode.parentNode;
+ var container = helpers._getParentNode(domNode);
if (!container) {
return domNode.clientWidth;
}
return isNaN(cw) ? w : Math.min(w, cw);
};
helpers.getMaximumHeight = function(domNode) {
- var container = domNode.parentNode;
+ var container = helpers._getParentNode(domNode);
if (!container) {
return domNode.clientHeight;
}
document.body.removeChild(div);
});
+ it ('should get the maximum width and height for a node in a ShadowRoot', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ if (!div.attachShadow) {
+ // Shadow DOM is not natively supported
+ return;
+ }
+
+ var shadow = div.attachShadow({mode: 'closed'});
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ shadow.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
+
+ document.body.removeChild(div);
+ });
+
it ('should get the maximum width of a node that has a max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');