Changeset 255


Ignore:
Timestamp:
11/28/13 01:14:09 (6 years ago)
Author:
nhoyt
Message:
  • New prototype version: 0.15.0
  • Added Inspect Element button in Rule Details views to invoke Firefox Inspector on element selected in Element Results table.
Location:
trunk/proto-15
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/proto-15/chrome/content/ai-sidebar.js

    r250 r255  
    2727}; 
    2828 
     29// import Page Inspector modules: devtools and gDevTools 
     30Components.utils.import("resource://gre/modules/devtools/Loader.jsm", ainspectorSidebar); 
     31Components.utils.import("resource:///modules/devtools/gDevTools.jsm", ainspectorSidebar); 
     32 
    2933/** 
    3034 * @function showTransition 
     
    150154  // initialize user interface components 
    151155  ainspectorSidebar.elementResultsTree    = document.getElementById("ainspector-element-results-tree"); 
     156  ainspectorSidebar.inspectElementButton  = document.getElementById("ainspector-inspect-element"); 
    152157  ainspectorSidebar.locationInfo          = document.getElementById("ainspector-location-info"); 
    153158  ainspectorSidebar.locationLabel         = document.getElementById("ainspector-location-label"); 
     
    302307 
    303308/** 
     309 * @function closePageInspector 
     310 * 
     311 * @memberOf ainspectorSidebar 
     312 * 
     313 * @desc Called when view is changed or sidebar is closed. 
     314 */ 
     315 
     316ainspectorSidebar.closePageInspector = function () { 
     317  let devtools  = ainspectorSidebar.devtools; 
     318  let gDevTools = ainspectorSidebar.gDevTools; 
     319  let gBrowser = parent.gBrowser; 
     320  let target = devtools.TargetFactory.forTab(gBrowser.selectedTab); 
     321 
     322  gDevTools.closeToolbox(target); 
     323}; 
     324 
     325/** 
    304326 * @function updateView 
    305327 * 
     
    313335  ainspector.log.debug("updateView: " + ainspector.getViewName(parent.AINSPECTOR.currentView)); 
    314336 
     337  ainspectorSidebar.closePageInspector(); 
    315338  ainspectorSidebar.viewTitle.value = ainspectorSidebar.getViewTitle(parent.AINSPECTOR.currentView); 
    316339 
     
    382405  ainspector.log.debug("selectPreviousView: " + ainspector.getViewName(parent.AINSPECTOR.previousView)); 
    383406 
     407  ainspectorSidebar.closePageInspector(); 
     408 
    384409  // remove highlighting 
    385410  ainspectorSidebar.highlightModule.removeHighlight(content.document); 
     
    484509  ainspectorSidebar.highlightModule.removeHighlight(content.document); 
    485510 
     511  // close Page Inspector 
     512  ainspectorSidebar.closePageInspector() 
     513 
    486514  // unregister progressListener 
    487515  parent.gBrowser.removeProgressListener(ainspectorSidebar.progressListener); 
  • trunk/proto-15/chrome/content/element-results.js

    r252 r255  
    214214 
    215215/** 
     216 * @function getDomElementNode 
     217 * 
     218 * @memberOf ainspectorSidebar 
     219 * 
     220 * @desc Get the DOM node from nodeResult 
     221 * 
     222 * @param {Object} - NodeResult object 
     223 * 
     224 * @returns {Object} - DOM node 
     225 */ 
     226 
     227ainspectorSidebar.getDomElementNode = function (nodeResult) { 
     228  var cacheItem  = nodeResult.getCacheItem(); 
     229 
     230  // Get DOMElement object: If cacheItem does not have dom_element property 
     231  // referencing an object, then cacheItem is itself a DOMElement. 
     232  var dom_element = (typeof cacheItem.dom_element === 'object') ? 
     233                    cacheItem.dom_element : cacheItem; 
     234   
     235  // If DOMElement type is TEXT_NODE then use its parent element, since 
     236  // that is where its computed style and tag name would come from. 
     237  if (dom_element.type === Node.TEXT_NODE) dom_element = dom_element.parent_element; 
     238 
     239  return dom_element.node; 
     240}; 
     241 
     242/** 
     243 * @function inspectNode 
     244 * 
     245 * @memberOf ainspectorSidebar  
     246 * 
     247 * @desc Invoke the Page Inspector on the specified DOM node. 
     248 */ 
     249 
     250ainspectorSidebar.inspectNode = function (node) { 
     251  let devtools  = ainspectorSidebar.devtools; 
     252  let gDevTools = ainspectorSidebar.gDevTools; 
     253  let gBrowser = parent.gBrowser; 
     254  let target = devtools.TargetFactory.forTab(gBrowser.selectedTab); 
     255 
     256  gDevTools.showToolbox(target, "inspector").then(function (toolbox) { 
     257    let inspector = toolbox.getCurrentPanel(); 
     258    inspector.selection.setNode(node, "browser-context-menu"); 
     259  }); 
     260}; 
     261 
     262/** 
     263 * @function inspectSelectedElement 
     264 * 
     265 * @memberOf  ainspectorSidebar 
     266 * 
     267 * @desc Event handler attached to Inspect Element button. The button is 
     268 *       enabled only if a row is selected in the Element Results tree. 
     269 */ 
     270 
     271ainspectorSidebar.inspectSelectedElement = function () { 
     272  let inspectorEnabled = Application.prefs.getValue("devtools.inspector.enabled",false); 
     273  if (!inspectorEnabled) { 
     274    var nls = ainspectorSidebar.nlsProperties; 
     275    var title = nls.getString("inspector.notEnabled.title"); 
     276    var message = nls.getString("inspector.notEnabled.message"); 
     277    var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] 
     278                        .getService(Components.interfaces.nsIPromptService); 
     279    promptService.alert(null, title, message); 
     280    return; 
     281  } 
     282   
     283  var tree = ainspectorSidebar.elementResultsTree; 
     284  var index = tree.currentIndex; 
     285  var isRowSelected = tree.view.selection.isSelected(index); 
     286 
     287  if (isRowSelected) { 
     288    var nodeResult = ainspectorSidebar.elementResultsTable[index].nodeResult; 
     289    var node = ainspectorSidebar.getDomElementNode(nodeResult); 
     290    ainspectorSidebar.inspectNode(node); 
     291  } 
     292}; 
     293 
     294/** 
     295 * @function updatePageInspector 
     296 * 
     297 * @memberOf  ainspectorSidebar 
     298 * 
     299 * @desc Similar functionality to inspectNode, except that the function 
     300 *       does nothing unless the Page Inspector is already visible. 
     301 */ 
     302 
     303ainspectorSidebar.updatePageInspector = function (node) { 
     304  let devtools  = ainspectorSidebar.devtools; 
     305  let gDevTools = ainspectorSidebar.gDevTools; 
     306  let gBrowser = parent.gBrowser; 
     307  let target = devtools.TargetFactory.forTab(gBrowser.selectedTab); 
     308 
     309  let toolbox = gDevTools.getToolbox(target); 
     310  if (toolbox) { 
     311    gDevTools.showToolbox(target, "inspector").then(function (toolbox) { 
     312      let inspector = toolbox.getCurrentPanel(); 
     313      inspector.selection.setNode(node, "browser-context-menu"); 
     314    }); 
     315  } 
     316}; 
     317 
     318/** 
    216319 * @function updateSelectedElement 
    217320 * 
     
    226329  var highlightOption = document.getElementById("ainspector-highlight-option").value; 
    227330 
    228   if (isRowSelected && highlightOption === "1") { 
     331  // Set state of Inspect Element button 
     332  ainspectorSidebar.inspectElementButton.disabled = isRowSelected ? false : true; 
     333 
     334  if (isRowSelected) { 
    229335    var nodeResult = ainspectorSidebar.elementResultsTable[index].nodeResult; 
    230     ainspectorSidebar.highlightModule.highlightNodeResults(content.document, nodeResult); 
     336   
     337    // Highlight selected element if Selected option is active 
     338    if (highlightOption === "1") { 
     339      ainspectorSidebar.highlightModule.highlightNodeResults(content.document, nodeResult); 
     340    } 
     341 
     342    // Update Page Inspector if it is visible 
     343    var node = ainspectorSidebar.getDomElementNode(nodeResult); 
     344    ainspectorSidebar.updatePageInspector(node); 
    231345  } 
    232346}; 
     
    247361  var highlightOption = document.getElementById("ainspector-highlight-option").value; 
    248362 
    249   // remove previous highlighting 
     363  // Remove previous highlighting 
    250364  ainspectorSidebar.highlightModule.removeHighlight(content.document); 
    251365 
  • trunk/proto-15/chrome/content/view-details.js

    r227 r255  
    4747  ainspectorSidebar.setDetailsRuleInfoContent(ruleResult); 
    4848 
     49  // set initial state of Inspect Element button 
     50  ainspectorSidebar.inspectElementButton.disabled = true; 
     51 
    4952  // update highlighting 
    5053  ainspectorSidebar.updateHighlight(); 
     
    8184  var summary = ainspectorSidebar.ruleDetailsSummary; 
    8285  summary.setData(ainspector.nullData); 
     86 
     87  // close Page Inspector and disable Inspect Element button 
     88  ainspectorSidebar.closePageInspector() 
     89  ainspectorSidebar.inspectElementButton.disabled = true; 
    8390}; 
    8491 
  • trunk/proto-15/chrome/content/view-details.xul

    r252 r255  
    111111          image="chrome://ai-sidebar/skin/back-button.png" 
    112112          tooltiptext="&ai-button.tooltip.backToCategory;" 
    113           style="margin-left: 0px; min-width: 0" 
     113          style="margin-left: 0px; margin-right: 0; min-width: 0" 
    114114          oncommand="ainspectorSidebar.selectPreviousView()"/> 
    115         <spacer flex="4"/> 
     115        <button 
     116          id="ainspector-inspect-element" 
     117          label="Inspect Element" 
     118          style="margin-left: 2px; min-width: 0" 
     119          oncommand="ainspectorSidebar.inspectSelectedElement()"/> 
     120        <spacer flex="1"/> 
    116121        <description>Highlight: </description> 
    117122        <menulist id="ainspector-highlight-option" 
  • trunk/proto-15/chrome/locale/en-US/ai-sidebar.properties

    r250 r255  
    8484option.recommended-rules.yes = Included 
    8585option.recommended-rules.no  = Excluded 
     86 
     87inspector.notEnabled.title = Firefox Inspector Not Enabled 
     88inspector.notEnabled.message = Please enable the Firefox Inspector to use the \u2035Inspect Element\u2032 feature. 
  • trunk/proto-15/install.rdf

    r250 r255  
    1010        <em:name>AInspector Sidebar</em:name> 
    1111        <em:type>2</em:type> 
    12         <em:version>0.14.4</em:version> 
     12        <em:version>0.15.0</em:version> 
    1313 
    1414        <em:targetApplication> 
Note: See TracChangeset for help on using the changeset viewer.