Bug 469684 - Unifinder-todo: raising of the context menu fires blur -event. r=philipp,a=philipp CLOSED TREE
authorMatthew Mecca <matthew.mecca@gmail.com>
Mon, 05 Sep 2011 21:26:00 +0200
changeset 10770 76e53d36be013043bef9048b8f99dc888f28081b
parent 10769 ff331d4a33a83b04f476a623c2552b5c439378cc
child 10771 90af3615e483080eb6e2169d4f5a55ca04099fda
push id6
push userbienvenu@nventure.com
push dateWed, 16 May 2012 22:24:51 +0000
treeherdertry-comm-central@ac395aea3008 [default view] [failures only]
reviewersphilipp, philipp
bugs469684
Bug 469684 - Unifinder-todo: raising of the context menu fires blur -event. r=philipp,a=philipp CLOSED TREE
calendar/base/content/calendar-common-sets.xul
calendar/base/content/calendar-task-tree.js
calendar/base/content/calendar-task-tree.xml
--- a/calendar/base/content/calendar-common-sets.xul
+++ b/calendar/base/content/calendar-common-sets.xul
@@ -354,17 +354,19 @@
                 label="&calendar.context.pasteevent.label;"
                 accesskey="&calendar.context.pasteevent.accesskey;"
                 key="key_paste"
                 observes="cmd_paste"
                 command="cmd_paste"/>
     </menupopup>
 
     <!-- TASK ITEM CONTEXT MENU -->
-    <menupopup id="taskitem-context-menu" onpopupshowing="changeContextMenuForTask(event);">
+    <menupopup id="taskitem-context-menu"
+               onpopupshowing="changeContextMenuForTask(event);"
+               onpopuphiding="handleTaskContextMenuStateChange(event);">
       <menuitem id="task-context-menu-modify"
                 label="&calendar.context.modifyorviewtask.label;"
                 accesskey="&calendar.context.modifyorviewtask.accesskey;"
                 command="calendar_modify_todo_command"
                 observes="calendar_modify_todo_command"/>
       <menuitem id="task-context-menu-modify-todaypane"
                 label="&calendar.context.modifyorviewtask.label;"
                 accesskey="&calendar.context.modifyorviewtask.accesskey;"
--- a/calendar/base/content/calendar-task-tree.js
+++ b/calendar/base/content/calendar-task-tree.js
@@ -24,16 +24,17 @@
  *                 Colin Phillips <colinp@oeone.com>
  *                 ArentJan Banck <ajbanck@planet.nl>
  *                 Curtis Jewell <csjewell@mail.freeshell.org>
  *                 Eric Belhaire <eric.belhaire@ief.u-psud.fr>
  *                 Mark Swaffer <swaff@fudo.org>
  *                 Michael Buettner <michael.buettner@sun.com>
  *                 Philipp Kewisch <mozilla@kewis.ch>
  *                 Berend Cornelius <berend.cornelius@sun.com>
+ *                 Matthew Mecca <matthew.mecca@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -91,16 +92,18 @@ function addCategoryNames(aEvent) {
 }
 
 /**
  * Change the opening context menu for the selected tasks.
  *
  * @param aEvent    The popupshowing event of the opening menu.
  */
 function changeContextMenuForTask(aEvent) {
+    handleTaskContextMenuStateChange(aEvent);
+
     let idnode = document.popupNode.id;
     let sunbird = cal.isSunbird();
     let items = getSelectedTasks(aEvent);
     document.getElementById("task-context-menu-new").hidden =
         (idnode == "unifinder-todo-tree" && !sunbird);
     document.getElementById("task-context-menu-modify").hidden =
         (idnode == "unifinder-todo-tree" && !sunbird);
     document.getElementById("task-context-menu-new-todaypane").hidden =
@@ -120,16 +123,29 @@ function changeContextMenuForTask(aEvent
 
     changeMenuForTask(aEvent);
 
     let menu = document.getElementById("task-context-menu-attendance-menu");
     setupAttendanceMenu(menu, items);
 }
 
 /**
+ * Notify the task tree that the context menu open state has changed.
+ *
+ * @param aEvent    The popupshowing or popuphiding event of the menu.
+ */
+function handleTaskContextMenuStateChange(aEvent) {
+    let tree = document.popupNode;
+
+    if (tree) {
+        tree.updateFocus();
+    }
+}
+
+/**
  * Change the opening menu for the selected tasks.
  *
  * @param aEvent    The popupshowing event of the opening menu.
  */
 function changeMenuForTask(aEvent) {
     let tasks = getSelectedTasks(aEvent);
     let tasksSelected = (tasks.length > 0);
     if (tasksSelected) {
--- a/calendar/base/content/calendar-task-tree.xml
+++ b/calendar/base/content/calendar-task-tree.xml
@@ -1154,35 +1154,53 @@
                 this.mFilter.endDate = this.getInitialDate().clone();
                 this.mFilter.endDate.addDuration(oneDay);
             }
 
             this.refresh();
         ]]></body>
       </method>
 
+      <method name="updateFocus">
+        <body><![CDATA[
+            let tree = document.getAnonymousElementByAttribute(this, "anonid", "calendar-task-tree");
+            let menuOpen = false;
+
+            // we need to consider the tree focused if the context menu is open.
+            if (this.hasAttribute("context")) {
+                let context = document.getElementById(this.getAttribute("context"));
+                if (context && context.state) {
+                    menuOpen = (context.state == "open") || (context.state == "showing");
+                }
+            }
+
+            let focused = (document.activeElement == tree) || menuOpen;
+
+            calendarController.onSelectionChanged({detail:(focused ? this.selectedTasks : [])});
+            calendarController.todo_tasktree_focused = focused;
+        ]]></body>
+      </method>
+
     </implementation>
 
     <handlers>
       <handler event="select"><![CDATA[
         this.mTreeView.onSelect(event);
         if (calendarController.todo_tasktree_focused) {
           calendarController.onSelectionChanged({detail:this.selectedTasks});
         }
       ]]></handler>
       <handler event="dblclick" button="0"><![CDATA[
         this.mTreeView.onDoubleClick(event);
       ]]></handler>
       <handler event="focus"><![CDATA[
-        calendarController.onSelectionChanged({detail:this.selectedTasks});
-        calendarController.todo_tasktree_focused = true;
+        this.updateFocus();
       ]]></handler>
       <handler event="blur"><![CDATA[
-        calendarController.onSelectionChanged({detail:[]});
-        calendarController.todo_tasktree_focused = false;
+        this.updateFocus();
       ]]></handler>
       <handler event="keypress"><![CDATA[
         this.mTreeView.onKeyPress(event);
       ]]></handler>
       <handler event="mousedown"><![CDATA[
         this.mTreeView.onMouseDown(event);
       ]]></handler>
       <handler event="draggesture"><![CDATA[