Chromium Code Reviews| Index: client/layout/ViewLayout.dart |
| diff --git a/client/layout/ViewLayout.dart b/client/layout/ViewLayout.dart |
| index b86155c720463a840f98df3503ba2bde729572fe..e06dae2c25afdc8c91cf19295741a1d42a6ae054 100644 |
| --- a/client/layout/ViewLayout.dart |
| +++ b/client/layout/ViewLayout.dart |
| @@ -27,12 +27,12 @@ interface Positionable { |
| class LayoutParams { |
| // TODO(jmesserly): should be const, but there's a bug in DartC preventing us |
| // from calling "window." in an initializer. See b/5332777 |
| - CSSStyleDeclaration style; |
| + Future<CSSStyleDeclaration> style; |
| int get layer() => 0; |
| LayoutParams(Element node) { |
| - style = window.getComputedStyle(node, ''); |
| + style = node.computedStyle; |
| } |
| } |
| @@ -71,6 +71,7 @@ class ViewLayout { |
| * to determine how this view should be laid out. |
| */ |
| LayoutParams layoutParams; |
| + Future<ElementRect> _cachedViewRect; |
| /** The view that this layout belongs to. */ |
| final Positionable view; |
| @@ -82,7 +83,7 @@ class ViewLayout { |
| */ |
| int _measuredLeft, _measuredTop, _measuredWidth, _measuredHeight; |
| - ViewLayout(this.view) {} |
| + ViewLayout(this.view); |
| /** |
| * Creates the appropriate view layout, depending on the properties. |
| @@ -101,10 +102,19 @@ class ViewLayout { |
| return view.customStyle['display'] == "-dart-grid"; |
| } |
| - CSSStyleDeclaration get _style() => layoutParams.style; |
| + CSSStyleDeclaration get _style() => layoutParams.style.value; |
| - int get currentWidth() => view.node.offsetWidth; |
| - int get currentHeight() => view.node.offsetHeight; |
| + void cacheExistingBrowserLayout() { |
| + _cachedViewRect = view.node.rect; |
| + } |
| + |
| + int get currentWidth() { |
| + return _cachedViewRect.value.offset.width; |
|
nweiz
2011/10/28 03:58:38
What happens when _cachedViewRect hasn't fired yet
Jacob
2011/10/31 22:09:50
by design it will always have fired due to appropr
nweiz
2011/11/01 00:49:22
Oh, futures throw an error when value doesn't exis
|
| + } |
| + |
| + int get currentHeight() { |
| + return _cachedViewRect.value.offset.height; |
| + } |
| int get borderLeftWidth() => _toPixels(_style.borderLeftWidth); |
|
nweiz
2011/10/28 03:58:38
Can't _style be null sometimes?
Jacob
2011/10/31 22:09:50
it can't be null, however a future not available y
nweiz
2011/11/01 00:49:22
The fact that it fires a "future not completed" er
|
| int get borderTopWidth() => _toPixels(_style.borderTopWidth); |
| @@ -112,9 +122,10 @@ class ViewLayout { |
| int get borderBottomWidth() => _toPixels(_style.borderBottomWidth); |
| int get borderWidth() => borderLeftWidth + borderRightWidth; |
| int get borderHeight() => borderTopWidth + borderBottomWidth; |
| - |
| + |
|
nweiz
2011/10/28 03:58:38
Style nit: trailing whitespace
Jacob
2011/10/31 22:09:50
Done.
|
| /** Implements the custom layout computation. */ |
| - bool measureLayout(int width, int height) => false; |
| + void measureLayout(Future<Size> size, Completer<bool> changed) { |
| + } |
| /** |
| * Positions the view within its parent container. |
| @@ -129,8 +140,9 @@ class ViewLayout { |
| // Note: we need to save the client height |
| _measuredWidth = width - borderWidth; |
| _measuredHeight = height - borderHeight; |
| - |
| - measureLayout(_measuredWidth, _measuredHeight); |
| + final completer = new Completer<Size>(); |
| + completer.complete(new Size(_measuredWidth, _measuredHeight)); |
| + measureLayout(completer.future, null); |
| } |
| /** Applies the layout to the node. */ |
| @@ -176,7 +188,7 @@ class ViewLayout { |
| } |
| int measureWidth(ViewLayout parent, ContentSizeMode mode) { |
| - final style = layoutParams.style; |
| + final style = layoutParams.style.value; |
| switch (mode) { |
| case ContentSizeMode.MIN: |
| return _styleToPixels( |
| @@ -189,7 +201,7 @@ class ViewLayout { |
| } |
| int measureHeight(ViewLayout parent, ContentSizeMode mode) { |
| - final style = layoutParams.style; |
| + final style = layoutParams.style.value; |
| switch (mode) { |
| case ContentSizeMode.MIN: |
| return _styleToPixels( |