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

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

Issue 19786005: Reapply Box Model convenience classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/dom/templates/html/impl/impl_CSSStyleDeclaration.darttemplate ('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 for ease of CSS manipulation on a group of elements. 160 * additional methods when compared to regular lists for ease of CSS
161 * manipulation on a group of elements.
161 */ 162 */
162 abstract class ElementList<T extends Element> extends ListBase<T> { 163 abstract class ElementList<T extends Element> extends ListBase<T> {
163 /** 164 /**
164 * 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.
165 * 166 *
166 * 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
167 * if present) the classes applied to a collection of elements. 168 * if present) the classes applied to a collection of elements.
168 * 169 *
169 * htmlList.classes.add('selected'); 170 * htmlList.classes.add('selected');
170 * htmlList.classes.toggle('isOnline'); 171 * htmlList.classes.toggle('isOnline');
171 * htmlList.classes.remove('selected'); 172 * htmlList.classes.remove('selected');
172 */ 173 */
173 CssClassSet get classes; 174 CssClassSet get classes;
174 175
175 /** Replace the classes with `value` for every element in this list. */ 176 /** Replace the classes with `value` for every element in this list. */
176 set classes(Iterable<String> value); 177 set classes(Iterable<String> value);
178
179 /**
180 * Access dimensions and position of the Elements in this list.
181 *
182 * Setting the height or width properties will set the height or width
183 * property for all elements in the list. This returns a rectangle with the
184 * dimenions actually available for content
185 * in this element, in pixels, regardless of this element's box-sizing
186 * property. Getting the height or width returns the height or width of the
187 * first Element in this list.
188 *
189 * Unlike [getBoundingClientRect], the dimensions of this rectangle
190 * will return the same numerical height if the element is hidden or not.
191 */
192 @Experimental()
193 CssRect get contentEdge;
194
195 /**
196 * Access dimensions and position of the first Element's content + padding box
197 * in this list.
198 *
199 * This returns a rectangle with the dimenions actually available for content
200 * in this element, in pixels, regardless of this element's box-sizing
201 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
202 * will return the same numerical height if the element is hidden or not. This
203 * can be used to retrieve jQuery's `innerHeight` value for an element. This
204 * is also a rectangle equalling the dimensions of clientHeight and
205 * clientWidth.
206 */
207 @Experimental()
208 CssRect get paddingEdge;
209
210 /**
211 * Access dimensions and position of the first Element's content + padding +
212 * border box in this list.
213 *
214 * This returns a rectangle with the dimenions actually available for content
215 * in this element, in pixels, regardless of this element's box-sizing
216 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
217 * will return the same numerical height if the element is hidden or not. This
218 * can be used to retrieve jQuery's `outerHeight` value for an element.
219 */
220 @Experimental()
221 CssRect get borderEdge;
222
223 /**
224 * Access dimensions and position of the first Element's content + padding +
225 * border + margin box in this list.
226 *
227 * This returns a rectangle with the dimenions actually available for content
228 * in this element, in pixels, regardless of this element's box-sizing
229 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
230 * will return the same numerical height if the element is hidden or not. This
231 * can be used to retrieve jQuery's `outerHeight` value for an element.
232 */
233 @Experimental()
234 CssRect get marginEdge;
177 } 235 }
178 236
179 // TODO(jacobr): this is an inefficient implementation but it is hard to see 237 // TODO(jacobr): this is an inefficient implementation but it is hard to see
180 // a better option given that we cannot quite force NodeList to be an 238 // a better option given that we cannot quite force NodeList to be an
181 // ElementList as there are valid cases where a NodeList JavaScript object 239 // ElementList as there are valid cases where a NodeList JavaScript object
182 // contains Node objects that are not Elements. 240 // contains Node objects that are not Elements.
183 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { 241 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList {
184 final List<Node> _nodeList; 242 final List<Node> _nodeList;
243 // The subset of _nodeList that are Elements.
244 List<Element> _elementList;
185 245
186 _FrozenElementList._wrap(this._nodeList); 246 _FrozenElementList._wrap(this._nodeList) {
247 _elementList = _nodeList.where((e) => e is Element).toList();
248 }
187 249
188 int get length => _nodeList.length; 250 int get length => _nodeList.length;
189 251
190 Element operator [](int index) => _nodeList[index]; 252 Element operator [](int index) => _nodeList[index];
191 253
192 void operator []=(int index, Element value) { 254 void operator []=(int index, Element value) {
193 throw new UnsupportedError('Cannot modify list'); 255 throw new UnsupportedError('Cannot modify list');
194 } 256 }
195 257
196 void set length(int newLength) { 258 void set length(int newLength) {
197 throw new UnsupportedError('Cannot modify list'); 259 throw new UnsupportedError('Cannot modify list');
198 } 260 }
199 261
200 void sort([Comparator<Element> compare]) { 262 void sort([Comparator<Element> compare]) {
201 throw new UnsupportedError('Cannot sort list'); 263 throw new UnsupportedError('Cannot sort list');
202 } 264 }
203 265
204 Element get first => _nodeList.first; 266 Element get first => _nodeList.first;
205 267
206 Element get last => _nodeList.last; 268 Element get last => _nodeList.last;
207 269
208 Element get single => _nodeList.single; 270 Element get single => _nodeList.single;
209 271
210 CssClassSet get classes => new _MultiElementCssClassSet( 272 CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
211 _nodeList.where((e) => e is Element));
212 273
213 void set classes(Iterable<String> value) { 274 void set classes(Iterable<String> value) {
214 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); 275 _elementList.forEach((e) => e.classes = value);
215 } 276 }
277
278 CssRect get contentEdge => new _ContentCssListRect(_elementList);
279
280 CssRect get paddingEdge => _elementList.first.paddingEdge;
281
282 CssRect get borderEdge => _elementList.first.borderEdge;
283
284 CssRect get marginEdge => _elementList.first.marginEdge;
216 } 285 }
217 286
218 /** 287 /**
219 * An abstract class, which all HTML elements extend. 288 * An abstract class, which all HTML elements extend.
220 */ 289 */
221 $(ANNOTATIONS)abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 290 $(ANNOTATIONS)abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
222 291
223 /** 292 /**
224 * Creates an HTML element from a valid fragment of HTML. 293 * Creates an HTML element from a valid fragment of HTML.
225 * 294 *
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 @Experimental() 986 @Experimental()
918 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate; 987 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
919 988
920 void _ensureTemplate() { 989 void _ensureTemplate() {
921 if (!isTemplate) { 990 if (!isTemplate) {
922 throw new UnsupportedError('$this is not a template.'); 991 throw new UnsupportedError('$this is not a template.');
923 } 992 }
924 TemplateElement.decorate(this); 993 TemplateElement.decorate(this);
925 } 994 }
926 995
996 /**
997 * Access this element's content position.
998 *
999 * This returns a rectangle with the dimenions actually available for content
1000 * in this element, in pixels, regardless of this element's box-sizing
1001 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1002 * will return the same numerical height if the element is hidden or not.
1003 *
1004 * _Important_ _note_: use of this method _will_ perform CSS calculations that
1005 * can trigger a browser reflow. Therefore, use of this property _during_ an
1006 * animation frame is discouraged. See also:
1007 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1008 */
1009 @Experimental()
1010 CssRect get contentEdge => new _ContentCssRect(this);
1011
1012 /**
1013 * Access the dimensions and position of this element's content + padding box.
1014 *
1015 * This returns a rectangle with the dimenions actually available for content
1016 * in this element, in pixels, regardless of this element's box-sizing
1017 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1018 * will return the same numerical height if the element is hidden or not. This
1019 * can be used to retrieve jQuery's
1020 * [innerHeight](http://api.jquery.com/innerHeight/) value for an element.
1021 * This is also a rectangle equalling the dimensions of clientHeight and
1022 * clientWidth.
1023 *
1024 * _Important_ _note_: use of this method _will_ perform CSS calculations that
1025 * can trigger a browser reflow. Therefore, use of this property _during_ an
1026 * animation frame is discouraged. See also:
1027 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1028 */
1029 @Experimental()
1030 CssRect get paddingEdge => new _PaddingCssRect(this);
1031
1032 /**
1033 * Access the dimensions and position of this element's content + padding +
1034 * border box.
1035 *
1036 * This returns a rectangle with the dimenions actually available for content
1037 * in this element, in pixels, regardless of this element's box-sizing
1038 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1039 * will return the same numerical height if the element is hidden or not. This
1040 * can be used to retrieve jQuery's
1041 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
1042 *
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
1045 * animation frame is discouraged. See also:
1046 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1047 */
1048 @Experimental()
1049 CssRect get borderEdge => new _BorderCssRect(this);
1050
1051 /**
1052 * Access the dimensions and position of this element's content + padding +
1053 * border + margin box.
1054 *
1055 * This returns a rectangle with the dimenions actually available for content
1056 * in this element, in pixels, regardless of this element's box-sizing
1057 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
1058 * will return the same numerical height if the element is hidden or not. This
1059 * can be used to retrieve jQuery's
1060 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
1061 *
1062 * _Important_ _note_: use of this method will perform CSS calculations that
1063 * can trigger a browser reflow. Therefore, use of this property _during_ an
1064 * animation frame is discouraged. See also:
1065 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
1066 */
1067 @Experimental()
1068 CssRect get marginEdge => new _MarginCssRect(this);
927 $!MEMBERS 1069 $!MEMBERS
928 } 1070 }
929 1071
930 1072
931 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); 1073 final _START_TAG_REGEXP = new RegExp('<(\\w+)');
932 class _ElementFactoryProvider { 1074 class _ElementFactoryProvider {
933 static const _CUSTOM_PARENT_TAG_MAP = const { 1075 static const _CUSTOM_PARENT_TAG_MAP = const {
934 'body' : 'html', 1076 'body' : 'html',
935 'head' : 'html', 1077 'head' : 'html',
936 'caption' : 'table', 1078 'caption' : 'table',
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 const ScrollAlignment._internal(this._value); 1206 const ScrollAlignment._internal(this._value);
1065 toString() => 'ScrollAlignment.$_value'; 1207 toString() => 'ScrollAlignment.$_value';
1066 1208
1067 /// Attempt to align the element to the top of the scrollable area. 1209 /// Attempt to align the element to the top of the scrollable area.
1068 static const TOP = const ScrollAlignment._internal('TOP'); 1210 static const TOP = const ScrollAlignment._internal('TOP');
1069 /// Attempt to center the element in the scrollable area. 1211 /// Attempt to center the element in the scrollable area.
1070 static const CENTER = const ScrollAlignment._internal('CENTER'); 1212 static const CENTER = const ScrollAlignment._internal('CENTER');
1071 /// Attempt to align the element to the bottom of the scrollable area. 1213 /// Attempt to align the element to the bottom of the scrollable area.
1072 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); 1214 static const BOTTOM = const ScrollAlignment._internal('BOTTOM');
1073 } 1215 }
OLDNEW
« no previous file with comments | « tools/dom/templates/html/impl/impl_CSSStyleDeclaration.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698