| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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 @js.JS('window') | |
| 6 library dom; | |
| 7 | |
| 8 import 'package:js/js.dart' as js; | |
| 9 | |
| 10 @js.JS() | |
| 11 class Window {} | |
| 12 | |
| 13 class Overload { | |
| 14 const Overload(); | |
| 15 } | |
| 16 const overload = const Overload(); | |
| 17 | |
| 18 external Document get document; | |
| 19 external Window get window; | |
| 20 | |
| 21 @js.JS() | |
| 22 abstract class Document extends Node { | |
| 23 Element createElement(String name); | |
| 24 Element querySelector(String selector); | |
| 25 | |
| 26 HTMLElement head; | |
| 27 HTMLElement body; | |
| 28 } | |
| 29 | |
| 30 @js.JS() | |
| 31 class Blob { | |
| 32 external Blob(blobParts, {String type}); | |
| 33 } | |
| 34 | |
| 35 class CustomEvent { | |
| 36 external CustomEvent(String type, {detail, bubbles, cancelable}); | |
| 37 } | |
| 38 | |
| 39 @js.JS() | |
| 40 abstract class Element extends Node { | |
| 41 void addEventListener(String type, EventListener callback, [bool capture]); | |
| 42 String textContent; | |
| 43 } | |
| 44 | |
| 45 @js.JS() | |
| 46 abstract class HTMLElement extends Element { | |
| 47 String innerHTML; | |
| 48 HTMLCollection get children; | |
| 49 } | |
| 50 | |
| 51 @js.JS() | |
| 52 abstract class Node { | |
| 53 bool hasChildNodes(); | |
| 54 NodeList get childNodes; | |
| 55 | |
| 56 Node insertBefore(Node node, [Node child]); | |
| 57 Node appendChild(Node node); | |
| 58 Node replaceChild(Node node, Node child); | |
| 59 Node removeChild(Node child); | |
| 60 } | |
| 61 | |
| 62 abstract class HTMLCollection { | |
| 63 int get length; | |
| 64 external Element operator [](num index); | |
| 65 } | |
| 66 | |
| 67 @js.JS() | |
| 68 class NodeList { | |
| 69 external NodeList(); | |
| 70 external num get length; | |
| 71 external set length(num _); | |
| 72 external Node item(num index); | |
| 73 | |
| 74 external Node operator [](num index); | |
| 75 external void operator []=(num index, Node); | |
| 76 } | |
| 77 | |
| 78 typedef void EventListener(Event e); | |
| 79 | |
| 80 @js.JS() | |
| 81 abstract class Event {} | |
| 82 | |
| 83 // TODO(jmesserly): rename these | |
| 84 @js.JS('HTMLInputElement') | |
| 85 abstract class InputElement extends HTMLElement { | |
| 86 String value; | |
| 87 } | |
| 88 | |
| 89 @js.JS('HTMLCanvasElement') | |
| 90 abstract class CanvasElement extends HTMLElement { | |
| 91 RenderingContext getContext(String contextId); | |
| 92 } | |
| 93 | |
| 94 @js.JS('HTMLDivElement') | |
| 95 abstract class DivElement extends HTMLElement { | |
| 96 RenderingContext getContext(String contextId); | |
| 97 } | |
| 98 | |
| 99 @js.JS('HTMLScriptElement') | |
| 100 abstract class ScriptElement extends HTMLElement { | |
| 101 String type; | |
| 102 } | |
| 103 | |
| 104 | |
| 105 // TODO(jmesserly): union type of CanvasRenderingContext2D and | |
| 106 // WebGLRenderingContext | |
| 107 abstract class RenderingContext {} | |
| 108 | |
| 109 // http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas_CR/ | |
| 110 @js.JS() | |
| 111 abstract class CanvasRenderingContext2D | |
| 112 implements CanvasDrawingStyles, CanvasPathMethods, RenderingContext { | |
| 113 | |
| 114 // back-reference to the canvas | |
| 115 CanvasElement get canvas; | |
| 116 | |
| 117 // state | |
| 118 void save(); // push state on state stack | |
| 119 void restore(); // pop state stack and restore state | |
| 120 | |
| 121 // transformations (default transform is the identity matrix) | |
| 122 void scale(num x, num y); | |
| 123 void rotate(num angle); | |
| 124 void translate(num x, num y); | |
| 125 void transform(num a, num b, num c, num d, num e, num f); | |
| 126 void setTransform(num a, num b, num c, num d, num e, num f); | |
| 127 | |
| 128 // compositing | |
| 129 num globalAlpha; // (default 1.0) | |
| 130 String globalCompositeOperation; // (default source-over) | |
| 131 | |
| 132 // colors and styles (see also the CanvasDrawingStyles interface) | |
| 133 Object strokeStyle; // (default black) | |
| 134 Object fillStyle; // (default black) | |
| 135 CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1); | |
| 136 CanvasGradient createRadialGradient( | |
| 137 num x0, num y0, num r0, num x1, num y1, num r1); | |
| 138 CanvasPattern createPattern(Element image, [String repetition]); | |
| 139 | |
| 140 // shadows | |
| 141 num shadowOffsetX; // (default 0) | |
| 142 num shadowOffsetY; // (default 0) | |
| 143 num shadowBlur; // (default 0) | |
| 144 String shadowColor; // (default transparent black) | |
| 145 | |
| 146 // rects | |
| 147 void clearRect(num x, num y, num w, num h); | |
| 148 void fillRect(num x, num y, num w, num h); | |
| 149 void strokeRect(num x, num y, num w, num h); | |
| 150 | |
| 151 // path API (see also CanvasPathMethods) | |
| 152 void beginPath(); | |
| 153 void fill(); | |
| 154 void stroke(); | |
| 155 void drawFocusIfNeeded(Element element); | |
| 156 void clip(); | |
| 157 bool isPointInPath(num x, num y); | |
| 158 | |
| 159 // text (see also the CanvasDrawingStyles interface) | |
| 160 void fillText(String text, num x, num y, [num maxWidth]); | |
| 161 void strokeText(String text, num x, num y, [num maxWidth]); | |
| 162 TextMetrics measureText(String text); | |
| 163 | |
| 164 // drawing images | |
| 165 void drawImage(Element image, num dx_or_sx, num dy_or_sy, | |
| 166 [num dw_or_sw, num dh_or_sh, num dx, num dy, num dw, num dh]); | |
| 167 @overload void _drawImage_0(Element image, num dx, num dy); | |
| 168 @overload void _drawImage_1(Element image, num dx, num dy, num dw, num dh); | |
| 169 @overload void _drawImage_2(Element image, num sx, num sy, num sw, num sh, | |
| 170 num dx, num dy, num dw, num dh); | |
| 171 | |
| 172 // hit regions | |
| 173 void addHitRegion({String id: '', Element control}); | |
| 174 void removeHitRegion(String id); | |
| 175 void clearHitRegions(); | |
| 176 | |
| 177 // pixel manipulation | |
| 178 ImageData createImageData(Object sw_or_imageData, [num sh]); | |
| 179 @overload ImageData _createImageData_0(num sw, num sh); | |
| 180 @overload ImageData _createImageData_1(ImageData imagedata); | |
| 181 | |
| 182 ImageData getImageData(num sx, num sy, num sw, num sh); | |
| 183 void putImageData(ImageData imagedata, num dx, num dy, | |
| 184 [num dirtyX, num dirtyY, num dirtyWidth, num dirtyHeight]); | |
| 185 @overload void _putImageData_0(ImageData imagedata, num dx, num dy, | |
| 186 num dirtyX, num dirtyY, num dirtyWidth, num dirtyHeight); | |
| 187 @overload void _putImageData_1(ImageData imagedata, num dx, num dy); | |
| 188 } | |
| 189 | |
| 190 abstract class CanvasDrawingStyles { | |
| 191 // line caps/joins | |
| 192 num lineWidth; // (default 1) | |
| 193 String lineCap; // "butt", "round", "square" (default "butt") | |
| 194 String lineJoin; // "round", "bevel", "miter" (default "miter") | |
| 195 num miterLimit; // (default 10) | |
| 196 | |
| 197 // dashed lines | |
| 198 void setLineDash(List<num> segments); // default empty | |
| 199 List<num> getLineDash(); | |
| 200 num lineDashOffset; | |
| 201 | |
| 202 // text | |
| 203 String font; // (default 10px sans-serif) | |
| 204 | |
| 205 // "start", "end", "left", "right", "center" (default: "start") | |
| 206 String textAlign; | |
| 207 | |
| 208 // "top", "hanging", "middle", "alphabetic", | |
| 209 // "ideographic", "bottom" (default: "alphabetic") | |
| 210 String textBaseline; | |
| 211 } | |
| 212 | |
| 213 abstract class CanvasPathMethods { | |
| 214 // shared path API methods | |
| 215 void closePath(); | |
| 216 void moveTo(num x, num y); | |
| 217 void lineTo(num x, num y); | |
| 218 void quadraticCurveTo(num cpx, num cpy, num x, num y); | |
| 219 void bezierCurveTo(num cp1x, num cp1y, num cp2x, num cp2y, num x, num y); | |
| 220 void arcTo(num x1, num y1, num x2, num y2, num radius); | |
| 221 void rect(num x, num y, num w, num h); | |
| 222 void arc(num x, num y, num radius, num startAngle, num endAngle, | |
| 223 [bool anticlockwise]); | |
| 224 } | |
| 225 | |
| 226 @js.JS() | |
| 227 abstract class CanvasGradient { | |
| 228 // opaque object | |
| 229 void addColorStop(num offset, String color); | |
| 230 } | |
| 231 | |
| 232 @js.JS() | |
| 233 abstract class CanvasPattern { | |
| 234 // opaque object | |
| 235 } | |
| 236 | |
| 237 @js.JS() | |
| 238 abstract class TextMetrics { | |
| 239 num get width; | |
| 240 } | |
| 241 | |
| 242 @js.JS() | |
| 243 abstract class ImageData { | |
| 244 int get width; | |
| 245 int get height; | |
| 246 // TODO: readonly Uint8ClampedArray data; | |
| 247 } | |
| OLD | NEW |