Tooltip: improve positioning in fallback case [devtools/devtools-frontend : main]

0 views
Skip to first unread message

Wolfgang Beyer (Gerrit)

unread,
Oct 31, 2025, 5:55:20 AM (6 days ago) Oct 31
to Ergün Erdoğmuş, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org
Attention needed from Ergün Erdoğmuş

Wolfgang Beyer voted and added 1 comment

Votes added by Wolfgang Beyer

Auto-Submit+1
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Wolfgang Beyer . resolved

PTAL

Open in Gerrit

Related details

Attention is currently required from:
  • Ergün Erdoğmuş
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: devtools/devtools-frontend
Gerrit-Branch: main
Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
Gerrit-Change-Number: 7105438
Gerrit-PatchSet: 2
Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
Gerrit-Attention: Ergün Erdoğmuş <erg...@chromium.org>
Gerrit-Comment-Date: Fri, 31 Oct 2025 09:55:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Ergün Erdoğmuş (Gerrit)

unread,
Oct 31, 2025, 6:38:41 AM (6 days ago) Oct 31
to Wolfgang Beyer, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org
Attention needed from Wolfgang Beyer

Ergün Erdoğmuş added 1 comment

File front_end/ui/components/tooltips/Tooltip.ts
Line 82, Patchset 2 (Parent): proposedRect.top = anchorRect.top - currentPopoverRect.height;
Ergün Erdoğmuş . unresolved

This change would cause the tooltip to be rendered on top of the anchor, when the anchor is at the bottom of the viewport even though there is still space on top of the anchor. Can we keep offsetting by the anchor rect for that case?

See the screencast on the last comment here: https://g-issues.chromium.org/issues/40248266#comment44

Open in Gerrit

Related details

Attention is currently required from:
  • Wolfgang Beyer
Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: devtools/devtools-frontend
    Gerrit-Branch: main
    Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
    Gerrit-Change-Number: 7105438
    Gerrit-PatchSet: 2
    Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
    Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
    Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
    Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
    Gerrit-Attention: Wolfgang Beyer <wo...@chromium.org>
    Gerrit-Comment-Date: Fri, 31 Oct 2025 10:38:36 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Wolfgang Beyer (Gerrit)

    unread,
    Oct 31, 2025, 7:14:21 AM (6 days ago) Oct 31
    to Ergün Erdoğmuş, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org
    Attention needed from Ergün Erdoğmuş

    Wolfgang Beyer voted and added 1 comment

    Votes added by Wolfgang Beyer

    Auto-Submit+1
    Commit-Queue+1

    1 comment

    File front_end/ui/components/tooltips/Tooltip.ts
    Line 82, Patchset 2 (Parent): proposedRect.top = anchorRect.top - currentPopoverRect.height;
    Ergün Erdoğmuş . resolved

    This change would cause the tooltip to be rendered on top of the anchor, when the anchor is at the bottom of the viewport even though there is still space on top of the anchor. Can we keep offsetting by the anchor rect for that case?

    See the screencast on the last comment here: https://g-issues.chromium.org/issues/40248266#comment44

    Wolfgang Beyer

    Very nice catch! If the anchor is in a corner, the Tooltip should not even need the fallback position. `isInBounds` incorrectly did not allow equality. Fixed.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ergün Erdoğmuş
    Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: devtools/devtools-frontend
      Gerrit-Branch: main
      Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
      Gerrit-Change-Number: 7105438
      Gerrit-PatchSet: 3
      Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Attention: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Comment-Date: Fri, 31 Oct 2025 11:14:16 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Ergün Erdoğmuş <erg...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Wolfgang Beyer (Gerrit)

      unread,
      Nov 4, 2025, 4:22:44 AM (2 days ago) Nov 4
      to Ergün Erdoğmuş, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org
      Attention needed from Ergün Erdoğmuş

      Wolfgang Beyer voted and added 1 comment

      Votes added by Wolfgang Beyer

      Auto-Submit+1

      1 comment

      Patchset-level comments
      File-level comment, Patchset 5 (Latest):
      Wolfgang Beyer . resolved

      PTAL again

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Ergün Erdoğmuş
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: devtools/devtools-frontend
      Gerrit-Branch: main
      Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
      Gerrit-Change-Number: 7105438
      Gerrit-PatchSet: 5
      Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Attention: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Comment-Date: Tue, 04 Nov 2025 09:22:40 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Ergün Erdoğmuş (Gerrit)

      unread,
      Nov 4, 2025, 7:19:04 AM (2 days ago) Nov 4
      to Wolfgang Beyer, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org
      Attention needed from Wolfgang Beyer

      Ergün Erdoğmuş voted and added 4 comments

      Votes added by Ergün Erdoğmuş

      Code-Review+1

      4 comments

      Patchset-level comments
      Ergün Erdoğmuş . resolved

      Picking the top or bottom based on which one has more space in that side sounds good to me!

      File front_end/ui/components/tooltips/Tooltip.ts
      Line 128, Patchset 5 (Latest): bottomVerticalOutOfBoundsAmount =
      Ergün Erdoğmuş . unresolved

      Instead of relying the side effects here, can we compute these values when needed?
      (e.g. we first try the rectangles from the `uniqueOrder`, if they're all out of bounds, we calculate the `bottomVerticalOutOfBoundsAmount` and `topVerticalOutOfBoundsAmount` and decide what to do based on that.

      Something like:
      ```
      const bottomProposed = positioningUtils.bottomSpanRight({anchorRect, currentPopoverRect});
      const bottomVerticalOutOfBounds =
      Math.max(0, bottomProposed.top + currentPopoverRect.height - inspectorViewRect.bottom);
        const topProposed = positioningUtils.topSpanRight({anchorRect, currentPopoverRect});
      const topVerticalOutOfBounds = Math.max(0, inspectorViewRect.top - topProposed.top);
        const prefersBottom = bottomVerticalOutOfBounds <= topVerticalOutOfBounds;
      ```

      We can also move this t a helper method I think.

      Line 157, Patchset 5 (Latest): const prefersBottom = bottomVerticalOutOfBoundsAmount <= topVerticalOutOfBoundsAmount;
      Ergün Erdoğmuş . unresolved
      (nit): Instead of comparing the indexes of the options, we can iterate over the `uniqueOrder` array and pick the first one that fits the criteria:
      ```
      const fallbackOption = uniqueOrder.find(option => {
      if (prefersBottom) {
      return option === PositionOption.BOTTOM_SPAN_LEFT || option === PositionOption.BOTTOM_SPAN_RIGHT;
      }
      return option === PositionOption.TOP_SPAN_LEFT || option === PositionOption.TOP_SPAN_RIGHT;
      }) ?? PositionOption.TOP_SPAN_RIGHT;
      ```
      Line 180, Patchset 5 (Latest): const bottomVerticalOutOfBoundsAmount =
      Ergün Erdoğmuş . unresolved

      (nit): Similarly, we can calculate the `bottomVerticalOutOfBoundsAmount` and `topVerticalOutOfBoundsAmount` when we need them.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Wolfgang Beyer
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: devtools/devtools-frontend
      Gerrit-Branch: main
      Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
      Gerrit-Change-Number: 7105438
      Gerrit-PatchSet: 5
      Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
      Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Attention: Wolfgang Beyer <wo...@chromium.org>
      Gerrit-Comment-Date: Tue, 04 Nov 2025 12:19:00 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Wolfgang Beyer (Gerrit)

      unread,
      Nov 4, 2025, 12:31:32 PM (2 days ago) Nov 4
      to Ergün Erdoğmuş, Devtools-frontend LUCI CQ, devtools-rev...@chromium.org

      Wolfgang Beyer voted and added 3 comments

      Votes added by Wolfgang Beyer

      Auto-Submit+1
      Commit-Queue+2

      3 comments

      File front_end/ui/components/tooltips/Tooltip.ts
      Line 128, Patchset 5: bottomVerticalOutOfBoundsAmount =
      Ergün Erdoğmuş . resolved

      Instead of relying the side effects here, can we compute these values when needed?
      (e.g. we first try the rectangles from the `uniqueOrder`, if they're all out of bounds, we calculate the `bottomVerticalOutOfBoundsAmount` and `topVerticalOutOfBoundsAmount` and decide what to do based on that.

      Something like:
      ```
      const bottomProposed = positioningUtils.bottomSpanRight({anchorRect, currentPopoverRect});
      const bottomVerticalOutOfBounds =
      Math.max(0, bottomProposed.top + currentPopoverRect.height - inspectorViewRect.bottom);
        const topProposed = positioningUtils.topSpanRight({anchorRect, currentPopoverRect});
      const topVerticalOutOfBounds = Math.max(0, inspectorViewRect.top - topProposed.top);
        const prefersBottom = bottomVerticalOutOfBounds <= topVerticalOutOfBounds;
      ```

      We can also move this t a helper method I think.

      Wolfgang Beyer

      Done

      Line 157, Patchset 5: const prefersBottom = bottomVerticalOutOfBoundsAmount <= topVerticalOutOfBoundsAmount;
      Ergün Erdoğmuş . resolved
      (nit): Instead of comparing the indexes of the options, we can iterate over the `uniqueOrder` array and pick the first one that fits the criteria:
      ```
      const fallbackOption = uniqueOrder.find(option => {
      if (prefersBottom) {
      return option === PositionOption.BOTTOM_SPAN_LEFT || option === PositionOption.BOTTOM_SPAN_RIGHT;
      }
      return option === PositionOption.TOP_SPAN_LEFT || option === PositionOption.TOP_SPAN_RIGHT;
      }) ?? PositionOption.TOP_SPAN_RIGHT;
      ```
      Wolfgang Beyer

      Done

      Line 180, Patchset 5: const bottomVerticalOutOfBoundsAmount =
      Ergün Erdoğmuş . resolved

      (nit): Similarly, we can calculate the `bottomVerticalOutOfBoundsAmount` and `topVerticalOutOfBoundsAmount` when we need them.

      Wolfgang Beyer

      `topVerticalOutOfBoundsAmount` is already only calculated if it's actually needed. So only `bottomVerticalOutOfBoundsAmount` is calculated speculatively. I prefer that to calculating the bottom proposed rectangle potentially twice.

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: devtools/devtools-frontend
        Gerrit-Branch: main
        Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
        Gerrit-Change-Number: 7105438
        Gerrit-PatchSet: 6
        Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
        Gerrit-Reviewer: Ergün Erdoğmuş <erg...@chromium.org>
        Gerrit-Reviewer: Wolfgang Beyer <wo...@chromium.org>
        Gerrit-CC: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
        Gerrit-Comment-Date: Tue, 04 Nov 2025 17:31:28 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Ergün Erdoğmuş <erg...@chromium.org>
        satisfied_requirement
        open
        diffy

        Devtools-frontend LUCI CQ (Gerrit)

        unread,
        Nov 4, 2025, 1:12:01 PM (2 days ago) Nov 4
        to Wolfgang Beyer, Ergün Erdoğmuş, devtools-rev...@chromium.org

        Devtools-frontend LUCI CQ submitted the change with unreviewed changes

        Unreviewed changes

        5 is the latest approved patch-set.
        The change was submitted with unreviewed changes in the following files:

        ```
        The name of the file: front_end/ui/components/tooltips/Tooltip.ts
        Insertions: 18, Deletions: 26.

        The diff is too large to show. Please review the diff.
        ```

        Change information

        Commit message:
        Tooltip: improve positioning in fallback case

        Simple tooltips try to position themselves to the bottom center or top
        center of their anchor. If neither of those options lie fully within
        the viewport, pick a fallback position:

        - Check whether top or bottom position is better, by picking the
        option which is vertically out-of-bounds by a smaller amount.
        - The tooltip position is then adjusted by moving it into the
        viewport. This means the tooltip is allowed to cover its anchor in
        the fallback case.

        Rich Tooltips try to position themselves to the bottom/top left/right
        of their anchor. If none of these 4 positions lie fully within the
        viewport, a fallback position is calculated:

        - Check whether top or bottom position is better, by picking the
        option which is vertically out-of-bounds by a smaller amount.
        - Choose left/right according to the preferred order.
        - The tooltip position is then adjusted such that the tooltip stays in
        the same corner of the viewport, but is moved into the viewport.
        This means the tooltip is allowed to cover its anchor in the
        fallback case.
        Fixed: 454879285
        Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
        Commit-Queue: Wolfgang Beyer <wo...@chromium.org>
        Reviewed-by: Ergün Erdoğmuş <erg...@chromium.org>
        Auto-Submit: Wolfgang Beyer <wo...@chromium.org>
        Files:
        • M front_end/ui/components/tooltips/Tooltip.test.ts
        • M front_end/ui/components/tooltips/Tooltip.ts
        Change size: M
        Delta: 2 files changed, 201 insertions(+), 42 deletions(-)
        Branch: refs/heads/main
        Submit Requirements:
        • requirement satisfiedCode-Review: +1 by Ergün Erdoğmuş
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: devtools/devtools-frontend
        Gerrit-Branch: main
        Gerrit-Change-Id: Ic3338c14ef8091ca4500f6fd290b3b0af1d78d5a
        Gerrit-Change-Number: 7105438
        Gerrit-PatchSet: 7
        Gerrit-Owner: Wolfgang Beyer <wo...@chromium.org>
        Gerrit-Reviewer: Devtools-frontend LUCI CQ <devtools-fro...@luci-project-accounts.iam.gserviceaccount.com>
        open
        diffy
        satisfied_requirement
        Reply all
        Reply to author
        Forward
        0 new messages