Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / components / InspectElementModeController.js
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  * @implements {WebInspector.TargetManager.Observer}
32  */
33 WebInspector.InspectElementModeController = function()
34 {
35     this._toggleSearchButton = new WebInspector.StatusBarButton(WebInspector.UIString("Select an element in the page to inspect it."), "node-search-status-bar-item");
36     this._shortcut = WebInspector.InspectElementModeController.createShortcut();
37     InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.EnterInspectElementMode, this._toggleSearch, this);
38     WebInspector.targetManager.observeTargets(this);
39 }
40
41 /**
42  * @return {!WebInspector.KeyboardShortcut.Descriptor}
43  */
44 WebInspector.InspectElementModeController.createShortcut = function()
45 {
46     return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
47 }
48
49 WebInspector.InspectElementModeController.prototype = {
50     /**
51      * @param {!WebInspector.Target} target
52      */
53     targetAdded: function(target)
54     {
55         // When DevTools are opening in the inspect element mode, the first target comes in
56         // much later than the InspectorFrontendAPI.enterInspectElementMode event.
57         if (this.enabled())
58             target.domModel.setInspectModeEnabled(true, WebInspector.settings.showUAShadowDOM.get());
59     },
60
61     /**
62      * @param {!WebInspector.Target} target
63      */
64     targetRemoved: function(target)
65     {
66     },
67
68     /**
69      * @return {boolean}
70      */
71     enabled: function()
72     {
73         return this._toggleSearchButton.toggled;
74     },
75
76     disable: function()
77     {
78         if (this.enabled())
79             this._toggleSearch();
80     },
81
82     _toggleSearch: function()
83     {
84         var enabled = !this.enabled();
85         this._toggleSearchButton.toggled = enabled;
86
87         var targets = WebInspector.targetManager.targets();
88         for (var i = 0; i < targets.length; ++i)
89             targets[i].domModel.setInspectModeEnabled(enabled, WebInspector.settings.showUAShadowDOM.get());
90     }
91 }
92
93 /**
94  * @constructor
95  * @implements {WebInspector.ActionDelegate}
96  */
97 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function()
98 {
99 }
100
101 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype = {
102     /**
103      * @return {boolean}
104      */
105     handleAction: function()
106     {
107         if (!WebInspector.inspectElementModeController)
108             return false;
109         WebInspector.inspectElementModeController._toggleSearch();
110         return true;
111     }
112 }
113
114 /**
115  * @constructor
116  * @implements {WebInspector.StatusBarItem.Provider}
117  */
118 WebInspector.InspectElementModeController.ToggleButtonProvider = function()
119 {
120 }
121
122 WebInspector.InspectElementModeController.ToggleButtonProvider.prototype = {
123     /**
124      * @return {?WebInspector.StatusBarItem}
125      */
126     item: function()
127     {
128         if (!WebInspector.inspectElementModeController)
129             return null;
130
131         return WebInspector.inspectElementModeController._toggleSearchButton;
132     }
133 }
134
135 /** @type {?WebInspector.InspectElementModeController} */
136 WebInspector.inspectElementModeController = null;