Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: client/view/view.dart

Issue 8363040: Implement measurement using futures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: take2 Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« client/touch/Scroller.dart ('K') | « client/view/SliderMenu.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/view/view.dart
diff --git a/client/view/view.dart b/client/view/view.dart
index 7a0070392f6551d979bb4504119c7b6ee235a5f2..8f0098b990b522bab6b011c33eca3726a98cae9f 100644
--- a/client/view/view.dart
+++ b/client/view/view.dart
@@ -16,6 +16,7 @@
#source('PagedViews.dart');
#source('SliderMenu.dart');
+
// TODO(rnystrom): Note! This class is undergoing heavy construction. It will
// temporary support both some old and some new ways of doing things until all
// subclasses are refactored to use the new way. There will be some scaffolding
@@ -316,25 +317,42 @@ class View implements Positionable {
}
void doLayout() {
- if (_measureLayout()) {
- _applyLayoutToChildren();
- }
+ _measureLayout().then((bool changed) {
+ if (changed) {
+ _applyLayoutToChildren();
+ }
+ });
+ }
+
+ Future<bool> _measureLayout() {
arv (Not doing code reviews) 2011/10/27 05:50:24 Yeah, this is cleaner than using a Callback like i
Jacob 2011/10/27 20:59:25 I agree that when there is some valid value to ret
+ final changed = new Completer<bool>();
+ _measureLayoutHelper(changed);
+
+ window.requestLayoutFrame(() {
+ if (!changed.future.isComplete) {
+ changed.complete(false);
+ }
+ });
+ return changed.future;
}
- bool _measureLayout() {
+ void _measureLayoutHelper(Completer<bool> changed) {
windowResized();
// TODO(jmesserly): this logic is more complex than it needs to be because
// we're taking pains to not initialize _layout if it's not needed. Is that
// a good tradeoff?
if (ViewLayout.hasCustomLayout(this)) {
- return layout.measureLayout(_node.clientWidth, _node.clientHeight);
+ Completer sizeCompleter = new Completer<Size>();
+ _node.rect.then((ElementRect rect) {
+ sizeCompleter.complete(
+ new Size(rect.client.width, rect.client.height));
+ });
+ layout.measureLayout(sizeCompleter.future, changed);
} else {
- bool changed = false;
for (final child in childViews) {
- if (child._measureLayout()) changed = true;
+ child._measureLayoutHelper(changed);
}
- return changed;
}
}
« client/touch/Scroller.dart ('K') | « client/view/SliderMenu.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698