Web Inspector: Remove redundant tooltips
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / DOMBreakpointTreeElement.js
1 /*
2  * Copyright (C) 2017 Apple 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WI.DOMBreakpointTreeElement = class DOMBreakpointTreeElement extends WI.GeneralTreeElement
27 {
28     constructor(breakpoint, className, title)
29     {
30         console.assert(breakpoint instanceof WI.DOMBreakpoint);
31
32         if (!className)
33             className = WI.BreakpointTreeElement.GenericLineIconStyleClassName;
34
35         if (!title)
36             title = WI.DOMBreakpointTreeElement.displayNameForType(breakpoint.type);
37
38         super(["breakpoint", className], title, null, breakpoint);
39
40         this._statusImageElement = document.createElement("img");
41         this._statusImageElement.classList.add("status-image", "resolved");
42         this.status = this._statusImageElement;
43         this.tooltipHandledSeparately = true;
44
45         breakpoint.addEventListener(WI.DOMBreakpoint.Event.DisabledStateDidChange, this._updateStatus, this);
46
47         this._updateStatus();
48     }
49
50     // Static
51
52     static displayNameForType(type)
53     {
54         switch (type) {
55         case WI.DOMBreakpoint.Type.SubtreeModified:
56             return WI.UIString("Subtree Modified");
57         case WI.DOMBreakpoint.Type.AttributeModified:
58             return WI.UIString("Attribute Modified");
59         case WI.DOMBreakpoint.Type.NodeRemoved:
60             return WI.UIString("Node Removed");
61         default:
62             console.error("Unexpected DOM breakpoint type: " + type);
63             return null;
64         }
65     }
66
67     // Protected
68
69     onattach()
70     {
71         super.onattach();
72
73         this._boundStatusImageElementClicked = this._statusImageElementClicked.bind(this);
74         this._boundStatusImageElementFocused = this._statusImageElementFocused.bind(this);
75         this._boundStatusImageElementMouseDown = this._statusImageElementMouseDown.bind(this);
76
77         this._statusImageElement.addEventListener("click", this._boundStatusImageElementClicked);
78         this._statusImageElement.addEventListener("focus", this._boundStatusImageElementFocused);
79         this._statusImageElement.addEventListener("mousedown", this._boundStatusImageElementMouseDown);
80     }
81
82     ondetach()
83     {
84         super.ondetach();
85
86         this._statusImageElement.removeEventListener("click", this._boundStatusImageElementClicked);
87         this._statusImageElement.removeEventListener("focus", this._boundStatusImageElementFocused);
88         this._statusImageElement.removeEventListener("mousedown", this._boundStatusImageElementMouseDown);
89
90         this._boundStatusImageElementClicked = null;
91         this._boundStatusImageElementFocused = null;
92         this._boundStatusImageElementMouseDown = null;
93     }
94
95     ondelete()
96     {
97         WI.domDebuggerManager.removeDOMBreakpoint(this.representedObject);
98         return true;
99     }
100
101     onenter()
102     {
103         this._toggleBreakpoint();
104         return true;
105     }
106
107     onspace()
108     {
109         this._toggleBreakpoint();
110         return true;
111     }
112
113     populateContextMenu(contextMenu, event)
114     {
115         let breakpoint = this.representedObject;
116         let label = breakpoint.disabled ? WI.UIString("Enable Breakpoint") : WI.UIString("Disable Breakpoint");
117         contextMenu.appendItem(label, this._toggleBreakpoint.bind(this));
118
119         contextMenu.appendSeparator();
120         contextMenu.appendItem(WI.UIString("Delete Breakpoint"), function() {
121             WI.domDebuggerManager.removeDOMBreakpoint(breakpoint);
122         });
123     }
124
125     // Private
126
127     _statusImageElementClicked(event)
128     {
129         this._toggleBreakpoint();
130     }
131
132     _statusImageElementFocused(event)
133     {
134         // Prevent tree outline focus.
135         event.stopPropagation();
136     }
137
138     _statusImageElementMouseDown(event)
139     {
140         // Prevent tree element selection.
141         event.stopPropagation();
142     }
143
144     _toggleBreakpoint()
145     {
146         this.representedObject.disabled = !this.representedObject.disabled;
147     }
148
149     _updateStatus()
150     {
151         this._statusImageElement.classList.toggle("disabled", this.representedObject.disabled);
152     }
153 };