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