| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Element which shows context menus and handles keyboard | 6 * @fileoverview Element which shows context menus and handles keyboard |
| 7 * shortcuts. | 7 * shortcuts. |
| 8 */ | 8 */ |
| 9 cr.define('bookmarks', function() { | 9 cr.define('bookmarks', function() { |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 * Display the command context menu positioned to cover the |target| | 85 * Display the command context menu positioned to cover the |target| |
| 86 * element. Commands will execute on the currently selected items. | 86 * element. Commands will execute on the currently selected items. |
| 87 * @param {!Element} target | 87 * @param {!Element} target |
| 88 */ | 88 */ |
| 89 openCommandMenuAtElement: function(target) { | 89 openCommandMenuAtElement: function(target) { |
| 90 this.menuIds_ = this.getState().selection.items; | 90 this.menuIds_ = this.getState().selection.items; |
| 91 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); | 91 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); |
| 92 }, | 92 }, |
| 93 | 93 |
| 94 closeCommandMenu: function() { | 94 closeCommandMenu: function() { |
| 95 this.menuIds_ = new Set(); |
| 95 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); | 96 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); |
| 96 }, | 97 }, |
| 97 | 98 |
| 98 //////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////// |
| 99 // Command handlers: | 100 // Command handlers: |
| 100 | 101 |
| 101 /** | 102 /** |
| 102 * Determine if the |command| can be executed with the given |itemIds|. | 103 * Determine if the |command| can be executed with the given |itemIds|. |
| 103 * Commands which appear in the context menu should be implemented | 104 * Commands which appear in the context menu should be implemented |
| 104 * separately using `isCommandVisible_` and `isCommandEnabled_`. | 105 * separately using `isCommandVisible_` and `isCommandEnabled_`. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /** | 148 /** |
| 148 * @param {Command} command | 149 * @param {Command} command |
| 149 * @param {!Set<string>} itemIds | 150 * @param {!Set<string>} itemIds |
| 150 * @return {boolean} True if the command should be clickable in the context | 151 * @return {boolean} True if the command should be clickable in the context |
| 151 * menu. | 152 * menu. |
| 152 */ | 153 */ |
| 153 isCommandEnabled_: function(command, itemIds) { | 154 isCommandEnabled_: function(command, itemIds) { |
| 154 switch (command) { | 155 switch (command) { |
| 155 case Command.OPEN_NEW_TAB: | 156 case Command.OPEN_NEW_TAB: |
| 156 case Command.OPEN_NEW_WINDOW: | 157 case Command.OPEN_NEW_WINDOW: |
| 158 return this.expandUrls_(itemIds).length > 0; |
| 157 case Command.OPEN_INCOGNITO: | 159 case Command.OPEN_INCOGNITO: |
| 158 return this.expandUrls_(itemIds).length > 0; | 160 return this.expandUrls_(itemIds).length > 0 && |
| 161 this.getState().prefs.incognitoAvailability != |
| 162 IncognitoAvailability.DISABLED; |
| 159 default: | 163 default: |
| 160 return true; | 164 return true; |
| 161 } | 165 } |
| 162 }, | 166 }, |
| 163 | 167 |
| 164 /** | 168 /** |
| 165 * @param {Command} command | 169 * @param {Command} command |
| 166 * @param {!Set<string>} itemIds | 170 * @param {!Set<string>} itemIds |
| 167 */ | 171 */ |
| 168 handle: function(command, itemIds) { | 172 handle: function(command, itemIds) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } else { | 323 } else { |
| 320 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); | 324 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); |
| 321 } | 325 } |
| 322 }, | 326 }, |
| 323 | 327 |
| 324 /** | 328 /** |
| 325 * @param {Event} e | 329 * @param {Event} e |
| 326 * @private | 330 * @private |
| 327 */ | 331 */ |
| 328 onCommandClick_: function(e) { | 332 onCommandClick_: function(e) { |
| 333 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); |
| 329 this.closeCommandMenu(); | 334 this.closeCommandMenu(); |
| 330 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); | |
| 331 }, | 335 }, |
| 332 | 336 |
| 333 /** | 337 /** |
| 334 * @param {!Event} e | 338 * @param {!Event} e |
| 335 * @private | 339 * @private |
| 336 */ | 340 */ |
| 337 onKeydown_: function(e) { | 341 onKeydown_: function(e) { |
| 338 var selection = this.getState().selection.items; | 342 var selection = this.getState().selection.items; |
| 339 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or | 343 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or |
| 340 // text field is focused. | 344 // text field is focused. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 356 * Close the menu on mousedown so clicks can propagate to the underlying UI. | 360 * Close the menu on mousedown so clicks can propagate to the underlying UI. |
| 357 * This allows the user to right click the list while a context menu is | 361 * This allows the user to right click the list while a context menu is |
| 358 * showing and get another context menu. | 362 * showing and get another context menu. |
| 359 * @param {Event} e | 363 * @param {Event} e |
| 360 * @private | 364 * @private |
| 361 */ | 365 */ |
| 362 onMenuMousedown_: function(e) { | 366 onMenuMousedown_: function(e) { |
| 363 if (e.path[0] != this.$.dropdown) | 367 if (e.path[0] != this.$.dropdown) |
| 364 return; | 368 return; |
| 365 | 369 |
| 366 this.$.dropdown.close(); | 370 this.closeCommandMenu(); |
| 367 }, | 371 }, |
| 368 | 372 |
| 369 /** | 373 /** |
| 370 * @param {Command} command | 374 * @param {Command} command |
| 371 * @return {string} | 375 * @return {string} |
| 372 * @private | 376 * @private |
| 373 */ | 377 */ |
| 374 getCommandLabel_: function(command) { | 378 getCommandLabel_: function(command) { |
| 375 var multipleNodes = this.menuIds_.size > 1 || | 379 var multipleNodes = this.menuIds_.size > 1 || |
| 376 this.containsMatchingNode_(this.menuIds_, function(node) { | 380 this.containsMatchingNode_(this.menuIds_, function(node) { |
| 377 return !node.url; | 381 return !node.url; |
| 378 }); | 382 }); |
| 379 var label; | 383 var label; |
| 380 switch (command) { | 384 switch (command) { |
| 381 case Command.EDIT: | 385 case Command.EDIT: |
| 382 if (this.menuIds_.size > 1) | 386 if (this.menuIds_.size != 1) |
| 383 return ''; | 387 return ''; |
| 384 | 388 |
| 385 var id = Array.from(this.menuIds_)[0]; | 389 var id = Array.from(this.menuIds_)[0]; |
| 386 var itemUrl = this.getState().nodes[id].url; | 390 var itemUrl = this.getState().nodes[id].url; |
| 387 label = itemUrl ? 'menuEdit' : 'menuRename'; | 391 label = itemUrl ? 'menuEdit' : 'menuRename'; |
| 388 break; | 392 break; |
| 389 case Command.COPY: | 393 case Command.COPY: |
| 390 label = 'menuCopyURL'; | 394 label = 'menuCopyURL'; |
| 391 break; | 395 break; |
| 392 case Command.DELETE: | 396 case Command.DELETE: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 421 | 425 |
| 422 /** @return {!bookmarks.CommandManager} */ | 426 /** @return {!bookmarks.CommandManager} */ |
| 423 CommandManager.getInstance = function() { | 427 CommandManager.getInstance = function() { |
| 424 return assert(CommandManager.instance_); | 428 return assert(CommandManager.instance_); |
| 425 }; | 429 }; |
| 426 | 430 |
| 427 return { | 431 return { |
| 428 CommandManager: CommandManager, | 432 CommandManager: CommandManager, |
| 429 }; | 433 }; |
| 430 }); | 434 }); |
| OLD | NEW |