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

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

Issue 9145004: Revert "Example showing alternate async measurement solution" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, 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 {
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.left = HtmlUtils.toPx(3); 667 _moveDragger.style.setProperty("left", HtmlUtils.toPx(3));
668 _moveDragger.style.top = HtmlUtils.toPx(3); 668 _moveDragger.style.setProperty("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 window.requestMeasurementFrame(() { 678 _spreadsheetElement.rect.then((ElementRect elementRect) {
679 ClientRect rect = _spreadsheetElement.rect.bounding; 679 ClientRect rect = elementRect.bounding;
680 int startX = rect.left; 680 int startX = rect.left;
681 int startY = rect.top; 681 int startY = rect.top;
682 return () { 682 _window.document.body.style.setProperty("cursor", "move");
683 _window.document.body.style.cursor = "move";
684 683
685 _setDragFunction((MouseEvent e_) { 684 _setDragFunction((MouseEvent e_) {
686 int x = startX + e_.x - mouseStartX; 685 int x = startX + e_.x - mouseStartX;
687 int y = startY + e_.y - mouseStartY; 686 int y = startY + e_.y - mouseStartY;
688 687
689 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH); 688 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH);
690 y = Math.max(y, CssStyles.SANDBAR_HEIGHT); 689 y = Math.max(y, CssStyles.SANDBAR_HEIGHT);
691 // Move the spreadsheet container 690 // Move the spreadsheet container
692 _spreadsheetElement.style.left = HtmlUtils.toPx(x); 691 _spreadsheetElement.style.setProperty("left", HtmlUtils.toPx(x));
693 _spreadsheetElement.style.top = HtmlUtils.toPx(y); 692 _spreadsheetElement.style.setProperty("top", HtmlUtils.toPx(y));
694 }); 693 });
695 }; 694 });
696 });
697 695
698 _setUndragFunction((MouseEvent e_) { 696 _setUndragFunction((MouseEvent e_) {
699 _window.document.body.style.cursor = "auto"; 697 _window.document.body.style.setProperty("cursor", "auto");
700 }); 698 });
701 }); 699 });
702 } 700 }
703 701
704 void _createResizeDragger(Document doc) { 702 void _createResizeDragger(Document doc) {
705 _resizeDragger = new Element.tag("div"); 703 _resizeDragger = new Element.tag("div");
706 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}"; 704 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}";
707 _resizeDragger.attributes["class"] = "resizeDragger"; 705 _resizeDragger.attributes["class"] = "resizeDragger";
708 _spreadsheetElement.nodes.add(_resizeDragger); 706 _spreadsheetElement.nodes.add(_resizeDragger);
709 707
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 _tableScrollContainer.style.setProperty("left", "0px"); 801 _tableScrollContainer.style.setProperty("left", "0px");
804 _tableScrollContainer.style.setProperty("top", "0px"); 802 _tableScrollContainer.style.setProperty("top", "0px");
805 _tableScrollContainer.nodes.add(_tableScrollDiv); 803 _tableScrollContainer.nodes.add(_tableScrollDiv);
806 _tableSizeChanged(); 804 _tableSizeChanged();
807 805
808 _tableScrollContainer.on.scroll.add((e) { 806 _tableScrollContainer.on.scroll.add((e) {
809 if (_scrolledByKeyboard) { 807 if (_scrolledByKeyboard) {
810 _scrolledByKeyboard = false; 808 _scrolledByKeyboard = false;
811 return; 809 return;
812 } 810 }
813 window.requestMeasurementFrame(() { 811 Future<ElementRect> future = _tableScrollContainer.rect;
814 final rect = _tableScrollContainer.rect; 812 future.then((ElementRect rect) {
815 int scrollTop = rect.scroll.top; 813 int scrollTop = rect.scroll.top;
816 int row = _getAbsRowOrColumn(scrollTop, ROW) - 1; 814 int row = _getAbsRowOrColumn(scrollTop, ROW) - 1;
817 int col = _getAbsRowOrColumn(rect.scroll.left, COL) - 1; 815 int col = _getAbsRowOrColumn(rect.scroll.left, COL) - 1;
818 int newRowShift = Math.max(0, row); 816 int newRowShift = Math.max(0, row);
819 int newColumnShift = Math.max(0, col); 817 int newColumnShift = Math.max(0, col);
820 if (newRowShift != _rowShift || newColumnShift != _columnShift) { 818 if (newRowShift != _rowShift || newColumnShift != _columnShift) {
821 _rowShift = newRowShift; 819 _rowShift = newRowShift;
822 _columnShift = newColumnShift; 820 _columnShift = newColumnShift;
823 return () { _spreadsheet.refresh(); }; 821 _spreadsheet.refresh();
824 } 822 }
825 }); 823 });
826 }); 824 });
827 } 825 }
828 826
829 // Return the number of milliseconds since the epoch 827 // Return the number of milliseconds since the epoch
830 int _currentTimeMllis() { 828 int _currentTimeMllis() {
831 Date now = new Date.now(); 829 Date now = new Date.now();
832 Date then = new Date.fromEpoch(0, now.timeZone); 830 Date then = new Date.fromEpoch(0, now.timeZone);
833 return now.difference(then).inMilliseconds; 831 return now.difference(then).inMilliseconds;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 883
886 // apply text selection now 884 // apply text selection now
887 _formulaCellSelectingSelectText(); 885 _formulaCellSelectingSelectText();
888 886
889 // show cell selecting div 887 // show cell selecting div
890 { 888 {
891 DivElement div = _table.formulaCellSelectingDiv; 889 DivElement div = _table.formulaCellSelectingDiv;
892 CSSStyleDeclaration divStyle = div.style; 890 CSSStyleDeclaration divStyle = div.style;
893 int borderWidth = 2 + 2; 891 int borderWidth = 2 + 2;
894 CellRange cellRange = new CellRange(_spreadsheet, minCorner, maxCorner); 892 CellRange cellRange = new CellRange(_spreadsheet, minCorner, maxCorner);
895 window.requestMeasurementFrame(() { 893 _selectionManager.getBoundingBoxForRange(cellRange).then(
896 final box = _selectionManager.getBoundingBoxForRange(cellRange); 894 (BoundingBox box) {
897 return () { 895 if (box != null) {
898 if (box != null) { 896 divStyle.setProperty("left", HtmlUtils.toPx(box.left));
899 divStyle.left = HtmlUtils.toPx(box.left); 897 divStyle.setProperty("top", HtmlUtils.toPx(box.top));
900 divStyle.top = HtmlUtils.toPx(box.top); 898 divStyle.setProperty("width", HtmlUtils.toPx(box.width - borderWidth)) ;
901 divStyle.width = HtmlUtils.toPx(box.width - borderWidth); 899 divStyle.setProperty("height", HtmlUtils.toPx(box.height - borderWidth ));
902 divStyle.height = HtmlUtils.toPx(box.height - borderWidth); 900 divStyle.removeProperty("display");
903 divStyle.removeProperty("display"); 901 } else {
904 } else { 902 divStyle.setProperty("display", "none");
905 divStyle.setProperty("display", "none"); 903 }
906 }
907 };
908 }); 904 });
909 } 905 }
910 } 906 }
911 907
912 void _formulaCellSelectingRememberSelectionRange() { 908 void _formulaCellSelectingRememberSelectionRange() {
913 _formulaCellSelectingTextStart = _formulaInput.selectionStart; 909 _formulaCellSelectingTextStart = _formulaInput.selectionStart;
914 _formulaCellSelectingTextEnd = _formulaInput.selectionEnd; 910 _formulaCellSelectingTextEnd = _formulaInput.selectionEnd;
915 } 911 }
916 912
917 void _formulaCellSelectingSelectText() { 913 void _formulaCellSelectingSelectText() {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1070
1075 // Return the number of _rows currently being displayed (not counting the colu mn header row) 1071 // Return the number of _rows currently being displayed (not counting the colu mn header row)
1076 int _getVisibleTableHeight() => _getShiftedRowEnd(_rowShift + _rows, _rowShift ); 1072 int _getVisibleTableHeight() => _getShiftedRowEnd(_rowShift + _rows, _rowShift );
1077 1073
1078 // Return the number of _columns currently being displayed (not counting the r ow header column) 1074 // Return the number of _columns currently being displayed (not counting the r ow header column)
1079 int _getVisibleTableWidth() => _getShiftedColumnEnd(_columnShift + _columns, _ columnShift); 1075 int _getVisibleTableWidth() => _getShiftedColumnEnd(_columnShift + _columns, _ columnShift);
1080 1076
1081 // Resize the formula input field to fit the contained text 1077 // Resize the formula input field to fit the contained text
1082 void _growFormulaInput() { 1078 void _growFormulaInput() {
1083 _formulaInputMeasure.text = _formulaInput.value; 1079 _formulaInputMeasure.text = _formulaInput.value;
1084 window.requestMeasurementFrame(() { 1080 _formulaInputMeasure.rect.then((ElementRect rect) {
1085 int textWidth = _formulaInputMeasure.rect.client.width; 1081 int textWidth = rect.client.width;
1086 int width = Math.max(textWidth + 25, _formulaCellWidth); 1082 int width = Math.max(textWidth + 25, _formulaCellWidth);
1087 return () { 1083 _formulaDiv.style.setProperty("width", HtmlUtils.toPx(width));
1088 _formulaDiv.style.width = HtmlUtils.toPx(width); 1084 _formulaInput.style.setProperty("width", HtmlUtils.toPx(width));
1089 _formulaInput.style.width = HtmlUtils.toPx(width);
1090 };
1091 }); 1085 });
1092 } 1086 }
1093 1087
1094 // Fade out the formula input field 1088 // Fade out the formula input field
1095 void _hideFormula() { 1089 void _hideFormula() {
1096 _hideFormulaCellSelecting(); 1090 _hideFormulaCellSelecting();
1097 _formulaEditing = false; 1091 _formulaEditing = false;
1098 _formulaDiv.classes.remove("fadeIn"); 1092 _formulaDiv.classes.remove("fadeIn");
1099 _formulaDiv.classes.add("fadeOut"); 1093 _formulaDiv.classes.add("fadeOut");
1100 } 1094 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 // update table row and column headers 1143 // update table row and column headers
1150 void _redrawHeaders() { 1144 void _redrawHeaders() {
1151 _setTableWidth(_getVisibleTableWidth()); 1145 _setTableWidth(_getVisibleTableWidth());
1152 _tableSizeChanged(); 1146 _tableSizeChanged();
1153 1147
1154 _table.redrawHeaders(_selectionManager, _rows, _columns, _rowShift, _columnS hift, 1148 _table.redrawHeaders(_selectionManager, _rows, _columns, _rowShift, _columnS hift,
1155 _cellDisplay); 1149 _cellDisplay);
1156 } 1150 }
1157 1151
1158 void _refreshResizeDragger() { 1152 void _refreshResizeDragger() {
1159 window.requestMeasurementFrame(() { 1153 _table.rect.then((ElementRect elementRect) {
1160 // We may be called before the dragger is ready 1154 // We may be called before the dragger is ready
1161 if (_resizeDragger == null) { 1155 if (_resizeDragger == null) {
1162 return; 1156 return;
1163 } 1157 }
1164 ClientRect rect = _table.rect.bounding; 1158 ClientRect rect = elementRect.bounding;
1165 return () { 1159
1166 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(rect.width)); 1160 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(rect.width));
1167 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(rect.height)); 1161 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(rect.height));
1168 };
1169 }); 1162 });
1170 } 1163 }
1171 1164
1172 // Remove the HTML elements corresponding to the given column 1165 // Remove the HTML elements corresponding to the given column
1173 void _removeTableColumnHtml(int col) { 1166 void _removeTableColumnHtml(int col) {
1174 _table.removeColumn(col); 1167 _table.removeColumn(col);
1175 int width = _spreadsheet.getColumnWidth(col); 1168 int width = _spreadsheet.getColumnWidth(col);
1176 _setTableWidth(_tableWidth - width); 1169 _setTableWidth(_tableWidth - width);
1177 } 1170 }
1178 1171
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 setDrag(COL, false); 1463 setDrag(COL, false);
1471 } 1464 }
1472 }); 1465 });
1473 1466
1474 // The inline cell editing UI is displayed when a user makes the same single 1467 // The inline cell editing UI is displayed when a user makes the same single
1475 // cell selection over again. We keep track of the current single cell that 1468 // cell selection over again. We keep track of the current single cell that
1476 // is selected here to know when to enter edit mode. 1469 // is selected here to know when to enter edit mode.
1477 CellLocation currentSelectedSingleCell = null; 1470 CellLocation currentSelectedSingleCell = null;
1478 1471
1479 void mouseMove(MouseEvent e) { 1472 void mouseMove(MouseEvent e) {
1480 window.requestMeasurementFrame(() { 1473 _table.rect.then((ElementRect rect) {
1481 // Set x and y to the mouse coordinates, relative to the top left of 1474 // Set x and y to the mouse coordinates, relative to the top left of
1482 // the spreadsheet table. 1475 // the spreadsheet table.
1483 ClientRect boundingRect = _table.rect.bounding; 1476 ClientRect boundingRect = rect.bounding;
1484 int scrollOffsetX = -boundingRect.left.toInt(); 1477 int scrollOffsetX = -boundingRect.left.toInt();
1485 int scrollOffsetY = -boundingRect.top.toInt(); 1478 int scrollOffsetY = -boundingRect.top.toInt();
1486 x = e.x + scrollOffsetX; 1479 x = e.x + scrollOffsetX;
1487 y = e.y + scrollOffsetY; 1480 y = e.y + scrollOffsetY;
1488 1481
1489 // Update the dragger position and optionally the actual row/column size 1482 // Update the dragger position and optionally the actual row/column size
1490 if (dragRowColumn(false)) { 1483 if (dragRowColumn(false)) {
1491 return; 1484 return;
1492 } 1485 }
1493 1486
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 }); 1535 });
1543 } 1536 }
1544 1537
1545 _setMove(mouseMove); 1538 _setMove(mouseMove);
1546 1539
1547 _table.on.mouseDown.add((MouseEvent e) { 1540 _table.on.mouseDown.add((MouseEvent e) {
1548 _moveToTop(); 1541 _moveToTop();
1549 1542
1550 // Right click toggles and positions the context menu 1543 // Right click toggles and positions the context menu
1551 if (e.button == 2 || (e.button == 0 && e.ctrlKey)) { 1544 if (e.button == 2 || (e.button == 0 && e.ctrlKey)) {
1552 window.requestMeasurementFrame(() { 1545 _table.rect.then((ElementRect rect) {
1553 ClientRect boundingRect = _table.rect.bounding; 1546 ClientRect boundingRect = rect.bounding;
1554 return () { 1547 int scrollOffsetX = -boundingRect.left;
1555 int scrollOffsetX = -boundingRect.left; 1548 int scrollOffsetY = -boundingRect.top;
1556 int scrollOffsetY = -boundingRect.top; 1549 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY);
1557 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY);
1558 };
1559 }); 1550 });
1560 return; 1551 return;
1561 } 1552 }
1562 1553
1563 _setDragFunction(mouseMove); 1554 _setDragFunction(mouseMove);
1564 1555
1565 _setUndragFunction((MouseEvent e_) { 1556 _setUndragFunction((MouseEvent e_) {
1566 dragRowColumn(true); 1557 dragRowColumn(true);
1567 _table.setDefaultCursor(); 1558 _table.setDefaultCursor();
1568 draggingSelection = false; 1559 draggingSelection = false;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 } 1681 }
1691 _activeInnerMenu = new InnerMenuView(_window, row, _selectionManager, style, 1682 _activeInnerMenu = new InnerMenuView(_window, row, _selectionManager, style,
1692 _spreadsheet.layout.getRowHeight(rowIndex), 1683 _spreadsheet.layout.getRowHeight(rowIndex),
1693 (){ _tableSizeChanged(); }, 1684 (){ _tableSizeChanged(); },
1694 (){ _hideInnerMenu(true); _repositionFormulaInput(null, false); }); 1685 (){ _hideInnerMenu(true); _repositionFormulaInput(null, false); });
1695 _innerMenuRowIndex = rowIndex; 1686 _innerMenuRowIndex = rowIndex;
1696 } 1687 }
1697 1688
1698 // Update the scroll mechanism due to a change in the visible table area 1689 // Update the scroll mechanism due to a change in the visible table area
1699 void _tableSizeChanged() { 1690 void _tableSizeChanged() {
1700 window.requestMeasurementFrame(() { 1691 _table.rect.then((ElementRect elementRect) {
1701 ClientRect rect = _table.rect.bounding; 1692 ClientRect rect = elementRect.bounding;
1702 return () {
1703 _tableScrollContainer.style.width = HtmlUtils.toPx(rect.width + 10);
1704 _spreadsheetElement.style.width = HtmlUtils.toPx(rect.width);
1705 1693
1706 _tableScrollContainer.style.height = HtmlUtils.toPx(rect.height + 10); 1694 _tableScrollContainer.style.width = HtmlUtils.toPx(rect.width + 10);
1707 _spreadsheetElement.style.height = HtmlUtils.toPx(rect.height); 1695 _spreadsheetElement.style.width = HtmlUtils.toPx(rect.width);
1708 1696
1709 _tableScrollDiv.style.width = HtmlUtils.toPx( 1697 _tableScrollContainer.style.height = HtmlUtils.toPx(rect.height + 10);
1710 _spreadsheet.getColumnEnd(_spreadsheet.columnCount())); 1698 _spreadsheetElement.style.height = HtmlUtils.toPx(rect.height);
1711 int extra = _activeInnerMenu == null ?
1712 0 : _activeInnerMenu.currentRowHeight;
1713 _tableScrollDiv.style.height = HtmlUtils.toPx(_spreadsheet.getRowEnd(
1714 _spreadsheet.rowCount()) + extra);
1715 1699
1716 // Reposition the scroll bars 1700 _tableScrollDiv.style.width = HtmlUtils.toPx(
1717 _scroll(_rowShift, _columnShift); 1701 _spreadsheet.getColumnEnd(_spreadsheet.columnCount()));
1718 // Move the resize dragger to the bottom-right corner 1702 int extra = _activeInnerMenu == null ?
1719 _refreshResizeDragger(); 1703 0 : _activeInnerMenu.currentRowHeight;
1720 }; 1704 _tableScrollDiv.style.height = HtmlUtils.toPx(_spreadsheet.getRowEnd(
1705 _spreadsheet.rowCount()) + extra);
1706
1707 // Reposition the scroll bars
1708 _scroll(_rowShift, _columnShift);
1709 // Move the resize dragger to the bottom-right corner
1710 _refreshResizeDragger();
1721 }); 1711 });
1722 } 1712 }
1723 1713
1724 void _updateInnerMenu() { 1714 void _updateInnerMenu() {
1725 if (_activeInnerMenu != null) { 1715 if (_activeInnerMenu != null) {
1726 _activeInnerMenu.updateSize(); 1716 _activeInnerMenu.updateSize();
1727 } 1717 }
1728 } 1718 }
1729 1719
1730 // Change the width/height of a column or row. 1720 // Change the width/height of a column or row.
1731 void _updateRowColumnSize(int rowOrCol, int index, int size, int oldSize, bool mouseUp) { 1721 void _updateRowColumnSize(int rowOrCol, int index, int size, int oldSize, bool mouseUp) {
1732 if (mouseUp) { 1722 if (mouseUp) {
1733 Command command = new ResizeRowColumnCommand(_spreadsheet, rowOrCol, index , size, oldSize); 1723 Command command = new ResizeRowColumnCommand(_spreadsheet, rowOrCol, index , size, oldSize);
1734 _spreadsheet.execute(command); 1724 _spreadsheet.execute(command);
1735 } else { 1725 } else {
1736 if (rowOrCol == COL) { 1726 if (rowOrCol == COL) {
1737 _spreadsheet.setColumnWidth(index, size); 1727 _spreadsheet.setColumnWidth(index, size);
1738 } else { 1728 } else {
1739 _spreadsheet.setRowHeight(index, size); 1729 _spreadsheet.setRowHeight(index, size);
1740 } 1730 }
1741 } 1731 }
1742 } 1732 }
1743 } 1733 }
OLDNEW
« no previous file with comments | « client/samples/total/src/SelectionManager.dart ('k') | client/tests/client/html/DocumentFragmentTests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698