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

Side by Side Diff: tools/dom/templates/html/impl/impl_Element.darttemplate

Issue 21093005: remove bindModel, the same effect can be achieved through createInstance (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 class _ChildrenElementList extends ListBase<Element> { 7 class _ChildrenElementList extends ListBase<Element> {
8 // Raw Element. 8 // Raw Element.
9 final Element _element; 9 final Element _element;
10 final HtmlCollection _childElements; 10 final HtmlCollection _childElements;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 151
152 Element get single { 152 Element get single {
153 if (length > 1) throw new StateError("More than one element"); 153 if (length > 1) throw new StateError("More than one element");
154 return first; 154 return first;
155 } 155 }
156 } 156 }
157 157
158 /** 158 /**
159 * An immutable list containing HTML elements. This list contains some 159 * An immutable list containing HTML elements. This list contains some
160 * additional methods when compared to regular lists for ease of CSS 160 * additional methods when compared to regular lists for ease of CSS
161 * manipulation on a group of elements. 161 * manipulation on a group of elements.
162 */ 162 */
163 abstract class ElementList<T extends Element> extends ListBase<T> { 163 abstract class ElementList<T extends Element> extends ListBase<T> {
164 /** 164 /**
165 * The union of all CSS classes applied to the elements in this list. 165 * The union of all CSS classes applied to the elements in this list.
166 * 166 *
167 * This set makes it easy to add, remove or toggle (add if not present, remove 167 * This set makes it easy to add, remove or toggle (add if not present, remove
168 * if present) the classes applied to a collection of elements. 168 * if present) the classes applied to a collection of elements.
169 * 169 *
170 * htmlList.classes.add('selected'); 170 * htmlList.classes.add('selected');
(...skipping 10 matching lines...) Expand all
181 * [ElementList]. 181 * [ElementList].
182 * 182 *
183 * Grouping the style objects all together provides easy editing of specific 183 * Grouping the style objects all together provides easy editing of specific
184 * properties of a collection of elements. Setting a specific property value 184 * properties of a collection of elements. Setting a specific property value
185 * will set that property in all [Element]s in the [ElementList]. Getting a 185 * will set that property in all [Element]s in the [ElementList]. Getting a
186 * specific property value will return the value of the property of the first 186 * specific property value will return the value of the property of the first
187 * element in the [ElementList]. 187 * element in the [ElementList].
188 */ 188 */
189 CssStyleDeclarationBase get style; 189 CssStyleDeclarationBase get style;
190 190
191 /** 191 /**
192 * Access dimensions and position of the Elements in this list. 192 * Access dimensions and position of the Elements in this list.
193 * 193 *
194 * Setting the height or width properties will set the height or width 194 * Setting the height or width properties will set the height or width
195 * property for all elements in the list. This returns a rectangle with the 195 * property for all elements in the list. This returns a rectangle with the
196 * dimenions actually available for content 196 * dimenions actually available for content
197 * in this element, in pixels, regardless of this element's box-sizing 197 * in this element, in pixels, regardless of this element's box-sizing
198 * property. Getting the height or width returns the height or width of the 198 * property. Getting the height or width returns the height or width of the
199 * first Element in this list. 199 * first Element in this list.
200 * 200 *
201 * Unlike [getBoundingClientRect], the dimensions of this rectangle 201 * Unlike [getBoundingClientRect], the dimensions of this rectangle
202 * will return the same numerical height if the element is hidden or not. 202 * will return the same numerical height if the element is hidden or not.
203 */ 203 */
204 @Experimental() 204 @Experimental()
205 CssRect get contentEdge; 205 CssRect get contentEdge;
206 206
207 /** 207 /**
208 * Access dimensions and position of the first Element's content + padding box 208 * Access dimensions and position of the first Element's content + padding box
209 * in this list. 209 * in this list.
210 * 210 *
211 * This returns a rectangle with the dimenions actually available for content 211 * This returns a rectangle with the dimenions actually available for content
212 * in this element, in pixels, regardless of this element's box-sizing 212 * in this element, in pixels, regardless of this element's box-sizing
213 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 213 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
214 * will return the same numerical height if the element is hidden or not. This 214 * will return the same numerical height if the element is hidden or not. This
215 * can be used to retrieve jQuery's `innerHeight` value for an element. This 215 * can be used to retrieve jQuery's `innerHeight` value for an element. This
216 * is also a rectangle equalling the dimensions of clientHeight and 216 * is also a rectangle equalling the dimensions of clientHeight and
217 * clientWidth. 217 * clientWidth.
218 */ 218 */
219 @Experimental() 219 @Experimental()
220 CssRect get paddingEdge; 220 CssRect get paddingEdge;
221 221
222 /** 222 /**
223 * Access dimensions and position of the first Element's content + padding + 223 * Access dimensions and position of the first Element's content + padding +
224 * border box in this list. 224 * border box in this list.
225 * 225 *
226 * This returns a rectangle with the dimenions actually available for content 226 * This returns a rectangle with the dimenions actually available for content
227 * in this element, in pixels, regardless of this element's box-sizing 227 * in this element, in pixels, regardless of this element's box-sizing
228 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 228 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
229 * will return the same numerical height if the element is hidden or not. This 229 * will return the same numerical height if the element is hidden or not. This
230 * can be used to retrieve jQuery's `outerHeight` value for an element. 230 * can be used to retrieve jQuery's `outerHeight` value for an element.
231 */ 231 */
232 @Experimental() 232 @Experimental()
233 CssRect get borderEdge; 233 CssRect get borderEdge;
234 234
235 /** 235 /**
236 * Access dimensions and position of the first Element's content + padding + 236 * Access dimensions and position of the first Element's content + padding +
237 * border + margin box in this list. 237 * border + margin box in this list.
238 * 238 *
239 * This returns a rectangle with the dimenions actually available for content 239 * This returns a rectangle with the dimenions actually available for content
240 * in this element, in pixels, regardless of this element's box-sizing 240 * in this element, in pixels, regardless of this element's box-sizing
241 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 241 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
242 * will return the same numerical height if the element is hidden or not. This 242 * will return the same numerical height if the element is hidden or not. This
243 * can be used to retrieve jQuery's `outerHeight` value for an element. 243 * can be used to retrieve jQuery's `outerHeight` value for an element.
244 */ 244 */
245 @Experimental() 245 @Experimental()
246 CssRect get marginEdge; 246 CssRect get marginEdge;
247 } 247 }
248 248
249 // TODO(jacobr): this is an inefficient implementation but it is hard to see 249 // TODO(jacobr): this is an inefficient implementation but it is hard to see
250 // a better option given that we cannot quite force NodeList to be an 250 // a better option given that we cannot quite force NodeList to be an
(...skipping 24 matching lines...) Expand all
275 throw new UnsupportedError('Cannot sort list'); 275 throw new UnsupportedError('Cannot sort list');
276 } 276 }
277 277
278 Element get first => _nodeList.first; 278 Element get first => _nodeList.first;
279 279
280 Element get last => _nodeList.last; 280 Element get last => _nodeList.last;
281 281
282 Element get single => _nodeList.single; 282 Element get single => _nodeList.single;
283 283
284 CssClassSet get classes => new _MultiElementCssClassSet(_elementList); 284 CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
285 285
286 CssStyleDeclarationBase get style => 286 CssStyleDeclarationBase get style =>
287 new _CssStyleDeclarationSet(_elementList); 287 new _CssStyleDeclarationSet(_elementList);
288 288
289 void set classes(Iterable<String> value) { 289 void set classes(Iterable<String> value) {
290 _elementList.forEach((e) => e.classes = value); 290 _elementList.forEach((e) => e.classes = value);
291 } 291 }
292 292
293 CssRect get contentEdge => new _ContentCssListRect(_elementList); 293 CssRect get contentEdge => new _ContentCssListRect(_elementList);
294 294
295 CssRect get paddingEdge => _elementList.first.paddingEdge; 295 CssRect get paddingEdge => _elementList.first.paddingEdge;
296 296
297 CssRect get borderEdge => _elementList.first.borderEdge; 297 CssRect get borderEdge => _elementList.first.borderEdge;
298 298
299 CssRect get marginEdge => _elementList.first.marginEdge; 299 CssRect get marginEdge => _elementList.first.marginEdge;
300 } 300 }
301 301
302 /** 302 /**
303 * An abstract class, which all HTML elements extend. 303 * An abstract class, which all HTML elements extend.
304 */ 304 */
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 * Gets the content of this template. 945 * Gets the content of this template.
946 * This is only supported if [isTemplate] is true. 946 * This is only supported if [isTemplate] is true.
947 */ 947 */
948 @Experimental() 948 @Experimental()
949 DocumentFragment get content { 949 DocumentFragment get content {
950 _ensureTemplate(); 950 _ensureTemplate();
951 return _templateContent; 951 return _templateContent;
952 } 952 }
953 953
954 /** 954 /**
955 * Creates an instance of the template, using the provided model and binding 955 * Creates an instance of the template, using the provided model and optional
956 * delegate. 956 * binding delegate.
957 * 957 *
958 * This is only supported if [isTemplate] is true. 958 * This is only supported if [isTemplate] is true.
959 */ 959 */
960 @Experimental() 960 @Experimental()
961 DocumentFragment createInstance(model, BindingDelegate delegate) { 961 DocumentFragment createInstance(model, [BindingDelegate delegate]) {
Jennifer Messerly 2013/07/31 02:47:02 it's not always easy to tell which things are inte
962 _ensureTemplate(); 962 _ensureTemplate();
963 return TemplateElement.mdvPackage(this).createInstance(model, delegate); 963 return TemplateElement.mdvPackage(this).createInstance(model, delegate);
964 } 964 }
965 965
966 /** 966 /**
967 * The data model which is inherited through the tree. 967 * The data model which is inherited through the tree.
968 * This is only supported if [isTemplate] is true. 968 * This is only supported if [isTemplate] is true.
969 */ 969 */
970 @Experimental() 970 @Experimental()
971 get model => TemplateElement.mdvPackage(this).model; 971 get model => TemplateElement.mdvPackage(this).model;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1027
1028 void _ensureTemplate() { 1028 void _ensureTemplate() {
1029 if (!isTemplate) { 1029 if (!isTemplate) {
1030 throw new UnsupportedError('$this is not a template.'); 1030 throw new UnsupportedError('$this is not a template.');
1031 } 1031 }
1032 TemplateElement.decorate(this); 1032 TemplateElement.decorate(this);
1033 } 1033 }
1034 1034
1035 /** 1035 /**
1036 * Access this element's content position. 1036 * Access this element's content position.
1037 * 1037 *
1038 * This returns a rectangle with the dimenions actually available for content 1038 * This returns a rectangle with the dimenions actually available for content
1039 * in this element, in pixels, regardless of this element's box-sizing 1039 * in this element, in pixels, regardless of this element's box-sizing
1040 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 1040 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1041 * will return the same numerical height if the element is hidden or not. 1041 * will return the same numerical height if the element is hidden or not.
1042 * 1042 *
1043 * _Important_ _note_: use of this method _will_ perform CSS calculations that 1043 * _Important_ _note_: use of this method _will_ perform CSS calculations that
1044 * can trigger a browser reflow. Therefore, use of this property _during_ an 1044 * can trigger a browser reflow. Therefore, use of this property _during_ an
1045 * animation frame is discouraged. See also: 1045 * animation frame is discouraged. See also:
1046 * [Browser Reflow](https://developers.google.com/speed/articles/reflow) 1046 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1047 */ 1047 */
1048 @Experimental() 1048 @Experimental()
1049 CssRect get contentEdge => new _ContentCssRect(this); 1049 CssRect get contentEdge => new _ContentCssRect(this);
1050 1050
1051 /** 1051 /**
1052 * Access the dimensions and position of this element's content + padding box. 1052 * Access the dimensions and position of this element's content + padding box.
1053 * 1053 *
1054 * This returns a rectangle with the dimenions actually available for content 1054 * This returns a rectangle with the dimenions actually available for content
1055 * in this element, in pixels, regardless of this element's box-sizing 1055 * in this element, in pixels, regardless of this element's box-sizing
1056 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 1056 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1057 * will return the same numerical height if the element is hidden or not. This 1057 * will return the same numerical height if the element is hidden or not. This
1058 * can be used to retrieve jQuery's 1058 * can be used to retrieve jQuery's
1059 * [innerHeight](http://api.jquery.com/innerHeight/) value for an element. 1059 * [innerHeight](http://api.jquery.com/innerHeight/) value for an element.
1060 * This is also a rectangle equalling the dimensions of clientHeight and 1060 * This is also a rectangle equalling the dimensions of clientHeight and
1061 * clientWidth. 1061 * clientWidth.
1062 * 1062 *
1063 * _Important_ _note_: use of this method _will_ perform CSS calculations that 1063 * _Important_ _note_: use of this method _will_ perform CSS calculations that
1064 * can trigger a browser reflow. Therefore, use of this property _during_ an 1064 * can trigger a browser reflow. Therefore, use of this property _during_ an
1065 * animation frame is discouraged. See also: 1065 * animation frame is discouraged. See also:
1066 * [Browser Reflow](https://developers.google.com/speed/articles/reflow) 1066 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1067 */ 1067 */
1068 @Experimental() 1068 @Experimental()
1069 CssRect get paddingEdge => new _PaddingCssRect(this); 1069 CssRect get paddingEdge => new _PaddingCssRect(this);
1070 1070
1071 /** 1071 /**
1072 * Access the dimensions and position of this element's content + padding + 1072 * Access the dimensions and position of this element's content + padding +
1073 * border box. 1073 * border box.
1074 * 1074 *
1075 * This returns a rectangle with the dimenions actually available for content 1075 * This returns a rectangle with the dimenions actually available for content
1076 * in this element, in pixels, regardless of this element's box-sizing 1076 * in this element, in pixels, regardless of this element's box-sizing
1077 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 1077 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1078 * will return the same numerical height if the element is hidden or not. This 1078 * will return the same numerical height if the element is hidden or not. This
1079 * can be used to retrieve jQuery's 1079 * can be used to retrieve jQuery's
1080 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element. 1080 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
1081 * 1081 *
1082 * _Important_ _note_: use of this method _will_ perform CSS calculations that 1082 * _Important_ _note_: use of this method _will_ perform CSS calculations that
1083 * can trigger a browser reflow. Therefore, use of this property _during_ an 1083 * can trigger a browser reflow. Therefore, use of this property _during_ an
1084 * animation frame is discouraged. See also: 1084 * animation frame is discouraged. See also:
1085 * [Browser Reflow](https://developers.google.com/speed/articles/reflow) 1085 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1086 */ 1086 */
1087 @Experimental() 1087 @Experimental()
1088 CssRect get borderEdge => new _BorderCssRect(this); 1088 CssRect get borderEdge => new _BorderCssRect(this);
1089 1089
1090 /** 1090 /**
1091 * Access the dimensions and position of this element's content + padding + 1091 * Access the dimensions and position of this element's content + padding +
1092 * border + margin box. 1092 * border + margin box.
1093 * 1093 *
1094 * This returns a rectangle with the dimenions actually available for content 1094 * This returns a rectangle with the dimenions actually available for content
1095 * in this element, in pixels, regardless of this element's box-sizing 1095 * in this element, in pixels, regardless of this element's box-sizing
1096 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle 1096 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1097 * will return the same numerical height if the element is hidden or not. This 1097 * will return the same numerical height if the element is hidden or not. This
1098 * can be used to retrieve jQuery's 1098 * can be used to retrieve jQuery's
1099 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element. 1099 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
1100 * 1100 *
1101 * _Important_ _note_: use of this method will perform CSS calculations that 1101 * _Important_ _note_: use of this method will perform CSS calculations that
1102 * can trigger a browser reflow. Therefore, use of this property _during_ an 1102 * can trigger a browser reflow. Therefore, use of this property _during_ an
1103 * animation frame is discouraged. See also: 1103 * animation frame is discouraged. See also:
1104 * [Browser Reflow](https://developers.google.com/speed/articles/reflow) 1104 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1105 */ 1105 */
1106 @Experimental() 1106 @Experimental()
1107 CssRect get marginEdge => new _MarginCssRect(this); 1107 CssRect get marginEdge => new _MarginCssRect(this);
1108 1108
1109 /** 1109 /**
1110 * Provides the coordinates of the element relative to the top of the 1110 * Provides the coordinates of the element relative to the top of the
1111 * document. 1111 * document.
1112 * 1112 *
1113 * This method is the Dart equivalent to jQuery's 1113 * This method is the Dart equivalent to jQuery's
1114 * [offset](http://api.jquery.com/offset/) method. 1114 * [offset](http://api.jquery.com/offset/) method.
1115 */ 1115 */
1116 Point get documentOffset => offsetTo(document.documentElement); 1116 Point get documentOffset => offsetTo(document.documentElement);
1117 1117
1118 /** 1118 /**
1119 * Provides the offset of this element's [borderEdge] relative to the 1119 * Provides the offset of this element's [borderEdge] relative to the
1120 * specified [parent]. 1120 * specified [parent].
1121 * 1121 *
1122 * This is the Dart equivalent of jQuery's 1122 * This is the Dart equivalent of jQuery's
1123 * [position](http://api.jquery.com/position/) method. Unlike jQuery's 1123 * [position](http://api.jquery.com/position/) method. Unlike jQuery's
1124 * position, however, [parent] can be any parent element of `this`, 1124 * position, however, [parent] can be any parent element of `this`,
1125 * rather than only `this`'s immediate [offsetParent]. If the specified 1125 * rather than only `this`'s immediate [offsetParent]. If the specified
1126 * element is _not_ an offset parent or transitive offset parent to this 1126 * element is _not_ an offset parent or transitive offset parent to this
1127 * element, an [ArgumentError] is thrown. 1127 * element, an [ArgumentError] is thrown.
1128 */ 1128 */
1129 Point offsetTo(Element parent) { 1129 Point offsetTo(Element parent) {
1130 return Element._offsetToHelper(this, parent); 1130 return Element._offsetToHelper(this, parent);
1131 } 1131 }
1132 1132
1133 static Point _offsetToHelper(Element current, Element parent) { 1133 static Point _offsetToHelper(Element current, Element parent) {
1134 // We're hopping from _offsetParent_ to offsetParent (not just parent), so 1134 // We're hopping from _offsetParent_ to offsetParent (not just parent), so
1135 // offsetParent, "tops out" at BODY. But people could conceivably pass in 1135 // offsetParent, "tops out" at BODY. But people could conceivably pass in
1136 // the document.documentElement and I want it to return an absolute offset, 1136 // the document.documentElement and I want it to return an absolute offset,
1137 // so we have the special case checking for HTML. 1137 // so we have the special case checking for HTML.
1138 bool foundAsParent = identical(current, parent) || parent.tagName == 'HTML'; 1138 bool foundAsParent = identical(current, parent) || parent.tagName == 'HTML';
1139 if (current == null || identical(current, parent)) { 1139 if (current == null || identical(current, parent)) {
1140 if (foundAsParent) return new Point(0, 0); 1140 if (foundAsParent) return new Point(0, 0);
1141 throw new ArgumentError("Specified element is not a transitive offset " 1141 throw new ArgumentError("Specified element is not a transitive offset "
1142 "parent of this element."); 1142 "parent of this element.");
1143 } 1143 }
1144 Element parentOffset = current.offsetParent; 1144 Element parentOffset = current.offsetParent;
1145 Point p = Element._offsetToHelper(parentOffset, parent); 1145 Point p = Element._offsetToHelper(parentOffset, parent);
1146 return new Point(p.x + current.offsetLeft, p.y + current.offsetTop); 1146 return new Point(p.x + current.offsetLeft, p.y + current.offsetTop);
1147 } 1147 }
1148 $!MEMBERS 1148 $!MEMBERS
1149 } 1149 }
1150 1150
1151 1151
1152 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); 1152 final _START_TAG_REGEXP = new RegExp('<(\\w+)');
1153 class _ElementFactoryProvider { 1153 class _ElementFactoryProvider {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 const ScrollAlignment._internal(this._value); 1285 const ScrollAlignment._internal(this._value);
1286 toString() => 'ScrollAlignment.$_value'; 1286 toString() => 'ScrollAlignment.$_value';
1287 1287
1288 /// Attempt to align the element to the top of the scrollable area. 1288 /// Attempt to align the element to the top of the scrollable area.
1289 static const TOP = const ScrollAlignment._internal('TOP'); 1289 static const TOP = const ScrollAlignment._internal('TOP');
1290 /// Attempt to center the element in the scrollable area. 1290 /// Attempt to center the element in the scrollable area.
1291 static const CENTER = const ScrollAlignment._internal('CENTER'); 1291 static const CENTER = const ScrollAlignment._internal('CENTER');
1292 /// Attempt to align the element to the bottom of the scrollable area. 1292 /// Attempt to align the element to the bottom of the scrollable area.
1293 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); 1293 static const BOTTOM = const ScrollAlignment._internal('BOTTOM');
1294 } 1294 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698