From e30525b1a78eb0662098e38e426eabe1b85bc40c Mon Sep 17 00:00:00 2001 From: Joey Arhar Date: Tue, 16 Nov 2021 13:02:39 +0000 Subject: [PATCH] Revert "Re-enable offsetParent and fix in webui's paper-tooltip" This reverts commit def507007a4d56a61c433f565c1f0beac7790831. Reason for revert: The polyfill I wrote, not the actual offsetParent flag, broke something else. I'll need to figure out what I did wrong in the polyfill and fix it in a reland: crbug.com/1264786 Fixed: 1264786 Original change's description: > Re-enable offsetParent and fix in webui's paper-tooltip > > When I first changed the behavior of offsetParent for crbug.com/920069 > it broke some webui pages which used paper-toolip: crbug.com/1200750 > > I minimized the broken case and determined that paper-tooltip was > broken. I made a PR on paper-tooltip here, but it's unlikely that it > will ever get merged: > https://github.com/PolymerElements/paper-tooltip/pull/156 > > The fix to paper-tooltip is to polyfill the old offsetParent behavior in > javascript. This patch applies the fix to paper-tooltip within chrome > and re-enables the new offsetParent behavior. > > Fixed: 920069 > Change-Id: Ib39c34a6c15b44161a7942c7ee9cfd4afe68acf7 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3061435 > Commit-Queue: Joey Arhar > Reviewed-by: dpapad > Cr-Commit-Position: refs/heads/main@{#935992} (cherry picked from commit 5c36b4e8268c42e6d206af77efe45d58419043fe) Change-Id: I27faaeb162a004130e4692595530ea5ab4300574 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3280437 Reviewed-by: Joey Arhar Reviewed-by: dpapad Auto-Submit: Joey Arhar Commit-Queue: dpapad Cr-Original-Commit-Position: refs/heads/main@{#941603} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3282903 Commit-Queue: Joey Arhar Cr-Commit-Position: refs/branch-heads/4692@{#200} Cr-Branched-From: 038cd96142d384c0d2238973f1cb277725a62eba-refs/heads/main@{#938553} --- third_party/polymer/v3_0/chromium.patch | 68 ------------------- .../paper-tooltip/paper-tooltip.js | 46 +------------ 2 files changed, 2 insertions(+), 112 deletions(-) diff --git a/third_party/polymer/v3_0/chromium.patch b/third_party/polymer/v3_0/chromium.patch index 5ea3dbe3e58dca..ae744dab92a839 100644 --- a/third_party/polymer/v3_0/chromium.patch +++ b/third_party/polymer/v3_0/chromium.patch @@ -433,71 +433,3 @@ index 6af2fa359336..c56a6737e1d8 100644 --paper-grey-50: #fafafa; --paper-grey-100: #f5f5f5; --paper-grey-200: #eeeeee; -diff --git a/components-chromium/paper-tooltip/paper-tooltip.js b/components-chromium/paper-tooltip/paper-tooltip.js -index 303d1bbdfc787..09cdae71e5334 100644 ---- a/components-chromium/paper-tooltip/paper-tooltip.js -+++ b/components-chromium/paper-tooltip/paper-tooltip.js -@@ -442,13 +442,16 @@ Polymer({ - * @return {void} - */ - updatePosition: function() { -- if (!this._target || !this.offsetParent) -+ if (!this._target) -+ return; -+ var offsetParent = this._composedOffsetParent(); -+ if (!offsetParent) - return; - var offset = this.offset; - // If a marginTop has been provided by the user (pre 1.0.3), use it. - if (this.marginTop != 14 && this.offset == 14) - offset = this.marginTop; -- var parentRect = this.offsetParent.getBoundingClientRect(); -+ var parentRect = offsetParent.getBoundingClientRect(); - var targetRect = this._target.getBoundingClientRect(); - var thisRect = this.getBoundingClientRect(); - var horizontalCenterOffset = (targetRect.width - thisRect.width) / 2; -@@ -594,5 +597,44 @@ Polymer({ - } - this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); - this.unlisten(this, 'mouseenter', 'hide'); -+ }, -+ -+ /** -+ * Polyfills the old offsetParent behavior from before the spec was changed: -+ * https://github.com/w3c/csswg-drafts/issues/159 -+ */ -+ _composedOffsetParent: function() { -+ let offsetParent = this.offsetParent; -+ let ancestor = this; -+ let foundInsideSlot = false; -+ while (ancestor && ancestor !== offsetParent) { -+ const assignedSlot = ancestor.assignedSlot; -+ if (assignedSlot) { -+ let newOffsetParent = assignedSlot.offsetParent; -+ -+ if (getComputedStyle(assignedSlot)['display'] === 'contents') { -+ const hadStyleAttribute = assignedSlot.hasAttribute('style'); -+ const oldDisplay = assignedSlot.style.display; -+ assignedSlot.style.display = getComputedStyle(ancestor).display; -+ -+ newOffsetParent = assignedSlot.offsetParent; -+ -+ assignedSlot.style.display = oldDisplay; -+ if (!hadStyleAttribute) { -+ assignedSlot.removeAttribute('style'); -+ } -+ } -+ -+ ancestor = assignedSlot; -+ if (offsetParent !== newOffsetParent) { -+ offsetParent = newOffsetParent; -+ foundInsideSlot = true; -+ } -+ } else if (ancestor.host && foundInsideSlot) { -+ break; -+ } -+ ancestor = ancestor.host || ancestor.parentNode; -+ } -+ return offsetParent; - } - }); diff --git a/third_party/polymer/v3_0/components-chromium/paper-tooltip/paper-tooltip.js b/third_party/polymer/v3_0/components-chromium/paper-tooltip/paper-tooltip.js index 09cdae71e53349..303d1bbdfc7874 100644 --- a/third_party/polymer/v3_0/components-chromium/paper-tooltip/paper-tooltip.js +++ b/third_party/polymer/v3_0/components-chromium/paper-tooltip/paper-tooltip.js @@ -442,16 +442,13 @@ Polymer({ * @return {void} */ updatePosition: function() { - if (!this._target) - return; - var offsetParent = this._composedOffsetParent(); - if (!offsetParent) + if (!this._target || !this.offsetParent) return; var offset = this.offset; // If a marginTop has been provided by the user (pre 1.0.3), use it. if (this.marginTop != 14 && this.offset == 14) offset = this.marginTop; - var parentRect = offsetParent.getBoundingClientRect(); + var parentRect = this.offsetParent.getBoundingClientRect(); var targetRect = this._target.getBoundingClientRect(); var thisRect = this.getBoundingClientRect(); var horizontalCenterOffset = (targetRect.width - thisRect.width) / 2; @@ -597,44 +594,5 @@ Polymer({ } this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); this.unlisten(this, 'mouseenter', 'hide'); - }, - - /** - * Polyfills the old offsetParent behavior from before the spec was changed: - * https://github.com/w3c/csswg-drafts/issues/159 - */ - _composedOffsetParent: function() { - let offsetParent = this.offsetParent; - let ancestor = this; - let foundInsideSlot = false; - while (ancestor && ancestor !== offsetParent) { - const assignedSlot = ancestor.assignedSlot; - if (assignedSlot) { - let newOffsetParent = assignedSlot.offsetParent; - - if (getComputedStyle(assignedSlot)['display'] === 'contents') { - const hadStyleAttribute = assignedSlot.hasAttribute('style'); - const oldDisplay = assignedSlot.style.display; - assignedSlot.style.display = getComputedStyle(ancestor).display; - - newOffsetParent = assignedSlot.offsetParent; - - assignedSlot.style.display = oldDisplay; - if (!hadStyleAttribute) { - assignedSlot.removeAttribute('style'); - } - } - - ancestor = assignedSlot; - if (offsetParent !== newOffsetParent) { - offsetParent = newOffsetParent; - foundInsideSlot = true; - } - } else if (ancestor.host && foundInsideSlot) { - break; - } - ancestor = ancestor.host || ancestor.parentNode; - } - return offsetParent; } });