Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the web engine publish view forward focus and unfocus events #50177

Merged
merged 3 commits into from
Feb 9, 2024

Conversation

tugorez
Copy link
Contributor

@tugorez tugorez commented Jan 30, 2024

Make the flutter web engine publish view focus events.

Relevant Issues are:

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jan 30, 2024
@tugorez tugorez changed the title Focus management web Make the web engine publish view focus events Jan 30, 2024
@tugorez tugorez changed the title Make the web engine publish view focus events Make the web engine publish view forward focus and unfocus events Jan 30, 2024
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes and comments. Thanks for this!

@tugorez tugorez force-pushed the focus-management-web branch 4 times, most recently from 53a7c17 to 8084028 Compare February 7, 2024 21:59
@tugorez tugorez requested a review from ditman February 7, 2024 22:05
@tugorez tugorez force-pushed the focus-management-web branch 2 times, most recently from 69f7fcb to 09b0bd2 Compare February 7, 2024 22:31
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty great to me!

QQ is there any way that I can use this to build my old element embedding demos to see if this yields the focus better, or are flutter framework parts still missing for this to fully work?

lib/web_ui/lib/src/engine/dom.dart Outdated Show resolved Hide resolved
lib/web_ui/lib/src/engine/initialization.dart Outdated Show resolved Hide resolved
return;
}

late final ui.ViewFocusEvent event;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to mark a local variable as late final if it's going to be initialized and returned immediately!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be just final as it access other fields/methods in the instance.

This comment was marked as resolved.

@tugorez tugorez force-pushed the focus-management-web branch 3 times, most recently from 977866d to f8ec60c Compare February 8, 2024 16:53
@tugorez
Copy link
Contributor Author

tugorez commented Feb 8, 2024

This is looking pretty great to me!

Thank you David 🤝. I do appreciate your feedback and thoughtful reviews, thank you!

QQ is there any way that I can use this to build my old element embedding demos to see if this yields the focus better, or are flutter framework parts still missing for this to fully work

No, you can't test any of these things yet end to end. FYI @gspencergoog will be driving the framework changes.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @mdebbar is happy, I'm happy. LGTM!

Comment on lines 73 to 79
extension on DomElement? {
int? get viewId => int.tryParse(viewIdAttribute ?? '');
String? get viewIdAttribute => closestView?.getAttribute(GlobalHtmlAttributes.flutterViewIdAttributeName);
DomElement? get closestView => this?.closest(DomManager.flutterViewTagName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this extension available outside of this file? If so, please remove, it's hyper-specific to what you're trying to do. If it's only available here, carry on! Fancy!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. AFAICT no, unnamed extensions can only be used within the library where they're declared.

https://dart.dev/language/extension-methods#unnamed-extensions

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some minor suggestions that are not blockers.

return;
}

late final ui.ViewFocusEvent event;

This comment was marked as resolved.

Comment on lines 73 to 79
extension on DomElement? {
int? get viewId => int.tryParse(viewIdAttribute ?? '');
String? get viewIdAttribute => closestView?.getAttribute(GlobalHtmlAttributes.flutterViewIdAttributeName);
DomElement? get closestView => this?.closest(DomManager.flutterViewTagName);
}

This comment was marked as outdated.

Comment on lines 73 to 79
extension on DomElement? {
int? get viewId => int.tryParse(viewIdAttribute ?? '');
String? get viewIdAttribute => closestView?.getAttribute(GlobalHtmlAttributes.flutterViewIdAttributeName);
DomElement? get closestView => this?.closest(DomManager.flutterViewTagName);
}

This comment was marked as outdated.

@tugorez
Copy link
Contributor Author

tugorez commented Feb 9, 2024

It is technically available to the entire engine in release mode (after we process sources through the sdk_rewriter, the entire engine is combined into a single library with part files).

Ohhhhhhh awesome feedback @mdebbar . I wasn't aware of this and similar differences between the engine and a regular dart program. Where can I read more about this rewriting process?

Decided it is best to keep everything within the class then. The extensions were removed.

@mdebbar
Copy link
Contributor

mdebbar commented Feb 9, 2024

Where can I read more about this rewriting process?

There's no documentation about this AFAIK. But here's where we do the rewriting:

  • The sdk rewriter implementation: https://github.com/flutter/engine/blob/main/web_sdk/sdk_rewriter.dart
  • The gn build template for invoking the rewriter:
    template("sdk_rewriter") {
    ui = defined(invoker.ui) && invoker.ui
    if (!ui) {
    assert(defined(invoker.library_name), "Must pass 'library_name'")
    assert(defined(invoker.api_file), "Must pass 'api_file'")
    }
    assert(defined(invoker.input_dir), "Must pass 'input_dir'")
    assert(defined(invoker.output_dir), "Must pass 'output_dir'")
    source_dart_files = exec_script("//third_party/dart/tools/list_dart_files.py",
    [
    "absolute",
    rebase_path(invoker.input_dir),
    ],
    "list lines")
    if (defined(invoker.exclude_patterns)) {
    filtered_files = filter_exclude(source_dart_files, invoker.exclude_patterns)
    source_dart_files = []
    source_dart_files = filtered_files
    }
    prebuilt_dart_action(target_name) {
    packages = dart_sdk_package_config
    pool = "//flutter/build/dart:dart_pool"
    script = "//flutter/web_sdk/sdk_rewriter.dart"
    inputs = source_dart_files + [ script ]
    stamp_location = "$target_gen_dir/$target_name.stamp"
    outputs = [
    stamp_location,
    invoker.output_dir,
    ]
    input_dir = rebase_path(invoker.input_dir)
    output_dir = rebase_path(invoker.output_dir)
    args = [
    "--output-dir=$output_dir",
    "--input-dir=$input_dir",
    "--stamp",
    rebase_path(stamp_location, root_build_dir),
    ]
    if (defined(invoker.is_public) && invoker.is_public) {
    args += [ "--public" ]
    }
    if (ui) {
    args += [ "--ui" ]
    } else {
    library_name = invoker.library_name
    api_file = rebase_path(invoker.api_file)
    args += [
    "--library-name=$library_name",
    "--api-file=$api_file",
    ]
    }
    foreach(source_file, source_dart_files) {
    path = rebase_path(source_file)
    args += [ "--source-file=$path" ]
    }
    }
    }
  • The invocations of the rewriter over various sub-parts of the engine:

    engine/web_sdk/BUILD.gn

    Lines 38 to 45 in 8c521eb

    sdk_rewriter("web_ui_library_sources") {
    ui = true
    input_dir = "//flutter/lib/web_ui/lib/"
    output_dir = "$root_out_dir/flutter_web_sdk/lib/ui/"
    # exclude everything in the engine directory, it will be a separate internal library
    exclude_patterns = [ rebase_path("//flutter/lib/web_ui/lib/src/*") ]
    }

    engine/web_sdk/BUILD.gn

    Lines 51 to 60 in 8c521eb

    sdk_rewriter("web_engine_library") {
    library_name = "engine"
    api_file = "//flutter/lib/web_ui/lib/src/engine.dart"
    input_dir = "//flutter/lib/web_ui/lib/src/engine/"
    output_dir = "$root_out_dir/flutter_web_sdk/lib/_engine/"
    # exclude skwasm, it will be a separate internal library
    exclude_patterns =
    [ rebase_path("//flutter/lib/web_ui/lib/src/engine/skwasm/*") ]
    }

@tugorez tugorez added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
Copy link
Contributor

auto-submit bot commented Feb 9, 2024

auto label is removed for flutter/engine/50177, due to - The status or check suite Linux Fuchsia FEMU has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
@tugorez tugorez added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
Copy link
Contributor

auto-submit bot commented Feb 9, 2024

auto label is removed for flutter/engine/50177, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
@tugorez tugorez added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
Copy link
Contributor

auto-submit bot commented Feb 9, 2024

auto label is removed for flutter/engine/50177, due to - The status or check suite Linux Fuchsia FEMU has failed. Please fix the issues identified (or deflake) before re-applying this label.

@tugorez tugorez added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
@auto-submit auto-submit bot merged commit 5e0df01 into flutter:main Feb 9, 2024
28 checks passed
@tugorez tugorez deleted the focus-management-web branch February 9, 2024 23:30
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 10, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 10, 2024
…143264)

flutter/engine@1b8f23b...e08b6c8

2024-02-10 dnfield@google.com Clean up additional NDK helper related code (flutter/engine#50518)
2024-02-09 tugorez@users.noreply.github.com Make the web engine publish view forward focus and unfocus events (flutter/engine#50177)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC chinmaygarde@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: 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
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
3 participants