1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WI.BreakpointPopoverController = class BreakpointPopoverController extends WI.Object
{
constructor()
{
super();
this._breakpoint = null;
this._popover = null;
this._popoverContentElement = null;
}
// Public
appendContextMenuItems(contextMenu, breakpoint, breakpointDisplayElement)
{
console.assert(document.body.contains(breakpointDisplayElement), "Breakpoint popover display element must be in the DOM.");
const editBreakpoint = () => {
console.assert(!this._popover, "Breakpoint popover already exists.");
if (this._popover)
return;
this._createPopoverContent(breakpoint);
this._popover = new WI.Popover(this);
this._popover.content = this._popoverContentElement;
let bounds = WI.Rect.rectFromClientRect(breakpointDisplayElement.getBoundingClientRect());
bounds.origin.x -= 1; // Move the anchor left one pixel so it looks more centered.
this._popover.present(bounds.pad(2), [WI.RectEdge.MAX_Y]);
};
const removeBreakpoint = () => {
WI.debuggerManager.removeBreakpoint(breakpoint);
};
const toggleBreakpoint = () => {
breakpoint.disabled = !breakpoint.disabled;
};
const toggleAutoContinue = () => {
breakpoint.autoContinue = !breakpoint.autoContinue;
};
const revealOriginalSourceCodeLocation = () => {
const options = {
ignoreNetworkTab: true,
ignoreSearchTab: true,
};
WI.showOriginalOrFormattedSourceCodeLocation(breakpoint.sourceCodeLocation, options);
};
if (WI.debuggerManager.isBreakpointEditable(breakpoint))
contextMenu.appendItem(WI.UIString("Edit Breakpoint…"), editBreakpoint);
if (breakpoint.autoContinue && !breakpoint.disabled) {
contextMenu.appendItem(WI.UIString("Disable Breakpoint"), toggleBreakpoint);
contextMenu.appendItem(WI.UIString("Cancel Automatic Continue"), toggleAutoContinue);
} else if (!breakpoint.disabled)
contextMenu.appendItem(WI.UIString("Disable Breakpoint"), toggleBreakpoint);
else
contextMenu.appendItem(WI.UIString("Enable Breakpoint"), toggleBreakpoint);
if (!breakpoint.autoContinue && !breakpoint.disabled && breakpoint.actions.length)
contextMenu.appendItem(WI.UIString("Set to Automatically Continue"), toggleAutoContinue);
if (WI.debuggerManager.isBreakpointRemovable(breakpoint)) {
contextMenu.appendSeparator();
contextMenu.appendItem(WI.UIString("Delete Breakpoint"), removeBreakpoint);
}
if (breakpoint._sourceCodeLocation.hasMappedLocation()) {
contextMenu.appendSeparator();
contextMenu.appendItem(WI.UIString("Reveal in Original Resource"), revealOriginalSourceCodeLocation);
}
}
// CodeMirrorCompletionController delegate
completionControllerShouldAllowEscapeCompletion()
{
return false;
}
// Private
_createPopoverContent(breakpoint)
{
console.assert(!this._popoverContentElement, "Popover content element already exists.");
if (this._popoverContentElement)
return;
this._breakpoint = breakpoint;
this._popoverContentElement = document.createElement("div");
this._popoverContentElement.className = "edit-breakpoint-popover-content";
let checkboxElement = document.createElement("input");
checkboxElement.type = "checkbox";
checkboxElement.checked = !this._breakpoint.disabled;
checkboxElement.addEventListener("change", this._popoverToggleEnabledCheckboxChanged.bind(this));
let checkboxLabel = document.createElement("label");
checkboxLabel.className = "toggle";
checkboxLabel.appendChild(checkboxElement);
checkboxLabel.append(this._breakpoint.sourceCodeLocation.displayLocationString());
let table = document.createElement("table");
let conditionRow = table.appendChild(document.createElement("tr"));
let conditionHeader = conditionRow.appendChild(document.createElement("th"));
let conditionData = conditionRow.appendChild(document.createElement("td"));
let conditionLabel = conditionHeader.appendChild(document.createElement("label"));
conditionLabel.textContent = WI.UIString("Condition");
let conditionEditorElement = conditionData.appendChild(document.createElement("div"));
conditionEditorElement.classList.add("edit-breakpoint-popover-condition", WI.SyntaxHighlightedStyleClassName);
this._conditionCodeMirror = WI.CodeMirrorEditor.create(conditionEditorElement, {
extraKeys: {Tab: false},
lineWrapping: false,
mode: "text/javascript",
matchBrackets: true,
placeholder: WI.UIString("Conditional expression"),
scrollbarStyle: null,
value: this._breakpoint.condition || "",
});
let conditionCodeMirrorInputField = this._conditionCodeMirror.getInputField();
conditionCodeMirrorInputField.id = "codemirror-condition-input-field";
conditionLabel.setAttribute("for", conditionCodeMirrorInputField.id);
this._conditionCodeMirrorEscapeOrEnterKeyHandler = this._conditionCodeMirrorEscapeOrEnterKey.bind(this);
this._conditionCodeMirror.addKeyMap({
"Esc": this._conditionCodeMirrorEscapeOrEnterKeyHandler,
"Enter": this._conditionCodeMirrorEscapeOrEnterKeyHandler,
});
this._conditionCodeMirror.on("change", this._conditionCodeMirrorChanged.bind(this));
this._conditionCodeMirror.on("beforeChange", this._conditionCodeMirrorBeforeChange.bind(this));
let completionController = new WI.CodeMirrorCompletionController(this._conditionCodeMirror, this);
completionController.addExtendedCompletionProvider("javascript", WI.javaScriptRuntimeCompletionProvider);
// CodeMirror needs a refresh after the popover displays, to layout, otherwise it doesn't appear.
setTimeout(() => {
this._conditionCodeMirror.refresh();
this._conditionCodeMirror.focus();
}, 0);
// COMPATIBILITY (iOS 7): Debugger.setBreakpoint did not support options.
if (DebuggerAgent.setBreakpoint.supports("options")) {
// COMPATIBILITY (iOS 9): Legacy backends don't support breakpoint ignore count. Since support
// can't be tested directly, check for CSS.getSupportedSystemFontFamilyNames.
// FIXME: Use explicit version checking once https://webkit.org/b/148680 is fixed.
if (CSSAgent.getSupportedSystemFontFamilyNames) {
let ignoreCountRow = table.appendChild(document.createElement("tr"));
let ignoreCountHeader = ignoreCountRow.appendChild(document.createElement("th"));
let ignoreCountLabel = ignoreCountHeader.appendChild(document.createElement("label"));
let ignoreCountData = ignoreCountRow.appendChild(document.createElement("td"));
this._ignoreCountInput = ignoreCountData.appendChild(document.createElement("input"));
this._ignoreCountInput.id = "edit-breakpoint-popover-ignore";
this._ignoreCountInput.type = "number";
this._ignoreCountInput.min = 0;
this._ignoreCountInput.value = 0;
this._ignoreCountInput.addEventListener("change", this._popoverIgnoreInputChanged.bind(this));
ignoreCountLabel.setAttribute("for", this._ignoreCountInput.id);
ignoreCountLabel.textContent = WI.UIString("Ignore");
this._ignoreCountText = ignoreCountData.appendChild(document.createElement("span"));
this._updateIgnoreCountText();
}
let actionRow = table.appendChild(document.createElement("tr"));
let actionHeader = actionRow.appendChild(document.createElement("th"));
let actionData = this._actionsContainer = actionRow.appendChild(document.createElement("td"));
let actionLabel = actionHeader.appendChild(document.createElement("label"));
actionLabel.textContent = WI.UIString("Action");
if (!this._breakpoint.actions.length)
this._popoverActionsCreateAddActionButton();
else {
this._popoverContentElement.classList.add(WI.BreakpointPopoverController.WidePopoverClassName);
for (let i = 0; i < this._breakpoint.actions.length; ++i) {
let breakpointActionView = new WI.BreakpointActionView(this._breakpoint.actions[i], this, true);
this._popoverActionsInsertBreakpointActionView(breakpointActionView, i);
}
}
let optionsRow = this._popoverOptionsRowElement = table.appendChild(document.createElement("tr"));
if (!this._breakpoint.actions.length)
optionsRow.classList.add(WI.BreakpointPopoverController.HiddenStyleClassName);
let optionsHeader = optionsRow.appendChild(document.createElement("th"));
let optionsData = optionsRow.appendChild(document.createElement("td"));
let optionsLabel = optionsHeader.appendChild(document.createElement("label"));
let optionsCheckbox = this._popoverOptionsCheckboxElement = optionsData.appendChild(document.createElement("input"));
let optionsCheckboxLabel = optionsData.appendChild(document.createElement("label"));
optionsCheckbox.id = "edit-breakpoint-popover-auto-continue";
optionsCheckbox.type = "checkbox";
optionsCheckbox.checked = this._breakpoint.autoContinue;
optionsCheckbox.addEventListener("change", this._popoverToggleAutoContinueCheckboxChanged.bind(this));
optionsLabel.textContent = WI.UIString("Options");
optionsCheckboxLabel.setAttribute("for", optionsCheckbox.id);
optionsCheckboxLabel.textContent = WI.UIString("Automatically continue after evaluating");
}
this._popoverContentElement.appendChild(checkboxLabel);
this._popoverContentElement.appendChild(table);
}
_popoverToggleEnabledCheckboxChanged(event)
{
this._breakpoint.disabled = !event.target.checked;
}
_conditionCodeMirrorChanged(codeMirror, change)
{
this._breakpoint.condition = (codeMirror.getValue() || "").trim();
}
_conditionCodeMirrorBeforeChange(codeMirror, change)
{
if (change.update) {
let newText = change.text.join("").replace(/\n/g, "");
change.update(change.from, change.to, [newText]);
}
return true;
}
_conditionCodeMirrorEscapeOrEnterKey()
{
if (!this._popover)
return;
this._popover.dismiss();
}
_popoverIgnoreInputChanged(event)
{
let ignoreCount = 0;
if (event.target.value) {
ignoreCount = parseInt(event.target.value, 10);
if (isNaN(ignoreCount) || ignoreCount < 0)
ignoreCount = 0;
}
this._ignoreCountInput.value = ignoreCount;
this._breakpoint.ignoreCount = ignoreCount;
this._updateIgnoreCountText();
}
_popoverToggleAutoContinueCheckboxChanged(event)
{
this._breakpoint.autoContinue = event.target.checked;
}
_popoverActionsCreateAddActionButton()
{
this._popoverContentElement.classList.remove(WI.BreakpointPopoverController.WidePopoverClassName);
this._actionsContainer.removeChildren();
let addActionButton = this._actionsContainer.appendChild(document.createElement("button"));
addActionButton.textContent = WI.UIString("Add Action");
addActionButton.addEventListener("click", this._popoverActionsAddActionButtonClicked.bind(this));
}
_popoverActionsAddActionButtonClicked(event)
{
this._popoverContentElement.classList.add(WI.BreakpointPopoverController.WidePopoverClassName);
this._actionsContainer.removeChildren();
let newAction = this._breakpoint.createAction(WI.Breakpoint.DefaultBreakpointActionType);
let newBreakpointActionView = new WI.BreakpointActionView(newAction, this);
this._popoverActionsInsertBreakpointActionView(newBreakpointActionView, -1);
this._popoverOptionsRowElement.classList.remove(WI.BreakpointPopoverController.HiddenStyleClassName);
this._popover.update();
}
_popoverActionsInsertBreakpointActionView(breakpointActionView, index)
{
if (index === -1)
this._actionsContainer.appendChild(breakpointActionView.element);
else {
let nextElement = this._actionsContainer.children[index + 1] || null;
this._actionsContainer.insertBefore(breakpointActionView.element, nextElement);
}
}
_updateIgnoreCountText()
{
if (this._breakpoint.ignoreCount === 1)
this._ignoreCountText.textContent = WI.UIString("time before stopping");
else
this._ignoreCountText.textContent = WI.UIString("times before stopping");
}
breakpointActionViewAppendActionView(breakpointActionView, newAction)
{
let newBreakpointActionView = new WI.BreakpointActionView(newAction, this);
let index = 0;
let children = this._actionsContainer.children;
for (let i = 0; children.length; ++i) {
if (children[i] === breakpointActionView.element) {
index = i;
break;
}
}
this._popoverActionsInsertBreakpointActionView(newBreakpointActionView, index);
this._popoverOptionsRowElement.classList.remove(WI.BreakpointPopoverController.HiddenStyleClassName);
this._popover.update();
}
breakpointActionViewRemoveActionView(breakpointActionView)
{
breakpointActionView.element.remove();
if (!this._actionsContainer.children.length) {
this._popoverActionsCreateAddActionButton();
this._popoverOptionsRowElement.classList.add(WI.BreakpointPopoverController.HiddenStyleClassName);
this._popoverOptionsCheckboxElement.checked = false;
}
this._popover.update();
}
breakpointActionViewResized(breakpointActionView)
{
this._popover.update();
}
willDismissPopover(popover)
{
console.assert(this._popover === popover);
this._popoverContentElement = null;
this._popoverOptionsRowElement = null;
this._popoverOptionsCheckboxElement = null;
this._actionsContainer = null;
this._popover = null;
}
didDismissPopover(popover)
{
// Remove Evaluate and Probe actions that have no data.
let emptyActions = this._breakpoint.actions.filter(function(action) {
if (action.type !== WI.BreakpointAction.Type.Evaluate && action.type !== WI.BreakpointAction.Type.Probe)
return false;
return !(action.data && action.data.trim());
});
for (let action of emptyActions)
this._breakpoint.removeAction(action);
this._breakpoint = null;
}
};
WI.BreakpointPopoverController.WidePopoverClassName = "wide";
WI.BreakpointPopoverController.HiddenStyleClassName = "hidden";
|