OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 typedef void EditCellRangeFunction(CellRange range); | 5 typedef void EditCellRangeFunction(CellRange range); |
6 | 6 |
7 /** | 7 /** |
8 * Spreadsheet widget. | 8 * Spreadsheet widget. |
9 */ | 9 */ |
10 class SpreadsheetPresenter implements SpreadsheetListener, SelectionListener { | 10 class SpreadsheetPresenter implements SpreadsheetListener, SelectionListener { |
11 | 11 |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 print("Error parsing formula '${value}': ${exception}"); | 657 print("Error parsing formula '${value}': ${exception}"); |
658 } | 658 } |
659 } | 659 } |
660 }); | 660 }); |
661 } | 661 } |
662 | 662 |
663 void _createMoveDragger(Document doc) { | 663 void _createMoveDragger(Document doc) { |
664 _moveDragger = new Element.tag("div"); | 664 _moveDragger = new Element.tag("div"); |
665 _moveDragger.id = "moveDragger-${_spreadsheet.name}"; | 665 _moveDragger.id = "moveDragger-${_spreadsheet.name}"; |
666 _moveDragger.attributes["class"] = "moveDragger"; | 666 _moveDragger.attributes["class"] = "moveDragger"; |
667 _moveDragger.style.setProperty("left", HtmlUtils.toPx(3)); | 667 _moveDragger.style.left = HtmlUtils.toPx(3); |
668 _moveDragger.style.setProperty("top", HtmlUtils.toPx(3)); | 668 _moveDragger.style.top = HtmlUtils.toPx(3); |
669 _spreadsheetElement.nodes.add(_moveDragger); | 669 _spreadsheetElement.nodes.add(_moveDragger); |
670 | 670 |
671 _moveDragger.on.mouseDown.add((MouseEvent e) { | 671 _moveDragger.on.mouseDown.add((MouseEvent e) { |
672 _moveToTop(); | 672 _moveToTop(); |
673 _hideInnerMenu(true); | 673 _hideInnerMenu(true); |
674 | 674 |
675 int mouseStartX = e.x; | 675 int mouseStartX = e.x; |
676 int mouseStartY = e.y; | 676 int mouseStartY = e.y; |
677 | 677 |
678 _spreadsheetElement.rect.then((ElementRect elementRect) { | 678 window.requestMeasurementFrame(() { |
679 ClientRect rect = elementRect.bounding; | 679 ClientRect rect = _spreadsheetElement.rect.bounding; |
680 int startX = rect.left; | 680 int startX = rect.left; |
681 int startY = rect.top; | 681 int startY = rect.top; |
682 _window.document.body.style.setProperty("cursor", "move"); | 682 return () { |
| 683 _window.document.body.style.cursor = "move"; |
683 | 684 |
684 _setDragFunction((MouseEvent e_) { | 685 _setDragFunction((MouseEvent e_) { |
685 int x = startX + e_.x - mouseStartX; | 686 int x = startX + e_.x - mouseStartX; |
686 int y = startY + e_.y - mouseStartY; | 687 int y = startY + e_.y - mouseStartY; |
687 | 688 |
688 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH); | 689 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH); |
689 y = Math.max(y, CssStyles.SANDBAR_HEIGHT); | 690 y = Math.max(y, CssStyles.SANDBAR_HEIGHT); |
690 // Move the spreadsheet container | 691 // Move the spreadsheet container |
691 _spreadsheetElement.style.setProperty("left", HtmlUtils.toPx(x)); | 692 _spreadsheetElement.style.left = HtmlUtils.toPx(x); |
692 _spreadsheetElement.style.setProperty("top", HtmlUtils.toPx(y)); | 693 _spreadsheetElement.style.top = HtmlUtils.toPx(y); |
693 }); | 694 }); |
694 }); | 695 }; |
| 696 }); |
695 | 697 |
696 _setUndragFunction((MouseEvent e_) { | 698 _setUndragFunction((MouseEvent e_) { |
697 _window.document.body.style.setProperty("cursor", "auto"); | 699 _window.document.body.style.cursor = "auto"; |
698 }); | 700 }); |
699 }); | 701 }); |
700 } | 702 } |
701 | 703 |
702 void _createResizeDragger(Document doc) { | 704 void _createResizeDragger(Document doc) { |
703 _resizeDragger = new Element.tag("div"); | 705 _resizeDragger = new Element.tag("div"); |
704 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}"; | 706 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}"; |
705 _resizeDragger.attributes["class"] = "resizeDragger"; | 707 _resizeDragger.attributes["class"] = "resizeDragger"; |
706 _spreadsheetElement.nodes.add(_resizeDragger); | 708 _spreadsheetElement.nodes.add(_resizeDragger); |
707 | 709 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 | 882 |
881 // apply text selection now | 883 // apply text selection now |
882 _formulaCellSelectingSelectText(); | 884 _formulaCellSelectingSelectText(); |
883 | 885 |
884 // show cell selecting div | 886 // show cell selecting div |
885 { | 887 { |
886 DivElement div = _table.formulaCellSelectingDiv; | 888 DivElement div = _table.formulaCellSelectingDiv; |
887 CSSStyleDeclaration divStyle = div.style; | 889 CSSStyleDeclaration divStyle = div.style; |
888 int borderWidth = 2 + 2; | 890 int borderWidth = 2 + 2; |
889 CellRange cellRange = new CellRange(_spreadsheet, minCorner, maxCorner); | 891 CellRange cellRange = new CellRange(_spreadsheet, minCorner, maxCorner); |
890 _selectionManager.getBoundingBoxForRange(cellRange).then( | 892 window.requestMeasurementFrame(() { |
891 (BoundingBox box) { | 893 final box = _selectionManager.getBoundingBoxForRange(cellRange); |
892 if (box != null) { | 894 return () { |
893 divStyle.setProperty("left", HtmlUtils.toPx(box.left)); | 895 if (box != null) { |
894 divStyle.setProperty("top", HtmlUtils.toPx(box.top)); | 896 divStyle.left = HtmlUtils.toPx(box.left); |
895 divStyle.setProperty("width", HtmlUtils.toPx(box.width - borderWidth))
; | 897 divStyle.top = HtmlUtils.toPx(box.top); |
896 divStyle.setProperty("height", HtmlUtils.toPx(box.height - borderWidth
)); | 898 divStyle.width = HtmlUtils.toPx(box.width - borderWidth); |
897 divStyle.removeProperty("display"); | 899 divStyle.height = HtmlUtils.toPx(box.height - borderWidth); |
898 } else { | 900 divStyle.removeProperty("display"); |
899 divStyle.setProperty("display", "none"); | 901 } else { |
900 } | 902 divStyle.setProperty("display", "none"); |
| 903 } |
| 904 }; |
901 }); | 905 }); |
902 } | 906 } |
903 } | 907 } |
904 | 908 |
905 void _formulaCellSelectingRememberSelectionRange() { | 909 void _formulaCellSelectingRememberSelectionRange() { |
906 _formulaCellSelectingTextStart = _formulaInput.selectionStart; | 910 _formulaCellSelectingTextStart = _formulaInput.selectionStart; |
907 _formulaCellSelectingTextEnd = _formulaInput.selectionEnd; | 911 _formulaCellSelectingTextEnd = _formulaInput.selectionEnd; |
908 } | 912 } |
909 | 913 |
910 void _formulaCellSelectingSelectText() { | 914 void _formulaCellSelectingSelectText() { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 | 1071 |
1068 // Return the number of _rows currently being displayed (not counting the colu
mn header row) | 1072 // Return the number of _rows currently being displayed (not counting the colu
mn header row) |
1069 int _getVisibleTableHeight() => _getShiftedRowEnd(_rowShift + _rows, _rowShift
); | 1073 int _getVisibleTableHeight() => _getShiftedRowEnd(_rowShift + _rows, _rowShift
); |
1070 | 1074 |
1071 // Return the number of _columns currently being displayed (not counting the r
ow header column) | 1075 // Return the number of _columns currently being displayed (not counting the r
ow header column) |
1072 int _getVisibleTableWidth() => _getShiftedColumnEnd(_columnShift + _columns, _
columnShift); | 1076 int _getVisibleTableWidth() => _getShiftedColumnEnd(_columnShift + _columns, _
columnShift); |
1073 | 1077 |
1074 // Resize the formula input field to fit the contained text | 1078 // Resize the formula input field to fit the contained text |
1075 void _growFormulaInput() { | 1079 void _growFormulaInput() { |
1076 _formulaInputMeasure.text = _formulaInput.value; | 1080 _formulaInputMeasure.text = _formulaInput.value; |
1077 _formulaInputMeasure.rect.then((ElementRect rect) { | 1081 window.requestMeasurementFrame(() { |
1078 int textWidth = rect.client.width; | 1082 int textWidth = _formulaInputMeasure.rect.client.width; |
1079 int width = Math.max(textWidth + 25, _formulaCellWidth); | 1083 int width = Math.max(textWidth + 25, _formulaCellWidth); |
1080 _formulaDiv.style.setProperty("width", HtmlUtils.toPx(width)); | 1084 return () { |
1081 _formulaInput.style.setProperty("width", HtmlUtils.toPx(width)); | 1085 _formulaDiv.style.width = HtmlUtils.toPx(width); |
| 1086 _formulaInput.style.width = HtmlUtils.toPx(width); |
| 1087 }; |
1082 }); | 1088 }); |
1083 } | 1089 } |
1084 | 1090 |
1085 // Fade out the formula input field | 1091 // Fade out the formula input field |
1086 void _hideFormula() { | 1092 void _hideFormula() { |
1087 _hideFormulaCellSelecting(); | 1093 _hideFormulaCellSelecting(); |
1088 _formulaEditing = false; | 1094 _formulaEditing = false; |
1089 _formulaDiv.classes.remove("fadeIn"); | 1095 _formulaDiv.classes.remove("fadeIn"); |
1090 _formulaDiv.classes.add("fadeOut"); | 1096 _formulaDiv.classes.add("fadeOut"); |
1091 } | 1097 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 // update table row and column headers | 1146 // update table row and column headers |
1141 void _redrawHeaders() { | 1147 void _redrawHeaders() { |
1142 _setTableWidth(_getVisibleTableWidth()); | 1148 _setTableWidth(_getVisibleTableWidth()); |
1143 _tableSizeChanged(); | 1149 _tableSizeChanged(); |
1144 | 1150 |
1145 _table.redrawHeaders(_selectionManager, _rows, _columns, _rowShift, _columnS
hift, | 1151 _table.redrawHeaders(_selectionManager, _rows, _columns, _rowShift, _columnS
hift, |
1146 _cellDisplay); | 1152 _cellDisplay); |
1147 } | 1153 } |
1148 | 1154 |
1149 void _refreshResizeDragger() { | 1155 void _refreshResizeDragger() { |
1150 _table.rect.then((ElementRect elementRect) { | 1156 window.requestMeasurementFrame(() { |
1151 // We may be called before the dragger is ready | 1157 // We may be called before the dragger is ready |
1152 if (_resizeDragger == null) { | 1158 if (_resizeDragger == null) { |
1153 return; | 1159 return; |
1154 } | 1160 } |
1155 ClientRect rect = elementRect.bounding; | 1161 ClientRect rect = _table.rect.bounding; |
1156 | 1162 return () { |
1157 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(rect.width)); | 1163 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(rect.width)); |
1158 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(rect.height)); | 1164 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(rect.height)); |
| 1165 }; |
1159 }); | 1166 }); |
1160 } | 1167 } |
1161 | 1168 |
1162 // Remove the HTML elements corresponding to the given column | 1169 // Remove the HTML elements corresponding to the given column |
1163 void _removeTableColumnHtml(int col) { | 1170 void _removeTableColumnHtml(int col) { |
1164 _table.removeColumn(col); | 1171 _table.removeColumn(col); |
1165 int width = _spreadsheet.getColumnWidth(col); | 1172 int width = _spreadsheet.getColumnWidth(col); |
1166 _setTableWidth(_tableWidth - width); | 1173 _setTableWidth(_tableWidth - width); |
1167 } | 1174 } |
1168 | 1175 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 setDrag(COL, false); | 1467 setDrag(COL, false); |
1461 } | 1468 } |
1462 }); | 1469 }); |
1463 | 1470 |
1464 // The inline cell editing UI is displayed when a user makes the same single | 1471 // The inline cell editing UI is displayed when a user makes the same single |
1465 // cell selection over again. We keep track of the current single cell that | 1472 // cell selection over again. We keep track of the current single cell that |
1466 // is selected here to know when to enter edit mode. | 1473 // is selected here to know when to enter edit mode. |
1467 CellLocation currentSelectedSingleCell = null; | 1474 CellLocation currentSelectedSingleCell = null; |
1468 | 1475 |
1469 void mouseMove(MouseEvent e) { | 1476 void mouseMove(MouseEvent e) { |
1470 _table.rect.then((ElementRect rect) { | 1477 window.requestMeasurementFrame(() { |
1471 // Set x and y to the mouse coordinates, relative to the top left of | 1478 // Set x and y to the mouse coordinates, relative to the top left of |
1472 // the spreadsheet table. | 1479 // the spreadsheet table. |
1473 ClientRect boundingRect = rect.bounding; | 1480 ClientRect boundingRect = _table.rect.bounding; |
1474 int scrollOffsetX = -boundingRect.left.toInt(); | 1481 int scrollOffsetX = -boundingRect.left.toInt(); |
1475 int scrollOffsetY = -boundingRect.top.toInt(); | 1482 int scrollOffsetY = -boundingRect.top.toInt(); |
1476 x = e.x + scrollOffsetX; | 1483 x = e.x + scrollOffsetX; |
1477 y = e.y + scrollOffsetY; | 1484 y = e.y + scrollOffsetY; |
1478 | 1485 |
1479 // Update the dragger position and optionally the actual row/column size | 1486 // Update the dragger position and optionally the actual row/column size |
1480 if (dragRowColumn(false)) { | 1487 if (dragRowColumn(false)) { |
1481 return; | 1488 return; |
1482 } | 1489 } |
1483 | 1490 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 }); | 1539 }); |
1533 } | 1540 } |
1534 | 1541 |
1535 _setMove(mouseMove); | 1542 _setMove(mouseMove); |
1536 | 1543 |
1537 _table.on.mouseDown.add((MouseEvent e) { | 1544 _table.on.mouseDown.add((MouseEvent e) { |
1538 _moveToTop(); | 1545 _moveToTop(); |
1539 | 1546 |
1540 // Right click toggles and positions the context menu | 1547 // Right click toggles and positions the context menu |
1541 if (e.button == 2 || (e.button == 0 && e.ctrlKey)) { | 1548 if (e.button == 2 || (e.button == 0 && e.ctrlKey)) { |
1542 _table.rect.then((ElementRect rect) { | 1549 window.requestMeasurementFrame(() { |
1543 ClientRect boundingRect = rect.bounding; | 1550 ClientRect boundingRect = _table.rect.bounding; |
1544 int scrollOffsetX = -boundingRect.left; | 1551 return () { |
1545 int scrollOffsetY = -boundingRect.top; | 1552 int scrollOffsetX = -boundingRect.left; |
1546 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY); | 1553 int scrollOffsetY = -boundingRect.top; |
| 1554 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY); |
| 1555 }; |
1547 }); | 1556 }); |
1548 return; | 1557 return; |
1549 } | 1558 } |
1550 | 1559 |
1551 _setDragFunction(mouseMove); | 1560 _setDragFunction(mouseMove); |
1552 | 1561 |
1553 _setUndragFunction((MouseEvent e_) { | 1562 _setUndragFunction((MouseEvent e_) { |
1554 dragRowColumn(true); | 1563 dragRowColumn(true); |
1555 _table.setDefaultCursor(); | 1564 _table.setDefaultCursor(); |
1556 draggingSelection = false; | 1565 draggingSelection = false; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 } | 1687 } |
1679 _activeInnerMenu = new InnerMenuView(_window, row, _selectionManager, style, | 1688 _activeInnerMenu = new InnerMenuView(_window, row, _selectionManager, style, |
1680 _spreadsheet.layout.getRowHeight(rowIndex), | 1689 _spreadsheet.layout.getRowHeight(rowIndex), |
1681 (){ _tableSizeChanged(); }, | 1690 (){ _tableSizeChanged(); }, |
1682 (){ _hideInnerMenu(true); _repositionFormulaInput(null, false); }); | 1691 (){ _hideInnerMenu(true); _repositionFormulaInput(null, false); }); |
1683 _innerMenuRowIndex = rowIndex; | 1692 _innerMenuRowIndex = rowIndex; |
1684 } | 1693 } |
1685 | 1694 |
1686 // Update the scroll mechanism due to a change in the visible table area | 1695 // Update the scroll mechanism due to a change in the visible table area |
1687 void _tableSizeChanged() { | 1696 void _tableSizeChanged() { |
1688 _table.rect.then((ElementRect elementRect) { | 1697 window.requestMeasurementFrame(() { |
1689 ClientRect rect = elementRect.bounding; | 1698 ClientRect rect = _table.rect.bounding; |
| 1699 return () { |
| 1700 _tableScrollContainer.style.width = HtmlUtils.toPx(rect.width + 10); |
| 1701 _spreadsheetElement.style.width = HtmlUtils.toPx(rect.width); |
1690 | 1702 |
1691 _tableScrollContainer.style.width = HtmlUtils.toPx(rect.width + 10); | 1703 _tableScrollContainer.style.height = HtmlUtils.toPx(rect.height + 10); |
1692 _spreadsheetElement.style.width = HtmlUtils.toPx(rect.width); | 1704 _spreadsheetElement.style.height = HtmlUtils.toPx(rect.height); |
1693 | 1705 |
1694 _tableScrollContainer.style.height = HtmlUtils.toPx(rect.height + 10); | 1706 _tableScrollDiv.style.width = HtmlUtils.toPx( |
1695 _spreadsheetElement.style.height = HtmlUtils.toPx(rect.height); | 1707 _spreadsheet.getColumnEnd(_spreadsheet.columnCount())); |
| 1708 int extra = _activeInnerMenu == null ? |
| 1709 0 : _activeInnerMenu.currentRowHeight; |
| 1710 _tableScrollDiv.style.height = HtmlUtils.toPx(_spreadsheet.getRowEnd( |
| 1711 _spreadsheet.rowCount()) + extra); |
1696 | 1712 |
1697 _tableScrollDiv.style.width = HtmlUtils.toPx( | 1713 // Reposition the scroll bars |
1698 _spreadsheet.getColumnEnd(_spreadsheet.columnCount())); | 1714 _scroll(_rowShift, _columnShift); |
1699 int extra = _activeInnerMenu == null ? | 1715 // Move the resize dragger to the bottom-right corner |
1700 0 : _activeInnerMenu.currentRowHeight; | 1716 _refreshResizeDragger(); |
1701 _tableScrollDiv.style.height = HtmlUtils.toPx(_spreadsheet.getRowEnd( | 1717 }; |
1702 _spreadsheet.rowCount()) + extra); | |
1703 | |
1704 // Reposition the scroll bars | |
1705 _scroll(_rowShift, _columnShift); | |
1706 // Move the resize dragger to the bottom-right corner | |
1707 _refreshResizeDragger(); | |
1708 }); | 1718 }); |
1709 } | 1719 } |
1710 | 1720 |
1711 void _updateInnerMenu() { | 1721 void _updateInnerMenu() { |
1712 if (_activeInnerMenu != null) { | 1722 if (_activeInnerMenu != null) { |
1713 _activeInnerMenu.updateSize(); | 1723 _activeInnerMenu.updateSize(); |
1714 } | 1724 } |
1715 } | 1725 } |
1716 | 1726 |
1717 // Change the width/height of a column or row. | 1727 // Change the width/height of a column or row. |
1718 void _updateRowColumnSize(int rowOrCol, int index, int size, int oldSize, bool
mouseUp) { | 1728 void _updateRowColumnSize(int rowOrCol, int index, int size, int oldSize, bool
mouseUp) { |
1719 if (mouseUp) { | 1729 if (mouseUp) { |
1720 Command command = new ResizeRowColumnCommand(_spreadsheet, rowOrCol, index
, size, oldSize); | 1730 Command command = new ResizeRowColumnCommand(_spreadsheet, rowOrCol, index
, size, oldSize); |
1721 _spreadsheet.execute(command); | 1731 _spreadsheet.execute(command); |
1722 } else { | 1732 } else { |
1723 if (rowOrCol == COL) { | 1733 if (rowOrCol == COL) { |
1724 _spreadsheet.setColumnWidth(index, size); | 1734 _spreadsheet.setColumnWidth(index, size); |
1725 } else { | 1735 } else { |
1726 _spreadsheet.setRowHeight(index, size); | 1736 _spreadsheet.setRowHeight(index, size); |
1727 } | 1737 } |
1728 } | 1738 } |
1729 } | 1739 } |
1730 } | 1740 } |
OLD | NEW |