Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@huanghongxun
Copy link
Contributor

@huanghongxun huanghongxun commented Feb 3, 2021

This pull request is part of #23985. For framework API, see flutter/flutter#74814.

This pull request adds platform view API to Linux shell.

Code changes:

  1. FlGestureHelper for accepting gesture, redistributing press, release and motion events to platform view. Because only Flutter framework knows about whether we can touch and operate with the platform view by hit test. If Flutter framework accepts a gesture, FlGestureHelper will send following pointer events to GtkWidget. For hover events, If Flutter framework has notified enter and exit event, FlGestureHelper will also send pointer hover event (or GdkEventMotion) to platform view.
  2. FlPlatformView to wrap a GtkWidget, owned by FlPlatformViewsPlugin. This abstraction allows us to owning a FlMethodChannel in FlPlatformView for communication with dart codes.
  3. FlPlatformViewFactory for creating platform views for specific view type. Flutter Framework will call functions of FlPlatformViewFactory when creating a new platform view.
  4. FlPlatformViewsPlugin for implementing SystemChannels.platform_views from Flutter services library.

A working demo with webview: https://github.com/wechat-miniprogram/gtktest.

This pr does not support applying mutations on the platform views yet. I will open a PR later to implement that feature.

This pr is part of platform view implementation on Linux, related issue: flutter/flutter#41724.

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 Hixie said 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.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

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

@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 to this rule, contact Hixie on the #hackers channel in Chat.

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.

@huanghongxun huanghongxun force-pushed the dev/platform_views branch 2 times, most recently from f30bd85 to d4cdf91 Compare February 3, 2021 15:02
@huanghongxun
Copy link
Contributor Author

huanghongxun commented Feb 3, 2021

@robert-ancell @wmww
Here's platform view implementation. Clipping mutations are not supported by this PR.

button.button.button = event->button;
button.button.device = event->device;
button.button.x_root = event->x_root;
button.button.y_root = event->y_root;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to copy each field individually instead of copying the whole event and making required adjustments? Seems to me like the latter would have less opportunities for subtle errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

int64_t id) {
gpointer p = g_hash_table_lookup(self->platform_views, GINT_TO_POINTER(id));
if (p && FL_IS_PLATFORM_VIEW(p)) {
return FL_PLATFORM_VIEW(p);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the FL_IS_PLATFORM_VIEW() check necessary? Will it ever be anything other than null or a platform view? Even if it is, the FL_PLATFORM_VIEW() cast should return null in that case (it would just print an error as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return FL_METHOD_RESPONSE(fl_method_error_response_new(
kBadArgumentsError, "View type does not exist", nullptr));
}
FlPlatformViewFactory* factory = FL_PLATFORM_VIEW_FACTORY(factory_pointer);
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably won't fail, but it can't hurt to move the FL_PLATFORM_VIEW_FACTORY() cast to above the check and then check if factory exists, rather than checking factory_pointer (assuming that factory shouldn't ever be null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

static FlMethodResponse* platform_views_accept_gesture(
FlPlatformViewsPlugin* self,
FlValue* args) {
if (fl_value_get_type(args) != FL_VALUE_TYPE_LIST) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should also check if the list has the expected number of elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

FlPlatformViewsPlugin* self,
int view_identifier) {
return (FlPlatformView*)g_hash_table_lookup(self->platform_views,
GINT_TO_POINTER(view_identifier));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a safe FL_PLATFORM_VIEW() cast?

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's safe, because we have checked its type in platform_views_create before inserting it into platform_views.

/**
* fl_platform_views_plugin_new:
* @messenger: an #FlBinaryMessenger.
* @gesture_helper: an #FlGestureHelper for accepting gestures by Dart side.
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said in the other comment, ownership of gesture_helper is unclear to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@wmww wmww left a comment

Choose a reason for hiding this comment

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

LGTM

@chinmaygarde
Copy link
Member

It's unclear who the owner of this PR is. Does this need additional reviews or can we land this?

cc @cbracken.

@huanghongxun
Copy link
Contributor Author

It's unclear who the owner of this PR is. Does this need additional reviews or can we land this?

cc @cbracken.

The native implementation and interfaces are approved by wmww. Because I have added logics to deal with messages from framework side channel SystemChannel.platform_views, we may review framework side patch flutter/flutter#74814 first, and land both of PRs together?

@chinmaygarde
Copy link
Member

chinmaygarde commented Feb 18, 2021

Thanks for the clarification. The framework patch does seem to be being actively reviewed. Once that is good to go, we can land this as well.

@huanghongxun huanghongxun force-pushed the dev/platform_views branch 3 times, most recently from e92cef5 to 098a052 Compare February 22, 2021 12:58
@chinmaygarde
Copy link
Member

A reviewer was added to the framework patch but it hasn't landed yet. @goderbauer Is there anything we can do to expedite that review? This patch has been pending for close to a month.

@chinmaygarde
Copy link
Member

@gspencergoog This is the engine patch for flutter/flutter#74814. Are we able to find a reviewer for this?

@gspencergoog
Copy link
Contributor

@chinmaygarde: working on it. @cbracken is going to take a look, and we think @cyanglaz might be a good candidate to review, if he's up for it.

@huanghongxun
Copy link
Contributor Author

There are a couple of things that need to be addressed, but I think this PR looks mostly good. Apart from the listed comments, the major ones are:

  1. Can we remove gesture_helper from this PR, and land it as another change set once this PR lands? I noticed that some of the methods there aren't used and wired up right now, also that class needs tests.
  2. Can we please fix the current test failures?

Thanks.

FlGestureHelper is used to bypass touch events from Framework to platform views, which is important.

@chinmaygarde
Copy link
Member

@iskakaushik and @robert-ancell I believe this is ready for another review.

@robert-ancell
Copy link
Contributor

@huanghongxun please remove the gesture helper and do in a following PR as requested by @iskakaushik. If there's anything else you can split out, that will help a lot. These PRs are really big and that makes them slow to review. I would much prefer to review 3 smaller PRs in a row than one big one and that will be faster.

@huanghongxun
Copy link
Contributor Author

huanghongxun commented May 20, 2021

@robert-ancell I have proposed #26288 with all requested changes resolved.

@zanderso
Copy link
Member

zanderso commented Oct 7, 2021

@huanghongxun Since this PR has not been updated in quite some time, I am going to close it as presumed stale.

@zanderso zanderso closed this Oct 7, 2021
@sliechti
Copy link

sliechti commented Oct 9, 2021

I don't know about others but I have been waiting so long for this PR. What's remaining? Address code reviews? Split the pull request? If @huanghongxun doesn't have time, maybe I can help.

In my opinion, getting webview to work on flutter desktop should be a priority for the Flutter team. I'm puzzled why is not?

@huanghongxun
Copy link
Contributor Author

@sliechti We are tracking the platform view implementation in #26288.

@sliechti
Copy link

sliechti commented Oct 9, 2021

Thank you @huanghongxun

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.