| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.Object} | 7 * @extends {WebInspector.Object} |
| 8 */ | 8 */ |
| 9 WebInspector.SwatchPopoverHelper = function() | 9 WebInspector.SwatchPopoverHelper = function() |
| 10 { | 10 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 this.reposition(); | 60 this.reposition(); |
| 61 | 61 |
| 62 var document = this._popover.element.ownerDocument; | 62 var document = this._popover.element.ownerDocument; |
| 63 document.addEventListener("mousedown", this._hideProxy, false); | 63 document.addEventListener("mousedown", this._hideProxy, false); |
| 64 document.defaultView.addEventListener("resize", this._hideProxy, false); | 64 document.defaultView.addEventListener("resize", this._hideProxy, false); |
| 65 this._view.contentElement.addEventListener("keydown", this._boundOnKeyDo
wn, false); | 65 this._view.contentElement.addEventListener("keydown", this._boundOnKeyDo
wn, false); |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 reposition: function() | 68 reposition: function() |
| 69 { | 69 { |
| 70 if (!this._previousFocusElement) | |
| 71 this._previousFocusElement = WebInspector.currentFocusElement(); | |
| 72 // Unbind "blur" listener to avoid reenterability: |popover.showView| wi
ll hide the popover and trigger it synchronously. | 70 // Unbind "blur" listener to avoid reenterability: |popover.showView| wi
ll hide the popover and trigger it synchronously. |
| 73 this._view.contentElement.removeEventListener("focusout", this._boundFoc
usOut, false); | 71 this._view.contentElement.removeEventListener("focusout", this._boundFoc
usOut, false); |
| 74 this._popover.showView(this._view, this._anchorElement); | 72 this._popover.showView(this._view, this._anchorElement); |
| 75 this._view.contentElement.addEventListener("focusout", this._boundFocusO
ut, false); | 73 this._view.contentElement.addEventListener("focusout", this._boundFocusO
ut, false); |
| 76 WebInspector.setCurrentFocusElement(this._view.contentElement); | 74 if (!this._focusRestorer) |
| 75 this._focusRestorer = new WebInspector.WidgetFocusRestorer(this._vie
w); |
| 77 }, | 76 }, |
| 78 | 77 |
| 79 /** | 78 /** |
| 80 * @param {boolean=} commitEdit | 79 * @param {boolean=} commitEdit |
| 81 */ | 80 */ |
| 82 hide: function(commitEdit) | 81 hide: function(commitEdit) |
| 83 { | 82 { |
| 84 if (this._isHidden) | 83 if (this._isHidden) |
| 85 return; | 84 return; |
| 86 var document = this._popover.element.ownerDocument; | 85 var document = this._popover.element.ownerDocument; |
| 87 this._isHidden = true; | 86 this._isHidden = true; |
| 88 this._popover.hide(); | 87 this._popover.hide(); |
| 89 | 88 |
| 90 document.removeEventListener("mousedown", this._hideProxy, false); | 89 document.removeEventListener("mousedown", this._hideProxy, false); |
| 91 document.defaultView.removeEventListener("resize", this._hideProxy, fals
e); | 90 document.defaultView.removeEventListener("resize", this._hideProxy, fals
e); |
| 92 | 91 |
| 93 if (this._hiddenCallback) | 92 if (this._hiddenCallback) |
| 94 this._hiddenCallback.call(null, !!commitEdit); | 93 this._hiddenCallback.call(null, !!commitEdit); |
| 95 | 94 |
| 96 WebInspector.setCurrentFocusElement(this._previousFocusElement); | 95 this._focusRestorer.restore(); |
| 97 delete this._previousFocusElement; | |
| 98 delete this._anchorElement; | 96 delete this._anchorElement; |
| 99 if (this._view) { | 97 if (this._view) { |
| 100 this._view.detach(); | 98 this._view.detach(); |
| 101 this._view.contentElement.removeEventListener("keydown", this._bound
OnKeyDown, false); | 99 this._view.contentElement.removeEventListener("keydown", this._bound
OnKeyDown, false); |
| 102 this._view.contentElement.removeEventListener("focusout", this._boun
dFocusOut, false); | 100 this._view.contentElement.removeEventListener("focusout", this._boun
dFocusOut, false); |
| 103 delete this._view; | 101 delete this._view; |
| 104 } | 102 } |
| 105 }, | 103 }, |
| 106 | 104 |
| 107 /** | 105 /** |
| 108 * @param {!Event} event | 106 * @param {!Event} event |
| 109 */ | 107 */ |
| 110 _onKeyDown: function(event) | 108 _onKeyDown: function(event) |
| 111 { | 109 { |
| 112 if (event.key === "Enter") { | 110 if (event.key === "Enter") { |
| 113 this.hide(true); | 111 this.hide(true); |
| 114 event.consume(true); | 112 event.consume(true); |
| 115 return; | 113 return; |
| 116 } | 114 } |
| 117 if (event.key === "Escape") { | 115 if (event.key === "Escape") { |
| 118 this.hide(false); | 116 this.hide(false); |
| 119 event.consume(true); | 117 event.consume(true); |
| 120 } | 118 } |
| 121 }, | 119 }, |
| 122 | 120 |
| 123 __proto__: WebInspector.Object.prototype | 121 __proto__: WebInspector.Object.prototype |
| 124 } | 122 } |
| OLD | NEW |