Changeset 187


Ignore:
Timestamp:
06/06/13 19:18:33 (6 years ago)
Author:
nhoyt
Message:

tree-view.js

  • Significantly expanded the comments section to explain use of prototype-based inheritance.
  • Added table param and properties/methods that utilize table, namely rowCount and getCellValue.

view-category.js

  • In TreeViewCategory? constructor, added call to TreeView? constructor.
  • Added call to inherits fn., which replaces the explicit setting of prototype and constructor properties, to implement prototype-based inheritance of TreeView? methods by TreeViewCategory? objects.
Location:
trunk/proto-13/chrome/content
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/proto-13/chrome/content/ff-overlay.js

    r184 r187  
    1414ainspector.utils = {}; 
    1515 
    16 // import Enum 
     16// import Enum and inherits 
    1717Components.utils.import("chrome://ai-sidebar/content/utilities/utils.js", ainspector.utils); 
    1818 
  • trunk/proto-13/chrome/content/tree-view.js

    r186 r187  
    22* @constructor TreeView 
    33* 
    4 * @desc Instantiate tree view object with shareable method implementations. 
     4* @desc Define TreeView object with minimal implementations of all shareable 
     5*       methods required by the XPCOM interface nsITreeView. This object can 
     6*       then be used via prototype-based inheritance by other tree-specific 
     7*       objects, which define non-shareable methods such as getCellText and 
     8*       getCellProperties. 
     9* 
     10*       Prototype-based inheritance can be implemented using this pattern: 
     11* 
     12*       1. var AnotherTreeView = function (args) { 
     13*                                  // call TreeView constructor 
     14*                                  TreeView.call(this, args); 
     15*                                  // define non-shareable methods 
     16*                                }; 
     17*       2. AnotherTreeView.prototype = Object.create(TreeView.prototype); 
     18*       3. AnotherTreeView.prototype.constructor = AnotherTreeView; 
     19* 
     20* @param table - Array of table row data objects 
    521*/ 
    622 
    7 var TreeView = function () {}; 
     23var TreeView = function (table) { 
     24  this.rowCount = table.length; 
     25  this.getCellValue = function (row, col) { return table[row][col.id]; }; 
     26}; 
    827 
    9 TreeView.prototype.setTree = function (treebox) { this.treebox = treebox; }; 
     28TreeView.prototype.cycleHeader = function (col, elem) {}; 
     29TreeView.prototype.getImageSrc = function (row, col) { return null; }; 
     30TreeView.prototype.getLevel = function (row) { return 0; }; 
     31TreeView.prototype.getColumnProperties = function (col, props) {}; 
     32TreeView.prototype.getRowProperties = function (row, props) {}; 
     33TreeView.prototype.isContainer = function (row) { return false; }; 
    1034TreeView.prototype.isEditable = function (row, col) { return col.editable;  }; 
    11 TreeView.prototype.isContainer = function (row) { return false; }; 
    1235TreeView.prototype.isSeparator = function (row) { return false; }; 
    1336TreeView.prototype.isSorted = function () { return false; }; 
    14 TreeView.prototype.getLevel = function (row) { return 0; }; 
    15 TreeView.prototype.getImageSrc = function (row, col) { return null; }; 
    16 TreeView.prototype.getRowProperties = function (row, props) {}; 
    17 TreeView.prototype.getColumnProperties = function (colid, col, props) {}; 
    18 TreeView.prototype.cycleHeader = function (col, elem) {}; 
     37TreeView.prototype.setTree = function (treebox) { this.treebox = treebox; }; 
  • trunk/proto-13/chrome/content/view-category.js

    r186 r187  
    11/** 
    2  * @file view-category.js 
    3  * 
    4  * @desc Define properties and methods for display of rule category information. 
    5  */ 
     2* @file view-category.js 
     3* 
     4* @desc Define properties and methods for display of rule category information. 
     5*/ 
    66 
    77Components.utils.import("chrome://ai-sidebar/content/ai-common.js"); 
    88 
    99/** 
    10  * @namespace ainspectorSidebar 
    11  */ 
     10* @namespace ainspectorSidebar 
     11*/ 
    1212var ainspectorSidebar = ainspectorSidebar || {}; 
    1313 
     
    3131 
    3232/** 
    33  * @function getRuleResultStrings 
    34  * 
    35  * @memberOf ainspectorSidebar 
    36  * 
    37  * @desc  
    38  */ 
     33* @function getRuleResultStrings 
     34* 
     35* @memberOf ainspectorSidebar 
     36* 
     37* @desc  
     38*/ 
    3939 
    4040ainspectorSidebar.getRuleResultStrings = function () { 
     
    5151 
    5252/** 
    53  * @function getRulesData 
    54  * 
    55  * @memberOf ainspectorSidebar 
    56  * 
    57  * @desc  
    58  */ 
     53* @function getRulesData 
     54* 
     55* @memberOf ainspectorSidebar 
     56* 
     57* @desc  
     58*/ 
    5959 
    6060ainspectorSidebar.getRulesData = function () { 
     
    8282 
    8383/** 
    84  * @constructor TreeViewCategory 
    85  * 
    86  * @memberOf ainspectorSidebar 
    87  * 
    88  * @augments TreeView (inherits from its prototype) 
    89  * 
    90  * @desc Define property rowCount and methods getCellText, getCellValue and 
    91  *       getCellProperties. Inherit all other methods from TreeView object. 
    92  */ 
     84* @constructor TreeViewCategory 
     85* 
     86* @memberOf ainspectorSidebar 
     87* 
     88* @augments TreeView (using prototype-based inheritance via the inherits fn.) 
     89* 
     90* @desc Define methods getCellText and getCellProperties. Inherit all other 
     91*       methods and properties from the TreeView object. 
     92* 
     93* @param table - Array of table row data objects 
     94*/ 
    9395 
    9496ainspectorSidebar.TreeViewCategory = function (table) { 
    95   // call the TreeView constructor (not strictly necessary for stub fn.) 
    96   // ainspectorSidebar.TreeView.call(this); 
     97  // call the parent constructor 
     98  ainspectorSidebar.TreeView.call(this, table); 
    9799 
    98100  var resultStrings = ainspectorSidebar.getRuleResultStrings(); 
    99101 
    100   // define properties and methods specific to this constructor 
    101   this.rowCount = table.length; 
    102  
     102  // Used by getCellProperties (but obsolete starting with Firefox 22) 
     103  var atomService = Components.classes["@mozilla.org/atom-service;1"]. 
     104                    getService(Components.interfaces.nsIAtomService); 
     105 
     106  // define methods specific to this particular tree view 
    103107  this.getCellText = function (row, col) {  
    104108    var value = table[row][col.id]; 
     
    130134  }; 
    131135 
    132   this.getCellValue = function (row, col) { return table[row][col.id]; }; 
    133  
    134136  this.getCellProperties = function (row, col, props) { 
    135     if (col.id === "ainspector-level-col" || col.id === "ainspector-required-col") { 
    136       var service = Components.classes["@mozilla.org/atom-service;1"]. 
    137                     getService(Components.interfaces.nsIAtomService); 
    138       props.AppendElement(service.getAtom("inner")); 
    139     } 
    140     if (col.id === "ainspector-viol-col" || col.id === "ainspector-mc-col" || col.id === "ainspector-pass-col") { 
    141       var service = Components.classes["@mozilla.org/atom-service;1"]. 
    142                     getService(Components.interfaces.nsIAtomService); 
    143       props.AppendElement(service.getAtom("numeric")); 
     137    switch (col.id) { 
     138      case "ainspector-level-col": 
     139      case "ainspector-required-col": 
     140      case "ainspector-wcag-sc-col": 
     141        props.AppendElement(atomService.getAtom("inner")); 
     142        break; 
     143      case "ainspector-viol-col": 
     144      case "ainspector-mc-col": 
     145      case "ainspector-pass-col": 
     146        props.AppendElement(atomService.getAtom("numeric")); 
     147        break; 
    144148    } 
    145149  }; 
    146150}; 
    147151 
    148 // Inherit the TreeView methods by setting the prototype property. 
    149 // Note: In this particular case, the value for the prototype property is 
    150 // an object created from another prototype object, which is the safe way of 
    151 // inheriting (prototypal inheritance). Using an object literal with its own 
    152 // instance properties as a prototype can cause unexpected side effects. 
    153  
    154 ainspectorSidebar.TreeViewCategory.prototype = Object.create(ainspectorSidebar.TreeView.prototype); 
    155  
    156 // The constructor property is used mainly for introspection, so not absolutely necessary to reset. 
    157 // ainspectorSidebar.TreeViewCategory.prototype.constructor = ainspectorSidebar.TreeViewCategory; 
    158  
    159 // An alternate way of setting prototype property, but involves unnecessary constructor call. 
    160 // ainspectorSidebar.TreeViewCategory.prototype = new ainspectorSidebar.TreeView(); 
    161  
    162 /** 
    163  * @function sortRulesTable 
    164  * 
    165  * @memberOf ainspectorSidebar 
    166  * 
    167  * @desc  
    168  */ 
     152// Finalize the definition of TreeViewCategory by inheriting the TreeView methods. 
     153ainspector.utils.inherits(ainspectorSidebar.TreeViewCategory, ainspectorSidebar.TreeView); 
     154 
     155/** 
     156* @function sortRulesTable 
     157* 
     158* @memberOf ainspectorSidebar 
     159* 
     160* @desc  
     161*/ 
    169162 
    170163ainspectorSidebar.sortRulesTable = function (column) { 
     
    244237 
    245238/** 
    246  * @function defaultSort 
    247  * 
    248  * @memberOf ainspectorSidebar 
    249  * 
    250  * @desc  
    251  */ 
     239* @function defaultSort 
     240* 
     241* @memberOf ainspectorSidebar 
     242* 
     243* @desc  
     244*/ 
    252245 
    253246ainspectorSidebar.defaultSort = function () { 
     
    259252 
    260253/** 
    261  * @function setCategoryView 
    262  * 
    263  * @memberOf ainspectorSidebar 
    264  * 
    265  * @desc  
    266  */ 
     254* @function setCategoryView 
     255* 
     256* @memberOf ainspectorSidebar 
     257* 
     258* @desc  
     259*/ 
    267260 
    268261ainspectorSidebar.setCategoryView = function () { 
     
    284277 
    285278/** 
    286  * @function clearCategoryView 
    287  * 
    288  * @memberOf ainspectorSidebar 
    289  * 
    290  * @desc  
    291  */ 
     279* @function clearCategoryView 
     280* 
     281* @memberOf ainspectorSidebar 
     282* 
     283* @desc  
     284*/ 
    292285 
    293286ainspectorSidebar.clearCategoryView = function () { 
     
    306299 
    307300/** 
    308  * @function updateSelectedRuleInfo 
    309  * 
    310  * @memberOf ainspectorSidebar 
    311  * 
    312  * @desc  
    313  */ 
     301* @function updateSelectedRuleInfo 
     302* 
     303* @memberOf ainspectorSidebar 
     304* 
     305* @desc  
     306*/ 
    314307 
    315308ainspectorSidebar.updateSelectedRuleInfo = function (tree) { 
     
    354347 
    355348/** 
    356  * @function handleRCTreeEvent 
    357  * 
    358  * @memberOf ainspectorSidebar 
    359  * 
    360  * @desc Handle dblclick and keypress events when row is selected. If user 
    361  *       double-clicks a row, or presses return, enter or spacebar when a 
    362  *       row is selected, go to Rule Details view. 
    363  */ 
     349* @function handleRCTreeEvent 
     350* 
     351* @memberOf ainspectorSidebar 
     352* 
     353* @desc Handle dblclick and keypress events when row is selected. If user 
     354*       double-clicks a row, or presses return, enter or spacebar when a 
     355*       row is selected, go to Rule Details view. 
     356*/ 
    364357 
    365358ainspectorSidebar.handleRCTreeEvent = function (event) { 
Note: See TracChangeset for help on using the changeset viewer.