Bug 1320225 - [DateTimeInput] Integration of input type=date input box with picker (part 1). r=mconley,smaug
authorJessica Jong <jjong@mozilla.com>
Tue, 17 Jan 2017 13:09:03 +0800
changeset 462454 87a0e0ccdc3417c33414bb91c3199e9b99dfa025
parent 462341 f81835544ab8e371a6d59a609a88567fce2183f5
child 462455 14a12ac05a4b9dddeb6919540ab05af08e730912
push id41763
push userbmo:ttromey@mozilla.com
push dateTue, 17 Jan 2017 14:39:59 +0000
reviewersmconley, smaug
bugs1320225
milestone53.0a1
Bug 1320225 - [DateTimeInput] Integration of input type=date input box with picker (part 1). r=mconley,smaug
dom/webidl/HTMLInputElement.webidl
toolkit/content/browser-content.js
toolkit/content/widgets/datetimebox.xml
toolkit/modules/DateTimePickerHelper.jsm
--- a/dom/webidl/HTMLInputElement.webidl
+++ b/dom/webidl/HTMLInputElement.webidl
@@ -235,16 +235,19 @@ partial interface HTMLInputElement {
 
   [Pref="dom.webkitBlink.dirPicker.enabled", BinaryName="WebkitDirectoryAttr", SetterThrows]
           attribute boolean webkitdirectory;
 };
 
 dictionary DateTimeValue {
   long hour;
   long minute;
+  long year;
+  long month;
+  long day;
 };
 
 partial interface HTMLInputElement {
   [Pref="dom.forms.datetime", ChromeOnly]
   DateTimeValue getDateTimeInputBoxValue();
 
   [Pref="dom.forms.datetime", ChromeOnly]
   void updateDateTimeInputBox(optional DateTimeValue value);
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -1731,16 +1731,17 @@ let DateTimePickerListener = {
             min: this._inputElement.min,
             max: this._inputElement.max,
           },
         });
         break;
       }
       case "MozUpdateDateTimePicker": {
         let value = this._inputElement.getDateTimeInputBoxValue();
+        value.type = this._inputElement.type;
         sendAsyncMessage("FormDateTime:UpdatePicker", { value });
         break;
       }
       case "MozCloseDateTimePicker": {
         sendAsyncMessage("FormDateTime:ClosePicker");
         this.close();
         break;
       }
--- a/toolkit/content/widgets/datetimebox.xml
+++ b/toolkit/content/widgets/datetimebox.xml
@@ -194,20 +194,34 @@
 
           this.log("setInputValueFromFields: " + date);
           this.mInputElement.setUserInput(date);
         ]]>
         </body>
       </method>
 
       <method name="setFieldsFromPicker">
+        <parameter name="aValue"/>
         <body>
         <![CDATA[
-          // TODO: Bug 1320225 - [DateTimeInput] Integration of input type=date
-          // input box with picker.
+          let year = aValue.year;
+          let month = aValue.month;
+          let day = aValue.day;
+
+          if (!this.isEmpty(year)) {
+            this.setFieldValue(this.mYearField, year);
+          }
+
+          if (!this.isEmpty(month)) {
+            this.setFieldValue(this.mMonthField, month);
+          }
+
+          if (!this.isEmpty(day)) {
+            this.setFieldValue(this.mDayField, day);
+          }
         ]]>
         </body>
       </method>
 
       <method name="handleKeypress">
         <parameter name="aEvent"/>
         <body>
         <![CDATA[
--- a/toolkit/modules/DateTimePickerHelper.jsm
+++ b/toolkit/modules/DateTimePickerHelper.jsm
@@ -92,23 +92,20 @@ this.DateTimePickerHelper = {
       }
       default:
         break;
     }
   },
 
   // Called when picker value has changed, notify input box about it.
   updateInputBoxValue(aEvent) {
-    // TODO: parse data based on input type.
-    const { hour, minute } = aEvent.detail;
-    debug("hour: " + hour + ", minute: " + minute);
     let browser = this.weakBrowser ? this.weakBrowser.get() : null;
     if (browser) {
       browser.messageManager.sendAsyncMessage(
-        "FormDateTime:PickerValueChanged", { hour, minute });
+        "FormDateTime:PickerValueChanged", aEvent.detail);
     }
   },
 
   // Get picker from browser and show it anchored to the input box.
   showPicker(aBrowser, aData) {
     let rect = aData.rect;
     let type = aData.type;
     let detail = aData.detail;