OLD | NEW |
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 library view; | 5 library view; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:math' as Math; | 9 import 'dart:math' as Math; |
10 | 10 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 Future<bool> _measureLayout() { | 331 Future<bool> _measureLayout() { |
332 final changed = new Completer<bool>(); | 332 final changed = new Completer<bool>(); |
333 _measureLayoutHelper(changed); | 333 _measureLayoutHelper(changed); |
334 | 334 |
335 var changedComplete = false; | 335 var changedComplete = false; |
336 changed.future.then((_) { | 336 changed.future.then((_) { |
337 changedComplete = true; | 337 changedComplete = true; |
338 }); | 338 }); |
339 | 339 |
340 window.setImmediate(() { | 340 window.immediate.then((_) { |
341 if (!changedComplete) { | 341 if (!changedComplete) { |
342 changed.complete(false); | 342 changed.complete(false); |
343 } | 343 } |
344 }); | 344 }); |
345 return changed.future; | 345 return changed.future; |
346 } | 346 } |
347 | 347 |
348 void _measureLayoutHelper(Completer<bool> changed) { | 348 void _measureLayoutHelper(Completer<bool> changed) { |
349 windowResized(); | 349 windowResized(); |
350 | 350 |
351 // TODO(jmesserly): this logic is more complex than it needs to be because | 351 // TODO(jmesserly): this logic is more complex than it needs to be because |
352 // we're taking pains to not initialize _layout if it's not needed. Is that | 352 // we're taking pains to not initialize _layout if it's not needed. Is that |
353 // a good tradeoff? | 353 // a good tradeoff? |
354 if (ViewLayout.hasCustomLayout(this)) { | 354 if (ViewLayout.hasCustomLayout(this)) { |
355 Completer sizeCompleter = new Completer<Size>(); | 355 Completer sizeCompleter = new Completer<Size>(); |
356 window.setImmediate(() { | 356 window.immediate.then((_) { |
357 sizeCompleter.complete( | 357 sizeCompleter.complete( |
358 new Size(_node.clientWidth, _node.clientHeight)); | 358 new Size(_node.clientWidth, _node.clientHeight)); |
359 }); | 359 }); |
360 layout.measureLayout(sizeCompleter.future, changed); | 360 layout.measureLayout(sizeCompleter.future, changed); |
361 } else { | 361 } else { |
362 for (final child in childViews) { | 362 for (final child in childViews) { |
363 child._measureLayoutHelper(changed); | 363 child._measureLayoutHelper(changed); |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 void _applyLayoutToChildren() { | 368 void _applyLayoutToChildren() { |
369 for (final child in childViews) { | 369 for (final child in childViews) { |
370 child._applyLayout(); | 370 child._applyLayout(); |
371 } | 371 } |
372 } | 372 } |
373 | 373 |
374 void _applyLayout() { | 374 void _applyLayout() { |
375 if (_layout != null) { | 375 if (_layout != null) { |
376 _layout.applyLayout(); | 376 _layout.applyLayout(); |
377 } | 377 } |
378 _applyLayoutToChildren(); | 378 _applyLayoutToChildren(); |
379 } | 379 } |
380 } | 380 } |
OLD | NEW |