From 8c6203d47df648483cbbe42c3d67871dbbee3b3c Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Tue, 30 Aug 2016 13:25:58 +0200 Subject: [PATCH] Bug 1298435 - upon browser window resize, update all the rects we track for each range we found and correctly reposition all oulines atop the mask. r=jaws MozReview-Commit-ID: 46q0hVxfczW --HG-- extra : rebase_source : aa33f2cc5432aa61ba8074af72109d0aeaadde99 --- toolkit/modules/FinderHighlighter.jsm | 56 +++++++++++++++++---------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/toolkit/modules/FinderHighlighter.jsm b/toolkit/modules/FinderHighlighter.jsm index 9c9341385716..166b38a3f664 100644 --- a/toolkit/modules/FinderHighlighter.jsm +++ b/toolkit/modules/FinderHighlighter.jsm @@ -762,13 +762,14 @@ FinderHighlighter.prototype = { * Read and store the rectangles that encompass the entire region of a range * for use by the drawing function of the highlighter. * - * @param {nsIDOMRange} range Range to fetch the rectangles from - * @param {Boolean} [checkIfDynamic] Whether we should check if the range - * is dynamic as per the rules in - * `_isInDynamicContainer()`. Optional, - * defaults to `true` - * @param {Object} [dict] Dictionary of properties belonging to - * the currently active window + * @param {nsIDOMRange} range Range to fetch the rectangles from + * @param {Boolean} [checkIfDynamic] Whether we should check if the range + * is dynamic as per the rules in + * `_isInDynamicContainer()`. Optional, + * defaults to `true` + * @param {Object} [dict] Dictionary of properties belonging to + * the currently active window + * @return {Set} Set of rects that were found for the range */ _updateRangeRects(range, checkIfDynamic = true, dict = null) { let window = range.startContainer.ownerDocument.defaultView; @@ -800,6 +801,7 @@ FinderHighlighter.prototype = { dict.modalHighlightRectsMap.set(range, rects); if (checkIfDynamic && this._isInDynamicContainer(range)) dict.dynamicRangesSet.add(range); + return rects; }, /** @@ -830,7 +832,7 @@ FinderHighlighter.prototype = { */ _updateRangeOutline(dict, textContent = [], fontStyle = null) { let outlineNode = dict.modalHighlightOutline; - let range = dict.currentFoundRange; + let range = this.finder._fastFind.getFoundRange(); if (!outlineNode || !range) return; let rect = range.getClientRects()[0]; @@ -964,11 +966,14 @@ FinderHighlighter.prototype = { let maskContent = []; const kRectClassName = kModalIdPrefix + "-findbar-modalHighlight-rect"; for (let [range, rects] of dict.modalHighlightRectsMap) { + if (dict.updateAllRanges) + rects = this._updateRangeRects(range); for (let rect of rects) { maskContent.push(`
`); } } + dict.updateAllRanges = false; maskNode.innerHTML = maskContent.join(""); } @@ -1012,14 +1017,17 @@ FinderHighlighter.prototype = { * @param {nsIDOMWindow} window * @param {Object} options Dictionary of painter hints that contains the * following properties: - * {Boolean} contentChanged Whether the documents' content changed in the - * meantime. This happens when the DOM is updated - * whilst the page is loaded. - * {Boolean} scrollOnly TRUE when the page has scrolled in the meantime, - * which means that the fixed positioned elements - * need to be repainted. + * {Boolean} contentChanged Whether the documents' content changed in the + * meantime. This happens when the DOM is updated + * whilst the page is loaded. + * {Boolean} scrollOnly TRUE when the page has scrolled in the meantime, + * which means that the fixed positioned elements + * need to be repainted. + * {Boolean} updateAllRanges Whether to recalculate the rects of all ranges + * that were found up until now. */ - _scheduleRepaintOfMask(window, { contentChanged, scrollOnly } = { contentChanged: false, scrollOnly: false }) { + _scheduleRepaintOfMask(window, { contentChanged, scrollOnly, updateAllRanges } = + { contentChanged: false, scrollOnly: false, updateAllRanges: false }) { if (!this._modal) return; @@ -1031,6 +1039,9 @@ FinderHighlighter.prototype = { // `_repaintHighlightAllMask()` right after the timeout. if (!dict.unconditionalRepaintRequested) dict.unconditionalRepaintRequested = !contentChanged || repaintFixedNodes; + // Some events, like a resize, call for recalculation of all the rects of all ranges. + if (!dict.updateAllRanges) + dict.updateAllRanges = updateAllRanges; if (dict.modalRepaintScheduler) return; @@ -1094,14 +1105,16 @@ FinderHighlighter.prototype = { window = window.top; dict.highlightListeners = [ this._scheduleRepaintOfMask.bind(this, window, { contentChanged: true }), + this._scheduleRepaintOfMask.bind(this, window, { updateAllRanges: true }), this._scheduleRepaintOfMask.bind(this, window, { scrollOnly: true }), this.hide.bind(this, window, null) ]; let target = this.iterator._getDocShell(window).chromeEventHandler; target.addEventListener("MozAfterPaint", dict.highlightListeners[0]); - target.addEventListener("DOMMouseScroll", dict.highlightListeners[1]); - target.addEventListener("mousewheel", dict.highlightListeners[1]); - target.addEventListener("click", dict.highlightListeners[2]); + target.addEventListener("resize", dict.highlightListeners[1]); + target.addEventListener("DOMMouseScroll", dict.highlightListeners[2]); + target.addEventListener("mousewheel", dict.highlightListeners[2]); + target.addEventListener("click", dict.highlightListeners[3]); }, /** @@ -1117,9 +1130,10 @@ FinderHighlighter.prototype = { let target = this.iterator._getDocShell(window).chromeEventHandler; target.removeEventListener("MozAfterPaint", dict.highlightListeners[0]); - target.removeEventListener("DOMMouseScroll", dict.highlightListeners[1]); - target.removeEventListener("mousewheel", dict.highlightListeners[1]); - target.removeEventListener("click", dict.highlightListeners[2]); + target.removeEventListener("resize", dict.highlightListeners[1]); + target.removeEventListener("DOMMouseScroll", dict.highlightListeners[2]); + target.removeEventListener("mousewheel", dict.highlightListeners[2]); + target.removeEventListener("click", dict.highlightListeners[3]); dict.highlightListeners = null; },