Changeset 238569 in webkit
- Timestamp:
- Nov 27, 2018 1:06:52 PM (5 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r238563 r238569 1 2018-11-27 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Cookies table needs copy keyboard shortcut and context menu support 4 https://bugs.webkit.org/show_bug.cgi?id=191482 5 <rdar://problem/45953002> 6 7 Reviewed by Joseph Pecoraro. 8 9 * UserInterface/Views/CookieStorageContentView.js: 10 (WI.CookieStorageContentView.prototype.handleCopyEvent): 11 (WI.CookieStorageContentView.prototype.tableCellContextMenuClicked): 12 As with Delete, if the target row is selected, all selected rows are copied. 13 Otherwise only the target row is copied. This distinction will be surfaced 14 in the UI in https://webkit.org/b/191095. 15 16 (WI.CookieStorageContentView.prototype.tablePopulateCell): 17 (WI.CookieStorageContentView.prototype._cookiesAtIndexes): 18 (WI.CookieStorageContentView.prototype._formatCookiesAsText): 19 (WI.CookieStorageContentView.prototype._formatCookiePropertyForColumn): 20 (WI.CookieStorageContentView): 21 Break Cookie property formatting into a helper method, which is used for 22 formatting Table cells and creating plain text for the clipboard. 23 24 * UserInterface/Views/Table.js: 25 (WI.Table.prototype.get columns): 26 1 27 2018-11-27 Matt Baker <mattbaker@apple.com> 2 28 -
trunk/Source/WebInspectorUI/UserInterface/Views/CookieStorageContentView.js
r237746 r238569 60 60 } 61 61 62 handleCopyEvent(event) 63 { 64 if (!this._table || !this._table.selectedRows.length) 65 return; 66 67 let cookies = this._cookiesAtIndexes(this._table.selectedRows); 68 if (!cookies.length) 69 return; 70 71 event.clipboardData.setData("text/plain", this._formatCookiesAsText(cookies)); 72 event.stopPropagation(); 73 event.preventDefault(); 74 } 75 62 76 // Table dataSource 63 77 … … 85 99 86 100 contextMenu.appendSeparator(); 101 contextMenu.appendItem(WI.UIString("Copy"), () => { 102 let rowIndexes; 103 if (table.isRowSelected(rowIndex)) 104 rowIndexes = table.selectedRows; 105 else 106 rowIndexes = [rowIndex]; 107 108 let cookies = this._cookiesAtIndexes(rowIndexes); 109 InspectorFrontendHost.copyText(this._formatCookiesAsText(cookies)); 110 }); 111 87 112 contextMenu.appendItem(WI.UIString("Delete"), () => { 88 113 if (table.isRowSelected(rowIndex)) … … 118 143 { 119 144 let cookie = this._cookies[rowIndex]; 120 121 const checkmark = "\u2713"; 122 123 switch (column.identifier) { 124 case "name": 125 cell.textContent = cookie.name; 126 break; 127 case "value": 128 cell.textContent = cookie.value; 129 break; 130 case "domain": 131 cell.textContent = cookie.domain || emDash; 132 break; 133 case "path": 134 cell.textContent = cookie.path || emDash; 135 break; 136 case "expires": 137 cell.textContent = cookie.expires ? new Date(cookie.expires).toLocaleString() : WI.UIString("Session"); 138 break; 139 case "size": 140 cell.textContent = Number.bytesToString(cookie.size); 141 break; 142 case "secure": 143 cell.textContent = cookie.secure ? checkmark : zeroWidthSpace; 144 break; 145 case "httpOnly": 146 cell.textContent = cookie.httpOnly ? checkmark : zeroWidthSpace; 147 break; 148 case "sameSite": 149 cell.textContent = cookie.sameSite === WI.Cookie.SameSiteType.None ? emDash : WI.Cookie.displayNameForSameSiteType(cookie.sameSite); 150 break; 151 } 152 145 cell.textContent = this._formatCookiePropertyForColumn(cookie, column); 153 146 return cell; 154 147 } … … 341 334 this._table.removeSelectedRows(); 342 335 } 336 337 _cookiesAtIndexes(indexes) 338 { 339 if (!this._cookies.length) 340 return []; 341 return indexes.map((index) => this._cookies[index]); 342 } 343 344 _formatCookiesAsText(cookies) 345 { 346 let visibleColumns = this._table.columns.filter((column) => !column.hidden); 347 if (!visibleColumns.length) 348 return ""; 349 350 let lines = cookies.map((cookie) => { 351 const usePunctuation = false; 352 let values = visibleColumns.map((column) => this._formatCookiePropertyForColumn(cookie, column, usePunctuation)); 353 return values.join("\t"); 354 }); 355 356 return lines.join("\n"); 357 } 358 359 _formatCookiePropertyForColumn(cookie, column, usePunctuation = true) 360 { 361 const checkmark = "\u2713"; 362 const missingValue = usePunctuation ? emDash : ""; 363 const missingCheckmark = usePunctuation ? zeroWidthSpace : ""; 364 365 switch (column.identifier) { 366 case "name": 367 return cookie.name; 368 case "value": 369 return cookie.value; 370 case "domain": 371 return cookie.domain || missingValue; 372 case "path": 373 return cookie.path || missingValue; 374 case "expires": 375 return cookie.expires ? new Date(cookie.expires).toLocaleString() : WI.UIString("Session"); 376 case "size": 377 return Number.bytesToString(cookie.size); 378 case "secure": 379 return cookie.secure ? checkmark : missingCheckmark; 380 case "httpOnly": 381 return cookie.httpOnly ? checkmark : missingCheckmark; 382 case "sameSite": 383 return cookie.sameSite === WI.Cookie.SameSiteType.None ? missingValue : WI.Cookie.displayNameForSameSiteType(cookie.sameSite); 384 } 385 386 console.assert("Unexpected table column " + column.identifier); 387 return ""; 388 } 343 389 }; 344 390 -
trunk/Source/WebInspectorUI/UserInterface/Views/Table.js
r238563 r238569 230 230 } 231 231 232 get columns() 233 { 234 return Array.from(this._columnSpecs.values()); 235 } 236 232 237 isRowSelected(rowIndex) 233 238 {
Note: See TracChangeset
for help on using the changeset viewer.