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

Side by Side Diff: Source/devtools/front_end/ui/EditorPopoverHelper.js

Issue 1155773002: Devtools Animations: Add cubic bezier easing editor for animations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
(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()
45 {
46 return this._anchorElement;
47 },
48
49 /**
50 * @param {!WebInspector.Widget} view
51 * @param {!Element} anchorElement
52 * @param {?Element} scrollerElement
53 * @param {function(boolean)=} hiddenCallback
54 */
55 show: function(view, anchorElement, scrollerElement, hiddenCallback)
56 {
57 if (this._popover.isShowing()) {
58 if (this._anchorElement === anchorElement)
59 return;
60
61 // Reopen the picker for another anchor element.
62 this.hide(true);
63 }
64
65 delete this._isHidden;
66 this._anchorElement = anchorElement;
67 this._scrollerElement = scrollerElement;
68 this._view = view;
69 this._hiddenCallback = hiddenCallback;
70 this._reposition();
71
72 var document = this._popover.element.ownerDocument;
73 document.addEventListener("mousedown", this._hideProxy, false);
74 document.defaultView.addEventListener("resize", this._hideProxy, false);
75 this._view.contentElement.addEventListener("keydown", this._boundOnKeyDo wn, false);
76
77 if (this._scrollerElement)
78 this._scrollerElement.addEventListener("scroll", this._repositionBou nd, false);
79 },
80
81 /**
82 * @param {!Event=} event
83 */
84 _reposition: function(event)
85 {
86 if (!this._previousFocusElement)
87 this._previousFocusElement = WebInspector.currentFocusElement();
88 // Unbind "blur" listener to avoid reenterability: |popover.showView| wi ll hide the popover and trigger it synchronously.
89 this._view.contentElement.removeEventListener("focusout", this._boundFoc usOut, false);
90 this._popover.showView(this._view, this._anchorElement);
91 this._view.contentElement.addEventListener("focusout", this._boundFocusO ut, false);
92 WebInspector.setCurrentFocusElement(this._view.contentElement);
93 },
94
95 /**
96 * @param {boolean=} commitEdit
97 */
98 hide: function(commitEdit)
99 {
100 if (this._isHidden)
101 return;
102 var document = this._popover.element.ownerDocument;
103 this._isHidden = true;
104 this._popover.hide();
105
106 if (this._scrollerElement)
107 this._scrollerElement.removeEventListener("scroll", this._reposition Bound, false);
108
109 document.removeEventListener("mousedown", this._hideProxy, false);
110 document.defaultView.removeEventListener("resize", this._hideProxy, fals e);
111
112 if (this._hiddenCallback)
113 this._hiddenCallback.call(null, !!commitEdit);
114
115 WebInspector.setCurrentFocusElement(this._previousFocusElement);
116 delete this._previousFocusElement;
117 delete this._anchorElement;
118 delete this._scrollerElement;
119 if (this._view) {
120 this._view.detach();
121 this._view.contentElement.removeEventListener("keydown", this._bound OnKeyDown, false);
122 this._view.contentElement.removeEventListener("focusout", this._boun dFocusOut, false);
123 delete this._view;
124 }
125 },
126
127 /**
128 * @param {!Event} event
129 */
130 _onKeyDown: function(event)
131 {
132 if (event.keyIdentifier === "Enter") {
133 this.hide(true);
134 event.consume(true);
135 return;
136 }
137 if (event.keyIdentifier === "U+001B") { // Escape key
138 this.hide(false);
139 event.consume(true);
140 }
141 },
142
143 __proto__: WebInspector.Object.prototype
144 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/AnimationModel.js ('k') | Source/devtools/front_end/ui/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698