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

Side by Side Diff: client/samples/total/src/SelectionManager.dart

Issue 8363040: Implement measurement using futures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove duplicated imports from html.dart Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // The callback method type invoked when the selection changes. 5 // The callback method type invoked when the selection changes.
6 typedef void SelectionCallback(); 6 typedef void SelectionCallback();
7 7
8 // The method type for the SelectionManager.applyToSelectedCells method. 8 // The method type for the SelectionManager.applyToSelectedCells method.
9 typedef void SelectionApply(CellLocation location); 9 typedef void SelectionApply(CellLocation location);
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Hide the selection marquee and empty the selection range 96 // Hide the selection marquee and empty the selection range
97 void clearSelection() { 97 void clearSelection() {
98 _selectionDiv.style.setProperty("display", "none"); 98 _selectionDiv.style.setProperty("display", "none");
99 _selectedCell = _selectionCorner = null; 99 _selectedCell = _selectionCorner = null;
100 selectionChanged(); 100 selectionChanged();
101 } 101 }
102 102
103 // Return a BoundingBox for the given CellRange, clipped to the visible region of the table 103 // Return a BoundingBox for the given CellRange, clipped to the visible region of the table
104 // TODO: deal with full row and/or column selection 104 // TODO: deal with full row and/or column selection
105 BoundingBox getBoundingBoxForRange(CellRange r) { 105 Future<BoundingBox> getBoundingBoxForRange(CellRange r) {
106 // Modify the overlay for entire row/column selection 106 // Modify the overlay for entire row/column selection
107 int minRow = r.minCorner.row; 107 int minRow = r.minCorner.row;
108 int maxRow = r.maxCorner.row; 108 int maxRow = r.maxCorner.row;
109 int minCol = r.minCorner.col; 109 int minCol = r.minCorner.col;
110 int maxCol = r.maxCorner.col; 110 int maxCol = r.maxCorner.col;
111 111
112 // FIXME - provide the table size to this class in a better way 112 // FIXME - provide the table size to this class in a better way
113 int maxVisibleRow = _table.numRows() - 1; 113 int maxVisibleRow = _table.numRows() - 1;
114 TableRowElement tableRow = _table.getRowElement(0); 114 TableRowElement tableRow = _table.getRowElement(0);
115 int maxVisibleCol = tableRow.cells.length - 1; 115 int maxVisibleCol = tableRow.cells.length - 1;
(...skipping 14 matching lines...) Expand all
130 if (maxRow <= _originRow) { 130 if (maxRow <= _originRow) {
131 return null; 131 return null;
132 } 132 }
133 if (minCol > _originColumn + maxVisibleCol) { 133 if (minCol > _originColumn + maxVisibleCol) {
134 return null; 134 return null;
135 } 135 }
136 if (minRow > _originRow + maxVisibleRow) { 136 if (minRow > _originRow + maxVisibleRow) {
137 return null; 137 return null;
138 } 138 }
139 139
140 final completer = new Completer<BoundingBox>();
141
140 // Clip the range to the visible region 142 // Clip the range to the visible region
141 int minPinned = _pin(minRow - _originRow, 1, maxVisibleRow); 143 int minPinned = _pin(minRow - _originRow, 1, maxVisibleRow);
142 TableRowElement minRowElmt = _table.getRowElement(minPinned); 144 TableRowElement minRowElmt = _table.getRowElement(minPinned);
143 TableCellElement minCellElmt = 145 TableCellElement minCellElmt =
144 minRowElmt.cells[_pin(minCol - _originColumn, 1, maxVisibleCol)]; 146 minRowElmt.cells[_pin(minCol - _originColumn, 1, maxVisibleCol)];
145 int maxPinned = _pin(maxRow - _originRow, 1, maxVisibleRow); 147 int maxPinned = _pin(maxRow - _originRow, 1, maxVisibleRow);
146 TableRowElement maxRowElmt = _table.getRowElement(maxPinned); 148 TableRowElement maxRowElmt = _table.getRowElement(maxPinned);
147 TableCellElement maxCellElmt = 149 TableCellElement maxCellElmt =
148 maxRowElmt.cells[_pin(maxCol - _originColumn, 1, maxVisibleCol)]; 150 maxRowElmt.cells[_pin(maxCol - _originColumn, 1, maxVisibleCol)];
149 151
150 // We need bounding box relative to the container which will be offset by cs s 152 // We need bounding box relative to the container which will be offset by
151 ClientRect orgP = _table.getBoundingClientRect(); 153 // css.
152 ClientRect minP = minCellElmt.getBoundingClientRect(); 154 final tableRect = _table.rect;
153 ClientRect maxP = maxCellElmt.getBoundingClientRect(); 155 final minCellElmtRect = minCellElmt.rect;
154 return new BoundingBox( 156 final maxCellElmtRect = maxCellElmt.rect;
155 (minP.left - orgP.left).toInt(), 157
156 (minP.top - orgP.top).toInt(), 158 window.requestLayoutFrame(() {
157 (maxP.left - minP.left + maxCellElmt.clientWidth).toInt(), 159 ClientRect orgP = tableRect.bounding;
158 (maxP.top - minP.top + maxCellElmt.clientHeight).toInt()); 160 ClientRect minP = minCellElmtRect.bounding;
161 ClientRect maxP = maxCellElmtRect.bounding;
162 completer.complete(new BoundingBox(
163 (minP.left - orgP.left).toInt(),
164 (minP.top - orgP.top).toInt(),
165 (maxP.left - minP.left + maxCellElmtRect.client.width).toInt(),
166 (maxP.top - minP.top + maxCellElmtRect.client.height).toInt()));
167 });
168 return completer.future;
159 } 169 }
160 170
161 CellRange getSelectionRange() => _getSelectionRange(_selectedCell, _selectionC orner); 171 CellRange getSelectionRange() => _getSelectionRange(_selectedCell, _selectionC orner);
162 172
163 bool isColumnSelected(int column) { 173 bool isColumnSelected(int column) {
164 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); 174 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner);
165 if (r == null) { 175 if (r == null) {
166 return false; 176 return false;
167 } 177 }
168 return r.minCorner.col <= column && r.maxCorner.col >= column; 178 return r.minCorner.col <= column && r.maxCorner.col >= column;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 220 }
211 221
212 // Draw or hide the selection marquee using current cell metrics 222 // Draw or hide the selection marquee using current cell metrics
213 void updateSelection() { 223 void updateSelection() {
214 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); 224 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner);
215 if (r == null) { 225 if (r == null) {
216 clearSelection(); 226 clearSelection();
217 return; 227 return;
218 } 228 }
219 229
220 BoundingBox box = getBoundingBoxForRange(r); 230 getBoundingBoxForRange(r).then((BoundingBox box) {
221 if (box != null) { 231 if (box != null) {
222 _selectionDiv.style.setProperty("left", HtmlUtils.toPx(box.left)); 232 _selectionDiv.style.setProperty("left", HtmlUtils.toPx(box.left));
223 _selectionDiv.style.setProperty("top", HtmlUtils.toPx(box.top)); 233 _selectionDiv.style.setProperty("top", HtmlUtils.toPx(box.top));
224 _selectionDiv.style.setProperty("width", HtmlUtils.toPx(box.width)); 234 _selectionDiv.style.setProperty("width", HtmlUtils.toPx(box.width));
225 _selectionDiv.style.setProperty("height", HtmlUtils.toPx(box.height)); 235 _selectionDiv.style.setProperty("height", HtmlUtils.toPx(box.height));
226 _selectionDiv.style.removeProperty("display"); 236 _selectionDiv.style.removeProperty("display");
227 } else { 237 } else {
228 _selectionDiv.style.setProperty("display", "none"); 238 _selectionDiv.style.setProperty("display", "none");
229 } 239 }
240 });
230 } 241 }
231 242
232 // Return the selection range for the given corners. 243 // Return the selection range for the given corners.
233 // If the first corner is on a row header, it is assumed that the entire 244 // If the first corner is on a row header, it is assumed that the entire
234 // row is selected, and the returned range has min.col == 0 and max.col == 0. 245 // row is selected, and the returned range has min.col == 0 and max.col == 0.
235 // If the first corner is on a column header, it is assumed that the entire 246 // If the first corner is on a column header, it is assumed that the entire
236 // column is selected, and the returned range has min.row == 0 and max.row == 0. 247 // column is selected, and the returned range has min.row == 0 and max.row == 0.
237 CellRange _getSelectionRange(CellLocation corner1, CellLocation corner2) { 248 CellRange _getSelectionRange(CellLocation corner1, CellLocation corner2) {
238 if (corner1 == null || corner2 == null) { 249 if (corner1 == null || corner2 == null) {
239 return null; 250 return null;
(...skipping 18 matching lines...) Expand all
258 return new CellRange.columns(corner1.spreadsheet, minCol, maxCol); 269 return new CellRange.columns(corner1.spreadsheet, minCol, maxCol);
259 } 270 }
260 271
261 return new CellRange(corner1.spreadsheet, new RowCol(minRow, minCol), 272 return new CellRange(corner1.spreadsheet, new RowCol(minRow, minCol),
262 new RowCol(maxRow, maxCol)); 273 new RowCol(maxRow, maxCol));
263 } 274 }
264 275
265 // Return the value closest to x in the range [min, max] 276 // Return the value closest to x in the range [min, max]
266 int _pin(int x, int min, int max) => Math.max(Math.min(x, max), min); 277 int _pin(int x, int min, int max) => Math.max(Math.min(x, max), min);
267 } 278 }
OLDNEW
« no previous file with comments | « client/samples/total/src/InnerMenuView.dart ('k') | client/samples/total/src/SpreadsheetPresenter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698