Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.Object} | |
| 8 */ | |
| 9 WebInspector.EditorPopoverHelper = function() | |
| 10 { | |
| 11 this._popover = new WebInspector.Popover(); | |
| 12 this._popover.setCanShrink(false); | |
| 13 this._popover.setNoMargins(true); | |
| 14 this._popover.element.addEventListener("mousedown", consumeEvent, false); | |
| 15 | |
| 16 this._hideProxy = this.hide.bind(this, true); | |
| 17 this._boundOnKeyDown = this._onKeyDown.bind(this); | |
| 18 this._repositionBound = this._reposition.bind(this); | |
| 19 this._boundFocusOut = this._onFocusOut.bind(this); | |
| 20 } | |
| 21 | |
| 22 WebInspector.EditorPopoverHelper.prototype = { | |
| 23 /** | |
| 24 * @param {!Event} event | |
| 25 */ | |
| 26 _onFocusOut: function(event) | |
| 27 { | |
| 28 if (!event.relatedTarget || event.relatedTarget.isSelfOrDescendant(this. _view.contentElement)) | |
| 29 return; | |
| 30 this._hideProxy(); | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * @return {boolean} | |
| 35 */ | |
| 36 isShowing: function() | |
| 37 { | |
| 38 return this._popover.isShowing(); | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * @return {?Element} | |
| 43 */ | |
| 44 anchorElement: function() | |
|
dgozman
2015/05/28 11:04:03
Who uses this?
samli
2015/05/28 11:48:14
I used this in AnimationTimeline to allow us to re
| |
| 45 { | |
| 46 return this._anchorElement; | |
| 47 }, | |
| 48 | |
| 49 /** | |
| 50 * @param {!WebInspector.Widget} view | |
| 51 * @param {!Element} anchorElement | |
| 52 * @param {function(boolean)=} hiddenCallback | |
| 53 */ | |
| 54 show: function(view, anchorElement, hiddenCallback) | |
| 55 { | |
| 56 if (this._popover.isShowing()) { | |
| 57 if (this._anchorElement === anchorElement) | |
| 58 return; | |
| 59 | |
| 60 // Reopen the picker for another anchor element. | |
| 61 this.hide(true); | |
| 62 } | |
| 63 | |
| 64 delete this._isHidden; | |
| 65 this._anchorElement = anchorElement; | |
| 66 this._view = view; | |
| 67 this._hiddenCallback = hiddenCallback; | |
| 68 this._reposition(); | |
| 69 | |
| 70 var document = this._popover.element.ownerDocument; | |
| 71 document.addEventListener("mousedown", this._hideProxy, false); | |
| 72 document.defaultView.addEventListener("resize", this._hideProxy, false); | |
| 73 this._view.contentElement.addEventListener("keydown", this._boundOnKeyDo wn, false); | |
| 74 | |
| 75 this._scrollerElement = anchorElement.enclosingNodeOrSelfWithClass("styl e-panes-wrapper"); | |
|
dgozman
2015/05/28 11:04:03
I guess this doesn't work in animation timeline. W
samli
2015/05/29 04:32:11
Done.
| |
| 76 if (this._scrollerElement) | |
| 77 this._scrollerElement.addEventListener("scroll", this._repositionBou nd, false); | |
| 78 }, | |
| 79 | |
| 80 /** | |
| 81 * @param {!Event=} event | |
| 82 */ | |
| 83 _reposition: function(event) | |
| 84 { | |
| 85 if (!this._previousFocusElement) | |
| 86 this._previousFocusElement = WebInspector.currentFocusElement(); | |
| 87 // Unbind "blur" listener to avoid reenterability: |popover.showView| wi ll hide the popover and trigger it synchronously. | |
| 88 this._view.contentElement.removeEventListener("focusout", this._boundFoc usOut, false); | |
| 89 this._popover.showView(this._view, this._anchorElement); | |
| 90 this._view.contentElement.addEventListener("focusout", this._boundFocusO ut, false); | |
| 91 WebInspector.setCurrentFocusElement(this._view.contentElement); | |
| 92 }, | |
| 93 | |
| 94 /** | |
| 95 * @param {boolean=} commitEdit | |
| 96 */ | |
| 97 hide: function(commitEdit) | |
| 98 { | |
| 99 if (this._isHidden) | |
| 100 return; | |
| 101 var document = this._popover.element.ownerDocument; | |
| 102 this._isHidden = true; | |
| 103 this._popover.hide(); | |
| 104 | |
| 105 if (this._scrollerElement) | |
| 106 this._scrollerElement.removeEventListener("scroll", this._reposition Bound, false); | |
| 107 | |
| 108 document.removeEventListener("mousedown", this._hideProxy, false); | |
| 109 document.defaultView.removeEventListener("resize", this._hideProxy, fals e); | |
| 110 | |
| 111 if (this._hiddenCallback) | |
| 112 this._hiddenCallback.call(null, !!commitEdit); | |
| 113 | |
| 114 WebInspector.setCurrentFocusElement(this._previousFocusElement); | |
| 115 delete this._previousFocusElement; | |
| 116 delete this._anchorElement; | |
| 117 if (this._view) { | |
| 118 this._view.detach(); | |
| 119 this._view.contentElement.removeEventListener("keydown", this._bound OnKeyDown, false); | |
| 120 this._view.contentElement.removeEventListener("focusout", this._boun dFocusOut, false); | |
| 121 delete this._view; | |
| 122 } | |
| 123 }, | |
| 124 | |
| 125 /** | |
| 126 * @param {!Event} event | |
| 127 */ | |
| 128 _onKeyDown: function(event) | |
| 129 { | |
| 130 if (event.keyIdentifier === "Enter") { | |
| 131 this.hide(true); | |
| 132 event.consume(true); | |
| 133 return; | |
| 134 } | |
| 135 if (event.keyIdentifier === "U+001B") { // Escape key | |
| 136 this.hide(false); | |
| 137 event.consume(true); | |
| 138 } | |
| 139 }, | |
| 140 | |
| 141 __proto__: WebInspector.Object.prototype | |
| 142 } | |
| OLD | NEW |