| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 InlineEditor.SwatchPopoverHelper = class extends Common.Object { | 7 InlineEditor.SwatchPopoverHelper = class extends Common.Object { |
| 8 constructor() { | 8 constructor() { |
| 9 super(); | 9 super(); |
| 10 this._popover = new UI.Popover(); | 10 this._popover = new UI.GlassPane(); |
| 11 this._popover.setNoPadding(true); | 11 this._popover.registerRequiredCSS('inline_editor/swatchPopover.css'); |
| 12 this._popover.setBlockPointerEvents(false); |
| 13 this._popover.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent); |
| 14 this._popover.setShowArrow(true); |
| 12 this._popover.element.addEventListener('mousedown', e => e.consume(), false)
; | 15 this._popover.element.addEventListener('mousedown', e => e.consume(), false)
; |
| 13 | 16 |
| 14 this._hideProxy = this.hide.bind(this, true); | 17 this._hideProxy = this.hide.bind(this, true); |
| 15 this._boundOnKeyDown = this._onKeyDown.bind(this); | 18 this._boundOnKeyDown = this._onKeyDown.bind(this); |
| 16 this._boundFocusOut = this._onFocusOut.bind(this); | 19 this._boundFocusOut = this._onFocusOut.bind(this); |
| 17 this._isHidden = true; | 20 this._isHidden = true; |
| 18 } | 21 } |
| 19 | 22 |
| 20 /** | 23 /** |
| 21 * @param {!Event} event | 24 * @param {!Event} event |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 this.reposition(); | 57 this.reposition(); |
| 55 view.focus(); | 58 view.focus(); |
| 56 | 59 |
| 57 var document = this._popover.element.ownerDocument; | 60 var document = this._popover.element.ownerDocument; |
| 58 document.addEventListener('mousedown', this._hideProxy, false); | 61 document.addEventListener('mousedown', this._hideProxy, false); |
| 59 document.defaultView.addEventListener('resize', this._hideProxy, false); | 62 document.defaultView.addEventListener('resize', this._hideProxy, false); |
| 60 this._view.contentElement.addEventListener('keydown', this._boundOnKeyDown,
false); | 63 this._view.contentElement.addEventListener('keydown', this._boundOnKeyDown,
false); |
| 61 } | 64 } |
| 62 | 65 |
| 63 reposition() { | 66 reposition() { |
| 64 // Unbind "blur" listener to avoid reenterability: |popover.showView| will h
ide the popover and trigger it synchronously. | 67 // Unbind "blur" listener to avoid reenterability: |popover.show()| will hid
e the popover and trigger it synchronously. |
| 65 this._view.contentElement.removeEventListener('focusout', this._boundFocusOu
t, false); | 68 this._view.contentElement.removeEventListener('focusout', this._boundFocusOu
t, false); |
| 66 this._popover.showView(this._view, this._anchorElement); | 69 this._view.show(this._popover.contentElement); |
| 70 this._popover.setContentAnchorBox(this._anchorElement.boxInWindow()); |
| 71 this._popover.show(this._anchorElement.ownerDocument); |
| 67 this._view.contentElement.addEventListener('focusout', this._boundFocusOut,
false); | 72 this._view.contentElement.addEventListener('focusout', this._boundFocusOut,
false); |
| 68 if (!this._focusRestorer) | 73 if (!this._focusRestorer) |
| 69 this._focusRestorer = new UI.WidgetFocusRestorer(this._view); | 74 this._focusRestorer = new UI.WidgetFocusRestorer(this._view); |
| 70 } | 75 } |
| 71 | 76 |
| 72 /** | 77 /** |
| 73 * @param {boolean=} commitEdit | 78 * @param {boolean=} commitEdit |
| 74 */ | 79 */ |
| 75 hide(commitEdit) { | 80 hide(commitEdit) { |
| 76 if (this._isHidden) | 81 if (this._isHidden) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 103 this.hide(true); | 108 this.hide(true); |
| 104 event.consume(true); | 109 event.consume(true); |
| 105 return; | 110 return; |
| 106 } | 111 } |
| 107 if (event.key === 'Escape') { | 112 if (event.key === 'Escape') { |
| 108 this.hide(false); | 113 this.hide(false); |
| 109 event.consume(true); | 114 event.consume(true); |
| 110 } | 115 } |
| 111 } | 116 } |
| 112 }; | 117 }; |
| OLD | NEW |