Make select popup anchor stay within web contents [chromium/src : main]

0 views
Skip to first unread message

Mason Freed (Gerrit)

unread,
May 27, 2026, 11:25:37 AM (5 days ago) May 27
to android-bu...@system.gserviceaccount.com, Chromium LUCI CQ, kinuko...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, blink-rev...@chromium.org
Attention needed from Joey Arhar

Mason Freed added 3 comments

File third_party/blink/renderer/core/html/forms/external_popup_menu.cc
Line 152, Patchset 2 (Latest): gfx::Rect viewport_rect(
Mason Freed . unresolved

This looks like just the size (at offset 0,0) of the viewport, and (maybe?) isn't scaled by dpr. How does this work? Also, what happens if the intersection is null (no overlap)?

File third_party/blink/renderer/core/html/forms/external_popup_menu_test.cc
Line 355, Patchset 2 (Latest): <style>
body { margin: 0; }
select {
position: fixed;
left: -50px;
top: -50px;
width: 200px;
height: 200px;
}
</style>
Mason Freed . unresolved

I think it'd be good to add a few more test cases, like the select is off screen down and to the right. Or has zero size. And test with different device pixel ratios, to make sure that math checks out. Etc.

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 5217, Patchset 2 (Latest): // Make select popup anchor stay within web contents to prevent
Mason Freed . unresolved

Please add a bug link, and the milestones when this shipped and can be removed.

Open in Gerrit

Related details

Attention is currently required from:
  • Joey Arhar
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • 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: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I239e1ff4d7212666153d432e3c10e18ba860dbec
Gerrit-Change-Number: 7876426
Gerrit-PatchSet: 2
Gerrit-Owner: Joey Arhar <jar...@chromium.org>
Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
Gerrit-Attention: Joey Arhar <jar...@chromium.org>
Gerrit-Comment-Date: Wed, 27 May 2026 15:25:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Joey Arhar (Gerrit)

unread,
May 27, 2026, 5:14:15 PM (5 days ago) May 27
to Mason Freed, android-bu...@system.gserviceaccount.com, Chromium LUCI CQ, kinuko...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, blink-rev...@chromium.org
Attention needed from Mason Freed

Joey Arhar added 2 comments

File third_party/blink/renderer/core/html/forms/external_popup_menu.cc
Line 152, Patchset 2: gfx::Rect viewport_rect(
Mason Freed . unresolved

This looks like just the size (at offset 0,0) of the viewport, and (maybe?) isn't scaled by dpr. How does this work? Also, what happens if the intersection is null (no overlap)?

Joey Arhar

Also, what happens if the intersection is null (no overlap)?

This code prevents the popup from showing at all when there is no overlap. I manually tested and verified it: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/forms/select_type.cc;l=754-761;drc=d6c78bad90b464eac484e75021d86c69d054021f

With this in mind, I added a CHECK to make sure that the intersection is not null.

This looks like just the size (at offset 0,0) of the viewport

Based on my manual testing, this does correctly move the macos popup to stay within the web contents in the problematic case where the select element's button is mostly outside of the viewport. So I think that this is the right thing.

and (maybe?) isn't scaled by dpr

I added tests with dpr and manually tested on my mac with dpr of 1.0 and 2.0 by using the builtin screen and an external monitor, and the normal case and the partially outside the viewport select case both look correct to me.

I also tested pinch zoom and panning to move the select element to the bottom right corner of the viewport, and the popup is still in the correct spot.

After adding more comprehensive tests, I found that clipping the select in the bottom right corner had an issue with dpr which ai fixed by adding dpr logic to the early return in MenuListSelectType::ShowPopup which matches the dpr calculations in externalpopupmenu.

File third_party/blink/renderer/core/html/forms/external_popup_menu_test.cc

body { margin: 0; }
select {
position: fixed;
left: -50px;
top: -50px;
width: 200px;
height: 200px;
}
</style>
Mason Freed . resolved

I think it'd be good to add a few more test cases, like the select is off screen down and to the right. Or has zero size. And test with different device pixel ratios, to make sure that math checks out. Etc.

Joey Arhar

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Mason Freed
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • 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: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I239e1ff4d7212666153d432e3c10e18ba860dbec
Gerrit-Change-Number: 7876426
Gerrit-PatchSet: 2
Gerrit-Owner: Joey Arhar <jar...@chromium.org>
Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
Gerrit-Attention: Mason Freed <mas...@chromium.org>
Gerrit-Comment-Date: Wed, 27 May 2026 21:14:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Mason Freed <mas...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Mason Freed (Gerrit)

unread,
May 28, 2026, 9:17:10 PM (4 days ago) May 28
to android-bu...@system.gserviceaccount.com, Chromium LUCI CQ, kinuko...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, blink-rev...@chromium.org
Attention needed from Joey Arhar

Mason Freed voted and added 5 comments

Votes added by Mason Freed

Code-Review+1

5 comments

Patchset-level comments
File-level comment, Patchset 6 (Latest):
Mason Freed . resolved

Thanks for the expanded test. Still some things to fix, but I'll mark it +1.

File third_party/blink/renderer/core/html/forms/external_popup_menu.cc
Line 152, Patchset 2: gfx::Rect viewport_rect(
Mason Freed . resolved

This looks like just the size (at offset 0,0) of the viewport, and (maybe?) isn't scaled by dpr. How does this work? Also, what happens if the intersection is null (no overlap)?

Joey Arhar

Also, what happens if the intersection is null (no overlap)?

This code prevents the popup from showing at all when there is no overlap. I manually tested and verified it: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/forms/select_type.cc;l=754-761;drc=d6c78bad90b464eac484e75021d86c69d054021f

With this in mind, I added a CHECK to make sure that the intersection is not null.

This looks like just the size (at offset 0,0) of the viewport

Based on my manual testing, this does correctly move the macos popup to stay within the web contents in the problematic case where the select element's button is mostly outside of the viewport. So I think that this is the right thing.

and (maybe?) isn't scaled by dpr

I added tests with dpr and manually tested on my mac with dpr of 1.0 and 2.0 by using the builtin screen and an external monitor, and the normal case and the partially outside the viewport select case both look correct to me.

I also tested pinch zoom and panning to move the select element to the bottom right corner of the viewport, and the popup is still in the correct spot.

After adding more comprehensive tests, I found that clipping the select in the bottom right corner had an issue with dpr which ai fixed by adding dpr logic to the early return in MenuListSelectType::ShowPopup which matches the dpr calculations in externalpopupmenu.

Mason Freed

Great! Thanks. The CHECK scared me a little, but I see that ShowPopup should keep that from getting hit.

File third_party/blink/renderer/core/html/forms/external_popup_menu_test.cc
Line 367, Patchset 6 (Latest):#ifdef OS_ANDROID
Mason Freed . unresolved

What's with these android differences? That feels a little weird.

Line 406, Patchset 6 (Latest): left: )HTML" +
Mason Freed . unresolved

This is kind of hard to parse - maybe use base::StringPrintf instead?

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 5232, Patchset 6 (Latest): // https://issues.chromium.org/issues/511869411
Mason Freed . unresolved

Can you use the normal `TODO(crbug...)` convention. And shipped in 150, removed in 152.

Open in Gerrit

Related details

Attention is currently required from:
  • Joey Arhar
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement 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: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I239e1ff4d7212666153d432e3c10e18ba860dbec
    Gerrit-Change-Number: 7876426
    Gerrit-PatchSet: 6
    Gerrit-Owner: Joey Arhar <jar...@chromium.org>
    Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
    Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
    Gerrit-Attention: Joey Arhar <jar...@chromium.org>
    Gerrit-Comment-Date: Fri, 29 May 2026 01:16:54 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Mason Freed <mas...@chromium.org>
    Comment-In-Reply-To: Joey Arhar <jar...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Joey Arhar (Gerrit)

    unread,
    2:07 PM (1 hour ago) 2:07 PM
    to Mason Freed, android-bu...@system.gserviceaccount.com, Chromium LUCI CQ, kinuko...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, blink-rev...@chromium.org

    Joey Arhar voted and added 4 comments

    Votes added by Joey Arhar

    Code-Review+1
    Commit-Queue+2

    4 comments

    File third_party/blink/renderer/core/html/forms/external_popup_menu_test.cc
    Line 367, Patchset 6:#ifdef OS_ANDROID
    Mason Freed . resolved

    What's with these android differences? That feels a little weird.

    Joey Arhar

    i added a comment explaining why it is there, it just corresponds to an existing os_android check in external_popup_menu.cc, and the next test in this file does a similar thing but disables the test completely on andorid

    Line 406, Patchset 6: left: )HTML" +
    Mason Freed . resolved

    This is kind of hard to parse - maybe use base::StringPrintf instead?

    Joey Arhar

    Done

    File third_party/blink/renderer/platform/runtime_enabled_features.json5
    Line 5217, Patchset 2: // Make select popup anchor stay within web contents to prevent
    Mason Freed . resolved

    Please add a bug link, and the milestones when this shipped and can be removed.

    Can you use the normal `TODO(crbug...)` convention. And shipped in 150, removed in 152.

    Joey Arhar

    Done

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • 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: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I239e1ff4d7212666153d432e3c10e18ba860dbec
      Gerrit-Change-Number: 7876426
      Gerrit-PatchSet: 7
      Gerrit-Owner: Joey Arhar <jar...@chromium.org>
      Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
      Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
      Gerrit-Comment-Date: Mon, 01 Jun 2026 18:07:25 +0000
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages