From 881e456c21fcbd96dfdb26ade62fed092071908e Mon Sep 17 00:00:00 2001 From: "blois@google.com" Date: Thu, 30 May 2013 16:31:09 +0000 Subject: [PATCH] Cleaning up some DOM APIs which were marked as deprecated because they were moved or renamed. There were basically two issues: - localName and namespaceUri moved from Node down to Element. - The transitionEnd event was polyfilled based on the deprecated webkitTransitionEnd event, so it was switched to the standard transtionEnd. The Attr change was needed because the node map was using localName on Attr (inherited from Node), when it should have been using name. Attr is not actually exposed anywhere, so made it private. BUG= R=efortuna@google.com Review URL: https://codereview.chromium.org//15814008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23423 260f80e4-7a28-3924-810f-c04153c831b5 --- sdk/lib/html/dart2js/html_dart2js.dart | 72 ++++++++++----- sdk/lib/html/dartium/html_dartium.dart | 89 ++++++++++++------- tests/html/svg_attrs_test.dart | 47 ++++++++++ tools/dom/dom.json | 1 + tools/dom/scripts/dartmetadata.py | 2 +- tools/dom/scripts/htmleventgenerator.py | 5 +- tools/dom/scripts/htmlrenamer.py | 3 +- tools/dom/src/AttributeMap.dart | 2 +- .../html/impl/impl_Element.darttemplate | 12 ++- .../html/impl/impl_Node.darttemplate | 3 +- 10 files changed, 176 insertions(+), 60 deletions(-) create mode 100644 tests/html/svg_attrs_test.dart diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 5e1296e487b..2c9feae06dc 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -426,15 +426,6 @@ class AreaElement extends Element native "HTMLAreaElement" { // BSD-style license that can be found in the LICENSE file. -@DocsEditable -@DomName('Attr') -class Attr extends Node native "Attr" { -} -// 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. - - @DocsEditable @DomName('HTMLAudioElement') class AudioElement extends MediaElement native "HTMLAudioElement" { @@ -7660,6 +7651,16 @@ abstract class Element extends Node implements ElementTraversal native "Element" _xtag = value; } + @DomName('Element.localName') + @DocsEditable + String get localName => $dom_localName; + + @DomName('Element.namespaceUri') + @DocsEditable + String get namespaceUri => $dom_namespaceUri; + + String toString() => localName; + /** * Scrolls this element into view. * @@ -7714,7 +7715,7 @@ abstract class Element extends Node implements ElementTraversal native "Element" } } - @DomName('Element.webkitTransitionEndEvent') + @DomName('Element.transitionEndEvent') static const EventStreamProvider transitionEndEvent = const _CustomEventStreamProvider( Element._determineTransitionEventType); @@ -8872,13 +8873,12 @@ abstract class Element extends Node implements ElementTraversal native "Element" @Experimental Stream get onTouchStart => touchStartEvent.forTarget(this); - @DomName('Element.onwebkitTransitionEnd') + @DomName('Element.ontransitionend') @DocsEditable @SupportedBrowser(SupportedBrowser.CHROME) @SupportedBrowser(SupportedBrowser.FIREFOX) @SupportedBrowser(SupportedBrowser.IE, '10') @SupportedBrowser(SupportedBrowser.SAFARI) - @deprecated Stream get onTransitionEnd => transitionEndEvent.forTarget(this); @DomName('Element.onwebkitfullscreenchange') @@ -15847,8 +15847,7 @@ class Node extends EventTarget native "Node" { /** * Print out a String representation of this Node. */ - String toString() => localName == null ? - (nodeValue == null ? super.toString() : nodeValue) : localName; + String toString() => nodeValue == null ? super.toString() : nodeValue; /** * Binds the attribute [name] to the [path] of the [model]. @@ -15943,11 +15942,12 @@ class Node extends EventTarget native "Node" { @DocsEditable final Node $dom_lastChild; + @JSName('localName') @DomName('Node.localName') @DocsEditable // http://dom.spec.whatwg.org/#dom-node-localname @deprecated // deprecated - final String localName; + final String $dom_localName; @JSName('namespaceURI') @DomName('Node.namespaceURI') @@ -23238,6 +23238,10 @@ class Window extends EventTarget implements WindowBase native "Window,DOMWindow" @Experimental Stream get onTouchStart => Element.touchStartEvent.forTarget(this); + @DomName('Window.ontransitionend') + @DocsEditable + Stream get onTransitionEnd => Element.transitionEndEvent.forTarget(this); + @DomName('Window.onunload') @DocsEditable Stream get onUnload => unloadEvent.forTarget(this); @@ -23257,11 +23261,6 @@ class Window extends EventTarget implements WindowBase native "Window,DOMWindow" @Experimental // untriaged Stream get onAnimationStart => animationStartEvent.forTarget(this); - @DomName('Window.onwebkitTransitionEnd') - @DocsEditable - @deprecated - Stream get onTransitionEnd => Element.transitionEndEvent.forTarget(this); - @DomName('DOMWindow.beforeunloadEvent') @DocsEditable @@ -23635,6 +23634,37 @@ class XsltProcessor native "XSLTProcessor" { // BSD-style license that can be found in the LICENSE file. +@DocsEditable +@DomName('Attr') +class _Attr extends Node native "Attr" { + + @DomName('Attr.isId') + @DocsEditable + final bool isId; + + @DomName('Attr.name') + @DocsEditable + final String name; + + @DomName('Attr.ownerElement') + @DocsEditable + @deprecated // deprecated + final Element ownerElement; + + @DomName('Attr.specified') + @DocsEditable + @deprecated // deprecated + final bool specified; + + @DomName('Attr.value') + @DocsEditable + String value; +} +// 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. + + @DocsEditable @DomName('CSSPrimitiveValue') // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface @@ -24875,7 +24905,7 @@ abstract class _AttributeMap implements Map { var keys = new List(); for (int i = 0, len = attributes.length; i < len; i++) { if (_matches(attributes[i])) { - keys.add(attributes[i].localName); + keys.add(attributes[i].name); } } return keys; diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart index 527f3754d61..c2222e27603 100644 --- a/sdk/lib/html/dartium/html_dartium.dart +++ b/sdk/lib/html/dartium/html_dartium.dart @@ -540,19 +540,6 @@ class AreaElement extends _Element_Merged { // WARNING: Do not edit - generated code. -@DocsEditable -@DomName('Attr') -class Attr extends Node { - Attr.internal() : super.internal(); - -} -// 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. - -// WARNING: Do not edit - generated code. - - @DocsEditable @DomName('HTMLAudioElement') class AudioElement extends MediaElement { @@ -8133,6 +8120,16 @@ abstract class Element extends Node implements ElementTraversal { _xtag = value; } + @DomName('Element.localName') + @DocsEditable + String get localName => $dom_localName; + + @DomName('Element.namespaceUri') + @DocsEditable + String get namespaceUri => $dom_namespaceUri; + + String toString() => localName; + /** * Scrolls this element into view. * @@ -8612,13 +8609,9 @@ abstract class Element extends Node implements ElementTraversal { @Experimental static const EventStreamProvider touchStartEvent = const EventStreamProvider('touchstart'); - @DomName('Element.webkitTransitionEndEvent') + @DomName('Element.transitionendEvent') @DocsEditable - @SupportedBrowser(SupportedBrowser.CHROME) - @SupportedBrowser(SupportedBrowser.SAFARI) - @Experimental - @deprecated - static const EventStreamProvider transitionEndEvent = const EventStreamProvider('webkitTransitionEnd'); + static const EventStreamProvider transitionEndEvent = const EventStreamProvider('transitionend'); @DomName('Element.webkitfullscreenchangeEvent') @DocsEditable @@ -9183,13 +9176,12 @@ abstract class Element extends Node implements ElementTraversal { @Experimental Stream get onTouchStart => touchStartEvent.forTarget(this); - @DomName('Element.onwebkitTransitionEnd') + @DomName('Element.ontransitionend') @DocsEditable @SupportedBrowser(SupportedBrowser.CHROME) @SupportedBrowser(SupportedBrowser.FIREFOX) @SupportedBrowser(SupportedBrowser.IE, '10') @SupportedBrowser(SupportedBrowser.SAFARI) - @deprecated Stream get onTransitionEnd => transitionEndEvent.forTarget(this); @DomName('Element.onwebkitfullscreenchange') @@ -16900,8 +16892,7 @@ class Node extends EventTarget { /** * Print out a String representation of this Node. */ - String toString() => localName == null ? - (nodeValue == null ? super.toString() : nodeValue) : localName; + String toString() => nodeValue == null ? super.toString() : nodeValue; /** * Binds the attribute [name] to the [path] of the [model]. @@ -16996,7 +16987,7 @@ class Node extends EventTarget { @DocsEditable // http://dom.spec.whatwg.org/#dom-node-localname @deprecated // deprecated - String get localName native "Node_localName_Getter"; + String get $dom_localName native "Node_localName_Getter"; @DomName('Node.namespaceURI') @DocsEditable @@ -24737,6 +24728,10 @@ class Window extends EventTarget implements WindowBase { @Experimental Stream get onTouchStart => Element.touchStartEvent.forTarget(this); + @DomName('Window.ontransitionend') + @DocsEditable + Stream get onTransitionEnd => Element.transitionEndEvent.forTarget(this); + @DomName('Window.onunload') @DocsEditable Stream get onUnload => unloadEvent.forTarget(this); @@ -24756,11 +24751,6 @@ class Window extends EventTarget implements WindowBase { @Experimental // untriaged Stream get onAnimationStart => animationStartEvent.forTarget(this); - @DomName('Window.onwebkitTransitionEnd') - @DocsEditable - @deprecated - Stream get onTransitionEnd => Element.transitionEndEvent.forTarget(this); - @DomName('DOMWindow.beforeunloadEvent') @DocsEditable @@ -25170,6 +25160,45 @@ class XsltProcessor extends NativeFieldWrapperClass1 { // WARNING: Do not edit - generated code. +@DocsEditable +@DomName('Attr') +class _Attr extends Node { + _Attr.internal() : super.internal(); + + @DomName('Attr.isId') + @DocsEditable + bool get isId native "Attr_isId_Getter"; + + @DomName('Attr.name') + @DocsEditable + String get name native "Attr_name_Getter"; + + @DomName('Attr.ownerElement') + @DocsEditable + @deprecated // deprecated + Element get ownerElement native "Attr_ownerElement_Getter"; + + @DomName('Attr.specified') + @DocsEditable + @deprecated // deprecated + bool get specified native "Attr_specified_Getter"; + + @DomName('Attr.value') + @DocsEditable + String get value native "Attr_value_Getter"; + + @DomName('Attr.value') + @DocsEditable + void set value(String value) native "Attr_value_Setter"; + +} +// 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. + +// WARNING: Do not edit - generated code. + + @DocsEditable @DomName('CSSPrimitiveValue') // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface @@ -26749,7 +26778,7 @@ abstract class _AttributeMap implements Map { var keys = new List(); for (int i = 0, len = attributes.length; i < len; i++) { if (_matches(attributes[i])) { - keys.add(attributes[i].localName); + keys.add(attributes[i].name); } } return keys; diff --git a/tests/html/svg_attrs_test.dart b/tests/html/svg_attrs_test.dart new file mode 100644 index 00000000000..ae3e6257247 --- /dev/null +++ b/tests/html/svg_attrs_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2013, 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. + +library SVGTest; +import '../../pkg/unittest/lib/unittest.dart'; +import '../../pkg/unittest/lib/html_config.dart'; +import 'dart:svg'; + +main() { + useHtmlConfiguration(); + + test('svg parsed attributes', () { + var content = """ + + +"""; + + var svg = new SvgElement.svg(content); + var img = svg.children[0]; + expect(img is ImageElement, isTrue); + var attrs = img.attributes; + expect(attrs.length, 0); + + var xlinkAttrs = + img.getNamespacedAttributes('http://www.w3.org/1999/xlink'); + expect(xlinkAttrs.length, 1); + expect(xlinkAttrs['href'], 'foo.jpg'); + + // validate that the namespaced attr was set by waiting for the image + // to fail to load. + return img.onError.first; + }); + + test('svg explicit attributes', () { + + var img = new ImageElement(); + var xlinkAttrs = + img.getNamespacedAttributes('http://www.w3.org/1999/xlink'); + xlinkAttrs['href'] = 'foo.jpg'; + + // validate that the namespaced attr was set by waiting for the image + // to fail to load. + return img.onError.first; + }); +} diff --git a/tools/dom/dom.json b/tools/dom/dom.json index c01a78fcfce..64d963ac558 100644 --- a/tools/dom/dom.json +++ b/tools/dom/dom.json @@ -2354,6 +2354,7 @@ "comment": "http://www.w3.org/TR/touch-events/, http://www.chromestatus.com/features", "support_level": "experimental" }, + "ontransitionend": {}, "onwebkitTransitionEnd": { "support_level": "deprecated" }, diff --git a/tools/dom/scripts/dartmetadata.py b/tools/dom/scripts/dartmetadata.py index 9daed68ec8c..3cbd9959f10 100644 --- a/tools/dom/scripts/dartmetadata.py +++ b/tools/dom/scripts/dartmetadata.py @@ -279,7 +279,7 @@ _annotations = monitored.Dict('dartmetadata._annotations', { 'DOMWindow.webkitNotifications': _webkit_experimental_annotations, 'DOMWindow.webkitRequestFileSystem': _file_system_annotations, 'DOMWindow.webkitResolveLocalFileSystemURL': _file_system_annotations, - 'Element.onwebkitTransitionEnd': _all_but_ie9_annotations, + 'Element.ontransitionend': _all_but_ie9_annotations, # Placeholder to add experimental flag, implementation for this is # pending in a separate CL. 'Element.webkitMatchesSelector': ['@Experimental()'], diff --git a/tools/dom/scripts/htmleventgenerator.py b/tools/dom/scripts/htmleventgenerator.py index 5a006f5a430..c2ead7ced55 100644 --- a/tools/dom/scripts/htmleventgenerator.py +++ b/tools/dom/scripts/htmleventgenerator.py @@ -15,7 +15,7 @@ _logger = logging.getLogger('dartgenerator') # onEventName methods in the IDL but some events aren't listed so we need # to manually add them here so that they are easy for users to find. _html_manual_events = monitored.Dict('htmleventgenerator._html_manual_events', { - 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], + 'Element': ['touchleave', 'touchenter', 'transitionend'], 'Window': ['DOMContentLoaded'] }) @@ -28,7 +28,6 @@ _on_attribute_to_event_name_mapping = monitored.Dict( 'webkitanimationiteration': 'webkitAnimationIteration', 'webkitanimationstart': 'webkitAnimationStart', 'webkitspeechchange': 'webkitSpeechChange', - 'webkittransitionend': 'webkitTransitionEnd', }) _html_event_types = monitored.Dict('htmleventgenerator._html_event_types', { @@ -108,7 +107,7 @@ _html_event_types = monitored.Dict('htmleventgenerator._html_event_types', { '*.webkitAnimationEnd': ('animationEnd', 'AnimationEvent'), '*.webkitAnimationIteration': ('animationIteration', 'AnimationEvent'), '*.webkitAnimationStart': ('animationStart', 'AnimationEvent'), - '*.webkitTransitionEnd': ('transitionEnd', 'TransitionEvent'), + '*.transitionend': ('transitionEnd', 'TransitionEvent'), '*.webkitfullscreenchange': ('fullscreenChange', 'Event'), '*.webkitfullscreenerror': ('fullscreenError', 'Event'), 'AbstractWorker.error': ('error', 'ErrorEvent'), diff --git a/tools/dom/scripts/htmlrenamer.py b/tools/dom/scripts/htmlrenamer.py index 7262ee1987e..b3d7354f225 100644 --- a/tools/dom/scripts/htmlrenamer.py +++ b/tools/dom/scripts/htmlrenamer.py @@ -23,6 +23,7 @@ typed_array_renames = { html_interface_renames = monitored.Dict('htmlrenamer.html_interface_renames', dict({ + 'Attr': '_Attr', 'CDATASection': 'CDataSection', 'Clipboard': 'DataTransfer', 'Database': 'SqlDatabase', # Avoid conflict with Index DB's Database. @@ -270,6 +271,7 @@ _private_html_members = monitored.Set('htmlrenamer._private_html_members', [ 'Node.childNodes', 'Node.firstChild', 'Node.lastChild', + 'Node.localName', 'Node.namespaceURI', 'Node.removeChild', 'Node.replaceChild', @@ -363,7 +365,6 @@ for member in convert_to_future_members: # to be suppressed but not the setter, etc. # TODO(jacobr): cleanup and augment this list. _removed_html_members = monitored.Set('htmlrenamer._removed_html_members', [ - 'Attr.*', 'AudioBufferSourceNode.looping', # TODO(vsm): Use deprecated IDL annotation 'CSSStyleDeclaration.getPropertyCSSValue', 'CanvasRenderingContext2D.clearShadow', diff --git a/tools/dom/src/AttributeMap.dart b/tools/dom/src/AttributeMap.dart index b0cb0cc7fe6..76a90648c18 100644 --- a/tools/dom/src/AttributeMap.dart +++ b/tools/dom/src/AttributeMap.dart @@ -44,7 +44,7 @@ abstract class _AttributeMap implements Map { var keys = new List(); for (int i = 0, len = attributes.length; i < len; i++) { if (_matches(attributes[i])) { - keys.add(attributes[i].localName); + keys.add(attributes[i].name); } } return keys; diff --git a/tools/dom/templates/html/impl/impl_Element.darttemplate b/tools/dom/templates/html/impl/impl_Element.darttemplate index f3bb261b668..7b8a594ce6f 100644 --- a/tools/dom/templates/html/impl/impl_Element.darttemplate +++ b/tools/dom/templates/html/impl/impl_Element.darttemplate @@ -468,6 +468,16 @@ $endif _xtag = value; } + @DomName('Element.localName') + @DocsEditable + String get localName => $dom_localName; + + @DomName('Element.namespaceUri') + @DocsEditable + String get namespaceUri => $dom_namespaceUri; + + String toString() => localName; + /** * Scrolls this element into view. * @@ -525,7 +535,7 @@ $if DART2JS } } - @DomName('Element.webkitTransitionEndEvent') + @DomName('Element.transitionEndEvent') static const EventStreamProvider transitionEndEvent = const _CustomEventStreamProvider( Element._determineTransitionEventType); diff --git a/tools/dom/templates/html/impl/impl_Node.darttemplate b/tools/dom/templates/html/impl/impl_Node.darttemplate index 287151fb059..b40cdb329b5 100644 --- a/tools/dom/templates/html/impl/impl_Node.darttemplate +++ b/tools/dom/templates/html/impl/impl_Node.darttemplate @@ -249,8 +249,7 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { /** * Print out a String representation of this Node. */ - String toString() => localName == null ? - (nodeValue == null ? super.toString() : nodeValue) : localName; + String toString() => nodeValue == null ? super.toString() : nodeValue; /** * Binds the attribute [name] to the [path] of the [model].