OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** Base class for all views. */ | 5 /** Base class for all views. */ |
6 class View { | 6 class View { |
7 Document doc; | 7 Document doc; |
8 View(this.doc) {} | 8 View(this.doc) {} |
9 } | 9 } |
10 | 10 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 "${total} <= ${accounted} (${hit} + ${miss}); ${sunk}"; | 272 "${total} <= ${accounted} (${hit} + ${miss}); ${sunk}"; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 /** Utility methods used by the views above. */ | 276 /** Utility methods used by the views above. */ |
277 class ViewUtil { | 277 class ViewUtil { |
278 | 278 |
279 /** Extract the position of a mouse event in a containing 500x500 grid. */ | 279 /** Extract the position of a mouse event in a containing 500x500 grid. */ |
280 static Future<List<int>> positionFromEvent(Element gridNode, MouseEvent e) { | 280 static Future<List<int>> positionFromEvent(Element gridNode, MouseEvent e) { |
281 final completer = new Completer<List<int>>(); | 281 final completer = new Completer<List<int>>(); |
282 gridNode.rect.then((ElementRect rect) { | 282 window.requestLayoutFrame(() { |
283 int x = (e.pageX - rect.offset.left) ~/ 50; | 283 int x = (e.pageX - gridNode.offsetLeft) ~/ 50; |
284 int y = (e.pageY - rect.offset.top) ~/ 50; | 284 int y = (e.pageY - gridNode.offsetTop) ~/ 50; |
285 completer.complete([x, y]); | 285 completer.complete([x, y]); |
286 }); | 286 }); |
287 return completer.future; | 287 return completer.future; |
288 } | 288 } |
289 | 289 |
290 /** Given a grid node (square or boat) place it at a grid coordinate. */ | 290 /** Given a grid node (square or boat) place it at a grid coordinate. */ |
291 static void placeNodeAt(Element node, int x, int y) { | 291 static void placeNodeAt(Element node, int x, int y) { |
292 int xoffset = x * 50; | 292 int xoffset = x * 50; |
293 int yoffset = y * 50; | 293 int yoffset = y * 50; |
294 node.style.setProperty("top", "${yoffset}px"); | 294 node.style.setProperty("top", "${yoffset}px"); |
295 node.style.setProperty("left", "${xoffset}px"); | 295 node.style.setProperty("left", "${xoffset}px"); |
296 } | 296 } |
297 | 297 |
298 /** Create a div node with a given class name. */ | 298 /** Create a div node with a given class name. */ |
299 static Element createDiv(String className) { | 299 static Element createDiv(String className) { |
300 Element node = new Element.tag("div"); | 300 Element node = new Element.tag("div"); |
301 node.attributes["class"] = className; | 301 node.attributes["class"] = className; |
302 return node; | 302 return node; |
303 } | 303 } |
304 } | 304 } |
OLD | NEW |