| 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 #library("view"); | 5 #library("view"); |
| 6 | 6 |
| 7 #import('../base/base.dart'); | 7 #import('../base/base.dart'); |
| 8 #import('../observable/observable.dart'); | 8 #import('../observable/observable.dart'); |
| 9 #import('../touch/touch.dart'); | 9 #import('../touch/touch.dart'); |
| 10 #import('../html/html.dart'); | 10 #import('../html/html.dart'); |
| 11 #import('../layout/layout.dart'); | 11 #import('../layout/layout.dart'); |
| 12 | 12 |
| 13 #source('CompositeView.dart'); | 13 #source('CompositeView.dart'); |
| 14 #source('ConveyorView.dart'); | 14 #source('ConveyorView.dart'); |
| 15 #source('MeasureText.dart'); | 15 #source('MeasureText.dart'); |
| 16 #source('PagedViews.dart'); | 16 #source('PagedViews.dart'); |
| 17 #source('SliderMenu.dart'); | 17 #source('SliderMenu.dart'); |
| 18 | 18 |
| 19 |
| 19 // TODO(rnystrom): Note! This class is undergoing heavy construction. It will | 20 // TODO(rnystrom): Note! This class is undergoing heavy construction. It will |
| 20 // temporary support both some old and some new ways of doing things until all | 21 // temporary support both some old and some new ways of doing things until all |
| 21 // subclasses are refactored to use the new way. There will be some scaffolding | 22 // subclasses are refactored to use the new way. There will be some scaffolding |
| 22 // and construction cones laying around. Try not to freak out. | 23 // and construction cones laying around. Try not to freak out. |
| 23 | 24 |
| 24 /** A generic view. */ | 25 /** A generic view. */ |
| 25 class View implements Positionable { | 26 class View implements Positionable { |
| 26 Element _node; | 27 Element _node; |
| 27 ViewLayout _layout; | 28 ViewLayout _layout; |
| 28 | 29 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 310 } |
| 310 | 311 |
| 311 void _unhookGlobalLayoutEvents() { | 312 void _unhookGlobalLayoutEvents() { |
| 312 if (_resizeHandler != null) { | 313 if (_resizeHandler != null) { |
| 313 window.on.resize.remove(_resizeHandler); | 314 window.on.resize.remove(_resizeHandler); |
| 314 _resizeHandler = null; | 315 _resizeHandler = null; |
| 315 } | 316 } |
| 316 } | 317 } |
| 317 | 318 |
| 318 void doLayout() { | 319 void doLayout() { |
| 319 if (_measureLayout()) { | 320 _measureLayout().then((bool changed) { |
| 320 _applyLayoutToChildren(); | 321 if (changed) { |
| 321 } | 322 _applyLayoutToChildren(); |
| 323 } |
| 324 }); |
| 322 } | 325 } |
| 323 | 326 |
| 324 bool _measureLayout() { | 327 Future<bool> _measureLayout() { |
| 328 final changed = new Completer<bool>(); |
| 329 _measureLayoutHelper(changed); |
| 330 |
| 331 window.requestLayoutFrame(() { |
| 332 if (!changed.future.isComplete) { |
| 333 changed.complete(false); |
| 334 } |
| 335 }); |
| 336 return changed.future; |
| 337 } |
| 338 |
| 339 void _measureLayoutHelper(Completer<bool> changed) { |
| 325 windowResized(); | 340 windowResized(); |
| 326 | 341 |
| 327 // TODO(jmesserly): this logic is more complex than it needs to be because | 342 // TODO(jmesserly): this logic is more complex than it needs to be because |
| 328 // we're taking pains to not initialize _layout if it's not needed. Is that | 343 // we're taking pains to not initialize _layout if it's not needed. Is that |
| 329 // a good tradeoff? | 344 // a good tradeoff? |
| 330 if (ViewLayout.hasCustomLayout(this)) { | 345 if (ViewLayout.hasCustomLayout(this)) { |
| 331 return layout.measureLayout(_node.clientWidth, _node.clientHeight); | 346 Completer sizeCompleter = new Completer<Size>(); |
| 347 _node.rect.then((ElementRect rect) { |
| 348 sizeCompleter.complete( |
| 349 new Size(rect.client.width, rect.client.height)); |
| 350 }); |
| 351 layout.measureLayout(sizeCompleter.future, changed); |
| 332 } else { | 352 } else { |
| 333 bool changed = false; | |
| 334 for (final child in childViews) { | 353 for (final child in childViews) { |
| 335 if (child._measureLayout()) changed = true; | 354 child._measureLayoutHelper(changed); |
| 336 } | 355 } |
| 337 return changed; | |
| 338 } | 356 } |
| 339 } | 357 } |
| 340 | 358 |
| 341 void _applyLayoutToChildren() { | 359 void _applyLayoutToChildren() { |
| 342 for (final child in childViews) { | 360 for (final child in childViews) { |
| 343 child._applyLayout(); | 361 child._applyLayout(); |
| 344 } | 362 } |
| 345 } | 363 } |
| 346 | 364 |
| 347 void _applyLayout() { | 365 void _applyLayout() { |
| 348 if (_layout != null) { | 366 if (_layout != null) { |
| 349 _layout.applyLayout(); | 367 _layout.applyLayout(); |
| 350 } | 368 } |
| 351 _applyLayoutToChildren(); | 369 _applyLayoutToChildren(); |
| 352 } | 370 } |
| 353 } | 371 } |
| OLD | NEW |