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

Unified Diff: client/samples/total/src/SelectionManager.dart

Issue 9148015: Example showing alternate async measurement solution (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Final version Created 8 years, 11 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
Index: client/samples/total/src/SelectionManager.dart
diff --git a/client/samples/total/src/SelectionManager.dart b/client/samples/total/src/SelectionManager.dart
index ead003dec75bd5db4cc02905ff6b9f8a99bd8ee3..7a747d8a8df20d32bc07c3814290d7151348a687 100644
--- a/client/samples/total/src/SelectionManager.dart
+++ b/client/samples/total/src/SelectionManager.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -55,7 +55,7 @@ class SelectionManager {
_selectionDiv = new Element.tag("div");
_selectionDiv.id = "selection-${_spreadsheet.name}";
_selectionDiv.attributes["class"] = "selection";
- _selectionDiv.style.setProperty("display", "none");
+ _selectionDiv.style.display = "none";
spreadsheetElement.nodes.add(_selectionDiv);
Element thumb = new Element.tag("div");
@@ -95,14 +95,15 @@ class SelectionManager {
// Hide the selection marquee and empty the selection range
void clearSelection() {
- _selectionDiv.style.setProperty("display", "none");
+ _selectionDiv.style.display = "none";
_selectedCell = _selectionCorner = null;
selectionChanged();
}
// Return a BoundingBox for the given CellRange, clipped to the visible region of the table
// TODO: deal with full row and/or column selection
- Future<BoundingBox> getBoundingBoxForRange(CellRange r) {
+ BoundingBox getBoundingBoxForRange(CellRange r) {
+ assert(window.inMeasurementFrame);
// Modify the overlay for entire row/column selection
int minRow = r.minCorner.row;
int maxRow = r.maxCorner.row;
@@ -151,21 +152,15 @@ class SelectionManager {
// We need bounding box relative to the container which will be offset by
// css.
- final tableRect = _table.rect;
- final minCellElmtRect = minCellElmt.rect;
- final maxCellElmtRect = maxCellElmt.rect;
-
- window.requestLayoutFrame(() {
- ClientRect orgP = tableRect.value.bounding;
- ClientRect minP = minCellElmtRect.value.bounding;
- ClientRect maxP = maxCellElmtRect.value.bounding;
- completer.complete(new BoundingBox(
- (minP.left - orgP.left).toInt(),
- (minP.top - orgP.top).toInt(),
- (maxP.left - minP.left + maxCellElmtRect.value.client.width).toInt(),
- (maxP.top - minP.top + maxCellElmtRect.value.client.height).toInt()));
- });
- return completer.future;
+
+ final orgP = _table.rect.bounding;
+ final minP = minCellElmt.rect.bounding;
+ final maxP = maxCellElmt.rect.bounding;
+ return new BoundingBox(
+ (minP.left - orgP.left).toInt(),
+ (minP.top - orgP.top).toInt(),
+ (maxP.left - minP.left + maxCellElmt.rect.client.width).toInt(),
+ (maxP.top - minP.top + maxCellElmt.rect.client.height).toInt());
}
CellRange getSelectionRange() => _getSelectionRange(_selectedCell, _selectionCorner);
@@ -227,16 +222,19 @@ class SelectionManager {
return;
}
- getBoundingBoxForRange(r).then((BoundingBox box) {
- if (box != null) {
- _selectionDiv.style.setProperty("left", HtmlUtils.toPx(box.left));
- _selectionDiv.style.setProperty("top", HtmlUtils.toPx(box.top));
- _selectionDiv.style.setProperty("width", HtmlUtils.toPx(box.width));
- _selectionDiv.style.setProperty("height", HtmlUtils.toPx(box.height));
- _selectionDiv.style.removeProperty("display");
- } else {
- _selectionDiv.style.setProperty("display", "none");
- }
+ window.requestMeasurementFrame(() {
+ final box = getBoundingBoxForRange(r);
+ return () {
+ if (box != null) {
+ _selectionDiv.style.left = HtmlUtils.toPx(box.left);
+ _selectionDiv.style.top = HtmlUtils.toPx(box.top);
+ _selectionDiv.style.width = HtmlUtils.toPx(box.width);
+ _selectionDiv.style.height = HtmlUtils.toPx(box.height);
+ _selectionDiv.style.removeProperty("display");
+ } else {
+ _selectionDiv.style.display = "none";
+ }
+ };
});
}

Powered by Google App Engine
This is Rietveld 408576698