Chromium Code Reviews| 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 // 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 Loading... | |
| 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 Loading... | |
| 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 |
|
arv (Not doing code reviews)
2011/10/27 05:50:24
by what?
Jacob
2011/10/27 20:59:25
Oops. Somehow I accidentally removed the word css.
| |
| 151 ClientRect orgP = _table.getBoundingClientRect(); | 153 final tableRect = _table.rect; |
| 152 ClientRect minP = minCellElmt.getBoundingClientRect(); | 154 final minCellElmtRect = minCellElmt.rect; |
| 153 ClientRect maxP = maxCellElmt.getBoundingClientRect(); | 155 final maxCellElmtRect = maxCellElmt.rect; |
| 154 return new BoundingBox( | 156 |
| 155 (minP.left - orgP.left).toInt(), | 157 window.requestLayoutFrame(() { |
| 156 (minP.top - orgP.top).toInt(), | 158 ClientRect orgP = tableRect.bounding; |
| 157 (maxP.left - minP.left + maxCellElmt.clientWidth).toInt(), | 159 ClientRect minP = minCellElmtRect.bounding; |
| 158 (maxP.top - minP.top + maxCellElmt.clientHeight).toInt()); | 160 ClientRect maxP = maxCellElmtRect.bounding; |
| 161 completer.complete(new BoundingBox( | |
| 162 (minP.left - orgP.left).toInt(), | |
|
arv (Not doing code reviews)
2011/10/27 05:50:24
it is sad that we do toInt() here when we for once
Jacob
2011/10/27 20:59:25
Perhaps the toInt calls are unneeded but this is j
| |
| 163 (minP.top - orgP.top).toInt(), | |
| 164 (maxP.left - minP.left + maxCellElmtRect.client.width).toInt(), | |
| 165 (maxP.top - minP.top + maxCellElmtRect.client.height).toInt())); | |
| 166 }); | |
| 167 return completer.future; | |
| 159 } | 168 } |
| 160 | 169 |
| 161 CellRange getSelectionRange() => _getSelectionRange(_selectedCell, _selectionC orner); | 170 CellRange getSelectionRange() => _getSelectionRange(_selectedCell, _selectionC orner); |
| 162 | 171 |
| 163 bool isColumnSelected(int column) { | 172 bool isColumnSelected(int column) { |
| 164 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); | 173 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); |
| 165 if (r == null) { | 174 if (r == null) { |
| 166 return false; | 175 return false; |
| 167 } | 176 } |
| 168 return r.minCorner.col <= column && r.maxCorner.col >= column; | 177 return r.minCorner.col <= column && r.maxCorner.col >= column; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 219 } |
| 211 | 220 |
| 212 // Draw or hide the selection marquee using current cell metrics | 221 // Draw or hide the selection marquee using current cell metrics |
| 213 void updateSelection() { | 222 void updateSelection() { |
| 214 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); | 223 CellRange r = _getSelectionRange(_selectedCell, _selectionCorner); |
| 215 if (r == null) { | 224 if (r == null) { |
| 216 clearSelection(); | 225 clearSelection(); |
| 217 return; | 226 return; |
| 218 } | 227 } |
| 219 | 228 |
| 220 BoundingBox box = getBoundingBoxForRange(r); | 229 getBoundingBoxForRange(r).then((BoundingBox box) { |
| 221 if (box != null) { | 230 if (box != null) { |
| 222 _selectionDiv.style.setProperty("left", HtmlUtils.toPx(box.left)); | 231 _selectionDiv.style.setProperty("left", HtmlUtils.toPx(box.left)); |
| 223 _selectionDiv.style.setProperty("top", HtmlUtils.toPx(box.top)); | 232 _selectionDiv.style.setProperty("top", HtmlUtils.toPx(box.top)); |
| 224 _selectionDiv.style.setProperty("width", HtmlUtils.toPx(box.width)); | 233 _selectionDiv.style.setProperty("width", HtmlUtils.toPx(box.width)); |
| 225 _selectionDiv.style.setProperty("height", HtmlUtils.toPx(box.height)); | 234 _selectionDiv.style.setProperty("height", HtmlUtils.toPx(box.height)); |
| 226 _selectionDiv.style.removeProperty("display"); | 235 _selectionDiv.style.removeProperty("display"); |
| 227 } else { | 236 } else { |
| 228 _selectionDiv.style.setProperty("display", "none"); | 237 _selectionDiv.style.setProperty("display", "none"); |
| 229 } | 238 } |
| 239 }); | |
| 230 } | 240 } |
| 231 | 241 |
| 232 // Return the selection range for the given corners. | 242 // Return the selection range for the given corners. |
| 233 // If the first corner is on a row header, it is assumed that the entire | 243 // 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. | 244 // 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 | 245 // 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. | 246 // column is selected, and the returned range has min.row == 0 and max.row == 0. |
| 237 CellRange _getSelectionRange(CellLocation corner1, CellLocation corner2) { | 247 CellRange _getSelectionRange(CellLocation corner1, CellLocation corner2) { |
| 238 if (corner1 == null || corner2 == null) { | 248 if (corner1 == null || corner2 == null) { |
| 239 return null; | 249 return null; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 258 return new CellRange.columns(corner1.spreadsheet, minCol, maxCol); | 268 return new CellRange.columns(corner1.spreadsheet, minCol, maxCol); |
| 259 } | 269 } |
| 260 | 270 |
| 261 return new CellRange(corner1.spreadsheet, new RowCol(minRow, minCol), | 271 return new CellRange(corner1.spreadsheet, new RowCol(minRow, minCol), |
| 262 new RowCol(maxRow, maxCol)); | 272 new RowCol(maxRow, maxCol)); |
| 263 } | 273 } |
| 264 | 274 |
| 265 // Return the value closest to x in the range [min, max] | 275 // 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); | 276 int _pin(int x, int min, int max) => Math.max(Math.min(x, max), min); |
| 267 } | 277 } |
| OLD | NEW |