Modified: trunk/Source/WebCore/ChangeLog (132595 => 132596)
--- trunk/Source/WebCore/ChangeLog 2012-10-26 09:40:37 UTC (rev 132595)
+++ trunk/Source/WebCore/ChangeLog 2012-10-26 09:56:23 UTC (rev 132596)
@@ -1,3 +1,30 @@
+2012-10-26 Keishi Hattori <[email protected]>
+
+ Refactor calendar picker to remove _x/_y from DaysTable
+ https://bugs.webkit.org/show_bug.cgi?id=100460
+
+ Reviewed by Kent Tamura.
+
+ _x/_y properties keep the coordinates for the selection but when we add
+ week and month picking capabilities, the selection can't be expressed as
+ a set of coordinates. This change will remove it.
+
+ No new tests. Covered by calendar-picker-*.html tests.
+
+ * Resources/pagepopups/calendarPicker.js:
+ (DaysTable): Removed _x/_y properties.
+ (DaysTable.prototype._hasSelection): Changed to refer to the DOM to see if we have a selection.
+ (DaysTable.prototype.navigateToMonthAndKeepSelectionPosition): Lookup the selection position.
+ (DaysTable.prototype.selectDate): Deselect first so we don't have two selections.
+ (DaysTable.prototype._selectRangeContainingNode): Selects date/week/month containing the given day node.
+ (DaysTable.prototype._selectRangeAtPosition): Selects date/week/month at the given position.
+ (DaysTable.prototype._firstNodeInSelectedRange): Returns first selected day node.
+ (DaysTable.prototype._deselect): Deselects all selections.
+ (DaysTable.prototype._handleMouseOver): Use _selectRangeContainingNode so we don't have many places handling the selection.
+ (DaysTable.prototype._handleMouseOut): Use _deselect.
+ (DaysTable.prototype._handleKey): Lookup the selection position.
+ (DaysTable.prototype.updateSelection): Use _selectRangeAtPosition.
+
2012-10-26 Ningxin Hu <[email protected]>
FileReader abort case causes Chromium renderer crash
Modified: trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js (132595 => 132596)
--- trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js 2012-10-26 09:40:37 UTC (rev 132595)
+++ trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js 2012-10-26 09:56:23 UTC (rev 132596)
@@ -803,14 +803,6 @@
/**
* @type {!number}
*/
- this._x = -1;
- /**
- * @type {!number}
- */
- this._y = -1;
- /**
- * @type {!number}
- */
this._currentYear = -1;
/**
* @type {!number}
@@ -822,7 +814,7 @@
* @return {!boolean}
*/
DaysTable.prototype._hasSelection = function() {
- return this._x >= 0 && this._y >= 0;
+ return !!this._firstNodeInSelectedRange();
}
/**
@@ -988,23 +980,26 @@
DaysTable.prototype.navigateToMonthAndKeepSelectionPosition = function(year, month) {
if (year == this._currentYear && month == this._currentMonth)
return;
+ var firstNodeInSelectedRange = this._firstNodeInSelectedRange();
this._navigateToMonthWithAnimation(year, month);
- if (this._hasSelection())
- this._days[this._y][this._x].classList.add(ClassNames.Selected);
+ if (firstNodeInSelectedRange) {
+ var x = parseInt(firstNodeInSelectedRange.dataset.positionX, 10);
+ var y = parseInt(firstNodeInSelectedRange.dataset.positionY, 10);
+ this._selectRangeAtPosition(x, y);
+ }
};
/**
* @param {!Date} date
*/
DaysTable.prototype.selectDate = function(date) {
+ this._deselect();
this._navigateToMonthWithAnimation(date.getUTCFullYear(), date.getUTCMonth());
var dateString = serializeDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
for (var w = 0; w < DaysTable._Weeks; w++) {
for (var d = 0; d < 7; d++) {
if (this._days[w][d].dataset.submitValue == dateString) {
this._days[w][d].classList.add(ClassNames.Selected);
- this._x = d;
- this._y = w;
break;
}
}
@@ -1012,6 +1007,38 @@
};
/**
+ * @param {!Element} dayNode
+ */
+DaysTable.prototype._selectRangeContainingNode = function(dayNode) {
+ this._deselect();
+ if (!dayNode || !dayNode.classList.contains(ClassNames.Day) || !dayNode.classList.contains(ClassNames.Available))
+ return;
+ // FIXME: Select date, week or month depending on the config.
+ dayNode.classList.add(ClassNames.Selected);
+};
+
+/**
+ * @param {!number} x
+ * @param {!number} y
+ */
+DaysTable.prototype._selectRangeAtPosition = function(x, y) {
+ this._selectRangeContainingNode(this._days[y][x]);
+};
+
+/**
+ * @return {!Element}
+ */
+DaysTable.prototype._firstNodeInSelectedRange = function() {
+ return this._daysContainer.getElementsByClassName(ClassNames.Selected)[0];
+};
+
+DaysTable.prototype._deselect = function() {
+ var selectedNodes = this._daysContainer.getElementsByClassName(ClassNames.Selected);
+ for (var node = selectedNodes[0]; node; node = selectedNodes[0])
+ node.classList.remove(ClassNames.Selected);
+};
+
+/**
* @return {!boolean}
*/
DaysTable.prototype._maybeSetPreviousMonth = function() {
@@ -1060,26 +1087,16 @@
*/
DaysTable.prototype._handleMouseOver = function(event) {
var node = event.target;
- if (this._hasSelection())
- this._days[this._y][this._x].classList.remove(ClassNames.Selected);
- if (!node.classList.contains(ClassNames.Day)) {
- this._x = -1;
- this._y = -1;
+ if (node.classList.contains(ClassNames.Selected))
return;
- }
- node.classList.add(ClassNames.Selected);
- this._x = Number(node.dataset.positionX);
- this._y = Number(node.dataset.positionY);
+ this._selectRangeContainingNode(node);
};
/**
* @param {Event} event
*/
DaysTable.prototype._handleMouseOut = function(event) {
- if (this._hasSelection())
- this._days[this._y][this._x].classList.remove(ClassNames.Selected);
- this._x = -1;
- this._y = -1;
+ this._deselect();
};
/**
@@ -1087,9 +1104,14 @@
*/
DaysTable.prototype._handleKey = function(event) {
this.picker.maybeUpdateFocusStyle();
- var x = this._x;
- var y = this._y;
+ var x = -1;
+ var y = -1;
var key = event.keyIdentifier;
+ var firstNodeInSelectedRange = this._firstNodeInSelectedRange();
+ if (firstNodeInSelectedRange) {
+ x = parseInt(firstNodeInSelectedRange.dataset.positionX, 10);
+ y = parseInt(firstNodeInSelectedRange.dataset.positionY, 10);
+ }
if (!this._hasSelection() && (key == "Left" || key == "Up" || key == "Right" || key == "Down")) {
// Put the selection on a center cell.
this.updateSelection(event, 3, Math.floor(DaysTable._Weeks / 2 - 1));
@@ -1158,7 +1180,6 @@
}
} else if (key == "U+0054") { // 't'
- this._days[this._y][this._x].classList.remove(ClassNames.Selected);
this.selectDate(new Date());
event.stopPropagation();
event.preventDefault();
@@ -1171,13 +1192,7 @@
* @param {!number} y
*/
DaysTable.prototype.updateSelection = function(event, x, y) {
- if (this._hasSelection())
- this._days[this._y][this._x].classList.remove(ClassNames.Selected);
- if (x >= 0 && y >= 0) {
- this._days[y][x].classList.add(ClassNames.Selected);
- this._x = x;
- this._y = y;
- }
+ this._selectRangeAtPosition(x, y);
event.stopPropagation();
event.preventDefault();
};