Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 31 | import * as Common from '../common/common.js'; |
| 32 | import * as SDK from '../sdk/sdk.js'; |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 33 | import * as Sources from '../sources/sources.js'; |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 34 | import * as UI from '../ui/ui.js'; |
| 35 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 36 | /** |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 37 | * @implements {UI.ContextFlavorListener.ContextFlavorListener} |
| 38 | * @implements {UI.ListControl.ListDelegate<!SDK.DOMDebuggerModel.DOMBreakpoint>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 39 | */ |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 40 | export class DOMBreakpointsSidebarPane extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 41 | constructor() { |
| 42 | super(true); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame] | 43 | this.registerRequiredCSS('browser_debugger/domBreakpointsSidebarPane.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 44 | |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 45 | /** @type {!WeakMap<!Element, !HTMLInputElement>} */ |
| 46 | this.elementToCheckboxes = new WeakMap(); |
| 47 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 48 | this._emptyElement = this.contentElement.createChild('div', 'gray-info-message'); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 49 | this._emptyElement.textContent = Common.UIString.UIString('No breakpoints'); |
| 50 | /** @type {!UI.ListModel.ListModel.<!SDK.DOMDebuggerModel.DOMBreakpoint>} */ |
| 51 | this._breakpoints = new UI.ListModel.ListModel(); |
| 52 | /** @type {!UI.ListControl.ListControl.<!SDK.DOMDebuggerModel.DOMBreakpoint>} */ |
| 53 | this._list = new UI.ListControl.ListControl(this._breakpoints, this, UI.ListControl.ListMode.NonViewport); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 54 | this.contentElement.appendChild(this._list.element); |
| 55 | this._list.element.classList.add('breakpoint-list', 'hidden'); |
| 56 | UI.ARIAUtils.markAsList(this._list.element); |
| 57 | UI.ARIAUtils.setAccessibleName(this._list.element, ls`DOM Breakpoints list`); |
| 58 | this._emptyElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 59 | |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 60 | SDK.SDKModel.TargetManager.instance().addModelListener( |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 61 | SDK.DOMDebuggerModel.DOMDebuggerModel, SDK.DOMDebuggerModel.Events.DOMBreakpointAdded, this._breakpointAdded, |
| 62 | this); |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 63 | SDK.SDKModel.TargetManager.instance().addModelListener( |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 64 | SDK.DOMDebuggerModel.DOMDebuggerModel, SDK.DOMDebuggerModel.Events.DOMBreakpointToggled, |
| 65 | this._breakpointToggled, this); |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 66 | SDK.SDKModel.TargetManager.instance().addModelListener( |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 67 | SDK.DOMDebuggerModel.DOMDebuggerModel, SDK.DOMDebuggerModel.Events.DOMBreakpointsRemoved, |
| 68 | this._breakpointsRemoved, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 70 | for (const domDebuggerModel of SDK.SDKModel.TargetManager.instance().models( |
| 71 | SDK.DOMDebuggerModel.DOMDebuggerModel)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 72 | domDebuggerModel.retrieveDOMBreakpoints(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 73 | for (const breakpoint of domDebuggerModel.domBreakpoints()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 74 | this._addBreakpoint(breakpoint); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 75 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | } |
| 77 | |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 78 | this._highlightedBreakpoint = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | this._update(); |
| 80 | } |
| 81 | |
| 82 | /** |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 83 | * @override |
| 84 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} item |
| 85 | * @return {!Element} |
| 86 | */ |
| 87 | createElementForItem(item) { |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 88 | const element = document.createElement('div'); |
| 89 | element.classList.add('breakpoint-entry'); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 90 | element.addEventListener('contextmenu', this._contextMenu.bind(this, item), true); |
| 91 | UI.ARIAUtils.markAsListitem(element); |
Christy Chen | d05ba96 | 2020-06-05 23:12:25 | [diff] [blame] | 92 | element.tabIndex = -1; |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 93 | |
Michael Liao | e7d3fb5 | 2020-10-01 21:44:04 | [diff] [blame] | 94 | const checkboxLabel = UI.UIUtils.CheckboxLabel.create(/* title */ undefined, item.enabled); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 95 | const checkboxElement = checkboxLabel.checkboxElement; |
| 96 | checkboxElement.addEventListener('click', this._checkboxClicked.bind(this, item), false); |
Christy Chen | d05ba96 | 2020-06-05 23:12:25 | [diff] [blame] | 97 | checkboxElement.tabIndex = this._list.selectedItem() === item ? 0 : -1; |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 98 | this.elementToCheckboxes.set(element, checkboxElement); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 99 | element.appendChild(checkboxLabel); |
| 100 | |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 101 | const labelElement = document.createElement('div'); |
| 102 | labelElement.classList.add('dom-breakpoint'); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 103 | element.appendChild(labelElement); |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 104 | const description = document.createElement('div'); |
Paul Lewis | 2a4f9fe | 2020-01-09 15:19:41 | [diff] [blame] | 105 | const breakpointTypeLabel = BreakpointTypeLabels.get(item.type); |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 106 | description.textContent = breakpointTypeLabel || null; |
Michael Liao | e7d3fb5 | 2020-10-01 21:44:04 | [diff] [blame] | 107 | UI.ARIAUtils.setAccessibleName(checkboxElement, ls`${breakpointTypeLabel}`); |
Tim van der Lippe | 6ab9f46 | 2020-05-01 14:22:38 | [diff] [blame] | 108 | const linkifiedNode = document.createElement('monospace'); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 109 | linkifiedNode.style.display = 'block'; |
| 110 | labelElement.appendChild(linkifiedNode); |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 111 | Common.Linkifier.Linkifier.linkify(item.node, {preventKeyboardFocus: true, tooltip: undefined}).then(linkified => { |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 112 | linkifiedNode.appendChild(linkified); |
| 113 | UI.ARIAUtils.setAccessibleName(checkboxElement, ls`${breakpointTypeLabel}: ${linkified.deepTextContent()}`); |
| 114 | }); |
| 115 | |
| 116 | labelElement.appendChild(description); |
| 117 | |
| 118 | const checkedStateText = item.enabled ? ls`checked` : ls`unchecked`; |
| 119 | if (item === this._highlightedBreakpoint) { |
| 120 | element.classList.add('breakpoint-hit'); |
| 121 | UI.ARIAUtils.setDescription(element, ls`${checkedStateText} breakpoint hit`); |
Christy Chen | d05ba96 | 2020-06-05 23:12:25 | [diff] [blame] | 122 | UI.ARIAUtils.setDescription(checkboxElement, ls`breakpoint hit`); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 123 | } else { |
| 124 | UI.ARIAUtils.setDescription(element, checkedStateText); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | this._emptyElement.classList.add('hidden'); |
| 129 | this._list.element.classList.remove('hidden'); |
| 130 | |
| 131 | return element; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @override |
| 136 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} item |
| 137 | * @return {number} |
| 138 | */ |
| 139 | heightForItem(item) { |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @override |
| 145 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} item |
| 146 | * @return {boolean} |
| 147 | */ |
| 148 | isItemSelectable(item) { |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @override |
| 154 | * @param {?Element} fromElement |
| 155 | * @param {?Element} toElement |
| 156 | * @return {boolean} |
| 157 | */ |
| 158 | updateSelectedItemARIA(fromElement, toElement) { |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @override |
| 164 | * @param {?SDK.DOMDebuggerModel.DOMBreakpoint} from |
| 165 | * @param {?SDK.DOMDebuggerModel.DOMBreakpoint} to |
| 166 | * @param {?Element} fromElement |
| 167 | * @param {?Element} toElement |
| 168 | */ |
| 169 | selectedItemChanged(from, to, fromElement, toElement) { |
| 170 | if (fromElement) { |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 171 | const fromCheckbox = this.elementToCheckboxes.get(fromElement); |
| 172 | if (fromCheckbox) { |
| 173 | fromCheckbox.tabIndex = -1; |
| 174 | } |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | if (toElement) { |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 178 | const toCheckbox = this.elementToCheckboxes.get(toElement); |
| 179 | if (!toCheckbox) { |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | this.setDefaultFocusedElement(toCheckbox); |
| 184 | toCheckbox.tabIndex = 0; |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 185 | if (this.hasFocus()) { |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 186 | toCheckbox.focus(); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 192 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | */ |
| 194 | _breakpointAdded(event) { |
| 195 | this._addBreakpoint(/** @type {!SDK.DOMDebuggerModel.DOMBreakpoint} */ (event.data)); |
| 196 | } |
| 197 | |
| 198 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 199 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | */ |
| 201 | _breakpointToggled(event) { |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 202 | const hadFocus = this.hasFocus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 203 | const breakpoint = /** @type {!SDK.DOMDebuggerModel.DOMBreakpoint} */ (event.data); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 204 | this._list.refreshItem(breakpoint); |
| 205 | if (hadFocus) { |
| 206 | this.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 207 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 211 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 212 | */ |
| 213 | _breakpointsRemoved(event) { |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 214 | const hadFocus = this.hasFocus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 215 | const breakpoints = /** @type {!Array<!SDK.DOMDebuggerModel.DOMBreakpoint>} */ (event.data); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 216 | let lastIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | for (const breakpoint of breakpoints) { |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 218 | const index = this._breakpoints.indexOf(breakpoint); |
| 219 | if (index >= 0) { |
| 220 | this._breakpoints.remove(index); |
| 221 | lastIndex = index; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 222 | } |
| 223 | } |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 224 | if (this._breakpoints.length === 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 225 | this._emptyElement.classList.remove('hidden'); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 226 | this.setDefaultFocusedElement(this._emptyElement); |
| 227 | this._list.element.classList.add('hidden'); |
| 228 | } else if (lastIndex >= 0) { |
| 229 | const breakpointToSelect = this._breakpoints.at(lastIndex); |
| 230 | if (breakpointToSelect) { |
| 231 | this._list.selectItem(breakpointToSelect); |
| 232 | } |
| 233 | } |
| 234 | if (hadFocus) { |
| 235 | this.focus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} breakpoint |
| 241 | */ |
| 242 | _addBreakpoint(breakpoint) { |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 243 | this._breakpoints.insertWithComparator(breakpoint, (breakpointA, breakpointB) => { |
| 244 | if (breakpointA.type > breakpointB.type) { |
| 245 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | } |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 247 | if (breakpointA.type < breakpointB.type) { |
| 248 | return 1; |
| 249 | } |
| 250 | return 0; |
| 251 | }); |
| 252 | if (!this.hasFocus()) { |
| 253 | this._list.selectItem(this._breakpoints.at(0)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 254 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} breakpoint |
| 259 | * @param {!Event} event |
| 260 | */ |
| 261 | _contextMenu(breakpoint, event) { |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 262 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 263 | contextMenu.defaultSection().appendItem( |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 264 | ls`Reveal DOM node in Elements panel`, () => Common.Revealer.reveal(breakpoint.node)); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 265 | contextMenu.defaultSection().appendItem(Common.UIString.UIString('Remove breakpoint'), () => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 266 | breakpoint.domDebuggerModel.removeDOMBreakpoint(breakpoint.node, breakpoint.type); |
| 267 | }); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 268 | contextMenu.defaultSection().appendItem(Common.UIString.UIString('Remove all DOM breakpoints'), () => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 269 | breakpoint.domDebuggerModel.removeAllDOMBreakpoints(); |
| 270 | }); |
| 271 | contextMenu.show(); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * @param {!SDK.DOMDebuggerModel.DOMBreakpoint} breakpoint |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 276 | * @param {!Event} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 277 | */ |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 278 | _checkboxClicked(breakpoint, event) { |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 279 | breakpoint.domDebuggerModel.toggleDOMBreakpoint( |
| 280 | breakpoint, event.target ? /** @type {!HTMLInputElement} */ (event.target).checked : false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * @override |
| 285 | * @param {?Object} object |
| 286 | */ |
| 287 | flavorChanged(object) { |
| 288 | this._update(); |
| 289 | } |
| 290 | |
| 291 | _update() { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 292 | const details = UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails); |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 293 | if (this._highlightedBreakpoint) { |
| 294 | const oldHighlightedBreakpoint = this._highlightedBreakpoint; |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 295 | this._highlightedBreakpoint = null; |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 296 | this._list.refreshItem(oldHighlightedBreakpoint); |
| 297 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 298 | if (!details || !details.auxData || details.reason !== SDK.DebuggerModel.BreakReason.DOM) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 299 | return; |
| 300 | } |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 301 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 302 | const domDebuggerModel = details.debuggerModel.target().model(SDK.DOMDebuggerModel.DOMDebuggerModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 303 | if (!domDebuggerModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 304 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 305 | } |
Sigurd Schneider | 5a5b735 | 2020-10-05 11:13:05 | [diff] [blame] | 306 | const data = domDebuggerModel.resolveDOMBreakpointData(/** @type {*} */ (details.auxData)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 307 | if (!data) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 308 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 309 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 310 | |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 311 | for (const breakpoint of this._breakpoints) { |
| 312 | if (breakpoint.node === data.node && breakpoint.type === data.type) { |
| 313 | this._highlightedBreakpoint = breakpoint; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 314 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 315 | } |
Jack Lynch | 8a34476 | 2019-12-12 03:17:38 | [diff] [blame] | 316 | if (this._highlightedBreakpoint) { |
| 317 | this._list.refreshItem(this._highlightedBreakpoint); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 318 | } |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 319 | UI.ViewManager.ViewManager.instance().showView('sources.domBreakpoints'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 320 | } |
Paul Lewis | 7f7a920 | 2019-11-26 16:10:56 | [diff] [blame] | 321 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 322 | |
Paul Lewis | 7f7a920 | 2019-11-26 16:10:56 | [diff] [blame] | 323 | export const BreakpointTypeLabels = new Map([ |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 324 | [Protocol.DOMDebugger.DOMBreakpointType.SubtreeModified, Common.UIString.UIString('Subtree modified')], |
| 325 | [Protocol.DOMDebugger.DOMBreakpointType.AttributeModified, Common.UIString.UIString('Attribute modified')], |
| 326 | [Protocol.DOMDebugger.DOMBreakpointType.NodeRemoved, Common.UIString.UIString('Node removed')], |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 327 | ]); |
| 328 | |
| 329 | /** |
| 330 | * @implements {UI.ContextMenu.Provider} |
| 331 | */ |
Paul Lewis | 7f7a920 | 2019-11-26 16:10:56 | [diff] [blame] | 332 | export class ContextMenuProvider { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 333 | /** |
| 334 | * @override |
| 335 | * @param {!Event} event |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 336 | * @param {!UI.ContextMenu.ContextMenu} contextMenu |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 337 | * @param {!Object} object |
| 338 | */ |
| 339 | appendApplicableItems(event, contextMenu, object) { |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 340 | const node = /** @type {!SDK.DOMModel.DOMNode} */ (object); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 341 | if (node.pseudoType()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 342 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 343 | } |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 344 | const domDebuggerModel = node.domModel().target().model(SDK.DOMDebuggerModel.DOMDebuggerModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 345 | if (!domDebuggerModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 346 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 347 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 348 | |
| 349 | /** |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 350 | * @param {!Protocol.DOMDebugger.DOMBreakpointType} type |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 351 | */ |
| 352 | function toggleBreakpoint(type) { |
Sigurd Schneider | 5a5b735 | 2020-10-05 11:13:05 | [diff] [blame] | 353 | if (!domDebuggerModel) { |
| 354 | return; |
| 355 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 356 | if (domDebuggerModel.hasDOMBreakpoint(node, type)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | domDebuggerModel.removeDOMBreakpoint(node, type); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 358 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 359 | domDebuggerModel.setDOMBreakpoint(node, type); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 360 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | } |
| 362 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 363 | const breakpointsMenu = contextMenu.debugSection().appendSubMenuItem(Common.UIString.UIString('Break on')); |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 364 | for (const type of Object.values(Protocol.DOMDebugger.DOMBreakpointType)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 365 | const label = Sources.DebuggerPausedMessage.BreakpointTypeNouns.get(type); |
Jack Franklin | 536a31d | 2020-09-25 13:15:24 | [diff] [blame] | 366 | if (label) { |
| 367 | breakpointsMenu.defaultSection().appendCheckboxItem( |
| 368 | label, toggleBreakpoint.bind(null, type), domDebuggerModel.hasDOMBreakpoint(node, type)); |
| 369 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 370 | } |
| 371 | } |
Paul Lewis | 7f7a920 | 2019-11-26 16:10:56 | [diff] [blame] | 372 | } |