Index: third_party/polymer/v1_0/components-chromium/iron-resizable-behavior/iron-resizable-behavior-extracted.js |
diff --git a/third_party/polymer/v1_0/components-chromium/iron-resizable-behavior/iron-resizable-behavior-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-resizable-behavior/iron-resizable-behavior-extracted.js |
index f199bc9dfae2afbf4e3d4e18b88ca0f9e663bda3..37efb02d4aaf57c179cbb4afc7330d8969e38029 100644 |
--- a/third_party/polymer/v1_0/components-chromium/iron-resizable-behavior/iron-resizable-behavior-extracted.js |
+++ b/third_party/polymer/v1_0/components-chromium/iron-resizable-behavior/iron-resizable-behavior-extracted.js |
@@ -17,9 +17,21 @@ |
**/ |
Polymer.IronResizableBehavior = { |
properties: { |
+ /** |
+ * The closest ancestor element that implements `IronResizableBehavior`. |
+ */ |
_parentResizable: { |
type: Object, |
observer: '_parentResizableChanged' |
+ }, |
+ |
+ /** |
+ * True if this element is currently notifying its descedant elements of |
+ * resize. |
+ */ |
+ _notifyingDescendant: { |
+ type: Boolean, |
+ value: false |
} |
}, |
@@ -37,7 +49,8 @@ |
attached: function() { |
this.fire('iron-request-resize-notifications', null, { |
node: this, |
- bubbles: true |
+ bubbles: true, |
+ cancelable: true |
}); |
if (!this._parentResizable) { |
@@ -66,16 +79,12 @@ |
} |
this._interestedResizables.forEach(function(resizable) { |
- // TODO(cdata): Currently behaviors cannot define "abstract" methods.. |
- if (!this.resizerShouldNotify || this.resizerShouldNotify(resizable)) { |
- resizable.notifyResize(); |
+ if (this.resizerShouldNotify(resizable)) { |
+ this._notifyDescendant(resizable); |
} |
}, this); |
- this.fire('iron-resize', null, { |
- node: this, |
- bubbles: false |
- }); |
+ this._fireResize(); |
}, |
/** |
@@ -95,18 +104,42 @@ |
if (index > -1) { |
this._interestedResizables.splice(index, 1); |
+ this.unlisten(target, 'iron-resize', '_onDescendantIronResize'); |
} |
}, |
- // TODO(cdata): Currently behaviors cannot define "abstract" methods. |
- // resizerShouldNotify: function(el) { return true; }, |
+ /** |
+ * This method can be overridden to filter nested elements that should or |
+ * should not be notified by the current element. Return true if an element |
+ * should be notified, or false if it should not be notified. |
+ * |
+ * @param {HTMLElement} element A candidate descendant element that |
+ * implements `IronResizableBehavior`. |
+ * @return {boolean} True if the `element` should be notified of resize. |
+ */ |
+ resizerShouldNotify: function(element) { return true; }, |
- _parentResizableChanged: function(parentResizable) { |
- if (parentResizable) { |
- window.removeEventListener('resize', this._boundNotifyResize); |
+ _onDescendantIronResize: function(event) { |
+ if (this._notifyingDescendant) { |
+ event.stopPropagation(); |
+ return; |
+ } |
+ |
+ // NOTE(cdata): In ShadowDOM, event retargetting makes echoing of the |
+ // otherwise non-bubbling event "just work." We do it manually here for |
+ // the case where Polymer is not using shadow roots for whatever reason: |
+ if (!Polymer.Settings.useShadow) { |
+ this._fireResize(); |
} |
}, |
+ _fireResize: function() { |
+ this.fire('iron-resize', null, { |
+ node: this, |
+ bubbles: false |
+ }); |
+ }, |
+ |
_onIronRequestResizeNotifications: function(event) { |
var target = event.path ? event.path[0] : event.target; |
@@ -116,10 +149,31 @@ |
if (this._interestedResizables.indexOf(target) === -1) { |
this._interestedResizables.push(target); |
+ this.listen(target, 'iron-resize', '_onDescendantIronResize'); |
} |
target.assignParentResizable(this); |
+ this._notifyDescendant(target); |
event.stopPropagation(); |
+ }, |
+ |
+ _parentResizableChanged: function(parentResizable) { |
+ if (parentResizable) { |
+ window.removeEventListener('resize', this._boundNotifyResize); |
+ } |
+ }, |
+ |
+ _notifyDescendant: function(descendant) { |
+ // NOTE(cdata): In IE10, attached is fired on children first, so it's |
+ // important not to notify them if the parent is not attached yet (or |
+ // else they will get redundantly notified when the parent attaches). |
+ if (!this.isAttached) { |
+ return; |
+ } |
+ |
+ this._notifyingDescendant = true; |
+ descendant.notifyResize(); |
+ this._notifyingDescendant = false; |
} |
}; |