Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Nov 16, 2024

Implements the framework side of secure paste milestone 2, where the iOS system context menu items can be customized.

Depends on PR #161103. Currently I've merged that PR into this one for testing, but I think that PR should merge separately first.

Widget API (most users)

TextField(
  contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) {
    return SystemContextMenu.editableText(
      editableTextState: editableTextState,
      // items is optional
      items: <IOSSystemContextMenuItem>[
        const IOSSystemContextMenuItemCut(),
        constIOS SystemContextMenuItemCopy(),
        const IOSSystemContextMenuItemPaste(),
        const IOSSystemContextMenuItemSelectAll(),
        const IOSSystemContextMenuItemSearchWeb(
          title: 'Search!', // title is optional for this button, defaults to localized string
        ),
        // Milestone 3:
        IOSSystemContextMenuItemCustom(
          // title and onPressed are required
          title: 'custom button',
          onPressed: () {
            print('pressed the custom button.');
          }
        ),
      ],
    );
  },
),

Raw Controller API

_systemContextMenuController.show(
  widget.anchor,
  <IOSSystemContextMenuItemData>[
    // Notice these are different classes than those used for the widget. That's
    // mainly because I can't provide localized defaults here, so the titles are
    // required in the classes that have titles.
    const IOSSystemContextMenuItemDataCut(),
    const IOSSystemContextMenuItemDataCopy(),
    const IOSSystemContextMenuItemDataPaste(),
    const IOSSystemContextMenuItemDataSelectAll(),
    const IOSSystemContextMenuItemDataSearchWeb(
      title: 'Search!', // title is required.
    ),
    // Milestone 3:
    IOSSystemContextMenuItemDataCustom(
      // title and onPressed are required as before.
      title: 'custom button',
      onPressed: () {
        print('pressed the custom button.');
      }
    ),
  ],
);
Json format
    return _channel.invokeMethod<Map<String, dynamic>>(
      'ContextMenu.showSystemContextMenu',
      <String, dynamic>{
        'targetRect': <String, double>{
          'x': targetRect.left,
          'y': targetRect.top,
          'width': targetRect.width,
          'height': targetRect.height,
        },
        'items': <dynamic>[
          <String, dynamic>{
            'type': 'default',
            'action': 'paste',
          },
          <String, dynamic>{
            'type': 'default',
            'action': 'copy',
          },
          <String, dynamic>{
            'type': 'default',
            'title': 'Crazy Title',
            'action': 'share',
          },
        ],
      },
    );

Localization changes

This change requires the SystemContextMenu widget in the widgets library to be able to look up the default localized label for several context menu buttons like "Copy", etc. Those strings previously resided in MaterialLocalizations and CupertinoLocalizations, but not in WidgetsLocalizations, so I have copied the necessary strings into WidgetsLocalizations.

@justinmc justinmc self-assigned this Nov 16, 2024
@justinmc justinmc marked this pull request as draft November 16, 2024 00:27
@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Nov 16, 2024
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

I tried to make it compatible with other platforms in the future.
Android has a different API.
 1. Do them inside of the AppleSystemContextMenuItem. That requires me
    to move that class to the widgets library. Not possible with sealed
    class?
 2. Do them inside of SystemContextMenu. But then it messes with the
    `json` method of SystemContextMenuItem. That would need the
    localized title in order to work.

Maybe there are 2 concepts here. One has to be the class that's
presented to the user (currently AppleSystemContextMenuItem), which
needs to be compact and understandable. The pure data representation.
The other is the data that is sent to the engine. Currently my problem
arises because these concepts are mixed: AppleSystemContextMenuItem
tries to provide a nice API to the user while also providing a toJson
method that talks to the engine.

Separate these two ideas. The user-facing thing shouldn't know about the
engine json. Maybe SystemContextMenu should do that conversion, since it
knows about both of these concepts and also has the localizations.
I've put all the localization logic in SystemContextMenu. The Items just
contain dumb data and don't know anything about their conversion to
json. I think this way is a lot better, but I should give a pass through
to clean up and see if I can improve the architecture more.
Really needs cleanup though, and I have to remove the custom buttons
stuff from this PR anyway. So next I should decide on the non-custom API
in a way that works nicely with custom buttons in the future, then once
that's solidified, delete the custom button stuff.
@justinmc justinmc force-pushed the secure-paste-milestone-2 branch from cef6cac to e0fe575 Compare December 9, 2024 21:42
@justinmc justinmc force-pushed the secure-paste-milestone-2 branch from 9596f33 to 802346f Compare December 11, 2024 21:55
No way to know if there is another SystemContextMenuController somewhere
in the app! Also, that's how it was before this PR.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 27, 2025
Manual roll requested by [email protected]

flutter/flutter@043b719...1659206

2025-02-24 [email protected] Roll Skia from 3dfb3fee52e1 to 28017200173a (2 revisions) (flutter/flutter#163981)
2025-02-24 [email protected] Add integration test for Gradle-initiated android builds with flavors (flutter/flutter#163737)
2025-02-23 [email protected] Roll Skia from 72f949950adb to 3dfb3fee52e1 (1 revision) (flutter/flutter#163959)
2025-02-23 [email protected] Roll Skia from 4bee660601de to 72f949950adb (1 revision) (flutter/flutter#163948)
2025-02-22 [email protected] Roll Skia from cca9328df6ca to 4bee660601de (1 revision) (flutter/flutter#163927)
2025-02-22 [email protected] Roll Dart SDK from bad289580d9b to aea6fff33f06 (3 revisions) (flutter/flutter#163912)
2025-02-22 [email protected] Roll Skia from 1d884bab8593 to cca9328df6ca (12 revisions) (flutter/flutter#163910)
2025-02-22 [email protected] [fuchsia] include more tests in the fuchsia builders (flutter/flutter#163800)
2025-02-21 [email protected] [Engine] Add RoundSuperellipse to drawing OP (flutter/flutter#160883)
2025-02-21 [email protected] [remake] Restore old back handling for FlutterFragmentActivity (flutter/flutter#161545)
2025-02-21 [email protected] Revert "Marks Mac_benchmark basic_material_app_macos__compile to be flaky" (flutter/flutter#163878)
2025-02-21 [email protected] Revert "Marks Mac_benchmark flutter_view_macos__start_up to be flaky" (flutter/flutter#163880)
2025-02-21 [email protected] Roll Dart SDK from c5e582f15b6c to bad289580d9b (1 revision) (flutter/flutter#163885)
2025-02-21 [email protected] Revert "Marks Windows_mokey native_assets_android to be flaky" (flutter/flutter#163881)
2025-02-21 [email protected] Mark platform_views_hcpp_scroll_perf__timeline_summary out of bringup (flutter/flutter#163883)
2025-02-21 [email protected] Roll Skia from 6da10829d017 to 1d884bab8593 (42 revisions) (flutter/flutter#163789)
2025-02-21 [email protected] Enable `linux_android_emulator_tests` on presubmit. (flutter/flutter#163879)
2025-02-21 [email protected] Update gradle memory properties in example and test projects (flutter/flutter#163798)
2025-02-21 [email protected] Secure paste milestone 2 (flutter/flutter#159013)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
)

Manual roll requested by [email protected]

flutter/flutter@043b719...1659206

2025-02-24 [email protected] Roll Skia from 3dfb3fee52e1 to 28017200173a (2 revisions) (flutter/flutter#163981)
2025-02-24 [email protected] Add integration test for Gradle-initiated android builds with flavors (flutter/flutter#163737)
2025-02-23 [email protected] Roll Skia from 72f949950adb to 3dfb3fee52e1 (1 revision) (flutter/flutter#163959)
2025-02-23 [email protected] Roll Skia from 4bee660601de to 72f949950adb (1 revision) (flutter/flutter#163948)
2025-02-22 [email protected] Roll Skia from cca9328df6ca to 4bee660601de (1 revision) (flutter/flutter#163927)
2025-02-22 [email protected] Roll Dart SDK from bad289580d9b to aea6fff33f06 (3 revisions) (flutter/flutter#163912)
2025-02-22 [email protected] Roll Skia from 1d884bab8593 to cca9328df6ca (12 revisions) (flutter/flutter#163910)
2025-02-22 [email protected] [fuchsia] include more tests in the fuchsia builders (flutter/flutter#163800)
2025-02-21 [email protected] [Engine] Add RoundSuperellipse to drawing OP (flutter/flutter#160883)
2025-02-21 [email protected] [remake] Restore old back handling for FlutterFragmentActivity (flutter/flutter#161545)
2025-02-21 [email protected] Revert "Marks Mac_benchmark basic_material_app_macos__compile to be flaky" (flutter/flutter#163878)
2025-02-21 [email protected] Revert "Marks Mac_benchmark flutter_view_macos__start_up to be flaky" (flutter/flutter#163880)
2025-02-21 [email protected] Roll Dart SDK from c5e582f15b6c to bad289580d9b (1 revision) (flutter/flutter#163885)
2025-02-21 [email protected] Revert "Marks Windows_mokey native_assets_android to be flaky" (flutter/flutter#163881)
2025-02-21 [email protected] Mark platform_views_hcpp_scroll_perf__timeline_summary out of bringup (flutter/flutter#163883)
2025-02-21 [email protected] Roll Skia from 6da10829d017 to 1d884bab8593 (42 revisions) (flutter/flutter#163789)
2025-02-21 [email protected] Enable `linux_android_emulator_tests` on presubmit. (flutter/flutter#163879)
2025-02-21 [email protected] Update gradle memory properties in example and test projects (flutter/flutter#163798)
2025-02-21 [email protected] Secure paste milestone 2 (flutter/flutter#159013)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
)

Manual roll requested by [email protected]

flutter/flutter@043b719...1659206

2025-02-24 [email protected] Roll Skia from 3dfb3fee52e1 to 28017200173a (2 revisions) (flutter/flutter#163981)
2025-02-24 [email protected] Add integration test for Gradle-initiated android builds with flavors (flutter/flutter#163737)
2025-02-23 [email protected] Roll Skia from 72f949950adb to 3dfb3fee52e1 (1 revision) (flutter/flutter#163959)
2025-02-23 [email protected] Roll Skia from 4bee660601de to 72f949950adb (1 revision) (flutter/flutter#163948)
2025-02-22 [email protected] Roll Skia from cca9328df6ca to 4bee660601de (1 revision) (flutter/flutter#163927)
2025-02-22 [email protected] Roll Dart SDK from bad289580d9b to aea6fff33f06 (3 revisions) (flutter/flutter#163912)
2025-02-22 [email protected] Roll Skia from 1d884bab8593 to cca9328df6ca (12 revisions) (flutter/flutter#163910)
2025-02-22 [email protected] [fuchsia] include more tests in the fuchsia builders (flutter/flutter#163800)
2025-02-21 [email protected] [Engine] Add RoundSuperellipse to drawing OP (flutter/flutter#160883)
2025-02-21 [email protected] [remake] Restore old back handling for FlutterFragmentActivity (flutter/flutter#161545)
2025-02-21 [email protected] Revert "Marks Mac_benchmark basic_material_app_macos__compile to be flaky" (flutter/flutter#163878)
2025-02-21 [email protected] Revert "Marks Mac_benchmark flutter_view_macos__start_up to be flaky" (flutter/flutter#163880)
2025-02-21 [email protected] Roll Dart SDK from c5e582f15b6c to bad289580d9b (1 revision) (flutter/flutter#163885)
2025-02-21 [email protected] Revert "Marks Windows_mokey native_assets_android to be flaky" (flutter/flutter#163881)
2025-02-21 [email protected] Mark platform_views_hcpp_scroll_perf__timeline_summary out of bringup (flutter/flutter#163883)
2025-02-21 [email protected] Roll Skia from 6da10829d017 to 1d884bab8593 (42 revisions) (flutter/flutter#163789)
2025-02-21 [email protected] Enable `linux_android_emulator_tests` on presubmit. (flutter/flutter#163879)
2025-02-21 [email protected] Update gradle memory properties in example and test projects (flutter/flutter#163798)
2025-02-21 [email protected] Secure paste milestone 2 (flutter/flutter#159013)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants