forked from mirrors/gecko-dev
		
	Bug 1472931 - Drop the autofocus feature of HTMLTooltip. r=birtles
This feature is no longer used. So this patch will remove this feature. Differential Revision: https://phabricator.services.mozilla.com/D4052 --HG-- extra : moz-landing-system : lando
This commit is contained in:
		
							parent
							
								
									69eb976056
								
							
						
					
					
						commit
						94698538d1
					
				
					 2 changed files with 6 additions and 64 deletions
				
			
		|  | @ -5,7 +5,7 @@ | ||||||
| "use strict"; | "use strict"; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Test the HTMLTooltip autofocus configuration option. |  * This is the sanity test for the HTMLTooltip focus | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| const HTML_NS = "http://www.w3.org/1999/xhtml"; | const HTML_NS = "http://www.w3.org/1999/xhtml"; | ||||||
|  | @ -30,17 +30,11 @@ add_task(async function() { | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| async function runTests(doc) { | async function runTests(doc) { | ||||||
|   await testNoAutoFocus(doc); |  | ||||||
|   await testAutoFocus(doc); |  | ||||||
|   await testAutoFocusPreservesFocusChange(doc); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| async function testNoAutoFocus(doc) { |  | ||||||
|   await focusNode(doc, "#box4-input"); |   await focusNode(doc, "#box4-input"); | ||||||
|   ok(doc.activeElement.closest("#box4-input"), "Focus is in the #box4-input"); |   ok(doc.activeElement.closest("#box4-input"), "Focus is in the #box4-input"); | ||||||
| 
 | 
 | ||||||
|   info("Test a tooltip without autofocus will not take focus"); |   info("Test a tooltip will not take focus"); | ||||||
|   const tooltip = await createTooltip(doc, false); |   const tooltip = await createTooltip(doc); | ||||||
| 
 | 
 | ||||||
|   await showTooltip(tooltip, doc.getElementById("box1")); |   await showTooltip(tooltip, doc.getElementById("box1")); | ||||||
|   ok(doc.activeElement.closest("#box4-input"), "Focus is still in the #box4-input"); |   ok(doc.activeElement.closest("#box4-input"), "Focus is still in the #box4-input"); | ||||||
|  | @ -51,50 +45,6 @@ async function testNoAutoFocus(doc) { | ||||||
|   tooltip.destroy(); |   tooltip.destroy(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function testAutoFocus(doc) { |  | ||||||
|   await focusNode(doc, "#box4-input"); |  | ||||||
|   ok(doc.activeElement.closest("#box4-input"), "Focus is in the #box4-input"); |  | ||||||
| 
 |  | ||||||
|   info("Test autofocus tooltip takes focus when displayed, " + |  | ||||||
|     "and restores the focus when hidden"); |  | ||||||
|   const tooltip = await createTooltip(doc, true); |  | ||||||
| 
 |  | ||||||
|   await showTooltip(tooltip, doc.getElementById("box1")); |  | ||||||
|   ok(doc.activeElement.closest(".tooltip-content"), "Focus is in the tooltip"); |  | ||||||
| 
 |  | ||||||
|   await hideTooltip(tooltip); |  | ||||||
|   ok(doc.activeElement.closest("#box4-input"), "Focus is in the #box4-input"); |  | ||||||
| 
 |  | ||||||
|   info("Blur the textbox before moving to the next test to reset the state."); |  | ||||||
|   await blurNode(doc, "#box4-input"); |  | ||||||
| 
 |  | ||||||
|   tooltip.destroy(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| async function testAutoFocusPreservesFocusChange(doc) { |  | ||||||
|   await focusNode(doc, "#box4-input"); |  | ||||||
|   ok(doc.activeElement.closest("#box4-input"), "Focus is still in the #box3-input"); |  | ||||||
| 
 |  | ||||||
|   info("Test autofocus tooltip takes focus when displayed, " + |  | ||||||
|     "but does not try to restore the active element if it is not focused when hidden"); |  | ||||||
|   const tooltip = await createTooltip(doc, true); |  | ||||||
| 
 |  | ||||||
|   await showTooltip(tooltip, doc.getElementById("box1")); |  | ||||||
|   ok(doc.activeElement.closest(".tooltip-content"), "Focus is in the tooltip"); |  | ||||||
| 
 |  | ||||||
|   info("Move the focus to #box3-input while the tooltip is displayed"); |  | ||||||
|   await focusNode(doc, "#box3-input"); |  | ||||||
|   ok(doc.activeElement.closest("#box3-input"), "Focus moved to the #box3-input"); |  | ||||||
| 
 |  | ||||||
|   await hideTooltip(tooltip); |  | ||||||
|   ok(doc.activeElement.closest("#box3-input"), "Focus is still in the #box3-input"); |  | ||||||
| 
 |  | ||||||
|   info("Blur the textbox before moving to the next test to reset the state."); |  | ||||||
|   await blurNode(doc, "#box3-input"); |  | ||||||
| 
 |  | ||||||
|   tooltip.destroy(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * Fpcus the node corresponding to the provided selector in the provided document. Returns |  * Fpcus the node corresponding to the provided selector in the provided document. Returns | ||||||
|  * a promise that will resolve when receiving the focus event on the node. |  * a promise that will resolve when receiving the focus event on the node. | ||||||
|  | @ -118,16 +68,15 @@ function blurNode(doc, selector) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Create an HTMLTooltip instance with the provided autofocus setting. |  * Create an HTMLTooltip instance. | ||||||
|  * |  * | ||||||
|  * @param {Document} doc |  * @param {Document} doc | ||||||
|  *        Document in which the tooltip should be created |  *        Document in which the tooltip should be created | ||||||
|  * @param {Boolean} autofocus |  | ||||||
|  * @return {Promise} promise that will resolve the HTMLTooltip instance created when the |  * @return {Promise} promise that will resolve the HTMLTooltip instance created when the | ||||||
|  *         tooltip content will be ready. |  *         tooltip content will be ready. | ||||||
|  */ |  */ | ||||||
| function createTooltip(doc, autofocus) { | function createTooltip(doc) { | ||||||
|   const tooltip = new HTMLTooltip(doc, {autofocus, useXulWrapper}); |   const tooltip = new HTMLTooltip(doc, {useXulWrapper}); | ||||||
|   const div = doc.createElementNS(HTML_NS, "div"); |   const div = doc.createElementNS(HTML_NS, "div"); | ||||||
|   div.classList.add("tooltip-content"); |   div.classList.add("tooltip-content"); | ||||||
|   div.style.height = "50px"; |   div.style.height = "50px"; | ||||||
|  |  | ||||||
|  | @ -294,8 +294,6 @@ const getRelativeRect = function(node, relativeTo) { | ||||||
|  *        - {String} type |  *        - {String} type | ||||||
|  *          Display type of the tooltip. Possible values: "normal", "arrow", and |  *          Display type of the tooltip. Possible values: "normal", "arrow", and | ||||||
|  *          "doorhanger". |  *          "doorhanger". | ||||||
|  *        - {Boolean} autofocus |  | ||||||
|  *          Defaults to false. Should the tooltip be focused when opening it. |  | ||||||
|  *        - {Boolean} consumeOutsideClicks |  *        - {Boolean} consumeOutsideClicks | ||||||
|  *          Defaults to true. The tooltip is closed when clicking outside. |  *          Defaults to true. The tooltip is closed when clicking outside. | ||||||
|  *          Should this event be stopped and consumed or not. |  *          Should this event be stopped and consumed or not. | ||||||
|  | @ -307,7 +305,6 @@ function HTMLTooltip(toolboxDoc, { | ||||||
|     id = "", |     id = "", | ||||||
|     className = "", |     className = "", | ||||||
|     type = "normal", |     type = "normal", | ||||||
|     autofocus = false, |  | ||||||
|     consumeOutsideClicks = true, |     consumeOutsideClicks = true, | ||||||
|     useXulWrapper = false, |     useXulWrapper = false, | ||||||
|   } = {}) { |   } = {}) { | ||||||
|  | @ -317,7 +314,6 @@ function HTMLTooltip(toolboxDoc, { | ||||||
|   this.id = id; |   this.id = id; | ||||||
|   this.className = className; |   this.className = className; | ||||||
|   this.type = type; |   this.type = type; | ||||||
|   this.autofocus = autofocus; |  | ||||||
|   this.consumeOutsideClicks = consumeOutsideClicks; |   this.consumeOutsideClicks = consumeOutsideClicks; | ||||||
|   this.useXulWrapper = this._isXUL() && useXulWrapper; |   this.useXulWrapper = this._isXUL() && useXulWrapper; | ||||||
|   this.preferredWidth = "auto"; |   this.preferredWidth = "auto"; | ||||||
|  | @ -451,9 +447,6 @@ HTMLTooltip.prototype = { | ||||||
| 
 | 
 | ||||||
|     this.doc.defaultView.clearTimeout(this.attachEventsTimer); |     this.doc.defaultView.clearTimeout(this.attachEventsTimer); | ||||||
|     this.attachEventsTimer = this.doc.defaultView.setTimeout(() => { |     this.attachEventsTimer = this.doc.defaultView.setTimeout(() => { | ||||||
|       if (this.autofocus) { |  | ||||||
|         this.focus(); |  | ||||||
|       } |  | ||||||
|       // Update the top window reference each time in case the host changes.
 |       // Update the top window reference each time in case the host changes.
 | ||||||
|       this.topWindow = this._getTopWindow(); |       this.topWindow = this._getTopWindow(); | ||||||
|       this.topWindow.addEventListener("click", this._onClick, true); |       this.topWindow.addEventListener("click", this._onClick, true); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Mantaroh Yoshinaga
						Mantaroh Yoshinaga