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