Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: third_party/polymer/v1_0/components/iron-resizable-behavior/iron-resizable-behavior.html

Issue 1221923003: Update bower.json for Polymer elements and add PRESUBMIT.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 @license 2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt 4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
7 Code distributed by Google as part of the polymer project is also 7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 --> 9 -->
10 10
(...skipping 11 matching lines...) Expand all
22 * This event will be fired when they become showing after having been hidden, 22 * This event will be fired when they become showing after having been hidden,
23 * when they are resized explicitly by another resizable, or when the window h as been 23 * when they are resized explicitly by another resizable, or when the window h as been
24 * resized. 24 * resized.
25 * Note, the `iron-resize` event is non-bubbling. 25 * Note, the `iron-resize` event is non-bubbling.
26 * 26 *
27 * @polymerBehavior Polymer.IronResizableBehavior 27 * @polymerBehavior Polymer.IronResizableBehavior
28 * @demo demo/index.html 28 * @demo demo/index.html
29 **/ 29 **/
30 Polymer.IronResizableBehavior = { 30 Polymer.IronResizableBehavior = {
31 properties: { 31 properties: {
32 /**
33 * The closest ancestor element that implements `IronResizableBehavior`.
34 */
32 _parentResizable: { 35 _parentResizable: {
33 type: Object, 36 type: Object,
34 observer: '_parentResizableChanged' 37 observer: '_parentResizableChanged'
38 },
39
40 /**
41 * True if this element is currently notifying its descedant elements of
42 * resize.
43 */
44 _notifyingDescendant: {
45 type: Boolean,
46 value: false
35 } 47 }
36 }, 48 },
37 49
38 listeners: { 50 listeners: {
39 'iron-request-resize-notifications': '_onIronRequestResizeNotifications' 51 'iron-request-resize-notifications': '_onIronRequestResizeNotifications'
40 }, 52 },
41 53
42 created: function() { 54 created: function() {
43 // We don't really need property effects on these, and also we want them 55 // We don't really need property effects on these, and also we want them
44 // to be created before the `_parentResizable` observer fires: 56 // to be created before the `_parentResizable` observer fires:
45 this._interestedResizables = []; 57 this._interestedResizables = [];
46 this._boundNotifyResize = this.notifyResize.bind(this); 58 this._boundNotifyResize = this.notifyResize.bind(this);
47 }, 59 },
48 60
49 attached: function() { 61 attached: function() {
50 this.fire('iron-request-resize-notifications', null, { 62 this.fire('iron-request-resize-notifications', null, {
51 node: this, 63 node: this,
52 bubbles: true 64 bubbles: true,
65 cancelable: true
53 }); 66 });
54 67
55 if (!this._parentResizable) { 68 if (!this._parentResizable) {
56 window.addEventListener('resize', this._boundNotifyResize); 69 window.addEventListener('resize', this._boundNotifyResize);
57 this.notifyResize(); 70 this.notifyResize();
58 } 71 }
59 }, 72 },
60 73
61 detached: function() { 74 detached: function() {
62 if (this._parentResizable) { 75 if (this._parentResizable) {
63 this._parentResizable.stopResizeNotificationsFor(this); 76 this._parentResizable.stopResizeNotificationsFor(this);
64 } else { 77 } else {
65 window.removeEventListener('resize', this._boundNotifyResize); 78 window.removeEventListener('resize', this._boundNotifyResize);
66 } 79 }
67 80
68 this._parentResizable = null; 81 this._parentResizable = null;
69 }, 82 },
70 83
71 /** 84 /**
72 * Can be called to manually notify a resizable and its descendant 85 * Can be called to manually notify a resizable and its descendant
73 * resizables of a resize change. 86 * resizables of a resize change.
74 */ 87 */
75 notifyResize: function() { 88 notifyResize: function() {
76 if (!this.isAttached) { 89 if (!this.isAttached) {
77 return; 90 return;
78 } 91 }
79 92
80 this._interestedResizables.forEach(function(resizable) { 93 this._interestedResizables.forEach(function(resizable) {
81 // TODO(cdata): Currently behaviors cannot define "abstract" methods.. 94 if (this.resizerShouldNotify(resizable)) {
82 if (!this.resizerShouldNotify || this.resizerShouldNotify(resizable)) { 95 this._notifyDescendant(resizable);
83 resizable.notifyResize();
84 } 96 }
85 }, this); 97 }, this);
86 98
87 this.fire('iron-resize', null, { 99 this._fireResize();
88 node: this,
89 bubbles: false
90 });
91 }, 100 },
92 101
93 /** 102 /**
94 * Used to assign the closest resizable ancestor to this resizable 103 * Used to assign the closest resizable ancestor to this resizable
95 * if the ancestor detects a request for notifications. 104 * if the ancestor detects a request for notifications.
96 */ 105 */
97 assignParentResizable: function(parentResizable) { 106 assignParentResizable: function(parentResizable) {
98 this._parentResizable = parentResizable; 107 this._parentResizable = parentResizable;
99 }, 108 },
100 109
101 /** 110 /**
102 * Used to remove a resizable descendant from the list of descendants 111 * Used to remove a resizable descendant from the list of descendants
103 * that should be notified of a resize change. 112 * that should be notified of a resize change.
104 */ 113 */
105 stopResizeNotificationsFor: function(target) { 114 stopResizeNotificationsFor: function(target) {
106 var index = this._interestedResizables.indexOf(target); 115 var index = this._interestedResizables.indexOf(target);
107 116
108 if (index > -1) { 117 if (index > -1) {
109 this._interestedResizables.splice(index, 1); 118 this._interestedResizables.splice(index, 1);
119 this.unlisten(target, 'iron-resize', '_onDescendantIronResize');
110 } 120 }
111 }, 121 },
112 122
113 // TODO(cdata): Currently behaviors cannot define "abstract" methods. 123 /**
114 // resizerShouldNotify: function(el) { return true; }, 124 * This method can be overridden to filter nested elements that should or
125 * should not be notified by the current element. Return true if an element
126 * should be notified, or false if it should not be notified.
127 *
128 * @param {HTMLElement} element A candidate descendant element that
129 * implements `IronResizableBehavior`.
130 * @return {boolean} True if the `element` should be notified of resize.
131 */
132 resizerShouldNotify: function(element) { return true; },
115 133
116 _parentResizableChanged: function(parentResizable) { 134 _onDescendantIronResize: function(event) {
117 if (parentResizable) { 135 if (this._notifyingDescendant) {
118 window.removeEventListener('resize', this._boundNotifyResize); 136 event.stopPropagation();
137 return;
119 } 138 }
139
140 // NOTE(cdata): In ShadowDOM, event retargetting makes echoing of the
141 // otherwise non-bubbling event "just work." We do it manually here for
142 // the case where Polymer is not using shadow roots for whatever reason:
143 if (!Polymer.Settings.useShadow) {
144 this._fireResize();
145 }
146 },
147
148 _fireResize: function() {
149 this.fire('iron-resize', null, {
150 node: this,
151 bubbles: false
152 });
120 }, 153 },
121 154
122 _onIronRequestResizeNotifications: function(event) { 155 _onIronRequestResizeNotifications: function(event) {
123 var target = event.path ? event.path[0] : event.target; 156 var target = event.path ? event.path[0] : event.target;
124 157
125 if (target === this) { 158 if (target === this) {
126 return; 159 return;
127 } 160 }
128 161
129 if (this._interestedResizables.indexOf(target) === -1) { 162 if (this._interestedResizables.indexOf(target) === -1) {
130 this._interestedResizables.push(target); 163 this._interestedResizables.push(target);
164 this.listen(target, 'iron-resize', '_onDescendantIronResize');
131 } 165 }
132 166
133 target.assignParentResizable(this); 167 target.assignParentResizable(this);
168 this._notifyDescendant(target);
134 169
135 event.stopPropagation(); 170 event.stopPropagation();
171 },
172
173 _parentResizableChanged: function(parentResizable) {
174 if (parentResizable) {
175 window.removeEventListener('resize', this._boundNotifyResize);
176 }
177 },
178
179 _notifyDescendant: function(descendant) {
180 // NOTE(cdata): In IE10, attached is fired on children first, so it's
181 // important not to notify them if the parent is not attached yet (or
182 // else they will get redundantly notified when the parent attaches).
183 if (!this.isAttached) {
184 return;
185 }
186
187 this._notifyingDescendant = true;
188 descendant.notifyResize();
189 this._notifyingDescendant = false;
136 } 190 }
137 }; 191 };
138 </script> 192 </script>
139 193
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698