Bug 1563151 - Prevent minimonth from trapping all key events; r=darktrojan
authorPaul Morris <paul@paulwmorris.com>
Wed, 03 Jul 2019 10:55:05 -0400
changeset 36052 24ee20470ce85851791de668a512347385941067
parent 36051 741524ea4c59cf9445e2a24115792606113026bd
child 36053 0549ec9b0487dbd1b9a0c4564c7e39192c6ccd9f
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersdarktrojan
bugs1563151
Bug 1563151 - Prevent minimonth from trapping all key events; r=darktrojan
calendar/base/content/widgets/calendar-minimonth.js
--- a/calendar/base/content/widgets/calendar-minimonth.js
+++ b/calendar/base/content/widgets/calendar-minimonth.js
@@ -165,57 +165,57 @@
             // Add pref observer.
             Services.prefs.getBranch("").addObserver("calendar.", this.nsIObserver);
 
             // Add event listeners.
             this.addEventListener("click", (event) => {
                 if (event.button == 0 &&
                     event.originalTarget.classList.contains("minimonth-day")) {
                     this.onDayActivate(event);
-                    event.stopPropagation();
-                    event.preventDefault();
                 }
             });
 
             this.addEventListener("keypress", (event) => {
                 if (event.originalTarget.classList.contains("minimonth-day")) {
                     switch (event.keyCode) {
                         case KeyEvent.DOM_VK_LEFT:
-                            this.moveDateByOffset(0, 0, -1);
+                            this.onDayMovement(event, 0, 0, -1);
                             break;
                         case KeyEvent.DOM_VK_RIGHT:
-                            this.moveDateByOffset(0, 0, 1);
+                            this.onDayMovement(event, 0, 0, 1);
                             break;
                         case KeyEvent.DOM_VK_UP:
-                            this.moveDateByOffset(0, 0, -7);
+                            this.onDayMovement(event, 0, 0, -7);
                             break;
                         case KeyEvent.DOM_VK_DOWN:
-                            this.moveDateByOffset(0, 0, 7);
+                            this.onDayMovement(event, 0, 0, 7);
                             break;
                         case KeyEvent.DOM_VK_PAGE_UP:
-                            this.moveDateByOffset(0, -1, 0);
+                            this.onDayMovement(event, 0, -1, 0);
                             break;
                         case KeyEvent.DOM_VK_PAGE_DOWN:
-                            this.moveDateByOffset(0, 1, 0);
+                            this.onDayMovement(event, 0, 1, 0);
                             break;
                         case KeyEvent.DOM_VK_ESCAPE:
                             this.focusDate(this.mValue || this.mExtraDate);
+                            event.stopPropagation();
+                            event.preventDefault();
                             break;
                         case KeyEvent.DOM_VK_HOME: {
                             const today = new Date();
                             this.update(today);
                             this.focusDate(today);
+                            event.stopPropagation();
+                            event.preventDefault();
                             break;
                         }
                         case KeyEvent.DOM_VK_RETURN:
                             this.onDayActivate(event);
                             break;
                     }
-                    event.stopPropagation();
-                    event.preventDefault();
                 }
             });
 
             this.addEventListener("wheel", (event) => {
                 const pixelThreshold = 150;
                 let deltaView = 0;
                 if (this.getAttribute("readonly") == "true") {
                     // No scrolling on readonly months.
@@ -932,16 +932,24 @@
         onDayActivate(aEvent) {
             // The associated date might change when setting this.value if month changes.
             const date = aEvent.originalTarget.date;
             if (this.getAttribute("readonly") != "true") {
                 this.value = date;
                 this.fireEvent("select");
             }
             this.setFocusedDate(date, true);
+            aEvent.stopPropagation();
+            aEvent.preventDefault();
+        }
+
+        onDayMovement(event, years, months, days) {
+            this.moveDateByOffset(years, months, days);
+            event.stopPropagation();
+            event.preventDefault();
         }
 
         disconnectedCallback() {
             if (this.mObservesComposite) {
                 cal.view.getCompositeCalendar(window).removeObserver(this.calICompositeObserver);
             }
 
             // Remove pref observer.