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

Side by Side Diff: client/html/src/shared_FactoryProviders.dart

Issue 9662010: Don't put private members in dart:html interfaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
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 class _TextFactoryProvider { 5 class _TextFactoryProvider {
6 6
7 factory Text(String data) => document._createTextNode(data); 7 factory Text(String data) {
8 final _DocumentImpl doc = document;
9 return doc._createTextNode(data);
10 }
8 } 11 }
9 12
10 class _EventFactoryProvider { 13 class _EventFactoryProvider {
11 factory Event(String type, [bool canBubble = true, 14 factory Event(String type, [bool canBubble = true,
12 bool cancelable = true]) { 15 bool cancelable = true]) {
13 _EventImpl e = document._createEvent("Event"); 16 final _DocumentImpl doc = document;
17 final _EventImpl e = doc._createEvent("Event");
14 e._initEvent(type, canBubble, cancelable); 18 e._initEvent(type, canBubble, cancelable);
15 return e; 19 return e;
16 } 20 }
17 } 21 }
18 22
19 class _MouseEventFactoryProvider { 23 class _MouseEventFactoryProvider {
20 factory MouseEvent(String type, Window view, int detail, 24 factory MouseEvent(String type, Window view, int detail,
21 int screenX, int screenY, int clientX, int clientY, int button, 25 int screenX, int screenY, int clientX, int clientY, int button,
22 [bool canBubble = true, bool cancelable = true, bool ctrlKey = false, 26 [bool canBubble = true, bool cancelable = true, bool ctrlKey = false,
23 bool altKey = false, bool shiftKey = false, bool metaKey = false, 27 bool altKey = false, bool shiftKey = false, bool metaKey = false,
24 EventTarget relatedTarget = null]) { 28 EventTarget relatedTarget = null]) {
25 final e = document._createEvent("MouseEvent"); 29 final _DocumentImpl doc = document;
30 final e = doc._createEvent("MouseEvent");
26 e._initMouseEvent(type, canBubble, cancelable, view, detail, 31 e._initMouseEvent(type, canBubble, cancelable, view, detail,
27 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, 32 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
28 button, relatedTarget); 33 button, relatedTarget);
29 return e; 34 return e;
30 } 35 }
31 } 36 }
32 37
33 class _CSSStyleDeclarationFactoryProvider { 38 class _CSSStyleDeclarationFactoryProvider {
34 factory CSSStyleDeclaration.css(String css) { 39 factory CSSStyleDeclaration.css(String css) {
35 var style = new Element.tag('div').style; 40 var style = new Element.tag('div').style;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // 4) Detatch the created element from its dummy parent. 73 // 4) Detatch the created element from its dummy parent.
69 String parentTag = 'div'; 74 String parentTag = 'div';
70 String tag; 75 String tag;
71 final match = _START_TAG_REGEXP.firstMatch(html); 76 final match = _START_TAG_REGEXP.firstMatch(html);
72 if (match !== null) { 77 if (match !== null) {
73 tag = match.group(1).toLowerCase(); 78 tag = match.group(1).toLowerCase();
74 if (_CUSTOM_PARENT_TAG_MAP.containsKey(tag)) { 79 if (_CUSTOM_PARENT_TAG_MAP.containsKey(tag)) {
75 parentTag = _CUSTOM_PARENT_TAG_MAP[tag]; 80 parentTag = _CUSTOM_PARENT_TAG_MAP[tag];
76 } 81 }
77 } 82 }
78 // TODO(jacobr): make type dom.HTMLElement when dartium allows it. 83 final _ElementImpl temp = new Element.tag(parentTag);
79 _ElementImpl temp = document._createElement(parentTag);
80 temp.innerHTML = html; 84 temp.innerHTML = html;
81 85
82 Element element; 86 Element element;
83 if (temp.elements.length == 1) { 87 if (temp.elements.length == 1) {
84 element = temp.elements.first; 88 element = temp.elements.first;
85 } else if (parentTag == 'html' && temp.elements.length == 2) { 89 } else if (parentTag == 'html' && temp.elements.length == 2) {
86 // Work around for edge case in WebKit and possibly other browsers where 90 // Work around for edge case in WebKit and possibly other browsers where
87 // both body and head elements are created even though the inner html 91 // both body and head elements are created even though the inner html
88 // only contains a head or body element. 92 // only contains a head or body element.
89 element = temp.elements[tag == 'head' ? 0 : 1]; 93 element = temp.elements[tag == 'head' ? 0 : 1];
90 } else { 94 } else {
91 throw new IllegalArgumentException('HTML had ${temp.elements.length} ' + 95 throw new IllegalArgumentException('HTML had ${temp.elements.length} ' +
92 'top level elements but 1 expected'); 96 'top level elements but 1 expected');
93 } 97 }
94 element.remove(); 98 element.remove();
95 return element; 99 return element;
96 } 100 }
97 101
98 /** @domName Document.createElement */ 102 /** @domName Document.createElement */
99 factory Element.tag(String tag) { 103 factory Element.tag(String tag) {
100 return document._createElement(tag); 104 final _DocumentImpl doc = document;
105 return doc._createElement(tag);
101 } 106 }
102 } 107 }
OLDNEW
« client/dom/templates/html/impl/impl_Element.darttemplate ('K') | « client/html/src/_Testing.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698