| 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 part of layout; | 5 part of layout; |
| 6 | 6 |
| 7 /** The interface that the layout algorithms use to talk to the view. */ | 7 /** The interface that the layout algorithms use to talk to the view. */ |
| 8 abstract class Positionable { | 8 abstract class Positionable { |
| 9 ViewLayout get layout; | 9 ViewLayout get layout; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Caches the layout parameters that were specified in CSS during a layout | 26 * Caches the layout parameters that were specified in CSS during a layout |
| 27 * computation. These values are immutable during a layout. | 27 * computation. These values are immutable during a layout. |
| 28 */ | 28 */ |
| 29 class LayoutParams { | 29 class LayoutParams { |
| 30 // TODO(jmesserly): should be const, but there's a bug in DartC preventing us | 30 // TODO(jmesserly): should be const, but there's a bug in DartC preventing us |
| 31 // from calling "window." in an initializer. See b/5332777 | 31 // from calling "window." in an initializer. See b/5332777 |
| 32 Future<CssStyleDeclaration> style; | 32 CssStyleDeclaration style; |
| 33 | 33 |
| 34 int get layer => 0; | 34 int get layer => 0; |
| 35 | 35 |
| 36 LayoutParams(Element node) { | 36 LayoutParams(Element node) { |
| 37 style = node.computedStyle; | 37 style = node.getComputedStyle(); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 // TODO(jmesserly): enums would really help here | 41 // TODO(jmesserly): enums would really help here |
| 42 class Dimension { | 42 class Dimension { |
| 43 // TODO(jmesserly): perhaps this should be X and Y | 43 // TODO(jmesserly): perhaps this should be X and Y |
| 44 static const WIDTH = const Dimension._internal('width'); | 44 static const WIDTH = const Dimension._internal('width'); |
| 45 static const HEIGHT = const Dimension._internal('height'); | 45 static const HEIGHT = const Dimension._internal('height'); |
| 46 | 46 |
| 47 final String name; // for debugging | 47 final String name; // for debugging |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return new GridLayout(view); | 98 return new GridLayout(view); |
| 99 } else { | 99 } else { |
| 100 return new ViewLayout(view); | 100 return new ViewLayout(view); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 static bool hasCustomLayout(Positionable view) { | 104 static bool hasCustomLayout(Positionable view) { |
| 105 return view.customStyle['display'] == "-dart-grid"; | 105 return view.customStyle['display'] == "-dart-grid"; |
| 106 } | 106 } |
| 107 | 107 |
| 108 CssStyleDeclaration get _style => layoutParams.style.value; | 108 CssStyleDeclaration get _style => layoutParams.style; |
| 109 | 109 |
| 110 void cacheExistingBrowserLayout() { | 110 void cacheExistingBrowserLayout() { |
| 111 _offsetWidth = view.node.offsetWidth; | 111 _offsetWidth = view.node.offsetWidth; |
| 112 _offsetHeight = view.node.offsetHeight; | 112 _offsetHeight = view.node.offsetHeight; |
| 113 } | 113 } |
| 114 | 114 |
| 115 int get currentWidth { | 115 int get currentWidth { |
| 116 return _offsetWidth; | 116 return _offsetWidth; |
| 117 } | 117 } |
| 118 | 118 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 int measureContent(ViewLayout parent, Dimension dimension, | 184 int measureContent(ViewLayout parent, Dimension dimension, |
| 185 [ContentSizeMode mode = null]) { | 185 [ContentSizeMode mode = null]) { |
| 186 if (dimension == Dimension.WIDTH) { | 186 if (dimension == Dimension.WIDTH) { |
| 187 return measureWidth(parent, mode); | 187 return measureWidth(parent, mode); |
| 188 } else if (dimension == Dimension.HEIGHT) { | 188 } else if (dimension == Dimension.HEIGHT) { |
| 189 return measureHeight(parent, mode); | 189 return measureHeight(parent, mode); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 int measureWidth(ViewLayout parent, ContentSizeMode mode) { | 193 int measureWidth(ViewLayout parent, ContentSizeMode mode) { |
| 194 final style = layoutParams.style.value; | 194 final style = layoutParams.style; |
| 195 if (mode == ContentSizeMode.MIN) { | 195 if (mode == ContentSizeMode.MIN) { |
| 196 return _styleToPixels( | 196 return _styleToPixels( |
| 197 style.minWidth, currentWidth, parent.currentWidth); | 197 style.minWidth, currentWidth, parent.currentWidth); |
| 198 } else if (mode == ContentSizeMode.MAX) { | 198 } else if (mode == ContentSizeMode.MAX) { |
| 199 return _styleToPixels( | 199 return _styleToPixels( |
| 200 style.maxWidth, currentWidth, parent.currentWidth); | 200 style.maxWidth, currentWidth, parent.currentWidth); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 int measureHeight(ViewLayout parent, ContentSizeMode mode) { | 204 int measureHeight(ViewLayout parent, ContentSizeMode mode) { |
| 205 final style = layoutParams.style.value; | 205 final style = layoutParams.style; |
| 206 if (mode == ContentSizeMode.MIN) { | 206 if (mode == ContentSizeMode.MIN) { |
| 207 return _styleToPixels( | 207 return _styleToPixels( |
| 208 style.minHeight, currentHeight, parent.currentHeight); | 208 style.minHeight, currentHeight, parent.currentHeight); |
| 209 } else if (mode == ContentSizeMode.MAX) { | 209 } else if (mode == ContentSizeMode.MAX) { |
| 210 return _styleToPixels( | 210 return _styleToPixels( |
| 211 style.maxHeight, currentHeight, parent.currentHeight); | 211 style.maxHeight, currentHeight, parent.currentHeight); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 static int _toPixels(String style) { | 215 static int _toPixels(String style) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 227 // For an unset max-content size, use the actual size | 227 // For an unset max-content size, use the actual size |
| 228 return size; | 228 return size; |
| 229 } | 229 } |
| 230 if (style.endsWith('%')) { | 230 if (style.endsWith('%')) { |
| 231 num percent = double.parse(style.substring(0, style.length - 1)); | 231 num percent = double.parse(style.substring(0, style.length - 1)); |
| 232 return ((percent / 100) * parentSize).toInt(); | 232 return ((percent / 100) * parentSize).toInt(); |
| 233 } | 233 } |
| 234 return _toPixels(style); | 234 return _toPixels(style); |
| 235 } | 235 } |
| 236 } | 236 } |
| OLD | NEW |