Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 * Display the command context menu positioned to cover the |target| | 82 * Display the command context menu positioned to cover the |target| |
| 83 * element. Commands will execute on the currently selected items. | 83 * element. Commands will execute on the currently selected items. |
| 84 * @param {!Element} target | 84 * @param {!Element} target |
| 85 */ | 85 */ |
| 86 openCommandMenuAtElement: function(target) { | 86 openCommandMenuAtElement: function(target) { |
| 87 this.menuIds_ = this.getState().selection.items; | 87 this.menuIds_ = this.getState().selection.items; |
| 88 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); | 88 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); |
| 89 }, | 89 }, |
| 90 | 90 |
| 91 closeCommandMenu: function() { | 91 closeCommandMenu: function() { |
| 92 this.menuIds_ = new Set(); | |
|
calamity
2017/05/29 06:52:27
Does this functionally change anything, or is it j
tsergeant
2017/05/30 00:18:21
Menu item bindings are based entirely on the menuI
calamity
2017/06/01 04:07:44
I see. So menu items that have enable conditions t
tsergeant
2017/06/01 05:27:16
Yup, exactly.
| |
| 92 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); | 93 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); |
| 93 }, | 94 }, |
| 94 | 95 |
| 95 //////////////////////////////////////////////////////////////////////////// | 96 //////////////////////////////////////////////////////////////////////////// |
| 96 // Command handlers: | 97 // Command handlers: |
| 97 | 98 |
| 98 /** | 99 /** |
| 99 * Determine if the |command| can be executed with the given |itemIds|. | 100 * Determine if the |command| can be executed with the given |itemIds|. |
| 100 * Commands which appear in the context menu should be implemented | 101 * Commands which appear in the context menu should be implemented |
| 101 * separately using `isCommandVisible_` and `isCommandEnabled_`. | 102 * separately using `isCommandVisible_` and `isCommandEnabled_`. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 /** | 142 /** |
| 142 * @param {Command} command | 143 * @param {Command} command |
| 143 * @param {!Set<string>} itemIds | 144 * @param {!Set<string>} itemIds |
| 144 * @return {boolean} True if the command should be clickable in the context | 145 * @return {boolean} True if the command should be clickable in the context |
| 145 * menu. | 146 * menu. |
| 146 */ | 147 */ |
| 147 isCommandEnabled_: function(command, itemIds) { | 148 isCommandEnabled_: function(command, itemIds) { |
| 148 switch (command) { | 149 switch (command) { |
| 149 case Command.OPEN_NEW_TAB: | 150 case Command.OPEN_NEW_TAB: |
| 150 case Command.OPEN_NEW_WINDOW: | 151 case Command.OPEN_NEW_WINDOW: |
| 152 return this.expandUrls_(itemIds).length > 0; | |
| 151 case Command.OPEN_INCOGNITO: | 153 case Command.OPEN_INCOGNITO: |
| 152 return this.expandUrls_(itemIds).length > 0; | 154 return this.expandUrls_(itemIds).length > 0 && |
| 155 this.getState().prefs.incognito != IncognitoAvailability.DISABLED; | |
| 153 default: | 156 default: |
| 154 return true; | 157 return true; |
| 155 } | 158 } |
| 156 }, | 159 }, |
| 157 | 160 |
| 158 /** | 161 /** |
| 159 * @param {Command} command | 162 * @param {Command} command |
| 160 * @param {!Set<string>} itemIds | 163 * @param {!Set<string>} itemIds |
| 161 */ | 164 */ |
| 162 handle: function(command, itemIds) { | 165 handle: function(command, itemIds) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } else { | 310 } else { |
| 308 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); | 311 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); |
| 309 } | 312 } |
| 310 }, | 313 }, |
| 311 | 314 |
| 312 /** | 315 /** |
| 313 * @param {Event} e | 316 * @param {Event} e |
| 314 * @private | 317 * @private |
| 315 */ | 318 */ |
| 316 onCommandClick_: function(e) { | 319 onCommandClick_: function(e) { |
| 320 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); | |
| 317 this.closeCommandMenu(); | 321 this.closeCommandMenu(); |
| 318 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); | |
| 319 }, | 322 }, |
| 320 | 323 |
| 321 /** | 324 /** |
| 322 * @param {!Event} e | 325 * @param {!Event} e |
| 323 * @private | 326 * @private |
| 324 */ | 327 */ |
| 325 onKeydown_: function(e) { | 328 onKeydown_: function(e) { |
| 326 var selection = this.getState().selection.items; | 329 var selection = this.getState().selection.items; |
| 327 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or | 330 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or |
| 328 // text field is focused. | 331 // text field is focused. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 344 * Close the menu on mousedown so clicks can propagate to the underlying UI. | 347 * Close the menu on mousedown so clicks can propagate to the underlying UI. |
| 345 * This allows the user to right click the list while a context menu is | 348 * This allows the user to right click the list while a context menu is |
| 346 * showing and get another context menu. | 349 * showing and get another context menu. |
| 347 * @param {Event} e | 350 * @param {Event} e |
| 348 * @private | 351 * @private |
| 349 */ | 352 */ |
| 350 onMenuMousedown_: function(e) { | 353 onMenuMousedown_: function(e) { |
| 351 if (e.path[0] != this.$.dropdown) | 354 if (e.path[0] != this.$.dropdown) |
| 352 return; | 355 return; |
| 353 | 356 |
| 354 this.$.dropdown.close(); | 357 this.closeCommandMenu(); |
| 355 }, | 358 }, |
| 356 | 359 |
| 357 /** | 360 /** |
| 358 * @param {Command} command | 361 * @param {Command} command |
| 359 * @return {string} | 362 * @return {string} |
| 360 * @private | 363 * @private |
| 361 */ | 364 */ |
| 362 getCommandLabel_: function(command) { | 365 getCommandLabel_: function(command) { |
| 363 var multipleNodes = this.menuIds_.size > 1 || | 366 var multipleNodes = this.menuIds_.size > 1 || |
| 364 this.containsMatchingNode_(this.menuIds_, function(node) { | 367 this.containsMatchingNode_(this.menuIds_, function(node) { |
| 365 return !node.url; | 368 return !node.url; |
| 366 }); | 369 }); |
| 367 var label; | 370 var label; |
| 368 switch (command) { | 371 switch (command) { |
| 369 case Command.EDIT: | 372 case Command.EDIT: |
| 370 if (this.menuIds_.size > 1) | 373 if (this.menuIds_.size != 1) |
| 371 return ''; | 374 return ''; |
| 372 | 375 |
| 373 var id = Array.from(this.menuIds_)[0]; | 376 var id = Array.from(this.menuIds_)[0]; |
| 374 var itemUrl = this.getState().nodes[id].url; | 377 var itemUrl = this.getState().nodes[id].url; |
| 375 label = itemUrl ? 'menuEdit' : 'menuRename'; | 378 label = itemUrl ? 'menuEdit' : 'menuRename'; |
| 376 break; | 379 break; |
| 377 case Command.COPY: | 380 case Command.COPY: |
| 378 label = 'menuCopyURL'; | 381 label = 'menuCopyURL'; |
| 379 break; | 382 break; |
| 380 case Command.DELETE: | 383 case Command.DELETE: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 409 | 412 |
| 410 /** @return {!bookmarks.CommandManager} */ | 413 /** @return {!bookmarks.CommandManager} */ |
| 411 CommandManager.getInstance = function() { | 414 CommandManager.getInstance = function() { |
| 412 return assert(CommandManager.instance_); | 415 return assert(CommandManager.instance_); |
| 413 }; | 416 }; |
| 414 | 417 |
| 415 return { | 418 return { |
| 416 CommandManager: CommandManager, | 419 CommandManager: CommandManager, |
| 417 }; | 420 }; |
| 418 }); | 421 }); |
| OLD | NEW |