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

Side by Side Diff: Source/WebCore/Resources/pagepopups/calendarPicker.js

Issue 12082066: Merge 140778 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1364/
Patch Set: Created 7 years, 10 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
OLDNEW
1 "use strict"; 1 "use strict";
2 /* 2 /*
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 }; 753 };
754 754
755 CalendarPicker.prototype.handleClear = function() { 755 CalendarPicker.prototype.handleClear = function() {
756 this.recordAction(CalendarPicker.Action.ClickedClearButton); 756 this.recordAction(CalendarPicker.Action.ClickedClearButton);
757 this.submitValue(""); 757 this.submitValue("");
758 }; 758 };
759 759
760 CalendarPicker.prototype.fixWindowSize = function() { 760 CalendarPicker.prototype.fixWindowSize = function() {
761 var yearMonthRightElement = this._element.getElementsByClassName(ClassNames. YearMonthButtonRight)[0]; 761 var yearMonthRightElement = this._element.getElementsByClassName(ClassNames. YearMonthButtonRight)[0];
762 var daysAreaElement = this._element.getElementsByClassName(ClassNames.DaysAr ea)[0]; 762 var daysAreaElement = this._element.getElementsByClassName(ClassNames.DaysAr ea)[0];
763 var clearButton = this._element.getElementsByClassName(ClassNames.ClearButto n)[0];
763 var headers = daysAreaElement.getElementsByClassName(ClassNames.DayLabel); 764 var headers = daysAreaElement.getElementsByClassName(ClassNames.DayLabel);
764 var maxCellWidth = 0; 765 var maxCellWidth = 0;
765 for (var i = 1; i < headers.length; ++i) { 766 for (var i = 1; i < headers.length; ++i) {
766 if (maxCellWidth < headers[i].offsetWidth) 767 if (maxCellWidth < headers[i].offsetWidth)
767 maxCellWidth = headers[i].offsetWidth; 768 maxCellWidth = headers[i].offsetWidth;
768 } 769 }
769 var weekColumnWidth = headers[0].offsetWidth; 770 var weekColumnWidth = headers[0].offsetWidth;
770 if (maxCellWidth > weekColumnWidth) 771 if (maxCellWidth > weekColumnWidth)
771 weekColumnWidth = maxCellWidth; 772 weekColumnWidth = maxCellWidth;
772 headers[0].style.width = weekColumnWidth + "px"; 773 headers[0].style.width = weekColumnWidth + "px";
773 var DaysAreaContainerBorder = 1; 774 var DaysAreaContainerBorder = 1;
774 var yearMonthEnd; 775 var yearMonthEnd;
775 var daysAreaEnd; 776 var daysAreaEnd;
777 var todayClearAreaEnd;
776 if (global.params.isLocaleRTL) { 778 if (global.params.isLocaleRTL) {
777 var startOffset = this._element.offsetLeft + this._element.offsetWidth; 779 var startOffset = this._element.offsetLeft + this._element.offsetWidth;
778 yearMonthEnd = startOffset - yearMonthRightElement.offsetLeft; 780 yearMonthEnd = startOffset - yearMonthRightElement.offsetLeft;
779 daysAreaEnd = startOffset - (daysAreaElement.offsetLeft + daysAreaElemen t.offsetWidth) + weekColumnWidth + maxCellWidth * 7 + DaysAreaContainerBorder; 781 daysAreaEnd = startOffset - (daysAreaElement.offsetLeft + daysAreaElemen t.offsetWidth) + weekColumnWidth + maxCellWidth * 7 + DaysAreaContainerBorder;
782 todayClearAreaEnd = startOffset - clearButton.offsetLeft;
780 } else { 783 } else {
781 yearMonthEnd = yearMonthRightElement.offsetLeft + yearMonthRightElement. offsetWidth; 784 yearMonthEnd = yearMonthRightElement.offsetLeft + yearMonthRightElement. offsetWidth;
782 daysAreaEnd = daysAreaElement.offsetLeft + weekColumnWidth + maxCellWidt h * 7 + DaysAreaContainerBorder; 785 daysAreaEnd = daysAreaElement.offsetLeft + weekColumnWidth + maxCellWidt h * 7 + DaysAreaContainerBorder;
786 todayClearAreaEnd = clearButton.offsetLeft + clearButton.offsetWidth;
783 } 787 }
784 var maxEnd = Math.max(yearMonthEnd, daysAreaEnd); 788 var maxEnd = Math.max(yearMonthEnd, daysAreaEnd, todayClearAreaEnd);
785 var MainPadding = 6; // FIXME: Fix name. 789 var MainPadding = 10; // FIXME: Fix name.
786 var MainBorder = 1; 790 var MainBorder = 1;
787 var desiredBodyWidth = maxEnd + MainPadding + MainBorder; 791 var desiredBodyWidth = maxEnd + MainPadding + MainBorder * 2;
788 792
789 var elementHeight = this._element.offsetHeight; 793 var elementHeight = this._element.offsetHeight;
790 this._element.style.width = "auto"; 794 this._element.style.width = "auto";
791 daysAreaElement.style.width = "100%"; 795 daysAreaElement.style.width = "100%";
792 daysAreaElement.style.tableLayout = "fixed"; 796 daysAreaElement.style.tableLayout = "fixed";
793 this._element.getElementsByClassName(ClassNames.YearMonthUpper)[0].style.dis play = "-webkit-box"; 797 this._element.getElementsByClassName(ClassNames.YearMonthUpper)[0].style.dis play = "-webkit-box";
794 this._element.getElementsByClassName(ClassNames.MonthSelectorBox)[0].style.d isplay = "block"; 798 this._element.getElementsByClassName(ClassNames.MonthSelectorBox)[0].style.d isplay = "block";
795 resizeWindow(desiredBodyWidth, elementHeight); 799 resizeWindow(desiredBodyWidth, elementHeight);
796 }; 800 };
797 801
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 this._monthPopup = createElement("div", ClassNames.MonthSelectorPopup); 878 this._monthPopup = createElement("div", ClassNames.MonthSelectorPopup);
875 this._monthPopup.addEventListener("click", this._handleYearMonthChange.bind( this), false); 879 this._monthPopup.addEventListener("click", this._handleYearMonthChange.bind( this), false);
876 this._monthPopup.addEventListener("keydown", this._handleMonthPopupKey.bind( this), false); 880 this._monthPopup.addEventListener("keydown", this._handleMonthPopupKey.bind( this), false);
877 this._monthPopup.addEventListener("mousemove", this._handleMouseMove.bind(th is), false); 881 this._monthPopup.addEventListener("mousemove", this._handleMouseMove.bind(th is), false);
878 this._updateSelectionOnMouseMove = true; 882 this._updateSelectionOnMouseMove = true;
879 this._monthPopup.tabIndex = 0; 883 this._monthPopup.tabIndex = 0;
880 this._monthPopupContents = createElement("div", ClassNames.MonthSelectorPopu pContents); 884 this._monthPopupContents = createElement("div", ClassNames.MonthSelectorPopu pContents);
881 this._monthPopup.appendChild(this._monthPopupContents); 885 this._monthPopup.appendChild(this._monthPopupContents);
882 box.appendChild(this._monthPopup); 886 box.appendChild(this._monthPopup);
883 this._month = createElement("div", ClassNames.MonthSelector); 887 this._month = createElement("div", ClassNames.MonthSelector);
888 this._monthLabel = createElement("span");
889 this._month.appendChild(this._monthLabel);
890 var disclosureTriangle = createElement("span");
891 disclosureTriangle.innerHTML = "<svg width='7' height='5'><polygon points='0 ,1 7,1 3.5,5' style='fill:#000000;' /></svg>";
892 this._month.appendChild(disclosureTriangle);
884 this._month.addEventListener("click", this._showPopup.bind(this), false); 893 this._month.addEventListener("click", this._showPopup.bind(this), false);
885 box.appendChild(this._month); 894 box.appendChild(this._month);
886 895
887 this._attachRightButtonsTo(innerContainer); 896 this._attachRightButtonsTo(innerContainer);
888 element.appendChild(outerContainer); 897 element.appendChild(outerContainer);
889 898
890 this._wall = createElement("div", ClassNames.MonthSelectorWall); 899 this._wall = createElement("div", ClassNames.MonthSelectorWall);
891 this._wall.addEventListener("click", this._closePopup.bind(this), false); 900 this._wall.addEventListener("click", this._closePopup.bind(this), false);
892 element.appendChild(this._wall); 901 element.appendChild(this._wall);
893 902
894 var month = this.picker.maximumMonth; 903 var month = this.picker.maximumMonth;
895 var maxWidth = 0; 904 var maxWidth = 0;
896 for (var m = 0; m < 12; ++m) { 905 for (var m = 0; m < 12; ++m) {
897 this._month.textContent = month.toLocaleString(); 906 this._monthLabel.textContent = month.toLocaleString();
898 maxWidth = Math.max(maxWidth, this._month.offsetWidth); 907 maxWidth = Math.max(maxWidth, this._month.offsetWidth);
899 month = month.previous(); 908 month = month.previous();
900 } 909 }
901 if (getLanguage() == "ja" && ImperialEraLimit < this.picker.maximumMonth.yea r) { 910 if (getLanguage() == "ja" && ImperialEraLimit < this.picker.maximumMonth.yea r) {
902 for (var m = 0; m < 12; ++m) { 911 for (var m = 0; m < 12; ++m) {
903 this._month.textContent = new Month(ImperialEraLimit, m).toLocaleStr ing(); 912 this._monthLabel.textContent = new Month(ImperialEraLimit, m).toLoca leString();
904 maxWidth = Math.max(maxWidth, this._month.offsetWidth); 913 maxWidth = Math.max(maxWidth, this._month.offsetWidth);
905 } 914 }
906 } 915 }
907 this._month.style.minWidth = maxWidth + 'px'; 916 this._month.style.minWidth = maxWidth + 'px';
908 917
909 this.picker.firstFocusableControl = this._left2; // FIXME: Should it be this .month? 918 this.picker.firstFocusableControl = this._left2; // FIXME: Should it be this .month?
910 }; 919 };
911 920
912 YearMonthController.addTenYearsButtons = false; 921 YearMonthController.addTenYearsButtons = false;
913 922
914 /** 923 /**
915 * @param {!Element} parent 924 * @param {!Element} parent
916 */ 925 */
917 YearMonthController.prototype._attachLeftButtonsTo = function(parent) { 926 YearMonthController.prototype._attachLeftButtonsTo = function(parent) {
918 var container = createElement("div", ClassNames.YearMonthButtonLeft); 927 var container = createElement("div", ClassNames.YearMonthButtonLeft);
919 parent.appendChild(container); 928 parent.appendChild(container);
920 929
921 if (YearMonthController.addTenYearsButtons) { 930 if (YearMonthController.addTenYearsButtons) {
922 this._left3 = createElement("input", ClassNames.YearMonthButton); 931 this._left3 = createElement("button", ClassNames.YearMonthButton);
923 this._left3.type = "button"; 932 this._left3.textContent = "<<<";
924 this._left3.value = "<<<";
925 this._left3.addEventListener("click", this._handleButtonClick.bind(this) , false); 933 this._left3.addEventListener("click", this._handleButtonClick.bind(this) , false);
926 container.appendChild(this._left3); 934 container.appendChild(this._left3);
927 } 935 }
928 936
929 this._left2 = createElement("input", ClassNames.YearMonthButton); 937 this._left2 = createElement("button", ClassNames.YearMonthButton);
930 this._left2.type = "button"; 938 this._left2.innerHTML = "<svg width='9' height='7'><polygon points='0,3.5 4, 7 4,0' style='fill:#6e6e6e;' /><polygon points='5,3.5 9,7 9,0' style='fill:#6e6e 6e;' /></svg>";
931 this._left2.value = "<<";
932 this._left2.addEventListener("click", this._handleButtonClick.bind(this), fa lse); 939 this._left2.addEventListener("click", this._handleButtonClick.bind(this), fa lse);
933 container.appendChild(this._left2); 940 container.appendChild(this._left2);
934 941
935 this._left1 = createElement("input", ClassNames.YearMonthButton); 942 this._left1 = createElement("button", ClassNames.YearMonthButton);
936 this._left1.type = "button"; 943 this._left1.innerHTML = "<svg width='4' height='7'><polygon points='0,3.5 4, 7 4,0' style='fill:#6e6e6e;' /></svg>";
937 this._left1.value = "<";
938 this._left1.addEventListener("click", this._handleButtonClick.bind(this), fa lse); 944 this._left1.addEventListener("click", this._handleButtonClick.bind(this), fa lse);
939 container.appendChild(this._left1); 945 container.appendChild(this._left1);
940 }; 946 };
941 947
942 /** 948 /**
943 * @param {!Element} parent 949 * @param {!Element} parent
944 */ 950 */
945 YearMonthController.prototype._attachRightButtonsTo = function(parent) { 951 YearMonthController.prototype._attachRightButtonsTo = function(parent) {
946 var container = createElement("div", ClassNames.YearMonthButtonRight); 952 var container = createElement("div", ClassNames.YearMonthButtonRight);
947 parent.appendChild(container); 953 parent.appendChild(container);
948 this._right1 = createElement("input", ClassNames.YearMonthButton); 954 this._right1 = createElement("button", ClassNames.YearMonthButton);
949 this._right1.type = "button"; 955 this._right1.innerHTML = "<svg width='4' height='7'><polygon points='0,7 0,0 , 4,3.5' style='fill:#6e6e6e;' /></svg>";
950 this._right1.value = ">";
951 this._right1.addEventListener("click", this._handleButtonClick.bind(this), f alse); 956 this._right1.addEventListener("click", this._handleButtonClick.bind(this), f alse);
952 container.appendChild(this._right1); 957 container.appendChild(this._right1);
953 958
954 this._right2 = createElement("input", ClassNames.YearMonthButton); 959 this._right2 = createElement("button", ClassNames.YearMonthButton);
955 this._right2.type = "button"; 960 this._right2.innerHTML = "<svg width='9' height='7'><polygon points='4,3.5 0 ,7 0,0' style='fill:#6e6e6e;' /><polygon points='9,3.5 5,7 5,0' style='fill:#6e6 e6e;' /></svg>";
956 this._right2.value = ">>";
957 this._right2.addEventListener("click", this._handleButtonClick.bind(this), f alse); 961 this._right2.addEventListener("click", this._handleButtonClick.bind(this), f alse);
958 container.appendChild(this._right2); 962 container.appendChild(this._right2);
959 963
960 if (YearMonthController.addTenYearsButtons) { 964 if (YearMonthController.addTenYearsButtons) {
961 this._right3 = createElement("input", ClassNames.YearMonthButton); 965 this._right3 = createElement("button", ClassNames.YearMonthButton);
962 this._right3.type = "button"; 966 this._right3.textContent = ">>>";
963 this._right3.value = ">>>";
964 this._right3.addEventListener("click", this._handleButtonClick.bind(this ), false); 967 this._right3.addEventListener("click", this._handleButtonClick.bind(this ), false);
965 container.appendChild(this._right3); 968 container.appendChild(this._right3);
966 } 969 }
967 }; 970 };
968 971
969 /** 972 /**
970 * @param {!Month} month 973 * @param {!Month} month
971 */ 974 */
972 YearMonthController.prototype.setMonth = function(month) { 975 YearMonthController.prototype.setMonth = function(month) {
973 var monthValue = month.valueOf(); 976 var monthValue = month.valueOf();
974 if (this._left3) 977 if (this._left3)
975 this._left3.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 13)); 978 this._left3.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 13));
976 this._left2.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 2 )); 979 this._left2.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 2 ));
977 this._left1.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 1 )); 980 this._left1.disabled = !this.picker.shouldShowMonth(new Month(monthValue - 1 ));
978 this._right1.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 1)); 981 this._right1.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 1));
979 this._right2.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 2)); 982 this._right2.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 2));
980 if (this._right3) 983 if (this._right3)
981 this._left3.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 13)); 984 this._left3.disabled = !this.picker.shouldShowMonth(new Month(monthValue + 13));
982 this._month.innerText = month.toLocaleString(); 985 this._monthLabel.innerText = month.toLocaleString();
983 while (this._monthPopupContents.hasChildNodes()) 986 while (this._monthPopupContents.hasChildNodes())
984 this._monthPopupContents.removeChild(this._monthPopupContents.firstChild ); 987 this._monthPopupContents.removeChild(this._monthPopupContents.firstChild );
985 988
986 for (var m = monthValue - 6; m <= monthValue + 6; m++) { 989 for (var m = monthValue - 6; m <= monthValue + 6; m++) {
987 var month = new Month(m); 990 var month = new Month(m);
988 if (!this.picker.shouldShowMonth(month)) 991 if (!this.picker.shouldShowMonth(month))
989 continue; 992 continue;
990 var option = createElement("div", ClassNames.MonthSelectorPopupEntry, mo nth.toLocaleString()); 993 var option = createElement("div", ClassNames.MonthSelectorPopupEntry, mo nth.toLocaleString());
991 option.dataset.value = month.toString(); 994 option.dataset.value = month.toString();
992 this._monthPopupContents.appendChild(option); 995 this._monthPopupContents.appendChild(option);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 /** 1145 /**
1143 * @const 1146 * @const
1144 * @type {number} 1147 * @type {number}
1145 */ 1148 */
1146 YearMonthController.NextTenYears = 120; 1149 YearMonthController.NextTenYears = 120;
1147 1150
1148 /** 1151 /**
1149 * @param {Event} event 1152 * @param {Event} event
1150 */ 1153 */
1151 YearMonthController.prototype._handleButtonClick = function(event) { 1154 YearMonthController.prototype._handleButtonClick = function(event) {
1152 if (event.target == this._left3) 1155 var button = enclosingNodeOrSelfWithClass(event.target, ClassNames.YearMonth Button);
1156 if (button == this._left3)
1153 this.moveRelatively(YearMonthController.PreviousTenYears); 1157 this.moveRelatively(YearMonthController.PreviousTenYears);
1154 else if (event.target == this._left2) { 1158 else if (button == this._left2) {
1155 this.picker.recordAction(CalendarPicker.Action.ClickedBackwardYearButton ); 1159 this.picker.recordAction(CalendarPicker.Action.ClickedBackwardYearButton );
1156 this.moveRelatively(YearMonthController.PreviousYear); 1160 this.moveRelatively(YearMonthController.PreviousYear);
1157 } else if (event.target == this._left1) { 1161 } else if (button == this._left1) {
1158 this.picker.recordAction(CalendarPicker.Action.ClickedBackwardMonthButto n); 1162 this.picker.recordAction(CalendarPicker.Action.ClickedBackwardMonthButto n);
1159 this.moveRelatively(YearMonthController.PreviousMonth); 1163 this.moveRelatively(YearMonthController.PreviousMonth);
1160 } else if (event.target == this._right1) { 1164 } else if (button == this._right1) {
1161 this.picker.recordAction(CalendarPicker.Action.ClickedForwardMonthButton ); 1165 this.picker.recordAction(CalendarPicker.Action.ClickedForwardMonthButton );
1162 this.moveRelatively(YearMonthController.NextMonth) 1166 this.moveRelatively(YearMonthController.NextMonth)
1163 } else if (event.target == this._right2) { 1167 } else if (button == this._right2) {
1164 this.picker.recordAction(CalendarPicker.Action.ClickedForwardYearButton) ; 1168 this.picker.recordAction(CalendarPicker.Action.ClickedForwardYearButton) ;
1165 this.moveRelatively(YearMonthController.NextYear); 1169 this.moveRelatively(YearMonthController.NextYear);
1166 } else if (event.target == this._right3) 1170 } else if (button == this._right3)
1167 this.moveRelatively(YearMonthController.NextTenYears); 1171 this.moveRelatively(YearMonthController.NextTenYears);
1168 else 1172 else
1169 return; 1173 return;
1170 }; 1174 };
1171 1175
1172 /** 1176 /**
1173 * @param {!number} amount 1177 * @param {!number} amount
1174 */ 1178 */
1175 YearMonthController.prototype.moveRelatively = function(amount) { 1179 YearMonthController.prototype.moveRelatively = function(amount) {
1176 var current = this.picker.currentMonth().valueOf(); 1180 var current = this.picker.currentMonth().valueOf();
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 this._hadKeyEvent = true; 1854 this._hadKeyEvent = true;
1851 this._element.classList.remove(ClassNames.NoFocusRing); 1855 this._element.classList.remove(ClassNames.NoFocusRing);
1852 } 1856 }
1853 1857
1854 if (window.dialogArguments) { 1858 if (window.dialogArguments) {
1855 initialize(dialogArguments); 1859 initialize(dialogArguments);
1856 } else { 1860 } else {
1857 window.addEventListener("message", handleMessage, false); 1861 window.addEventListener("message", handleMessage, false);
1858 window.setTimeout(handleArgumentsTimeout, 1000); 1862 window.setTimeout(handleArgumentsTimeout, 1000);
1859 } 1863 }
OLDNEW
« no previous file with comments | « Source/WebCore/Resources/pagepopups/calendarPicker.css ('k') | Source/WebCore/Resources/pagepopups/calendarPickerMac.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698