Changeset 133434 in webkit
- Timestamp:
- Nov 4, 2012 11:13:27 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r133433 r133434 1 2012-11-04 Keishi Hattori <keishi@webkit.org> 2 3 Introduce Month class to calendar picker 4 https://bugs.webkit.org/show_bug.cgi?id=101024 5 6 Reviewed by Kent Tamura. 7 8 * platform/chromium-win/platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations-expected.txt: 9 * platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations-expected.txt: 10 * platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations.html: Adjust the expectation because we changed the month string format. 11 * platform/chromium/fast/forms/calendar-picker/calendar-picker-mouse-operations-expected.txt: 12 * platform/chromium/fast/forms/calendar-picker/calendar-picker-mouse-operations.html: Ditto. 13 1 14 2012-11-04 Kent Tamura <tkent@chromium.org> 2 15 -
trunk/LayoutTests/platform/chromium-win/platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations-expected.txt
r133293 r133434 9 9 PASS popupWindow.pagePopupController.toString() is "[object PagePopupController]" 10 10 PASS selectedDate() is "2000-01-02" 11 PASS currentMonth() is "2000-0 "11 PASS currentMonth() is "2000-01" 12 12 Check that arrow keys work properly even when going between weeks and months. 13 13 PASS selectedDate() is "1999-12-26" 14 PASS currentMonth() is "2000-0 "14 PASS currentMonth() is "2000-01" 15 15 PASS selectedDate() is "2000-01-02" 16 PASS currentMonth() is "1999-1 1"16 PASS currentMonth() is "1999-12" 17 17 PASS selectedDate() is "1999-12-26" 18 PASS currentMonth() is "2000-0 "18 PASS currentMonth() is "2000-01" 19 19 PASS selectedDate() is "2000-01-02" 20 PASS currentMonth() is "2000-0 "20 PASS currentMonth() is "2000-01" 21 21 PASS selectedDate() is "1999-12-26" 22 PASS currentMonth() is "2000-0 "22 PASS currentMonth() is "2000-01" 23 23 PASS selectedDate() is "2000-01-08" 24 PASS currentMonth() is "1999-1 1"24 PASS currentMonth() is "1999-12" 25 25 PASS selectedDate() is "1999-12-26" 26 PASS currentMonth() is "2000-0 "26 PASS currentMonth() is "2000-01" 27 27 press m 28 28 PASS selectedDate() is "2000-01-30" 29 PASS currentMonth() is "2000- 1"29 PASS currentMonth() is "2000-02" 30 30 press shift + m 31 31 PASS selectedDate() is "1999-12-26" 32 PASS currentMonth() is "2000-0 "32 PASS currentMonth() is "2000-01" 33 33 press y 34 34 PASS selectedDate() is "2000-12-31" 35 PASS currentMonth() is "2001-0 "35 PASS currentMonth() is "2001-01" 36 36 press shift + y 37 37 PASS selectedDate() is "1999-12-26" 38 PASS currentMonth() is "2000-0 "38 PASS currentMonth() is "2000-01" 39 39 press d 40 40 PASS selectedDate() is "2009-12-27" 41 PASS currentMonth() is "2010-0 "41 PASS currentMonth() is "2010-01" 42 42 press shift + d 43 43 PASS selectedDate() is "1999-12-26" 44 PASS currentMonth() is "2000-0 "44 PASS currentMonth() is "2000-01" 45 45 PASS document.getElementById("mock-page-popup") is null 46 46 PASS document.getElementById("date").value is "1999-12-26" -
trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations-expected.txt
r133293 r133434 9 9 PASS popupWindow.pagePopupController.toString() is "[object PagePopupController]" 10 10 PASS selectedDate() is "2000-01-02" 11 PASS currentMonth() is "2000-0 "11 PASS currentMonth() is "2000-01" 12 12 Check that arrow keys work properly even when going between weeks and months. 13 13 PASS selectedDate() is "1999-12-26" 14 PASS currentMonth() is "2000-0 "14 PASS currentMonth() is "2000-01" 15 15 PASS selectedDate() is "2000-01-02" 16 PASS currentMonth() is "1999-1 1"16 PASS currentMonth() is "1999-12" 17 17 PASS selectedDate() is "1999-12-26" 18 PASS currentMonth() is "2000-0 "18 PASS currentMonth() is "2000-01" 19 19 PASS selectedDate() is "2000-01-02" 20 PASS currentMonth() is "2000-0 "20 PASS currentMonth() is "2000-01" 21 21 PASS selectedDate() is "1999-12-26" 22 PASS currentMonth() is "2000-0 "22 PASS currentMonth() is "2000-01" 23 23 PASS selectedDate() is "2000-01-08" 24 PASS currentMonth() is "1999-1 1"24 PASS currentMonth() is "1999-12" 25 25 PASS selectedDate() is "1999-12-26" 26 PASS currentMonth() is "2000-0 "26 PASS currentMonth() is "2000-01" 27 27 press m 28 28 PASS selectedDate() is "2000-01-30" 29 PASS currentMonth() is "2000- 1"29 PASS currentMonth() is "2000-02" 30 30 press shift + m 31 31 PASS selectedDate() is "1999-12-26" 32 PASS currentMonth() is "2000-0 "32 PASS currentMonth() is "2000-01" 33 33 press y 34 34 PASS selectedDate() is "2000-12-31" 35 PASS currentMonth() is "2001-0 "35 PASS currentMonth() is "2001-01" 36 36 press shift + y 37 37 PASS selectedDate() is "1999-12-26" 38 PASS currentMonth() is "2000-0 "38 PASS currentMonth() is "2000-01" 39 39 press d 40 40 PASS selectedDate() is "2009-12-27" 41 PASS currentMonth() is "2010-0 "41 PASS currentMonth() is "2010-01" 42 42 press shift + d 43 43 PASS selectedDate() is "1999-12-26" 44 PASS currentMonth() is "2000-0 "44 PASS currentMonth() is "2000-01" 45 45 PASS document.getElementById("mock-page-popup") is null 46 46 PASS document.getElementById("date").value is "1999-12-26" -
trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/calendar-picker-key-operations.html
r133293 r133434 23 23 24 24 shouldBe('selectedDate()', '"2000-01-02"'); 25 shouldBe('currentMonth()', '"2000-0 "');25 shouldBe('currentMonth()', '"2000-01"'); 26 26 27 27 debug('Check that arrow keys work properly even when going between weeks and months.'); … … 29 29 eventSender.keyDown('upArrow'); 30 30 shouldBe('selectedDate()', '"1999-12-26"'); 31 shouldBe('currentMonth()', '"2000-0 "');31 shouldBe('currentMonth()', '"2000-01"'); 32 32 // Move from first row of January 2000 to last row of December 1999. 33 33 eventSender.keyDown('upArrow'); 34 34 shouldBe('selectedDate()', '"2000-01-02"'); 35 shouldBe('currentMonth()', '"1999-1 1"');35 shouldBe('currentMonth()', '"1999-12"'); 36 36 37 37 eventSender.keyDown('downArrow'); 38 38 shouldBe('selectedDate()', '"1999-12-26"'); 39 shouldBe('currentMonth()', '"2000-0 "');39 shouldBe('currentMonth()', '"2000-01"'); 40 40 eventSender.keyDown('downArrow'); 41 41 shouldBe('selectedDate()', '"2000-01-02"'); 42 shouldBe('currentMonth()', '"2000-0 "');42 shouldBe('currentMonth()', '"2000-01"'); 43 43 44 44 eventSender.keyDown('upArrow'); 45 45 shouldBe('selectedDate()', '"1999-12-26"'); 46 shouldBe('currentMonth()', '"2000-0 "');46 shouldBe('currentMonth()', '"2000-01"'); 47 47 48 48 // Move from top left of January 2000 to bottom right of December 1999. 49 49 eventSender.keyDown('leftArrow'); 50 50 shouldBe('selectedDate()', '"2000-01-08"'); 51 shouldBe('currentMonth()', '"1999-1 1"');51 shouldBe('currentMonth()', '"1999-12"'); 52 52 53 53 eventSender.keyDown('rightArrow'); 54 54 shouldBe('selectedDate()', '"1999-12-26"'); 55 shouldBe('currentMonth()', '"2000-0 "');55 shouldBe('currentMonth()', '"2000-01"'); 56 56 57 57 debug("press m"); 58 58 eventSender.keyDown('m'); 59 59 shouldBe('selectedDate()', '"2000-01-30"'); 60 shouldBe('currentMonth()', '"2000- 1"');60 shouldBe('currentMonth()', '"2000-02"'); 61 61 62 62 debug("press shift + m"); 63 63 eventSender.keyDown('M'); 64 64 shouldBe('selectedDate()', '"1999-12-26"'); 65 shouldBe('currentMonth()', '"2000-0 "');65 shouldBe('currentMonth()', '"2000-01"'); 66 66 67 67 debug("press y"); 68 68 eventSender.keyDown('y'); 69 69 shouldBe('selectedDate()', '"2000-12-31"'); 70 shouldBe('currentMonth()', '"2001-0 "');70 shouldBe('currentMonth()', '"2001-01"'); 71 71 72 72 debug("press shift + y"); 73 73 eventSender.keyDown('Y'); 74 74 shouldBe('selectedDate()', '"1999-12-26"'); 75 shouldBe('currentMonth()', '"2000-0 "');75 shouldBe('currentMonth()', '"2000-01"'); 76 76 77 77 debug("press d"); 78 78 eventSender.keyDown('d'); 79 79 shouldBe('selectedDate()', '"2009-12-27"'); 80 shouldBe('currentMonth()', '"2010-0 "');80 shouldBe('currentMonth()', '"2010-01"'); 81 81 82 82 debug("press shift + d"); 83 83 eventSender.keyDown('D'); 84 84 shouldBe('selectedDate()', '"1999-12-26"'); 85 shouldBe('currentMonth()', '"2000-0 "');85 shouldBe('currentMonth()', '"2000-01"'); 86 86 87 87 eventSender.keyDown('\n'); … … 122 122 var now = new Date(); 123 123 var expectedDate = serializeDate(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); 124 var expectedMonth = now.getUTCFullYear() + "-" + now.getMonth();124 var expectedMonth = popupWindow.Month.createFromDate(now).toString(); 125 125 return selectedDate() === expectedDate && currentMonth() === expectedMonth; 126 126 } -
trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/calendar-picker-mouse-operations-expected.txt
r131538 r133434 7 7 PASS document.getElementById("mock-page-popup") is null 8 8 PASS selectedDate() is "2000-01-02" 9 PASS currentMonth() is "2000-0 "9 PASS currentMonth() is "2000-01" 10 10 Check that hovering over an entry highlights it. 11 11 PASS selectedDate() is "1999-12-31" 12 PASS currentMonth() is "2000-0 "12 PASS currentMonth() is "2000-01" 13 13 PASS selectedDate() is "2000-01-04" 14 PASS currentMonth() is "2000-0 "14 PASS currentMonth() is "2000-01" 15 15 Check that navigating between months maintains selection position. 16 16 PASS selectedDate() is "2000-02-08" 17 PASS currentMonth() is "2000- 1"17 PASS currentMonth() is "2000-02" 18 18 Check that moving the mouse outside the popup de-highlights entries. 19 19 PASS selectedDate() is undefined. -
trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/calendar-picker-mouse-operations.html
r132028 r133434 21 21 function test() { 22 22 shouldBe('selectedDate()', '"2000-01-02"'); 23 shouldBe('currentMonth()', '"2000-0 "');23 shouldBe('currentMonth()', '"2000-01"'); 24 24 25 25 debug('Check that hovering over an entry highlights it.'); 26 26 hoverOverElement(popupWindow.document.getElementsByClassName("day")[5]); 27 27 shouldBe('selectedDate()', '"1999-12-31"'); 28 shouldBe('currentMonth()', '"2000-0 "');28 shouldBe('currentMonth()', '"2000-01"'); 29 29 30 30 hoverOverElement(popupWindow.document.getElementsByClassName("day")[9]); 31 31 shouldBe('selectedDate()', '"2000-01-04"'); 32 shouldBe('currentMonth()', '"2000-0 "');32 shouldBe('currentMonth()', '"2000-01"'); 33 33 34 34 debug('Check that navigating between months maintains selection position.'); 35 35 eventSender.keyDown('m'); 36 36 shouldBe('selectedDate()', '"2000-02-08"'); 37 shouldBe('currentMonth()', '"2000- 1"');37 shouldBe('currentMonth()', '"2000-02"'); 38 38 39 39 debug('Check that moving the mouse outside the popup de-highlights entries.'); -
trunk/Source/WebCore/ChangeLog
r133432 r133434 1 2012-11-04 Keishi Hattori <keishi@webkit.org> 2 3 Introduce Month class to calendar picker 4 https://bugs.webkit.org/show_bug.cgi?id=101024 5 6 Reviewed by Kent Tamura. 7 8 Month class needs to be introduced to implement a month picker. This 9 patch just introduces the Month class into the calendar picker without 10 changing the current behavior. 11 12 No new tests. Covered by existing calendar-picker-*.html tests. 13 14 * Resources/pagepopups/calendarPicker.js: 15 (Month.prototype.toLocaleString): Returns a localized month string. 16 (Month): Takes a Month object, number representing the month, or year and month numbers. 17 (Month.parse): Returns a new Month from an ISO month string. 18 (Month.createFromDate): Returns a new Month containing the given datetime. 19 (Month.prototype.equals): Returns true if the given month is the same. 20 (Month.prototype.previous): Returns the previous month. 21 (Month.prototype.next): Returns the next month. 22 (Month.prototype.startDate): Returns a datetime that is the start of this month. The value is inclusive. 23 (Month.prototype.endDate): Returns a datetime that is the end of this month. The value is exclusive. 24 (Month.prototype.valueOf): Returns a number representing the month. 25 (Month.prototype.toString): Returns an ISO month string. 26 (YearMonthController): Use Month object. 27 (YearMonthController.prototype.attachTo): Year 275760 ends in September so use the year before to measure the label width. 28 (YearMonthController.prototype.setMonth): Take a month object. 29 (YearMonthController.prototype._redraw): Use ISO month string for element.dataset.value. 30 (YearMonthController.prototype._handleYearMonthChange): 31 (YearMonthController.prototype.moveRelatively): 32 (DaysTable): Use Month object. 33 (DaysTable.prototype._renderMonth): Take a month object. Testing for isNaN is moved up to fix a bug when showing September, 275760. 34 (DaysTable.prototype._navigateToMonth): Take a month object. 35 (DaysTable.prototype._navigateToMonthWithAnimation): Take a month object. 36 (DaysTable.prototype.navigateToMonthAndKeepSelectionPosition): Take a month object. 37 (DaysTable.prototype.selectDate): 38 (DaysTable.prototype._maybeSetPreviousMonth): Use Month object to calculate the previous month. 39 (DaysTable.prototype._maybeSetNextMonth): Use Month object to calculate the next month. 40 1 41 2012-11-04 Halton Huo <halton.huo@intel.com> 2 42 -
trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js
r132596 r133434 140 140 141 141 /** 142 * @param {!number} year143 * @param {!number} month144 142 * @return {!string} 145 143 */ 146 function formatYearMonth(year, month) { 147 var yearString = localizeNumber(year); 148 var monthString = global.params.monthLabels[month]; 144 Month.prototype.toLocaleString = function() { 145 if (isNaN(this.year) || isNaN(this.year)) 146 return "Invalid Month"; 147 var yearString = localizeNumber(this.year); 148 var monthString = global.params.monthLabels[this.month]; 149 149 switch (getLanguage()) { 150 150 case "eu": … … 159 159 return yearString + ". " + monthString; 160 160 case "ja": 161 return yearString + "年" + formatJapaneseImperialEra( year,month) + " " + monthString;161 return yearString + "年" + formatJapaneseImperialEra(this.year, this.month) + " " + monthString; 162 162 case "zh": 163 163 return yearString + "年" + monthString; … … 173 173 return monthString + " " + yearString; 174 174 } 175 } 175 }; 176 176 177 177 function createUTCDate(year, month, date) { … … 209 209 return yearString + "-" + ("0" + (month + 1)).substr(-2, 2) + "-" + ("0" + day).substr(-2, 2); 210 210 } 211 212 /** 213 * @param {!number|Month} valueOrMonthOrYear 214 * @param {!number=} month 215 */ 216 function Month(valueOrMonthOrYear, month) { 217 if (arguments.length == 2) { 218 this.year = valueOrMonthOrYear; 219 this.month = month; 220 } else if (valueOrMonthOrYear instanceof Month) { 221 this.year = valueOrMonthOrYear.year; 222 this.month = valueOrMonthOrYear.month; 223 } else { 224 this.year = Math.floor(valueOrMonthOrYear / 12) + 1970; 225 this.month = valueOrMonthOrYear % 12; 226 } 227 this.year = this.year + Math.floor(this.month / 12); 228 this.month = this.month < 0 ? this.month % 12 + 12 : this.month % 12; 229 if (this.year < 0 || Month.Maximum < this) { 230 this.year = NaN; 231 this.month = NaN; 232 } 233 }; 234 235 Month.ISOStringRegExp = /^(\d+)-(\d+)$/; 236 237 // See WebCore/platform/DateComponents.h. 238 Month.Maximum = new Month(275760, 8); 239 240 /** 241 * @param {!string} str 242 * @return {?Month} 243 */ 244 Month.parse = function(str) { 245 var match = Month.ISOStringRegExp.exec(str); 246 if (!match) 247 return null; 248 var year = parseInt(match[1], 10); 249 var month = parseInt(match[2], 10) - 1; 250 return new Month(year, month); 251 }; 252 253 /** 254 * @param {!Date} date 255 * @return {!Month} 256 */ 257 Month.createFromDate = function(date) { 258 return new Month(date.getUTCFullYear(), date.getUTCMonth()); 259 }; 260 261 /** 262 * @param {!Month} other 263 * @return {!bool} 264 */ 265 Month.prototype.equals = function(other) { 266 return this.year === other.year && this.month === other.month; 267 }; 268 269 /** 270 * @return {!Month} 271 */ 272 Month.prototype.previous = function() { 273 return new Month(this.year, this.month - 1); 274 }; 275 276 /** 277 * @return {!Month} 278 */ 279 Month.prototype.next = function() { 280 return new Month(this.year, this.month + 1); 281 }; 282 283 /** 284 * @return {!Date} 285 */ 286 Month.prototype.startDate = function() { 287 return createUTCDate(this.year, this.month, 1); 288 }; 289 290 /** 291 * @return {!Date} 292 */ 293 Month.prototype.endDate = function() { 294 if (this.equals(Month.Maximum)) 295 return CalendarPicker.MaximumPossibleDate; 296 return this.next().startDate(); 297 }; 298 299 /** 300 * @return {!number} 301 */ 302 Month.prototype.valueOf = function() { 303 return (this.year - 1970) * 12 + this.month; 304 }; 305 306 /** 307 * @return {!string} 308 */ 309 Month.prototype.toString = function() { 310 var yearString = String(this.year); 311 if (yearString.length < 4) 312 yearString = ("000" + yearString).substr(-4, 4); 313 return yearString + "-" + ("0" + (this.month + 1)).substr(-2, 2); 314 }; 211 315 212 316 // ---------------------------------------------------------------- … … 434 538 this.picker = picker; 435 539 /** 436 * @type { !number}540 * @type {?Month} 437 541 */ 438 this._currentYear = -1; 439 /** 440 * @type {!number} 441 */ 442 this._currentMonth = -1; 542 this._currentMonth = null; 443 543 } 444 544 … … 478 578 479 579 var maximumYear = this.picker.maximumDate.getUTCFullYear(); 580 // Because the maximum possible year is September we should use the year before it. 581 if (maximumYear === Month.Maximum.year) 582 maximumYear--; 480 583 var maxWidth = 0; 481 584 for (var m = 0; m < 12; ++m) { 482 this._month.textContent = formatYearMonth(maximumYear, m);585 this._month.textContent = new Month(maximumYear, m).toLocaleString(); 483 586 maxWidth = Math.max(maxWidth, this._month.offsetWidth); 484 587 } 485 588 if (getLanguage() == "ja" && ImperialEraLimit < maximumYear) { 486 589 for (var m = 0; m < 12; ++m) { 487 this._month.textContent = formatYearMonth(ImperialEraLimit, m);590 this._month.textContent = new Month(ImperialEraLimit, m).toLocaleString(); 488 591 maxWidth = Math.max(maxWidth, this._month.offsetWidth); 489 592 } … … 552 655 553 656 /** 554 * @return {!number} 555 */ 556 YearMonthController.prototype.year = function() { 557 return this._currentYear; 558 }; 559 560 /** 561 * @return {!number} 657 * @return {?Month} 562 658 */ 563 659 YearMonthController.prototype.month = function() { … … 566 662 567 663 /** 568 * @param {!number} year 569 * @param {!number} month 570 */ 571 YearMonthController.prototype.setYearMonth = function(year, month) { 572 this._currentYear = year; 573 this._currentMonth = month; 664 * @param {!Month} month 665 */ 666 YearMonthController.prototype.setMonth = function(month) { 667 this._currentMonth = new Month(month); 574 668 this._redraw(); 575 669 }; 576 670 577 671 YearMonthController.prototype._redraw = function() { 578 var min = this.picker.minimumDate.getUTCFullYear() * 12 + this.picker.minimumDate.getUTCMonth();579 var max = this.picker.maximumDate.getUTCFullYear() * 12 + this.picker.maximumDate.getUTCMonth();580 var current = this._current Year * 12 + this._currentMonth;672 var min = Month.createFromDate(this.picker.minimumDate).valueOf(); 673 var max = Month.createFromDate(this.picker.maximumDate).valueOf(); 674 var current = this._currentMonth.valueOf(); 581 675 if (this._left3) 582 676 this._left3.disabled = current - 13 < min; … … 587 681 if (this._right3) 588 682 this._right3.disabled = current + 13 > max; 589 this._month.innerText = formatYearMonth(this._currentYear, this._currentMonth);683 this._month.innerText = this._currentMonth.toLocaleString(); 590 684 while (this._monthPopupContents.hasChildNodes()) 591 685 this._monthPopupContents.removeChild(this._monthPopupContents.firstChild); … … 594 688 if (m < min || m > max) 595 689 continue; 596 var option = createElement("div", ClassNames.MonthSelectorPopupEntry, formatYearMonth(Math.floor(m / 12), m % 12)); 597 option.dataset.value = String(Math.floor(m / 12)) + "-" + String(m % 12); 690 var month = new Month(m); 691 var option = createElement("div", ClassNames.MonthSelectorPopupEntry, month.toLocaleString()); 692 option.dataset.value = month.toString(); 598 693 this._monthPopupContents.appendChild(option); 599 694 if (m == current) … … 716 811 if (!selection) 717 812 return; 718 var value = selection.dataset.value; 719 var result = value.match(/(\d+)-(\d+)/); 720 if (!result) 721 return; 722 var newYear = Number(result[1]); 723 var newMonth = Number(result[2]); 724 this.picker.daysTable.navigateToMonthAndKeepSelectionPosition(newYear, newMonth); 813 this.picker.daysTable.navigateToMonthAndKeepSelectionPosition(Month.parse(selection.dataset.value)); 725 814 }; 726 815 … … 780 869 */ 781 870 YearMonthController.prototype.moveRelatively = function(amount) { 782 var min = this.picker.minimumDate.getUTCFullYear() * 12 + this.picker.minimumDate.getUTCMonth();783 var max = this.picker.maximumDate.getUTCFullYear() * 12 + this.picker.maximumDate.getUTCMonth();784 var current = this._current Year * 12 + this._currentMonth;871 var min = Month.createFromDate(this.picker.minimumDate).valueOf(); 872 var max = Month.createFromDate(this.picker.maximumDate).valueOf(); 873 var current = this._currentMonth.valueOf(); 785 874 var updated = current; 786 875 if (amount < 0) … … 790 879 if (updated == current) 791 880 return; 792 this.picker.daysTable.navigateToMonthAndKeepSelectionPosition( Math.floor(updated / 12), updated % 12);881 this.picker.daysTable.navigateToMonthAndKeepSelectionPosition(new Month(updated)); 793 882 }; 794 883 … … 802 891 this.picker = picker; 803 892 /** 804 * @type { !number}893 * @type {?Month} 805 894 */ 806 this._currentYear = -1; 807 /** 808 * @type {!number} 809 */ 810 this._currentMonth = -1; 895 this._currentMonth = null; 811 896 } 812 897 … … 890 975 * @param {!number} month 891 976 */ 892 DaysTable.prototype._renderMonth = function(year, month) { 893 this._currentYear = year; 894 this._currentMonth = month; 895 var dayIterator = createUTCDate(year, month, 1); 977 DaysTable.prototype._renderMonth = function(month) { 978 this._currentMonth = new Month(month); 979 var dayIterator = this._currentMonth.startDate(); 896 980 var monthStartDay = dayIterator.getUTCDay(); 897 981 var weekStartDay = global.params.weekStartDay || 0; … … 902 986 for (var w = 0; w < DaysTable._Weeks; w++) { 903 987 for (var d = 0; d < 7; d++) { 904 var iterYear = dayIterator.getUTCFullYear(); 905 var iterMonth = dayIterator.getUTCMonth(); 988 var iterMonth = Month.createFromDate(dayIterator); 906 989 var time = dayIterator.getTime(); 907 990 var element = this._days[w][d]; 908 991 element.innerText = localizeNumber(dayIterator.getUTCDate()); 909 992 element.className = ClassNames.Day; 910 element.dataset.submitValue = serializeDate(iterYear, iterMonth, dayIterator.getUTCDate()); 911 if (this.picker.outOfRange(time)) 993 element.dataset.submitValue = serializeDate(iterMonth.year, iterMonth.month, dayIterator.getUTCDate()); 994 if (isNaN(time)) { 995 element.innerText = "-"; 996 element.classList.add(ClassNames.Unavailable); 997 } else if (this.picker.outOfRange(time)) 912 998 element.classList.add(ClassNames.Unavailable); 913 999 else if (this.picker.stepMismatch(time)) 914 1000 element.classList.add(ClassNames.Unavailable); 915 else if ( (iterYear == year && dayIterator.getUTCMonth() < month) || (month == 0 && iterMonth == 11)) {1001 else if (!iterMonth.equals(this._currentMonth)) { 916 1002 element.classList.add(ClassNames.Available); 917 1003 element.classList.add(ClassNames.NotThisMonth); 918 } else if ((iterYear == year && dayIterator.getUTCMonth() > month) || (month == 11 && iterMonth == 0)) {919 element.classList.add(ClassNames.Available);920 element.classList.add(ClassNames.NotThisMonth);921 } else if (isNaN(time)) {922 element.innerText = "-";923 element.classList.add(ClassNames.Unavailable);924 1004 } else 925 1005 element.classList.add(ClassNames.Available); … … 932 1012 933 1013 /** 934 * @param {!number} year 935 * @param {!number} month 936 */ 937 DaysTable.prototype._navigateToMonth = function(year, month) { 938 this.picker.yearMonthController.setYearMonth(year, month); 939 this._renderMonth(year, month); 940 }; 941 942 /** 943 * @param {!number} year 944 * @param {!number} month 945 */ 946 DaysTable.prototype._navigateToMonthWithAnimation = function(year, month) { 947 if (this._currentYear >= 0 && this._currentMonth >= 0) { 948 if (year == this._currentYear && month == this._currentMonth) 1014 * @param {!Month} month 1015 */ 1016 DaysTable.prototype._navigateToMonth = function(month) { 1017 this.picker.yearMonthController.setMonth(month); 1018 this._renderMonth(month); 1019 }; 1020 1021 /** 1022 * @param {!Month} month 1023 */ 1024 DaysTable.prototype._navigateToMonthWithAnimation = function(month) { 1025 if (this._currentMonth) { 1026 var delta = this._currentMonth.valueOf() - month.valueOf(); 1027 if (delta === 0) 949 1028 return; 950 var decreasing = false;951 if (year < this._currentYear)952 decreasing = true;953 else if (year > this._currentYear)954 decreasing = false;955 else956 decreasing = month < this._currentMonth;957 1029 var daysStyle = this._daysContainer.style; 958 1030 daysStyle.position = "relative"; 959 1031 daysStyle.webkitTransition = "left 0.1s ease"; 960 daysStyle.left = (de creasing? "" : "-") + this._daysContainer.offsetWidth + "px";961 } 962 this._navigateToMonth( year,month);1032 daysStyle.left = (delta > 0 ? "" : "-") + this._daysContainer.offsetWidth + "px"; 1033 } 1034 this._navigateToMonth(month); 963 1035 }; 964 1036 … … 975 1047 976 1048 /** 977 * @param {!number} year 978 * @param {!number} month 979 */ 980 DaysTable.prototype.navigateToMonthAndKeepSelectionPosition = function(year, month) { 981 if (year == this._currentYear && month == this._currentMonth) 1049 * @param {!Month} month 1050 */ 1051 DaysTable.prototype.navigateToMonthAndKeepSelectionPosition = function(month) { 1052 if (this._currentMonth.equals(month)) 982 1053 return; 983 1054 var firstNodeInSelectedRange = this._firstNodeInSelectedRange(); 984 this._navigateToMonthWithAnimation( year,month);1055 this._navigateToMonthWithAnimation(month); 985 1056 if (firstNodeInSelectedRange) { 986 1057 var x = parseInt(firstNodeInSelectedRange.dataset.positionX, 10); … … 995 1066 DaysTable.prototype.selectDate = function(date) { 996 1067 this._deselect(); 997 this._navigateToMonthWithAnimation( date.getUTCFullYear(), date.getUTCMonth());1068 this._navigateToMonthWithAnimation(Month.createFromDate(date)); 998 1069 var dateString = serializeDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); 999 1070 for (var w = 0; w < DaysTable._Weeks; w++) { … … 1043 1114 */ 1044 1115 DaysTable.prototype._maybeSetPreviousMonth = function() { 1045 var year = this.picker.yearMonthController.year(); 1046 var month = this.picker.yearMonthController.month(); 1047 var thisMonthStartTime = createUTCDate(year, month, 1).getTime(); 1048 if (this.picker.minimumDate.getTime() >= thisMonthStartTime) 1116 var currentMonth = this.picker.yearMonthController.month(); 1117 if (this.picker.minimumDate >= currentMonth.startDate()) 1049 1118 return false; 1050 if (month == 0) { 1051 year--; 1052 month = 11; 1053 } else 1054 month--; 1055 this._navigateToMonthWithAnimation(year, month); 1119 this._navigateToMonthWithAnimation(currentMonth.previous()); 1056 1120 return true; 1057 1121 }; … … 1061 1125 */ 1062 1126 DaysTable.prototype._maybeSetNextMonth = function() { 1063 var year = this.picker.yearMonthController.year(); 1064 var month = this.picker.yearMonthController.month(); 1065 if (month == 11) { 1066 year++; 1067 month = 0; 1068 } else 1069 month++; 1070 var nextMonthStartTime = createUTCDate(year, month, 1).getTime(); 1071 if (this.picker.maximumDate.getTime() < nextMonthStartTime) 1127 var currentMonth = this.picker.yearMonthController.month(); 1128 if (this.picker.maximumDate < currentMonth.endDate()) 1072 1129 return false; 1073 this._navigateToMonthWithAnimation( year, month);1130 this._navigateToMonthWithAnimation(currentMonth.next()); 1074 1131 return true; 1075 1132 };
Note: See TracChangeset
for help on using the changeset viewer.