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

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

Issue 1271193002: Devtools UI: Behavior and UI update to tooltips (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/devtools/front_end/ui/Toolbar.js ('k') | Source/devtools/front_end/ui/tooltip.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 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 * @param {!Document} doc 7 * @param {!Document} doc
8 */ 8 */
9 WebInspector.Tooltip = function(doc) 9 WebInspector.Tooltip = function(doc)
10 { 10 {
11 this.element = doc.body.createChild("div"); 11 this.element = doc.body.createChild("div");
12 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element) ; 12 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element) ;
13 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool tip.css")); 13 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool tip.css"));
14 14
15 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); 15 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip");
16 this._arrowElement = this._shadowRoot.createChild("div", "tooltip-arrow");
17 doc.addEventListener("mousemove", this._mouseMove.bind(this), false); 16 doc.addEventListener("mousemove", this._mouseMove.bind(this), false);
17 doc.addEventListener("mousedown", this._hide.bind(this), false);
18 } 18 }
19 19
20 WebInspector.Tooltip.Timing = { 20 WebInspector.Tooltip.Timing = {
21 // Max time between tooltips showing that no opening delay is required. 21 // Max time between tooltips showing that no opening delay is required.
22 "InstantThreshold": 300, 22 "InstantThreshold": 300,
23 // Wait time before opening a tooltip. 23 // Wait time before opening a tooltip.
24 "OpeningDelay": 400 24 "OpeningDelay": 600
25 } 25 }
26 26
27 WebInspector.Tooltip.AlignmentOverride = { 27 WebInspector.Tooltip.AlignmentOverride = {
28 Right: "Right" 28 Right: "Right"
29 } 29 }
30 30
31 WebInspector.Tooltip.prototype = { 31 WebInspector.Tooltip.prototype = {
32 /** 32 /**
33 * @param {!Event} event 33 * @param {!Event} event
34 */ 34 */
35 _mouseMove: function(event) 35 _mouseMove: function(event)
36 { 36 {
37 var path = event.deepPath ? event.deepPath : event.path; 37 var path = event.deepPath ? event.deepPath : event.path;
38 if (!path) 38 if (!path || event.buttons !== 0)
39 return; 39 return;
40 40
41 if (this._anchorElement && path.indexOf(this._anchorElement) === -1) 41 if (this._anchorElement && path.indexOf(this._anchorElement) === -1)
42 this._hide(); 42 this._hide();
43 43
44 for (var element of path) { 44 for (var element of path) {
45 if (element === this._anchorElement) { 45 if (element === this._anchorElement) {
46 return; 46 return;
47 } else if (element[WebInspector.Tooltip._symbol]) { 47 } else if (element[WebInspector.Tooltip._symbol]) {
48 this._show(element); 48 this._show(element);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 this._tooltipLastOpened = instant ? now : now + WebInspector.Tooltip.Tim ing.OpeningDelay; 83 this._tooltipLastOpened = instant ? now : now + WebInspector.Tooltip.Tim ing.OpeningDelay;
84 84
85 // Get container element. 85 // Get container element.
86 var container = WebInspector.Dialog.modalHostView().element; 86 var container = WebInspector.Dialog.modalHostView().element;
87 if (!anchorElement.isDescendant(container)) 87 if (!anchorElement.isDescendant(container))
88 container = this.element.parentElement; 88 container = this.element.parentElement;
89 89
90 // Posititon tooltip based on the anchor element. 90 // Posititon tooltip based on the anchor element.
91 var containerOffset = container.offsetRelativeToWindow(this.element.wind ow()); 91 var containerOffset = container.offsetRelativeToWindow(this.element.wind ow());
92 var containerOffsetWidth = container.offsetWidth; 92 var containerOffsetWidth = container.offsetWidth;
93 var containerOffsetHeight = container.offsetHeight;
93 var anchorBox = this._anchorElement.boxInWindow(this.element.window()); 94 var anchorBox = this._anchorElement.boxInWindow(this.element.window());
94 const arrowSize = 4; 95 const anchorOffset = 2;
95 const pageMargin = 2; 96 const pageMargin = 2;
96 this._tooltipElement.style.maxWidth = (containerOffsetWidth - pageMargin * 2) + "px"; 97 this._tooltipElement.style.maxWidth = (containerOffsetWidth - pageMargin * 2) + "px";
97 var tooltipWidth = this._tooltipElement.offsetWidth; 98 var tooltipWidth = this._tooltipElement.offsetWidth;
98 var tooltipHeight = this._tooltipElement.offsetHeight; 99 var tooltipHeight = this._tooltipElement.offsetHeight;
99 var tooltipX = anchorBox.x + anchorBox.width / 2 - tooltipWidth / 2; 100 var tooltipX = anchorBox.x;
100 if (tooltip.alignment === WebInspector.Tooltip.AlignmentOverride.Right)
101 tooltipX = anchorBox.x;
102 tooltipX = Number.constrain(tooltipX, 101 tooltipX = Number.constrain(tooltipX,
103 containerOffset.x + pageMargin, 102 containerOffset.x + pageMargin,
104 containerOffset.x + containerOffsetWidth - tooltipWidth - pageMargin ); 103 containerOffset.x + containerOffsetWidth - tooltipWidth - pageMargin );
105 var onBottom = anchorBox.y - arrowSize - anchorBox.height < containerOff set.y; 104 var onBottom = anchorBox.y + anchorOffset + anchorBox.height < container Offset.y + containerOffsetHeight;
106 var tooltipY = onBottom ? anchorBox.y + anchorBox.height + arrowSize : a nchorBox.y - tooltipHeight - arrowSize; 105 var tooltipY = onBottom ? anchorBox.y + anchorBox.height + anchorOffset : anchorBox.y - tooltipHeight - anchorOffset;
107 this._tooltipElement.positionAt(tooltipX, tooltipY); 106 this._tooltipElement.positionAt(tooltipX, tooltipY);
108
109 // Position arrow next to anchor element.
110 this._arrowElement.positionAt(anchorBox.x + anchorBox.width / 2, onBotto m ? anchorBox.y + anchorBox.height : anchorBox.y - arrowSize);
111 this._arrowElement.classList.toggle("tooltip-arrow-top", !onBottom);
112 }, 107 },
113 108
114 _hide: function() 109 _hide: function()
115 { 110 {
116 delete this._anchorElement; 111 delete this._anchorElement;
117 this._tooltipElement.classList.remove("shown"); 112 this._tooltipElement.classList.remove("shown");
118 if (Date.now() > this._tooltipLastOpened) 113 if (Date.now() > this._tooltipLastOpened)
119 this._tooltipLastClosed = Date.now(); 114 this._tooltipLastClosed = Date.now();
120 } 115 }
121 } 116 }
122 117
123 WebInspector.Tooltip._symbol = Symbol("Tooltip"); 118 WebInspector.Tooltip._symbol = Symbol("Tooltip");
124 119
125 /** 120 /**
126 * @param {!Document} doc 121 * @param {!Document} doc
127 */ 122 */
128 WebInspector.Tooltip.installHandler = function(doc) 123 WebInspector.Tooltip.installHandler = function(doc)
129 { 124 {
130 new WebInspector.Tooltip(doc); 125 new WebInspector.Tooltip(doc);
131 } 126 }
132 127
133 /** 128 /**
134 * @param {!Element} element 129 * @param {!Element} element
135 * @param {!Element|string} tooltipContent 130 * @param {!Element|string} tooltipContent
136 * @param {string=} alignment
137 * @param {string=} actionId 131 * @param {string=} actionId
138 */ 132 */
139 WebInspector.Tooltip.install = function(element, tooltipContent, alignment, acti onId) 133 WebInspector.Tooltip.install = function(element, tooltipContent, actionId)
140 { 134 {
135 if (Runtime.experiments.isEnabled("tooltips") && typeof tooltipContent === " string" && tooltipContent === "")
136 return;
141 if (Runtime.experiments.isEnabled("tooltips")) 137 if (Runtime.experiments.isEnabled("tooltips"))
142 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, alig nment: alignment, actionId: actionId }; 138 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, acti onId: actionId };
143 else if (typeof tooltipContent === "string") 139 else if (typeof tooltipContent === "string")
144 element.title = tooltipContent; 140 element.title = tooltipContent;
145 else 141 else
146 console.assert("Cannot set an element without custom tooltips enabled"); 142 console.assert("Cannot set an element without custom tooltips enabled");
147 } 143 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/Toolbar.js ('k') | Source/devtools/front_end/ui/tooltip.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698