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

Unified Diff: samples/ui_lib/view/PagedViews.dart

Issue 11367040: Removing Element.rect. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
Index: samples/ui_lib/view/PagedViews.dart
diff --git a/samples/ui_lib/view/PagedViews.dart b/samples/ui_lib/view/PagedViews.dart
index 5dde4d839ed63529c51efb6e1eba85952bdf464e..fd30b78e5a79155aaa695d2a2c753b75540bf3d0 100644
--- a/samples/ui_lib/view/PagedViews.dart
+++ b/samples/ui_lib/view/PagedViews.dart
@@ -116,12 +116,7 @@ class PagedColumnView extends View {
true /* horizontalScrollEnabled */,
true /* momementumEnabled */,
() {
- final completer = new Completer<Size>();
- _container.rect.then((ElementRect rect) {
- // Only view width matters.
- completer.complete(new Size(_getViewLength(rect), 1));
- });
- return completer.future;
+ return new Size(_getViewLength(_container), 1);
},
Scroller.FAST_SNAP_DECELERATION_FACTOR);
@@ -131,8 +126,8 @@ class PagedColumnView extends View {
return node;
}
- int _getViewLength(ElementRect rect) {
- return _computePageSize(rect) * pages.length.value;
+ int _getViewLength(Element element) {
+ return _computePageSize(element) * pages.length.value;
}
// TODO(jmesserly): would be better to not have this code in enterDocument.
@@ -185,17 +180,17 @@ class PagedColumnView extends View {
// The content needs to have its height explicitly set, or columns don't
// flow to the right correctly. So we copy our own height and set the height
// of the content.
- node.rect.then((ElementRect rect) {
- contentView.node.style.height = '${rect.offset.height}px';
+ window.requestLayoutFrame(() {
+ contentView.node.style.height = '${node.offsetHeight}px';
});
_updatePageCount(null);
}
bool _updatePageCount(Callback callback) {
int pageLength = 1;
- _container.rect.then((ElementRect rect) {
- if (rect.scroll.width > rect.offset.width) {
- pageLength = (rect.scroll.width / _computePageSize(rect))
+ window.requestLayoutFrame(() {
+ if (_container.scrollWidth > _container.offsetWidth) {
+ pageLength = (_container.scrollWidth / _computePageSize(_container))
.ceil().toInt();
}
pageLength = Math.max(pageLength, 1);
@@ -218,9 +213,9 @@ class PagedColumnView extends View {
}
void _onContentMoved(Event e) {
- _container.rect.then((ElementRect rect) {
+ window.requestLayoutFrame(() {
num current = scroller.contentOffset.x;
- int pageSize = _computePageSize(rect);
+ int pageSize = _computePageSize(_container);
pages.current.value = -(current / pageSize).round().toInt();
});
}
@@ -228,8 +223,8 @@ class PagedColumnView extends View {
void _snapToPage(Event e) {
num current = scroller.contentOffset.x;
num currentTarget = scroller.currentTarget.x;
- _container.rect.then((ElementRect rect) {
- int pageSize = _computePageSize(rect);
+ window.requestLayoutFrame(() {
+ int pageSize = _computePageSize(_container);
int destination;
num currentPageNumber = -(current / pageSize).round();
num pageNumber = -currentTarget / pageSize;
@@ -239,7 +234,8 @@ class PagedColumnView extends View {
} else {
if (currentPageNumber == pageNumber.round() &&
(pageNumber - currentPageNumber).abs() > MIN_THROW_PAGE_FRACTION &&
- -current + _viewportSize < _getViewLength(rect) && current < 0) {
+ -current + _viewportSize < _getViewLength(_container) &&
+ current < 0) {
// The user is trying to throw so we want to round up to the
// nearest page in the direction they are throwing.
pageNumber = currentTarget < current
@@ -260,11 +256,11 @@ class PagedColumnView extends View {
});
}
- int _computePageSize(ElementRect rect) {
+ int _computePageSize(Element element) {
// Hacky: we need to duplicate the way the columns are being computed,
// including rounding, to figure out how far to translate the div.
// See http://www.w3.org/TR/css3-multicol/#column-width
- _viewportSize = rect.offset.width;
+ _viewportSize = element.offsetWidth;
// Figure out how many columns we're rendering.
// The algorithm ensures we're bigger than the specified min size.
@@ -279,8 +275,8 @@ class PagedColumnView extends View {
}
void _onPageSelected() {
- _container.rect.then((ElementRect rect) {
- int translate = -pages.target.value * _computePageSize(rect);
+ window.requestLayoutFrame(() {
+ int translate = -pages.target.value * _computePageSize(_container);
scroller.throwTo(translate, 0);
});
}

Powered by Google App Engine
This is Rietveld 408576698