Changeset 144423 in webkit


Ignore:
Timestamp:
Feb 28, 2013 11:48:35 PM (11 years ago)
Author:
keishi@webkit.org
Message:

Add calendar table view for the new calendar picker
https://bugs.webkit.org/show_bug.cgi?id=110970

Reviewed by Kent Tamura.

The calendar table that will be used in the new calendar picker (Bug 109439).

No new tests. Code is not used yet.

  • Resources/pagepopups/calendarPicker.js:

(DayCell): Cell which represents one day in the calendar.
(DayCell.recycleOrCreate):
(DayCell.prototype._recycleBin):
(DayCell.prototype.throwAway):
(DayCell.prototype.setHighlighted): Sets the highlighted class on the element.
(DayCell.prototype.setDisabled): Sets the disabled class on the element.
(DayCell.prototype.setIsInCurrentMonth): Sets the current-month class on the element.
(DayCell.prototype.setIsToday): Sets the today class on the element.
(DayCell.prototype.reset): Resets the day cell to be reused.
(WeekNumberCell): Cell used for the week number column.
(WeekNumberCell.prototype._recycleBin):
(WeekNumberCell.recycleOrCreate):
(WeekNumberCell.prototype.reset):
(WeekNumberCell.prototype.throwAway):
(WeekNumberCell.prototype.setHighlighted): Sets the highlighted class on the element.
(WeekNumberCell.prototype.setDisabled): Sets the disabled class on the element.
(CalendarTableHeaderView): Header for the calendar table. Contains the column labels.
(CalendarRowCell): Row containing day cells and maybe a week number cell.
(CalendarRowCell.prototype._recycleBin):
(CalendarRowCell.prototype.reset):
(CalendarRowCell.prototype.throwAway):
(CalendarTableView): A list view showing a grid of days.
(CalendarTableView.prototype.rowAtScrollOffset): Returns the row number currently at the scroll offset.
(CalendarTableView.prototype.scrollOffsetForRow): Returns the current scroll offset for the given row.
(CalendarTableView.prototype.onClick): If the click is on a DayCell or WeekNumberCell, select the appropriate date range.
(CalendarTableView.prototype.onMouseOver): If the click is on a DayCell or WeekNumberCell, highlight the appropriate date range.
(CalendarTableView.prototype.onMouseOut):
(CalendarTableView.prototype.prepareNewCell): Prepares a new row cell by recycling or creating a new one.
(CalendarTableView.prototype.height): Returns the height of the view in pixels.
(CalendarTableView.prototype.setHeight): Sets the height of the view in pixels.
(CalendarTableView.prototype.scrollToMonth): Scrolls to reveal the given month.
(CalendarTableView.prototype.dayAtColumnAndRow): Day at a given column and row. Column number doesn't count week number column.
(CalendarTableView.prototype.columnAndRowForDay): Column and row for the given day.
(CalendarTableView.prototype.updateCells): Update the position and appearance of the cell.s
(CalendarTableView.prototype.prepareNewDayCell): Prepares a new day cell. The cell is registered to this._dayCells.
(CalendarTableView.prototype.prepareNewWeekNumberCell): Prepares a new week number cell. The cell is registered to this._weekNumberCells.
(CalendarTableView.prototype.throwAwayDayCell): The cell is unregistered from this._dayCells.
(CalendarTableView.prototype.throwAwayWeekNumberCell): The cell is unregistered from this._weekNumberCells.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r144422 r144423  
     12013-02-28  Keishi Hattori  <keishi@webkit.org>
     2
     3        Add calendar table view for the new calendar picker
     4        https://bugs.webkit.org/show_bug.cgi?id=110970
     5
     6        Reviewed by Kent Tamura.
     7
     8        The calendar table that will be used in the new calendar picker (Bug 109439).
     9
     10        No new tests. Code is not used yet.
     11
     12        * Resources/pagepopups/calendarPicker.js:
     13        (DayCell): Cell which represents one day in the calendar.
     14        (DayCell.recycleOrCreate):
     15        (DayCell.prototype._recycleBin):
     16        (DayCell.prototype.throwAway):
     17        (DayCell.prototype.setHighlighted): Sets the highlighted class on the element.
     18        (DayCell.prototype.setDisabled): Sets the disabled class on the element.
     19        (DayCell.prototype.setIsInCurrentMonth): Sets the current-month class on the element.
     20        (DayCell.prototype.setIsToday): Sets the today class on the element.
     21        (DayCell.prototype.reset): Resets the day cell to be reused.
     22        (WeekNumberCell): Cell used for the week number column.
     23        (WeekNumberCell.prototype._recycleBin):
     24        (WeekNumberCell.recycleOrCreate):
     25        (WeekNumberCell.prototype.reset):
     26        (WeekNumberCell.prototype.throwAway):
     27        (WeekNumberCell.prototype.setHighlighted): Sets the highlighted class on the element.
     28        (WeekNumberCell.prototype.setDisabled): Sets the disabled class on the element.
     29        (CalendarTableHeaderView): Header for the calendar table. Contains the column labels.
     30        (CalendarRowCell): Row containing day cells and maybe a week number cell.
     31        (CalendarRowCell.prototype._recycleBin):
     32        (CalendarRowCell.prototype.reset):
     33        (CalendarRowCell.prototype.throwAway):
     34        (CalendarTableView): A list view showing a grid of days.
     35        (CalendarTableView.prototype.rowAtScrollOffset): Returns the row number currently at the scroll offset.
     36        (CalendarTableView.prototype.scrollOffsetForRow): Returns the current scroll offset for the given row.
     37        (CalendarTableView.prototype.onClick): If the click is on a DayCell or WeekNumberCell, select the appropriate date range.
     38        (CalendarTableView.prototype.onMouseOver): If the click is on a DayCell or WeekNumberCell, highlight the appropriate date range.
     39        (CalendarTableView.prototype.onMouseOut):
     40        (CalendarTableView.prototype.prepareNewCell): Prepares a new row cell by recycling or creating a new one.
     41        (CalendarTableView.prototype.height): Returns the height of the view in pixels.
     42        (CalendarTableView.prototype.setHeight): Sets the height of the view in pixels.
     43        (CalendarTableView.prototype.scrollToMonth): Scrolls to reveal the given month.
     44        (CalendarTableView.prototype.dayAtColumnAndRow): Day at a given column and row. Column number doesn't count week number column.
     45        (CalendarTableView.prototype.columnAndRowForDay): Column and row for the given day.
     46        (CalendarTableView.prototype.updateCells): Update the position and appearance of the cell.s
     47        (CalendarTableView.prototype.prepareNewDayCell): Prepares a new day cell. The cell is registered to this._dayCells.
     48        (CalendarTableView.prototype.prepareNewWeekNumberCell): Prepares a new week number cell. The cell is registered to this._weekNumberCells.
     49        (CalendarTableView.prototype.throwAwayDayCell): The cell is unregistered from this._dayCells.
     50        (CalendarTableView.prototype.throwAwayWeekNumberCell): The cell is unregistered from this._weekNumberCells.
     51
    1522013-02-28  Alexey Proskuryakov  <ap@apple.com>
    253
  • trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js

    r144298 r144423  
    3232// FIXME:
    3333//  - Touch event
     34//  - Adjust hit target size for touch
    3435
    3536/**
     
    27322733    var monthContainingToday = Month.createFromToday();
    27332734    this._todayButton.setDisabled(this.disabled || monthContainingToday < this.calendarPicker.minimumMonth || monthContainingToday > this.calendarPicker.maximumMonth);
     2735};
     2736
     2737/**
     2738 * @constructor
     2739 * @extends ListCell
     2740 */
     2741function DayCell() {
     2742    ListCell.call(this);
     2743    this.element.classList.add(DayCell.ClassNameDayCell);
     2744    this.element.style.width = DayCell.Width + "px";
     2745    this.element.style.height = DayCell.Height + "px";
     2746    this.element.style.lineHeight = (DayCell.Height - DayCell.BorderWidth * 2) + "px";
     2747    /**
     2748     * @type {?Day}
     2749     */
     2750    this.day = null;
     2751};
     2752
     2753DayCell.prototype = Object.create(ListCell.prototype);
     2754
     2755DayCell.Width = 34;
     2756DayCell.Height = 20;
     2757DayCell.BorderWidth = 1;
     2758DayCell.ClassNameDayCell = "day-cell";
     2759DayCell.ClassNameHighlighted = "highlighted";
     2760DayCell.ClassNameDisabled = "disabled";
     2761DayCell.ClassNameCurrentMonth = "current-month";
     2762DayCell.ClassNameToday = "today";
     2763
     2764DayCell._recycleBin = [];
     2765
     2766DayCell.recycleOrCreate = function() {
     2767    return DayCell._recycleBin.pop() || new DayCell();
     2768};
     2769
     2770/**
     2771 * @return {!Array}
     2772 * @override
     2773 */
     2774DayCell.prototype._recycleBin = function() {
     2775    return DayCell._recycleBin;
     2776};
     2777
     2778/**
     2779 * @override
     2780 */
     2781DayCell.prototype.throwAway = function() {
     2782    ListCell.prototype.throwAway.call(this);
     2783    this.day = null;
     2784};
     2785
     2786/**
     2787 * @param {!boolean} highlighted
     2788 */
     2789DayCell.prototype.setHighlighted = function(highlighted) {
     2790    if (highlighted)
     2791        this.element.classList.add(DayCell.ClassNameHighlighted);
     2792    else
     2793        this.element.classList.remove(DayCell.ClassNameHighlighted);
     2794};
     2795
     2796/**
     2797 * @param {!boolean} disabled
     2798 */
     2799DayCell.prototype.setDisabled = function(disabled) {
     2800    if (disabled)
     2801        this.element.classList.add(DayCell.ClassNameDisabled);
     2802    else
     2803        this.element.classList.remove(DayCell.ClassNameDisabled);
     2804};
     2805
     2806/**
     2807 * @param {!boolean} selected
     2808 */
     2809DayCell.prototype.setIsInCurrentMonth = function(selected) {
     2810    if (selected)
     2811        this.element.classList.add(DayCell.ClassNameCurrentMonth);
     2812    else
     2813        this.element.classList.remove(DayCell.ClassNameCurrentMonth);
     2814};
     2815
     2816/**
     2817 * @param {!boolean} selected
     2818 */
     2819DayCell.prototype.setIsToday = function(selected) {
     2820    if (selected)
     2821        this.element.classList.add(DayCell.ClassNameToday);
     2822    else
     2823        this.element.classList.remove(DayCell.ClassNameToday);
     2824};
     2825
     2826/**
     2827 * @param {!Day} day
     2828 */
     2829DayCell.prototype.reset = function(day) {
     2830    this.day = day;
     2831    this.element.textContent = localizeNumber(this.day.date.toString());
     2832    this.show();
     2833};
     2834
     2835/**
     2836 * @constructor
     2837 * @extends ListCell
     2838 */
     2839function WeekNumberCell() {
     2840    ListCell.call(this);
     2841    this.element.classList.add(WeekNumberCell.ClassNameWeekNumberCell);
     2842    this.element.style.width = (WeekNumberCell.Width - WeekNumberCell.RightBorderWidth) + "px";
     2843    this.element.style.height = WeekNumberCell.Height + "px";
     2844    /**
     2845     * @type {?Week}
     2846     */
     2847    this.week = null;
     2848};
     2849
     2850WeekNumberCell.prototype = Object.create(ListCell.prototype);
     2851
     2852WeekNumberCell.Width = 48;
     2853WeekNumberCell.Height = DayCell.Height;
     2854WeekNumberCell.RightBorderWidth = 1;
     2855WeekNumberCell.ClassNameWeekNumberCell = "week-number-cell";
     2856WeekNumberCell.ClassNameHighlighted = "highlighted";
     2857WeekNumberCell.ClassNameDisabled = "disabled";
     2858
     2859WeekNumberCell._recycleBin = [];
     2860
     2861/**
     2862 * @return {!Array}
     2863 * @override
     2864 */
     2865WeekNumberCell.prototype._recycleBin = function() {
     2866    return WeekNumberCell._recycleBin;
     2867};
     2868
     2869/**
     2870 * @return {!WeekNumberCell}
     2871 */
     2872WeekNumberCell.recycleOrCreate = function() {
     2873    return WeekNumberCell._recycleBin.pop() || new WeekNumberCell();
     2874};
     2875
     2876/**
     2877 * @param {!Week} week
     2878 */
     2879WeekNumberCell.prototype.reset = function(week) {
     2880    this.week = week;
     2881    this.element.textContent = localizeNumber(this.week.week.toString());
     2882    this.show();
     2883};
     2884
     2885/**
     2886 * @override
     2887 */
     2888WeekNumberCell.prototype.throwAway = function() {
     2889    ListCell.prototype.throwAway.call(this);
     2890    this.week = null;
     2891};
     2892
     2893WeekNumberCell.prototype.setHighlighted = function(highlighted) {
     2894    if (highlighted)
     2895        this.element.classList.add(WeekNumberCell.ClassNameHighlighted);
     2896    else
     2897        this.element.classList.remove(WeekNumberCell.ClassNameHighlighted);
     2898};
     2899
     2900WeekNumberCell.prototype.setDisabled = function(disabled) {
     2901    if (disabled)
     2902        this.element.classList.add(WeekNumberCell.ClassNameDisabled);
     2903    else
     2904        this.element.classList.remove(WeekNumberCell.ClassNameDisabled);
     2905};
     2906
     2907/**
     2908 * @constructor
     2909 * @extends View
     2910 * @param {!boolean} hasWeekNumberColumn
     2911 */
     2912function CalendarTableHeaderView(hasWeekNumberColumn) {
     2913    View.call(this, createElement("div", "calendar-table-header-view"));
     2914    if (hasWeekNumberColumn) {
     2915        var weekNumberLabelElement = createElement("div", "week-number-label", global.params.weekLabel);
     2916        weekNumberLabelElement.style.width = WeekNumberCell.Width + "px";
     2917        this.element.appendChild(weekNumberLabelElement);
     2918    }
     2919    for (var i = 0; i < DaysPerWeek; ++i) {
     2920        var weekDayNumber = (global.params.weekStartDay + i) % DaysPerWeek;
     2921        var labelElement = createElement("div", "week-day-label", global.params.dayLabels[weekDayNumber]);
     2922        labelElement.style.width = DayCell.Width + "px";
     2923        this.element.appendChild(labelElement);
     2924        if (getLanguage() === "ja") {
     2925            if (weekDayNumber === 0)
     2926                labelElement.style.color = "red";
     2927            else if (weekDayNumber === 6)
     2928                labelElement.style.color = "blue";
     2929        }
     2930    }
     2931}
     2932
     2933CalendarTableHeaderView.prototype = Object.create(View.prototype);
     2934
     2935CalendarTableHeaderView.Height = 25;
     2936
     2937/**
     2938 * @constructor
     2939 * @extends ListCell
     2940 */
     2941function CalendarRowCell() {
     2942    ListCell.call(this);
     2943    this.element.classList.add(CalendarRowCell.ClassNameCalendarRowCell);
     2944    this.element.style.height = CalendarRowCell.Height + "px";
     2945
     2946    /**
     2947     * @type {!Array}
     2948     * @protected
     2949     */
     2950    this._dayCells = [];
     2951    /**
     2952     * @type {!number}
     2953     */
     2954    this.row = 0;
     2955    /**
     2956     * @type {?CalendarTableView}
     2957     */
     2958    this.calendarTableView = null;
     2959}
     2960
     2961CalendarRowCell.prototype = Object.create(ListCell.prototype);
     2962
     2963CalendarRowCell.Height = DayCell.Height;
     2964CalendarRowCell.ClassNameCalendarRowCell = "calendar-row-cell";
     2965
     2966CalendarRowCell._recycleBin = [];
     2967
     2968/**
     2969 * @return {!Array}
     2970 * @override
     2971 */
     2972CalendarRowCell.prototype._recycleBin = function() {
     2973    return CalendarRowCell._recycleBin;
     2974};
     2975
     2976/**
     2977 * @param {!number} row
     2978 * @param {!CalendarTableView} calendarTableView
     2979 */
     2980CalendarRowCell.prototype.reset = function(row, calendarTableView) {
     2981    this.row = row;
     2982    this.calendarTableView = calendarTableView;
     2983    if (this.calendarTableView.hasWeekNumberColumn) {
     2984        var middleDay = this.calendarTableView.dayAtColumnAndRow(3, row);
     2985        var week = Week.createFromDay(middleDay);
     2986        this.weekNumberCell = this.calendarTableView.prepareNewWeekNumberCell(week);
     2987        this.weekNumberCell.attachTo(this);
     2988    }
     2989    var day = calendarTableView.dayAtColumnAndRow(0, row);
     2990    for (var i = 0; i < DaysPerWeek; ++i) {
     2991        var dayCell = this.calendarTableView.prepareNewDayCell(day);
     2992        dayCell.attachTo(this);
     2993        this._dayCells.push(dayCell);
     2994        day = day.next();
     2995    }
     2996    this.show();
     2997};
     2998
     2999/**
     3000 * @override
     3001 */
     3002CalendarRowCell.prototype.throwAway = function() {
     3003    ListCell.prototype.throwAway.call(this);
     3004    if (this.weekNumberCell)
     3005        this.calendarTableView.throwAwayWeekNumberCell(this.weekNumberCell);
     3006    this._dayCells.forEach(this.calendarTableView.throwAwayDayCell, this.calendarTableView);
     3007    this._dayCells.length = 0;
     3008};
     3009
     3010/**
     3011 * @constructor
     3012 * @extends ListView
     3013 * @param {!CalendarPicker} calendarPicker
     3014 */
     3015function CalendarTableView(calendarPicker) {
     3016    ListView.call(this);
     3017    this.element.classList.add(CalendarTableView.ClassNameCalendarTableView);
     3018    this.element.tabIndex = 0;
     3019
     3020    /**
     3021     * @type {!boolean}
     3022     * @const
     3023     */
     3024    this.hasWeekNumberColumn = calendarPicker.type === "week";
     3025    /**
     3026     * @type {!CalendarPicker}
     3027     * @const
     3028     */
     3029    this.calendarPicker = calendarPicker;
     3030    /**
     3031     * @type {!Object}
     3032     * @const
     3033     */
     3034    this._dayCells = {};
     3035    var headerView = new CalendarTableHeaderView(this.hasWeekNumberColumn);
     3036    headerView.attachTo(this, this.scrollView);
     3037
     3038    if (this.hasWeekNumberColumn) {
     3039        this.setWidth(DayCell.Width * DaysPerWeek + WeekNumberCell.Width);
     3040        /**
     3041         * @type {?Array}
     3042         * @const
     3043         */
     3044        this._weekNumberCells = [];
     3045    } else {
     3046        this.setWidth(DayCell.Width * DaysPerWeek);
     3047    }
     3048   
     3049    /**
     3050     * @type {!boolean}
     3051     * @protected
     3052     */
     3053    this._ignoreMouseOutUntillNextMouseOver = false;
     3054
     3055    this.element.addEventListener("click", this.onClick, false);
     3056    this.element.addEventListener("mouseover", this.onMouseOver, false);
     3057    this.element.addEventListener("mouseout", this.onMouseOut, false);
     3058
     3059    // you shouldn't be able to use the mouse wheel to scroll.
     3060    this.scrollView.element.removeEventListener("mousewheel", this.scrollView.onMouseWheel, false);
     3061}
     3062
     3063CalendarTableView.prototype = Object.create(ListView.prototype);
     3064
     3065CalendarTableView.BorderWidth = 1;
     3066CalendarTableView.ClassNameCalendarTableView = "calendar-table-view";
     3067
     3068/**
     3069 * @param {!number} scrollOffset
     3070 * @return {!number}
     3071 */
     3072CalendarTableView.prototype.rowAtScrollOffset = function(scrollOffset) {
     3073    return Math.floor(scrollOffset / CalendarRowCell.Height);
     3074};
     3075
     3076/**
     3077 * @param {!number} row
     3078 * @return {!number}
     3079 */
     3080CalendarTableView.prototype.scrollOffsetForRow = function(row) {
     3081    return row * CalendarRowCell.Height;
     3082};
     3083
     3084/**
     3085 * @param {?Event} event
     3086 */
     3087CalendarTableView.prototype.onClick = function(event) {
     3088    if (this.hasWeekNumberColumn) {
     3089        var weekNumberCellElement = enclosingNodeOrSelfWithClass(event.target, WeekNumberCell.ClassNameWeekNumberCell);
     3090        if (weekNumberCellElement) {
     3091            var weekNumberCell = weekNumberCellElement.$view;
     3092            this.calendarPicker.selectRangeContainingDay(weekNumberCell.week.firstDay());
     3093            return;
     3094        }
     3095    }
     3096    var dayCellElement = enclosingNodeOrSelfWithClass(event.target, DayCell.ClassNameDayCell);
     3097    if (!dayCellElement)
     3098        return;
     3099    var dayCell = dayCellElement.$view;
     3100    this.calendarPicker.selectRangeContainingDay(dayCell.day);
     3101};
     3102
     3103/**
     3104 * @param {?Event} event
     3105 */
     3106CalendarTableView.prototype.onMouseOver = function(event) {
     3107    if (this.hasWeekNumberColumn) {
     3108        var weekNumberCellElement = enclosingNodeOrSelfWithClass(event.target, WeekNumberCell.ClassNameWeekNumberCell);
     3109        if (weekNumberCellElement) {
     3110            var weekNumberCell = weekNumberCellElement.$view;
     3111            this.calendarPicker.highlightRangeContainingDay(weekNumberCell.week.firstDay());
     3112            this._ignoreMouseOutUntillNextMouseOver = false;
     3113            return;
     3114        }
     3115    }
     3116    var dayCellElement = enclosingNodeOrSelfWithClass(event.target, DayCell.ClassNameDayCell);
     3117    if (!dayCellElement)
     3118        return;
     3119    var dayCell = dayCellElement.$view;
     3120    this.calendarPicker.highlightRangeContainingDay(dayCell.day);
     3121    this._ignoreMouseOutUntillNextMouseOver = false;
     3122};
     3123
     3124/**
     3125 * @param {?Event} event
     3126 */
     3127CalendarTableView.prototype.onMouseOut = function(event) {
     3128    if (this._ignoreMouseOutUntillNextMouseOver)
     3129        return;
     3130    var dayCellElement = enclosingNodeOrSelfWithClass(event.target, DayCell.ClassNameDayCell);
     3131    if (!dayCellElement) {
     3132        this.calendarPicker.highlightRangeContainingDay(null);
     3133    }
     3134};
     3135
     3136/**
     3137 * @param {!number} row
     3138 * @return {!CalendarRowCell}
     3139 */
     3140CalendarTableView.prototype.prepareNewCell = function(row) {
     3141    var cell = CalendarRowCell._recycleBin.pop() || new CalendarRowCell();
     3142    cell.reset(row, this);
     3143    return cell;
     3144};
     3145
     3146/**
     3147 * @return {!number} Height in pixels.
     3148 */
     3149CalendarTableView.prototype.height = function() {
     3150    return this.scrollView.height() + CalendarTableHeaderView.Height + CalendarTableView.BorderWidth * 2;
     3151};
     3152
     3153/**
     3154 * @param {!number} height Height in pixels.
     3155 */
     3156CalendarTableView.prototype.setHeight = function(height) {
     3157    this.scrollView.setHeight(height - CalendarTableHeaderView.Height - CalendarTableView.BorderWidth * 2);
     3158};
     3159
     3160/**
     3161 * @param {!Month} month
     3162 * @param {!boolean} animate
     3163 */
     3164CalendarTableView.prototype.scrollToMonth = function(month, animate) {
     3165    var rowForFirstDayInMonth = this.columnAndRowForDay(month.firstDay()).row;
     3166    this.scrollView.scrollTo(this.scrollOffsetForRow(rowForFirstDayInMonth), animate);
     3167};
     3168
     3169/**
     3170 * @param {!number} column
     3171 * @param {!number} row
     3172 * @return {!Day}
     3173 */
     3174CalendarTableView.prototype.dayAtColumnAndRow = function(column, row) {
     3175    var daysSinceMinimum = row * DaysPerWeek + column + global.params.weekStartDay - CalendarTableView._MinimumDayWeekDay;
     3176    return Day.createFromValue(daysSinceMinimum * MillisecondsPerDay + CalendarTableView._MinimumDayValue);
     3177};
     3178
     3179CalendarTableView._MinimumDayValue = Day.Minimum.valueOf();
     3180CalendarTableView._MinimumDayWeekDay = Day.Minimum.weekDay();
     3181
     3182/**
     3183 * @param {!Day} day
     3184 * @return {!Object} Object with properties column and row.
     3185 */
     3186CalendarTableView.prototype.columnAndRowForDay = function(day) {
     3187    var daysSinceMinimum = (day.valueOf() - CalendarTableView._MinimumDayValue) / MillisecondsPerDay;
     3188    var offset = daysSinceMinimum + CalendarTableView._MinimumDayWeekDay - global.params.weekStartDay;
     3189    var row = Math.floor(offset / DaysPerWeek);
     3190    var column = offset - row * DaysPerWeek;
     3191    return {
     3192        column: column,
     3193        row: row
     3194    };
     3195};
     3196
     3197CalendarTableView.prototype.updateCells = function() {
     3198    ListView.prototype.updateCells.call(this);
     3199
     3200    var selection = this.calendarPicker.selection();
     3201    var firstDayInSelection;
     3202    var lastDayInSelection;
     3203    if (selection) {
     3204        firstDayInSelection = selection.firstDay().valueOf();
     3205        lastDayInSelection = selection.lastDay().valueOf();
     3206    } else {
     3207        firstDayInSelection = Infinity;
     3208        lastDayInSelection = Infinity;
     3209    }
     3210    var highlight = this.calendarPicker.highlight();
     3211    var firstDayInHighlight;
     3212    var lastDayInHighlight;
     3213    if (highlight) {
     3214        firstDayInHighlight = highlight.firstDay().valueOf();
     3215        lastDayInHighlight = highlight.lastDay().valueOf();
     3216    } else {
     3217        firstDayInHighlight = Infinity;
     3218        lastDayInHighlight = Infinity;
     3219    }
     3220    var currentMonth = this.calendarPicker.currentMonth();
     3221    var firstDayInCurrentMonth = currentMonth.firstDay().valueOf();
     3222    var lastDayInCurrentMonth = currentMonth.lastDay().valueOf();
     3223    for (var dayString in this._dayCells) {
     3224        var dayCell = this._dayCells[dayString];
     3225        var day = dayCell.day;
     3226        dayCell.setIsToday(Day.createFromToday().equals(day));
     3227        dayCell.setSelected(day >= firstDayInSelection && day <= lastDayInSelection);
     3228        dayCell.setHighlighted(day >= firstDayInHighlight && day <= lastDayInHighlight);
     3229        dayCell.setIsInCurrentMonth(day >= firstDayInCurrentMonth && day <= lastDayInCurrentMonth);
     3230        dayCell.setDisabled(!this.calendarPicker.isValidDay(day));
     3231    }
     3232    if (this.hasWeekNumberColumn) {
     3233        for (var weekString in this._weekNumberCells) {
     3234            var weekNumberCell = this._weekNumberCells[weekString];
     3235            var week = weekNumberCell.week;
     3236            weekNumberCell.setSelected(selection && selection.equals(week));
     3237            weekNumberCell.setHighlighted(highlight && highlight.equals(week));
     3238            weekNumberCell.setDisabled(!this.calendarPicker.isValid(week));
     3239        }
     3240    }
     3241};
     3242
     3243/**
     3244 * @param {!Day} day
     3245 * @return {!DayCell}
     3246 */
     3247CalendarTableView.prototype.prepareNewDayCell = function(day) {
     3248    var dayCell = DayCell.recycleOrCreate();
     3249    dayCell.reset(day);
     3250    this._dayCells[dayCell.day.toString()] = dayCell;
     3251    return dayCell;
     3252};
     3253
     3254/**
     3255 * @param {!Week} week
     3256 * @return {!WeekNumberCell}
     3257 */
     3258CalendarTableView.prototype.prepareNewWeekNumberCell = function(week) {
     3259    var weekNumberCell = WeekNumberCell.recycleOrCreate();
     3260    weekNumberCell.reset(week);
     3261    this._weekNumberCells[weekNumberCell.week.toString()] = weekNumberCell;
     3262    return weekNumberCell;
     3263};
     3264
     3265/**
     3266 * @param {!DayCell} dayCell
     3267 */
     3268CalendarTableView.prototype.throwAwayDayCell = function(dayCell) {
     3269    delete this._dayCells[dayCell.day.toString()];
     3270    dayCell.throwAway();
     3271};
     3272
     3273/**
     3274 * @param {!WeekNumberCell} weekNumberCell
     3275 */
     3276CalendarTableView.prototype.throwAwayWeekNumberCell = function(weekNumberCell) {
     3277    delete this._weekNumberCells[weekNumberCell.week.toString()];
     3278    weekNumberCell.throwAway();
    27343279};
    27353280
Note: See TracChangeset for help on using the changeset viewer.