From b57fa6add7ae2cd7c5bbf20119a70f19facac858 Mon Sep 17 00:00:00 2001 From: "ginn.chen%sun.com" Date: Wed, 14 Feb 2007 06:06:05 +0000 Subject: [PATCH] Bug 365907 use spin controls for xul calendar patch by surkov.alexander r=Olli.Pettay, aaronr git-svn-id: svn://10.0.0.236/trunk@220106 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xforms/resources/content/input-xul.xml | 9 +- .../xforms/resources/content/widgets-xul.xml | 354 ++++++++++++------ .../xforms/resources/content/widgets.xml | 10 +- .../xforms/resources/content/xforms.css | 34 +- .../xforms/resources/skin/widgets-xul.css | 2 +- 5 files changed, 272 insertions(+), 137 deletions(-) diff --git a/mozilla/extensions/xforms/resources/content/input-xul.xml b/mozilla/extensions/xforms/resources/content/input-xul.xml index 49c6aa7a207..31fc624dacc 100644 --- a/mozilla/extensions/xforms/resources/content/input-xul.xml +++ b/mozilla/extensions/xforms/resources/content/input-xul.xml @@ -204,7 +204,8 @@ xbl:inherits="disabled"/> - + @@ -241,8 +242,10 @@ var pickerChangeHandler = { inputControl: this, handleEvent: function(aEvent) { - this.inputControl.control.value = this.inputControl.picker.value; - this.inputControl.hidePicker(); + if (aEvent.originalTarget == this.inputControl.picker) { + this.inputControl.control.value = this.inputControl.picker.value; + this.inputControl.hidePicker(); + } } }; this.picker.addEventListener("change", pickerChangeHandler, false); diff --git a/mozilla/extensions/xforms/resources/content/widgets-xul.xml b/mozilla/extensions/xforms/resources/content/widgets-xul.xml index 3cdb494fa9a..f202fc7ca38 100644 --- a/mozilla/extensions/xforms/resources/content/widgets-xul.xml +++ b/mozilla/extensions/xforms/resources/content/widgets-xul.xml @@ -45,7 +45,8 @@ xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl" xmlns:html="http://www.w3.org/1999/xhtml" - xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:mozType="http://www.mozilla.org/projects/xforms/2005/type"> - - - - - - - - - - - - - - - - - + @@ -265,103 +249,62 @@ this.refreshInternal(aCurrentDay, aDaysRefreshOnly); - this.monthsLabel.value = - new Date(this.year, this.month - 1).toLocaleFormat("%B"); - - this.yearsLabel.value = this.year; + this.monthyearBox.month = this.month - 1; + this.monthyearBox.year = this.year; + + var handler = { + handleEvent: function handleEvent(aEvent) { + this.widget.setDate(this.monthyear.year, this.monthyear.month + 1); + }, + widget: this, + monthyear: this.monthyearBox + }; + this.monthyearBox.addEventListener("change", handler, false); + - + - if (!this._prevmonthButton) { - this._prevmonthButton = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "prevmonth-btn"); + if (!this._monthyearBox) { + this._monthyearBox = this.ownerDocument. + getAnonymousElementByAttribute(this, "anonid", "monthyear"); } - return this._prevmonthButton; + return this._monthyearBox; - null - - - - if (!this._nextmonthButton) { - this._nextmonthButton = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "nextmonth-btn"); - } - return this._nextmonthButton; - - - null - - - - if (!this._prevyearButton) { - this._prevyearButton = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "prevyear-btn"); - } - return this._prevyearButton; - - - null - - - - if (!this._nextyearButton) { - this._nextyearButton = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "nextyear-btn"); - } - return this._nextyearButton; - - - null - - - - if (!this._monthsLabel) { - this._monthsLabel = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "months-label"); - } - return this._monthsLabel; - - - null - - - - if (!this._yearsLabel) { - this._yearsLabel = this.ownerDocument. - getAnonymousElementByAttribute(this, "anonid", "years-label"); - } - return this._yearsLabel; - - - null + null - - var target = event.originalTarget; - switch (target) { - case this.prevmonthButton: - this.processAction("prevMonth", null, true); - break; - case this.nextmonthButton: - this.processAction("nextMonth", null, true); - break; - case this.prevyearButton: - this.year--; - break; - case this.nextyearButton: - this.year++; - break; - } + + if (!this.hasAttribute("internaltabhandling")) + return; + + event.preventDefault(); + + if (this.monthyearBox.isMonthFocused()) + this.monthyearBox.focusYear(); + else if (this.monthyearBox.isYearFocused()) + this.focus(); + else + this.monthyearBox.focusMonth(); - - this.year = this.yearsLabel.value; + + if (!this.hasAttribute("internaltabhandling")) + return; + + event.preventDefault(); + + if (this.monthyearBox.isMonthFocused()) + this.focus(); + else if (this.monthyearBox.isYearFocused()) + this.monthyearBox.focusMonth(); + else + this.monthyearBox.focusYear(); @@ -762,11 +705,11 @@ ]]> - + this._modifyUp(); - + this._modifyDown(); @@ -778,7 +721,186 @@ } + + + + + + + + + + + + + + + + + + + + 11) + val = 0; + + if (!this.monthNames.length) { + for (var month = 0; month < 12; month++) { + var loc = new Date(1970, month).toLocaleFormat("%B"); + this.monthNames.push(loc); + this.monthValues[loc] = month; + } + } + + this.inputField.value = this.monthNames[val]; + ]]> + + + + + + this.value++; + this.fireEvent("change"); + this.fireEvent("spinup"); + + + + + + this.value--; + this.fireEvent("change"); + this.fireEvent("spindown"); + + + + + + + var evt = document.createEvent("Events"); + evt.initEvent(aName, true, false); + this.dispatchEvent(evt); + + + + + if (this.value == undefined) + this.value = 0; + + + new Array() + new Object() + + + + + this._modifyUp(); + + + this._modifyDown(); + + + + + + + + + + + + + + + + + + + + this.monthField.focus(); + + + + + + this.yearField.focus(); + + + + + + return this.getFocusedElement() == this.monthField; + + + + + + return this.getFocusedElement() == this.yearField; + + + + + + + var focused = this.ownerDocument.commandDispatcher.focusedElement; + if (!focused) + return; + + var binding = this.ownerDocument.getBindingParent(focused); + return binding; + + + + + var handler = { + handleEvent: function handleEvent(aEvent) { + if (aEvent.type == "spinup") { + if (this.widget.month == 0) + this.widget.year++; + } else if (this.widget.month == 11) { + this.widget.year--; + } + }, + widget: this + }; + this.monthField.addEventListener("spinup", handler, false); + this.monthField.addEventListener("spindown", handler, false); + + + + + if (!this._monthField) + this._monthField = this.ownerDocument. + getAnonymousElementByAttribute(this, "anonid", "month"); + return this._monthField; + + + null + + + + if (!this._yearField) + this._yearField = this.ownerDocument. + getAnonymousElementByAttribute(this, "anonid", "year"); + return this._yearField; + + + null + diff --git a/mozilla/extensions/xforms/resources/content/widgets.xml b/mozilla/extensions/xforms/resources/content/widgets.xml index 1b757f9655f..ef16eb65b7e 100644 --- a/mozilla/extensions/xforms/resources/content/widgets.xml +++ b/mozilla/extensions/xforms/resources/content/widgets.xml @@ -338,6 +338,8 @@ var currentIndex = null; if (aCurrentDay) currentIndex = this.dayOffset + parseInt(aCurrentDay) - 1; + else + currentIndex = this.currentDayIndex; this.setSelectedDayByIndex(selectedIndex, currentIndex); ]]> @@ -404,10 +406,9 @@