Skip to content

Commit

Permalink
Revert "Re-enable offsetParent and fix in webui's paper-tooltip"
Browse files Browse the repository at this point in the history
This reverts commit def5070.

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:
> PolymerElements/paper-tooltip#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 <[email protected]>
> Reviewed-by: dpapad <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#935992}

(cherry picked from commit 5c36b4e)

Change-Id: I27faaeb162a004130e4692595530ea5ab4300574
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3280437
Reviewed-by: Joey Arhar <[email protected]>
Reviewed-by: dpapad <[email protected]>
Auto-Submit: Joey Arhar <[email protected]>
Commit-Queue: dpapad <[email protected]>
Cr-Original-Commit-Position: refs/heads/main@{#941603}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3282903
Commit-Queue: Joey Arhar <[email protected]>
Cr-Commit-Position: refs/branch-heads/4692@{chromium#200}
Cr-Branched-From: 038cd96-refs/heads/main@{#938553}
  • Loading branch information
josepharhar authored and Chromium LUCI CQ committed Nov 16, 2021
1 parent e83c59c commit e30525b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 112 deletions.
68 changes: 0 additions & 68 deletions third_party/polymer/v3_0/chromium.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
});

0 comments on commit e30525b

Please sign in to comment.