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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Issue 11348111: Adding support for accessing attributes in alternate namespaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporating review feedback. Created 8 years, 1 month 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
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/html/scripts/htmlrenamer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index e430f598a515e60f9c7edd214ba00c4b6b53ab79..d35e6394f08e93c539b24394dde84f42791faa4a 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -9401,171 +9401,6 @@ class _FrozenElementListIterator implements Iterator<Element> {
bool get hasNext => _index < _list.length;
}
-class _ElementAttributeMap implements Map<String, String> {
-
- final Element _element;
-
- _ElementAttributeMap(this._element);
-
- bool containsValue(String value) {
- final attributes = _element.$dom_attributes;
- for (int i = 0, len = attributes.length; i < len; i++) {
- if(value == attributes[i].value) {
- return true;
- }
- }
- return false;
- }
-
- bool containsKey(String key) {
- return _element.$dom_hasAttribute(key);
- }
-
- String operator [](String key) {
- return _element.$dom_getAttribute(key);
- }
-
- void operator []=(String key, value) {
- _element.$dom_setAttribute(key, '$value');
- }
-
- String putIfAbsent(String key, String ifAbsent()) {
- if (!containsKey(key)) {
- this[key] = ifAbsent();
- }
- return this[key];
- }
-
- String remove(String key) {
- String value = _element.$dom_getAttribute(key);
- _element.$dom_removeAttribute(key);
- return value;
- }
-
- void clear() {
- final attributes = _element.$dom_attributes;
- for (int i = attributes.length - 1; i >= 0; i--) {
- remove(attributes[i].name);
- }
- }
-
- void forEach(void f(String key, String value)) {
- final attributes = _element.$dom_attributes;
- for (int i = 0, len = attributes.length; i < len; i++) {
- final item = attributes[i];
- f(item.name, item.value);
- }
- }
-
- Collection<String> get keys {
- // TODO(jacobr): generate a lazy collection instead.
- final attributes = _element.$dom_attributes;
- final keys = new List<String>(attributes.length);
- for (int i = 0, len = attributes.length; i < len; i++) {
- keys[i] = attributes[i].name;
- }
- return keys;
- }
-
- Collection<String> get values {
- // TODO(jacobr): generate a lazy collection instead.
- final attributes = _element.$dom_attributes;
- final values = new List<String>(attributes.length);
- for (int i = 0, len = attributes.length; i < len; i++) {
- values[i] = attributes[i].value;
- }
- return values;
- }
-
- /**
- * The number of {key, value} pairs in the map.
- */
- int get length {
- return _element.$dom_attributes.length;
- }
-
- /**
- * Returns true if there is no {key, value} pair in the map.
- */
- bool get isEmpty {
- return length == 0;
- }
-}
-
-/**
- * Provides a Map abstraction on top of data-* attributes, similar to the
- * dataSet in the old DOM.
- */
-class _DataAttributeMap implements Map<String, String> {
-
- final Map<String, String> $dom_attributes;
-
- _DataAttributeMap(this.$dom_attributes);
-
- // interface Map
-
- // TODO: Use lazy iterator when it is available on Map.
- bool containsValue(String value) => values.some((v) => v == value);
-
- bool containsKey(String key) => $dom_attributes.containsKey(_attr(key));
-
- String operator [](String key) => $dom_attributes[_attr(key)];
-
- void operator []=(String key, value) {
- $dom_attributes[_attr(key)] = '$value';
- }
-
- String putIfAbsent(String key, String ifAbsent()) =>
- $dom_attributes.putIfAbsent(_attr(key), ifAbsent);
-
- String remove(String key) => $dom_attributes.remove(_attr(key));
-
- void clear() {
- // Needs to operate on a snapshot since we are mutating the collection.
- for (String key in keys) {
- remove(key);
- }
- }
-
- void forEach(void f(String key, String value)) {
- $dom_attributes.forEach((String key, String value) {
- if (_matches(key)) {
- f(_strip(key), value);
- }
- });
- }
-
- Collection<String> get keys {
- final keys = new List<String>();
- $dom_attributes.forEach((String key, String value) {
- if (_matches(key)) {
- keys.add(_strip(key));
- }
- });
- return keys;
- }
-
- Collection<String> get values {
- final values = new List<String>();
- $dom_attributes.forEach((String key, String value) {
- if (_matches(key)) {
- values.add(value);
- }
- });
- return values;
- }
-
- int get length => keys.length;
-
- // TODO: Use lazy iterator when it is available on Map.
- bool get isEmpty => length == 0;
-
- // Helpers.
- String _attr(String key) => 'data-$key';
- bool _matches(String key) => key.startsWith('data-');
- String _strip(String key) => key.substring(5);
-}
-
class _ElementCssClassSet extends CssClassSet {
final Element _element;
@@ -9678,6 +9513,14 @@ abstract class Element extends Node implements ElementTraversal {
}
}
+ /**
+ * Gets a map for manipulating the attributes of a particular namespace.
+ * This is primarily useful for SVG attributes such as xref:link.
+ */
+ Map<String, String> getNamespacedAttributes(String namespace) {
+ return new _NamespacedAttributeMap(this, namespace);
+ }
+
/** @domName Window.getComputedStyle */
Future<CSSStyleDeclaration> get computedStyle {
// TODO(jacobr): last param should be null, see b/5045788
@@ -9913,6 +9756,10 @@ abstract class Element extends Node implements ElementTraversal {
String $dom_getAttribute(String name) native "Element_getAttribute_Callback";
+ /** @domName Element.getAttributeNS */
+ String $dom_getAttributeNS(String namespaceURI, String localName) native "Element_getAttributeNS_Callback";
+
+
/** @domName Element.getBoundingClientRect */
ClientRect getBoundingClientRect() native "Element_getBoundingClientRect_Callback";
@@ -9933,6 +9780,10 @@ abstract class Element extends Node implements ElementTraversal {
bool $dom_hasAttribute(String name) native "Element_hasAttribute_Callback";
+ /** @domName Element.hasAttributeNS */
+ bool $dom_hasAttributeNS(String namespaceURI, String localName) native "Element_hasAttributeNS_Callback";
+
+
/** @domName Element.querySelector */
Element $dom_querySelector(String selectors) native "Element_querySelector_Callback";
@@ -9949,6 +9800,10 @@ abstract class Element extends Node implements ElementTraversal {
void $dom_removeAttribute(String name) native "Element_removeAttribute_Callback";
+ /** @domName Element.removeAttributeNS */
+ void $dom_removeAttributeNS(String namespaceURI, String localName) native "Element_removeAttributeNS_Callback";
+
+
/** @domName Element.scrollByLines */
void scrollByLines(int lines) native "Element_scrollByLines_Callback";
@@ -9977,6 +9832,10 @@ abstract class Element extends Node implements ElementTraversal {
void $dom_setAttribute(String name, String value) native "Element_setAttribute_Callback";
+ /** @domName Element.setAttributeNS */
+ void $dom_setAttributeNS(String namespaceURI, String qualifiedName, String value) native "Element_setAttributeNS_Callback";
+
+
/** @domName Element.webkitMatchesSelector */
bool matchesSelector(String selectors) native "Element_webkitMatchesSelector_Callback";
@@ -18001,6 +17860,14 @@ class Node extends EventTarget {
Node get $dom_lastChild native "Node_lastChild_Getter";
+ /** @domName Node.localName */
+ String get $dom_localName native "Node_localName_Getter";
+
+
+ /** @domName Node.namespaceURI */
+ String get $dom_namespaceURI native "Node_namespaceURI_Getter";
+
+
/** @domName Node.nextSibling */
Node get nextNode native "Node_nextSibling_Getter";
@@ -28501,6 +28368,228 @@ class _XSLTProcessorFactoryProvider {
// BSD-style license that can be found in the LICENSE file.
+abstract class _AttributeMap implements Map<String, String> {
+
+ bool containsValue(String value) {
+ for (var v in this.values) {
+ if (value == v) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ String putIfAbsent(String key, String ifAbsent()) {
+ if (!containsKey(key)) {
+ this[key] = ifAbsent();
+ }
+ return this[key];
+ }
+
+ void clear() {
+ for (var key in keys) {
+ remove(key);
+ }
+ }
+
+ void forEach(void f(String key, String value)) {
+ for (var key in keys) {
+ var value = this[key];
+ f(key, value);
+ }
+ }
+
+ Collection<String> get keys {
+ // TODO: generate a lazy collection instead.
+ var attributes = _element.$dom_attributes;
+ var keys = new List<String>();
+ for (int i = 0, len = attributes.length; i < len; i++) {
+ if (_matches(attributes[i])) {
+ keys.add(attributes[i].$dom_localName);
+ }
+ }
+ return keys;
+ }
+
+ Collection<String> get values {
+ // TODO: generate a lazy collection instead.
+ var attributes = _element.$dom_attributes;
+ var values = new List<String>();
+ for (int i = 0, len = attributes.length; i < len; i++) {
+ if (_matches(attributes[i])) {
+ values.add(attributes[i].value);
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Returns true if there is no {key, value} pair in the map.
+ */
+ bool get isEmpty {
+ return length == 0;
+ }
+
+ /**
+ * Checks to see if the node should be included in this map.
+ */
+ bool _matches(Node node);
+}
+
+/**
+ * Wrapper to expose Element.attributes as a typed map.
+ */
+class _ElementAttributeMap extends _AttributeMap {
+
+ final Element _element;
+
+ _ElementAttributeMap(this._element);
+
+ bool containsKey(String key) {
+ return _element.$dom_hasAttribute(key);
+ }
+
+ String operator [](String key) {
+ return _element.$dom_getAttribute(key);
+ }
+
+ void operator []=(String key, value) {
+ _element.$dom_setAttribute(key, '$value');
+ }
+
+ String remove(String key) {
+ String value = _element.$dom_getAttribute(key);
+ _element.$dom_removeAttribute(key);
+ return value;
+ }
+
+ /**
+ * The number of {key, value} pairs in the map.
+ */
+ int get length {
+ return keys.length;
+ }
+
+ bool _matches(Node node) => node.$dom_namespaceURI == null;
+}
+
+/**
+ * Wrapper to expose namespaced attributes as a typed map.
+ */
+class _NamespacedAttributeMap extends _AttributeMap {
+
+ final Element _element;
+ final String _namespace;
+
+ _NamespacedAttributeMap(this._element, this._namespace);
+
+ bool containsKey(String key) {
+ return _element.$dom_hasAttributeNS(_namespace, key);
+ }
+
+ String operator [](String key) {
+ return _element.$dom_getAttributeNS(_namespace, key);
+ }
+
+ void operator []=(String key, value) {
+ _element.$dom_setAttributeNS(_namespace, key, '$value');
+ }
+
+ String remove(String key) {
+ String value = this[key];
+ _element.$dom_removeAttributeNS(_namespace, key);
+ return value;
+ }
+
+ /**
+ * The number of {key, value} pairs in the map.
+ */
+ int get length {
+ return keys.length;
+ }
+
+ bool _matches(Node node) => node.$dom_namespaceURI == _namespace;
+}
+
+
+/**
+ * Provides a Map abstraction on top of data-* attributes, similar to the
+ * dataSet in the old DOM.
+ */
+class _DataAttributeMap implements Map<String, String> {
+
+ final Map<String, String> $dom_attributes;
+
+ _DataAttributeMap(this.$dom_attributes);
+
+ // interface Map
+
+ // TODO: Use lazy iterator when it is available on Map.
+ bool containsValue(String value) => values.some((v) => v == value);
+
+ bool containsKey(String key) => $dom_attributes.containsKey(_attr(key));
+
+ String operator [](String key) => $dom_attributes[_attr(key)];
+
+ void operator []=(String key, value) {
+ $dom_attributes[_attr(key)] = '$value';
+ }
+
+ String putIfAbsent(String key, String ifAbsent()) =>
+ $dom_attributes.putIfAbsent(_attr(key), ifAbsent);
+
+ String remove(String key) => $dom_attributes.remove(_attr(key));
+
+ void clear() {
+ // Needs to operate on a snapshot since we are mutating the collection.
+ for (String key in keys) {
+ remove(key);
+ }
+ }
+
+ void forEach(void f(String key, String value)) {
+ $dom_attributes.forEach((String key, String value) {
+ if (_matches(key)) {
+ f(_strip(key), value);
+ }
+ });
+ }
+
+ Collection<String> get keys {
+ final keys = new List<String>();
+ $dom_attributes.forEach((String key, String value) {
+ if (_matches(key)) {
+ keys.add(_strip(key));
+ }
+ });
+ return keys;
+ }
+
+ Collection<String> get values {
+ final values = new List<String>();
+ $dom_attributes.forEach((String key, String value) {
+ if (_matches(key)) {
+ values.add(value);
+ }
+ });
+ return values;
+ }
+
+ int get length => keys.length;
+
+ // TODO: Use lazy iterator when it is available on Map.
+ bool get isEmpty => length == 0;
+
+ // Helpers.
+ String _attr(String key) => 'data-$key';
+ bool _matches(String key) => key.startsWith('data-');
+ String _strip(String key) => key.substring(5);
+}
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+
/**
* An object representing the top-level context object for web scripting.
*
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/html/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698