Changeset 258


Ignore:
Timestamp:
12/09/13 16:33:41 (6 years ago)
Author:
nhoyt
Message:

Overview: Now using a factory function, getTreeEventHandler, to initialize the ondblclick and onkeypress handlers for both the Rule Category and Element Results trees.

element-results.js

  • Added handleERTreeEvent fn., initialized by calling generic getTreeEventHandler fn. with appropriate callback.

tree-event.js

  • Converted the function handleTreeEvent into a factory function, getTreeEventHandler, that returns a handler function with an action callback predefined.

view-category.js

  • Reinstated handleRCTreeEvent fn., but now initialized by call to getTreeEventHandler.

view-category.xul

  • Changed ainspector-rule-category-tree ondlbclick and onkeypress values to handleRCTreeEvent.

view-details.xul

  • Changed ainspector-element-results-tree ondlbclick and onkeypress values to handleERTreeEvent.
Location:
trunk/proto-15/chrome/content
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/proto-15/chrome/content/element-results.js

    r257 r258  
    1717  .loadSubScript("chrome://ai-sidebar/content/tree-sort.js", ainspectorSidebar); 
    1818 
    19 // Load the handleTreeEvent function 
     19// Load the getTreeEventHandler function 
    2020Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 
    2121  .getService(Components.interfaces.mozIJSSubScriptLoader) 
     
    417417  } 
    418418}; 
     419 
     420/** 
     421 * @function handleERTreeEvent 
     422 * 
     423 * @memberOf ainspectorSidebar 
     424 * 
     425 * @desc Handle dblclick and keypress events when row is selected. If user 
     426 *       double-clicks a row, or presses return, enter or spacebar when a 
     427 *       row is selected, open the Firefox Inspector. 
     428 */ 
     429 
     430ainspectorSidebar.handleERTreeEvent = 
     431  ainspectorSidebar.getTreeEventHandler(ainspectorSidebar.inspectSelectedElement); 
  • trunk/proto-15/chrome/content/tree-event.js

    r257 r258  
    11/** 
    2  * @function handleTreeEvent 
     2 * @function getTreeEventHandler 
    33 * 
    4  * @desc Handle dblclick and keypress events when row is selected. If user 
    5  *       double-clicks a row, or presses return, enter or spacebar when a 
    6  *       row is selected, go to Rule Details view. 
     4 * @desc Return a function that takes an event argument and handles dblclick 
     5 *       and keypress events when a tree row is selected. If the user double- 
     6 *       clicks a row, or presses return, enter or spacebar when a row is 
     7 *       selected, the handler calls the function specified by callback. 
     8 * 
     9 * @param callback - Reference to callback function that is called by the 
     10 *                   handler when the event criteria are met. 
    711 */ 
    812 
    9 var handleTreeEvent = function (event, flag) { 
    10   var tree = event.currentTarget; 
    11   var index = tree.currentIndex; 
    12   var isRowSelected = tree.view.selection.isSelected(index); 
    13   var tbo = tree.treeBoxObject; 
    14   var callback = null; 
     13var getTreeEventHandler = function (callback) { 
     14  return function (event) { 
     15    var tree = event.currentTarget; 
     16    var index = tree.currentIndex; 
     17    var isRowSelected = tree.view.selection.isSelected(index); 
     18    var tbo = tree.treeBoxObject; 
    1519 
    16   // do nothing when no row is selected 
    17   if (!isRowSelected) return; 
     20    // do nothing when no row is selected 
     21    if (!isRowSelected) return; 
    1822 
    19   switch (flag) { 
    20     case 1: // Rule Results tree 
    21       callback = function () { ainspectorSidebar.selectView(ainspector.viewConst.DETAILS) }; 
    22       break; 
    23     case 2: // Element Results tree 
    24       callback = ainspectorSidebar.inspectSelectedElement; 
    25       break; 
    26   } 
    27  
    28   switch (event.type) { 
    29     case "dblclick": 
    30       // user must dblclick on an actual row 
    31       var row = { }, col = { }, child = { }; 
    32       tbo.getCellAt(event.clientX, event.clientY, row, col, child); 
    33       if (row.value !== -1) 
    34         callback(); 
    35       break; 
    36     case "keypress": 
    37       // handle return (13), enter (3) and spacebar (32) keypress 
    38       if (event.keyCode === 13  || event.keyCode === 3 || event.charCode === 32) 
    39         callback(); 
    40       break; 
    41   } 
     23    switch (event.type) { 
     24      case "dblclick": 
     25        // user must dblclick on an actual row 
     26        var row = { }, col = { }, child = { }; 
     27        tbo.getCellAt(event.clientX, event.clientY, row, col, child); 
     28        if (row.value !== -1) 
     29          callback(); 
     30        break; 
     31      case "keypress": 
     32        // handle return (13), enter (3) and spacebar (32) keypress 
     33        if (event.keyCode === 13  || event.keyCode === 3 || event.charCode === 32) 
     34          callback(); 
     35        break; 
     36    } 
     37  }; 
    4238}; 
    43  
    44 var handleTreeEventOld = function (event) { 
    45   var tree = null; 
    46   var callback = null; 
    47   switch (event.currentTarget.id) { 
    48     case "ainspector-rule-category-tree": 
    49       tree = ainspectorSidebar.ruleCategoryTree; 
    50       callback = function () { ainspectorSidebar.selectView(ainspector.viewConst.DETAILS) }; 
    51       break; 
    52     case "ainspector-element-results-tree": 
    53       tree = ainspectorSidebar.elementResultsTree; 
    54       callback = ainspectorSidebar.inspectSelectedElement; 
    55       break; 
    56   } 
    57  
    58   if (tree === null) return; 
    59   var tbo = tree.treeBoxObject; 
    60   var index = tree.currentIndex; 
    61   var isRowSelected = tree.view.selection.isSelected(index); 
    62  
    63   // do nothing when no row is selected 
    64   if (!isRowSelected) return; 
    65  
    66   switch (event.type) { 
    67     case "dblclick": 
    68       // user must dblclick on an actual row 
    69       var row = { }, col = { }, child = { }; 
    70       tbo.getCellAt(event.clientX, event.clientY, row, col, child); 
    71       if (row.value !== -1) 
    72         callback(); 
    73       break; 
    74     case "keypress": 
    75       // handle return (13), enter (3) and spacebar (32) keypress 
    76       if (event.keyCode === 13  || event.keyCode === 3 || event.charCode === 32) 
    77         callback(); 
    78       break; 
    79   } 
    80 }; 
  • trunk/proto-15/chrome/content/view-category.js

    r257 r258  
    2222  .loadSubScript("chrome://ai-sidebar/content/tree-sort.js", ainspectorSidebar); 
    2323 
    24 // Load the handleTreeEvent function 
     24// Load the getTreeEventHandler function 
    2525Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 
    2626  .getService(Components.interfaces.mozIJSSubScriptLoader) 
     
    361361  } 
    362362}; 
     363 
     364/** 
     365 * @function handleRCTreeEvent 
     366 * 
     367 * @memberOf ainspectorSidebar 
     368 * 
     369 * @desc Handle dblclick and keypress events when row is selected. If user 
     370 *       double-clicks a row, or presses return, enter or spacebar when a 
     371 *       row is selected, go to Rule Details view. 
     372 */ 
     373 
     374ainspectorSidebar.handleRCTreeEvent = ainspectorSidebar.getTreeEventHandler( 
     375  function () { ainspectorSidebar.selectView(ainspector.viewConst.DETAILS) }); 
  • trunk/proto-15/chrome/content/view-category.xul

    r257 r258  
    4545      sortResource="ainspector-result-col" 
    4646      onselect="ainspectorSidebar.updateSelectedRuleInfo(this)" 
    47       ondblclick="ainspectorSidebar.handleTreeEvent(event, 1)" 
    48       onkeypress="ainspectorSidebar.handleTreeEvent(event, 1)"> 
     47      ondblclick="ainspectorSidebar.handleRCTreeEvent(event)" 
     48      onkeypress="ainspectorSidebar.handleRCTreeEvent(event)"> 
    4949      <treecols> 
    5050        <treecol id="ainspector-rule-col" 
  • trunk/proto-15/chrome/content/view-details.xul

    r257 r258  
    3838            hidecolumnpicker="true" 
    3939            onselect="ainspectorSidebar.updateSelectedElement(this)" 
    40             ondblclick="ainspectorSidebar.handleTreeEvent(event, 2)" 
    41             onkeypress="ainspectorSidebar.handleTreeEvent(event, 2)"> 
     40            ondblclick="ainspectorSidebar.handleERTreeEvent(event)" 
     41            onkeypress="ainspectorSidebar.handleERTreeEvent(event)"> 
    4242            <treecols> 
    4343              <treecol id="ainspector-element-col" 
Note: See TracChangeset for help on using the changeset viewer.