Home | History | Annotate | Download | only in components
      1 /*
      2  * Copyright (C) 2013 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *
     11  * 2. Redistributions in binary form must reproduce the above
     12  * copyright notice, this list of conditions and the following disclaimer
     13  * in the documentation and/or other materials provided with the
     14  * distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
     17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
     20  * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 /**
     30  * @constructor
     31  */
     32 WebInspector.InspectElementModeController = function()
     33 {
     34     this._toggleSearchButton = new WebInspector.StatusBarButton(WebInspector.UIString("Select an element in the page to inspect it."), "node-search-status-bar-item");
     35     this._shortcut = WebInspector.InspectElementModeController.createShortcut();
     36     InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.EnterInspectElementMode, this._toggleSearch, this);
     37 }
     38 
     39 /**
     40  * @return {!WebInspector.KeyboardShortcut.Descriptor}
     41  */
     42 WebInspector.InspectElementModeController.createShortcut = function()
     43 {
     44     return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
     45 }
     46 
     47 WebInspector.InspectElementModeController.prototype = {
     48     /**
     49      * @return {boolean}
     50      */
     51     enabled: function()
     52     {
     53         return this._toggleSearchButton.toggled;
     54     },
     55 
     56     disable: function()
     57     {
     58         if (this.enabled())
     59             this._toggleSearch();
     60     },
     61 
     62     _toggleSearch: function()
     63     {
     64         var enabled = !this.enabled();
     65         this._toggleSearchButton.toggled = enabled;
     66 
     67         var targets = WebInspector.targetManager.targets();
     68         for (var i = 0; i < targets.length; ++i)
     69             targets[i].domModel.setInspectModeEnabled(enabled, WebInspector.settings.showUAShadowDOM.get());
     70     }
     71 }
     72 
     73 /**
     74  * @constructor
     75  * @implements {WebInspector.ActionDelegate}
     76  */
     77 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function()
     78 {
     79 }
     80 
     81 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype = {
     82     /**
     83      * @return {boolean}
     84      */
     85     handleAction: function()
     86     {
     87         if (!WebInspector.inspectElementModeController)
     88             return false;
     89         WebInspector.inspectElementModeController._toggleSearch();
     90         return true;
     91     }
     92 }
     93 
     94 /**
     95  * @constructor
     96  * @implements {WebInspector.StatusBarItem.Provider}
     97  */
     98 WebInspector.InspectElementModeController.ToggleButtonProvider = function()
     99 {
    100 }
    101 
    102 WebInspector.InspectElementModeController.ToggleButtonProvider.prototype = {
    103     /**
    104      * @return {?WebInspector.StatusBarItem}
    105      */
    106     item: function()
    107     {
    108         if (!WebInspector.inspectElementModeController)
    109             return null;
    110 
    111         return WebInspector.inspectElementModeController._toggleSearchButton;
    112     }
    113 }
    114 
    115 /** @type {?WebInspector.InspectElementModeController} */
    116 WebInspector.inspectElementModeController = null;
    117