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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 21182002: Allow "bulk editing" of the CssStyleDeclaration objects in an ElementList as well (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:
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 6bd9e6c6428990929562323e0eef3bbd4756ed95..6ccd84979608b179fd08a25c69014d497ca75bab 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -2634,7 +2634,8 @@ class CssRule extends Interceptor native "CSSRule" {
@DomName('CSSStyleDeclaration')
-class CssStyleDeclaration extends Interceptor native "CSSStyleDeclaration,MSStyleCSSProperties,CSS2Properties" {
+ class CssStyleDeclaration extends Interceptor with
+ CssStyleDeclarationMixin native "CSSStyleDeclaration,MSStyleCSSProperties,CSS2Properties" {
factory CssStyleDeclaration() => new CssStyleDeclaration.css('');
factory CssStyleDeclaration.css(String css) {
@@ -2642,7 +2643,43 @@ class CssStyleDeclaration extends Interceptor native "CSSStyleDeclaration,MSStyl
style.cssText = css;
return style;
}
+}
+
+/**
+ * A collection of [CssStyleDeclaration]s that are associated with an
+ * [ElementList].
+ *
+ * Grouping the style objects all together provides easy editing of specific
+ * properties of a collection of elements. Setting a specific property value
+ * will set that property in all [Element]s in the [ElementList]. Getting a
+ * specific property value will return the value of the property of the first
+ * element in the [ElementList].
+ */
+class CssStyleDeclarationSet extends Interceptor with CssStyleDeclarationMixin {
+ final Iterable<Element> _elementIterable;
+ Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable;
+
+ CssStyleDeclarationSet._(this._elementIterable) {
+ _elementCssStyleDeclarationSetIterable = new List.from(
+ _elementIterable).map((e) => e.style);
+ }
+ String getPropertyValue(String propertyName) =>
+ _elementCssStyleDeclarationSetIterable.first.getPropertyValue(
+ propertyName);
+
+ void setProperty(String propertyName, String value, [String priority]) {
+ _elementCssStyleDeclarationSetIterable.forEach((e) =>
+ e.setProperty(propertyName, value, priority));
+ }
+ // Important note: CssStyleDeclarationSet does NOT implement every method
+ // available in CssStyleDeclaration. Some of the methods don't make so much
+ // sense in terms of having a resonable value to return when you're
+ // considering a list of Elements. You will need to manually add any of the
+ // items in the MEMBERS set if you want that functionality.
+}
+
+abstract class CssStyleDeclarationMixin {
@DomName('CSSStyleDeclaration.cssText')
@DocsEditable()
@@ -2677,7 +2714,6 @@ class CssStyleDeclaration extends Interceptor native "CSSStyleDeclaration,MSStyl
@DocsEditable()
String removeProperty(String propertyName) native;
-
String getPropertyValue(String propertyName) {
var propValue = _getPropertyValue(propertyName);
return propValue != null ? propValue : '';
@@ -7989,6 +8025,9 @@ abstract class ElementList<T extends Element> extends ListBase<T> {
/** Replace the classes with `value` for every element in this list. */
set classes(Iterable<String> value);
+ /** The union of all styles associated with the [Element]s in this list. */
+ CssStyleDeclarationSet get style;
+
/**
* Access dimensions and position of the Elements in this list.
*
@@ -8084,6 +8123,9 @@ class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme
CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
+ CssStyleDeclarationSet get style =>
+ new CssStyleDeclarationSet._(_elementList);
+
void set classes(Iterable<String> value) {
_elementList.forEach((e) => e.classes = value);
}

Powered by Google App Engine
This is Rietveld 408576698