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

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

Issue 9478021: Add some sweet XML classes. (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
« no previous file with comments | « client/html/src/XMLDocument.dart ('k') | client/html/src/XMLElement.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class XMLDocumentWrappingImplementation extends DocumentWrappingImplementation
6 implements XMLDocument {
7 // This really just wants to extend both DocumentWrappingImplementation and
8 // XMLElementWrappingImplementation, but since that's not possible we delegate
9 // to the latter.
10 XMLElement documentEl;
11
12 XMLDocumentWrappingImplementation._wrap(documentPtr, ptr) :
13 super._wrap(documentPtr, ptr) {
14 // We want to wrap the pointer in an XMLElement to use its implementation of
15 // various Element methods, but DOMWrapperBase complains if
16 // dartObjectLocalStorage is already set.
17 ptr.dartObjectLocalStorage = null;
18 this.documentEl = new XMLElementWrappingImplementation._wrap(ptr);
19 ptr.dartObjectLocalStorage = this;
20 }
21
22 factory XMLDocumentWrappingImplementation.xml(String xml) {
23 final parser = new dom.DOMParser();
24 final xmlDoc = LevelDom.wrapDocument(
25 parser.parseFromString(xml, 'text/xml'));
26 // When XML parsing fails, the browser creates a document containing a
27 // PARSERERROR element. We want to throw an exception when parsing fails,
28 // but we don't want false positives if the user intends to create a
29 // PARSERERROR element for some reason, so we check for that in the input.
30 //
31 // TODO(nweiz): This is pretty hacky, it would be nice to this some other
32 // way if we can find one.
33 if (!xml.toLowerCase().contains('<parsererror') &&
34 xmlDoc.query('parsererror') != null) {
35 throw new IllegalArgumentException('Error parsing XML: "$xml"');
36 }
37 return xmlDoc;
38 }
39
40 Node get parent() => null;
41
42 Node _insertAdjacentNode(String where, Node node) {
43 switch (where.toLowerCase()) {
44 case "beforebegin":
45 return null;
46 case "afterend":
47 return null;
48 case "afterbegin":
49 this.insertBefore(node, nodes.first);
50 return node;
51 case "beforeend":
52 this.nodes.add(node);
53 return node;
54 default:
55 throw new IllegalArgumentException("Invalid position ${where}");
56 }
57 }
58
59 XMLElement insertAdjacentElement([String where = null,
60 XMLElement element = null]) => this._insertAdjacentNode(where, element);
61
62 void insertAdjacentText([String where = null, String text = null]) {
63 this._insertAdjacentNode(where, new Text(text));
64 }
65
66 void insertAdjacentHTML(
67 [String position_OR_where = null, String text = null]) {
68 this._insertAdjacentNode(
69 position_OR_where, new DocumentFragment.xml(text));
70 }
71
72 Future<ElementRect> get rect() => documentEl.rect;
73
74 Future<Range> caretRangeFromPoint([int x = null, int y = null]) =>
75 new Future<Range>.immediate(null);
76
77 Future<Element> elementFromPoint([int x = null, int y = null]) =>
78 new Future<Element>.immediate(null);
79
80 bool execCommand([String command = null, bool userInterface = null,
81 String value = null]) => false;
82
83 bool queryCommandEnabled([String command = null]) => false;
84 bool queryCommandIndeterm([String command = null]) => false;
85 bool queryCommandState([String command = null]) => false;
86 bool queryCommandSupported([String command = null]) => false;
87 void blur() {}
88 void focus() {}
89 void scrollByLines([int lines = null]) {}
90 void scrollByPages([int pages = null]) {}
91 void scrollIntoView([bool centerIfNeeded = null]) {}
92 XMLElement get activeElement() => null;
93 String get domain() => "";
94
95 void set body(Element value) {
96 throw new UnsupportedOperationException("XML documents don't have a body.");
97 }
98
99 String get cookie() {
100 throw new UnsupportedOperationException(
101 "XML documents don't support cookies.");
102 }
103
104 void set cookie(String value) {
105 throw new UnsupportedOperationException(
106 "XML documents don't support cookies.");
107 }
108
109 String get manifest() => "";
110
111 void set manifest(String value) {
112 throw new UnsupportedOperationException(
113 "Manifest can't be set for XML documents.");
114 }
115
116 Set<String> get classes() => documentEl.classes;
117
118 ElementList get elements() => documentEl.elements;
119
120 // TODO: The type of value should be Collection<Element>. See http://b/5392897
121 void set elements(value) { documentEl.elements = value; }
122
123 String get outerHTML() => documentEl.outerHTML;
124
125 String get innerHTML() => documentEl.innerHTML;
126
127 void set innerHTML(String xml) { documentEl.innerHTML = xml; }
128
129 String get contentEditable() => documentEl.contentEditable;
130
131 void set contentEditable(String value) { documentEl.contentEditable = value; }
132
133 bool get isContentEditable() => documentEl.isContentEditable;
134
135 bool get draggable() => documentEl.draggable;
136
137 void set draggable(bool value) { documentEl.draggable = value; }
138
139 bool get spellcheck() => documentEl.spellcheck;
140
141 void set spellcheck(bool value) { documentEl.spellcheck = value; }
142
143 bool get hidden() => documentEl.hidden;
144
145 void set hidden(bool value) { documentEl.hidden = value; }
146
147 int get tabIndex() => documentEl.tabIndex;
148
149 void set tabIndex(int value) { documentEl.tabIndex = value; }
150
151 String get id() => documentEl.id;
152
153 void set id(String value) { documentEl.id = value; }
154
155 String get title() => documentEl.title;
156
157 void set title(String value) { documentEl.title = value; }
158
159 String get webkitdropzone() => documentEl.webkitdropzone;
160
161 void set webkitdropzone(String value) { documentEl.webkitdropzone = value; }
162
163 String get lang() => documentEl.lang;
164
165 void set lang(String value) { documentEl.lang = value; }
166
167 String get dir() => documentEl.dir;
168
169 void set dir(String value) { documentEl.dir = value; }
170 }
OLDNEW
« no previous file with comments | « client/html/src/XMLDocument.dart ('k') | client/html/src/XMLElement.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698