Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SoftContextMenu.js

Issue 2801373002: [DevTools] Listen to mousedown in SoftContextMenu once (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/GlassPane.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 * @param {!AnchorBox} anchorBox 43 * @param {!AnchorBox} anchorBox
44 */ 44 */
45 show(document, anchorBox) { 45 show(document, anchorBox) {
46 if (!this._items.length) 46 if (!this._items.length)
47 return; 47 return;
48 48
49 this._document = document; 49 this._document = document;
50 50
51 this._glassPane = new UI.GlassPane(); 51 this._glassPane = new UI.GlassPane();
52 this._glassPane.setBlockPointerEvents(!this._parentMenu); 52 this._glassPane.setBlockPointerEvents(!this._parentMenu);
53 this._glassPane.setSetOutsideClickCallback(event => {
lushnikov 2017/04/07 22:25:40 can we fix the setSetOutsideClickCallback name?
dgozman 2017/04/07 22:30:32 Yeah, in a separate patch?
54 this._discardMenu(true, event);
55 event.consume();
lushnikov 2017/04/07 22:25:40 why does the bug happen in the first place? As far
dgozman 2017/04/07 22:30:32 This is because we have two nested menus, and clic
56 });
57 this._glassPane.registerRequiredCSS('ui/softContextMenu.css'); 53 this._glassPane.registerRequiredCSS('ui/softContextMenu.css');
58 this._glassPane.setContentAnchorBox(anchorBox); 54 this._glassPane.setContentAnchorBox(anchorBox);
59 this._glassPane.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent); 55 this._glassPane.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent);
60 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin); 56 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin);
61 this._glassPane.setAnchorBehavior( 57 this._glassPane.setAnchorBehavior(
62 this._parentMenu ? UI.GlassPane.AnchorBehavior.PreferRight : UI.GlassPan e.AnchorBehavior.PreferBottom); 58 this._parentMenu ? UI.GlassPane.AnchorBehavior.PreferRight : UI.GlassPan e.AnchorBehavior.PreferBottom);
63 59
64 this._contextMenuElement = this._glassPane.contentElement.createChild('div', 'soft-context-menu'); 60 this._contextMenuElement = this._glassPane.contentElement.createChild('div', 'soft-context-menu');
65 this._contextMenuElement.tabIndex = 0; 61 this._contextMenuElement.tabIndex = 0;
66 this._contextMenuElement.addEventListener('mouseup', e => e.consume(), false ); 62 this._contextMenuElement.addEventListener('mouseup', e => e.consume(), false );
67 this._contextMenuElement.addEventListener('keydown', this._menuKeyDown.bind( this), false); 63 this._contextMenuElement.addEventListener('keydown', this._menuKeyDown.bind( this), false);
68 64
69 for (var i = 0; i < this._items.length; ++i) 65 for (var i = 0; i < this._items.length; ++i)
70 this._contextMenuElement.appendChild(this._createMenuItem(this._items[i])) ; 66 this._contextMenuElement.appendChild(this._createMenuItem(this._items[i])) ;
71 67
72 this._glassPane.show(document); 68 this._glassPane.show(document);
73 this._focus(); 69 this._focus();
70
71 if (!this._parentMenu) {
72 this._onBodyMouseDown = event => this._discardMenu(true, event);
73 this._document.body.addEventListener('mousedown', this._onBodyMouseDown, f alse);
74 }
74 } 75 }
75 76
76 discard() { 77 discard() {
77 this._discardMenu(true); 78 this._discardMenu(true);
78 } 79 }
79 80
80 _createMenuItem(item) { 81 _createMenuItem(item) {
81 if (item.type === 'separator') 82 if (item.type === 'separator')
82 return this._createSeparator(); 83 return this._createSeparator();
83 84
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (event) 324 if (event)
324 event.consume(true); 325 event.consume(true);
325 } 326 }
326 327
327 _discardSubMenus() { 328 _discardSubMenus() {
328 if (this._subMenu) 329 if (this._subMenu)
329 this._subMenu._discardSubMenus(); 330 this._subMenu._discardSubMenus();
330 if (this._glassPane) { 331 if (this._glassPane) {
331 this._glassPane.hide(); 332 this._glassPane.hide();
332 delete this._glassPane; 333 delete this._glassPane;
334 if (this._onBodyMouseDown) {
335 this._document.body.removeEventListener('mousedown', this._onBodyMouseDo wn, false);
336 delete this._onBodyMouseDown;
337 }
333 } 338 }
334 if (this._parentMenu) 339 if (this._parentMenu)
335 delete this._parentMenu._subMenu; 340 delete this._parentMenu._subMenu;
336 } 341 }
337 }; 342 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/GlassPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698