This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Add platform view support for Linux shell #24169
Closed
huanghongxun
wants to merge
19
commits into
flutter:master
from
wechat-miniprogram:dev/platform_views
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2bc8aaf
Add platform view support for Linux shell
huanghongxun df150a6
Fix docs
huanghongxun 14dc152
Add scroll event propagation
huanghongxun d3c96ee
Add platform views plugin test
huanghongxun 92fc86b
Apply clipping mutators to platform views
huanghongxun 4caf889
Merge branch 'master' into dev/platform_views
huanghongxun f14f743
Update licenses_flutter
huanghongxun d81f161
Support setDirection
huanghongxun 25f61be
Merge branch 'master' of https://github.com/flutter/engine into dev/p…
huanghongxun fca32cf
fix: transformation
huanghongxun d7960d2
Merge branch 'master' of https://github.com/flutter/engine into dev/p…
huanghongxun 6647f90
Add comments
huanghongxun a9a8a22
fix: nits
huanghongxun bed4f49
fix: nits
huanghongxun 615b93a
Merge branch 'master' of https://github.com/flutter/engine into dev/p…
huanghongxun ca9e391
Fix leaking error
huanghongxun e4b3fde
Fix no dispose
huanghongxun 6eeb321
Fix: clipping_view's mutations cannot be null
huanghongxun 48345f5
Merge branch 'master' of https://github.com/flutter/engine into dev/p…
huanghongxun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/platform/linux/fl_clipping_view.h" | ||
|
|
||
| #include "flutter/shell/platform/embedder/embedder.h" | ||
|
|
||
| struct _FlClippingView { | ||
| GtkEventBox parent_instance; | ||
|
|
||
| GdkRectangle geometry; | ||
| GPtrArray* mutations; | ||
| }; | ||
|
|
||
| G_DEFINE_TYPE(FlClippingView, fl_clipping_view, GTK_TYPE_EVENT_BOX) | ||
|
|
||
| static void fl_clipping_view_dispose(GObject* gobject) { | ||
| FlClippingView* self = FL_CLIPPING_VIEW(gobject); | ||
|
|
||
| g_clear_pointer(&self->mutations, g_ptr_array_unref); | ||
|
|
||
| G_OBJECT_CLASS(fl_clipping_view_parent_class)->dispose(gobject); | ||
| } | ||
|
|
||
| // Implements GtkWidget::size-allocate. | ||
| static void fl_clipping_view_size_allocate(GtkWidget* widget, | ||
| GtkAllocation* allocation) { | ||
| FlClippingView* self = FL_CLIPPING_VIEW(widget); | ||
|
|
||
| gtk_widget_set_allocation(widget, allocation); | ||
|
|
||
| if (gtk_widget_get_has_window(widget)) { | ||
| if (gtk_widget_get_realized(widget)) | ||
| gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, | ||
| allocation->y, allocation->width, | ||
| allocation->height); | ||
| } | ||
|
|
||
| GtkWidget* child = gtk_bin_get_child(GTK_BIN(self)); | ||
| if (!child || !gtk_widget_get_visible(child)) | ||
| return; | ||
|
|
||
| GtkAllocation child_allocation = self->geometry; | ||
| if (!gtk_widget_get_has_window(widget)) { | ||
| child_allocation.x += allocation->x; | ||
| child_allocation.y += allocation->y; | ||
| } | ||
| gtk_widget_size_allocate(child, &child_allocation); | ||
| } | ||
|
|
||
| // Implements GtkWidget::draw. | ||
| static gboolean fl_clipping_view_draw(GtkWidget* widget, cairo_t* cr) { | ||
| FlClippingView* self = FL_CLIPPING_VIEW(widget); | ||
|
|
||
| // We currently can only clip widgets that have no GdkWindow. | ||
|
|
||
| cairo_save(cr); | ||
| if (self->mutations) { | ||
| for (guint i = 0; i < self->mutations->len; i++) { | ||
| FlutterPlatformViewMutation* mutation = | ||
| reinterpret_cast<FlutterPlatformViewMutation*>( | ||
| self->mutations->pdata[i]); | ||
| switch (mutation->type) { | ||
| case kFlutterPlatformViewMutationTypeOpacity: { | ||
| // opacitiy is applied in fl_clipping_view_reset (). | ||
| } break; | ||
| case kFlutterPlatformViewMutationTypeClipRect: { | ||
| cairo_rectangle(cr, mutation->clip_rect.left, mutation->clip_rect.top, | ||
| mutation->clip_rect.right - mutation->clip_rect.left, | ||
| mutation->clip_rect.bottom - mutation->clip_rect.top); | ||
| cairo_clip(cr); | ||
| } break; | ||
| case kFlutterPlatformViewMutationTypeClipRoundedRect: { | ||
| FlutterSize* top_left_radii = | ||
| &mutation->clip_rounded_rect.upper_left_corner_radius; | ||
| FlutterSize* top_right_radii = | ||
| &mutation->clip_rounded_rect.upper_right_corner_radius; | ||
| FlutterSize* bottom_left_radii = | ||
| &mutation->clip_rounded_rect.lower_left_corner_radius; | ||
| FlutterSize* bottom_right_radii = | ||
| &mutation->clip_rounded_rect.lower_right_corner_radius; | ||
| FlutterRect* rect = &mutation->clip_rounded_rect.rect; | ||
| cairo_move_to(cr, rect->left + top_left_radii->width, rect->top); | ||
|
|
||
| cairo_line_to(cr, rect->right - top_right_radii->width, rect->top); | ||
| cairo_curve_to(cr, rect->right, rect->top, // | ||
| rect->right, rect->top + top_right_radii->height, | ||
| rect->right, rect->top + top_right_radii->height); | ||
|
|
||
| cairo_line_to(cr, rect->right, | ||
| rect->bottom - bottom_right_radii->height); | ||
| cairo_curve_to(cr, rect->right, rect->bottom, | ||
| rect->right - bottom_right_radii->width, rect->bottom, | ||
| rect->right - bottom_right_radii->width, rect->bottom); | ||
|
|
||
| cairo_line_to(cr, rect->left + bottom_left_radii->width, | ||
| rect->bottom); | ||
| cairo_curve_to(cr, rect->left, rect->bottom, // | ||
| rect->left, rect->bottom - bottom_left_radii->height, | ||
| rect->left, rect->bottom - bottom_left_radii->height); | ||
|
|
||
| cairo_line_to(cr, rect->left, rect->top + top_left_radii->height); | ||
| cairo_curve_to(cr, rect->left, rect->top, | ||
| rect->left + top_left_radii->width, rect->top, | ||
| rect->left + top_left_radii->width, rect->top); | ||
|
|
||
| cairo_close_path(cr); | ||
| cairo_clip(cr); | ||
| } break; | ||
| case kFlutterPlatformViewMutationTypeTransformation: { | ||
| cairo_matrix_t matrix = { | ||
| .xx = mutation->transformation.scaleX, | ||
| .yx = mutation->transformation.skewY, | ||
| .xy = mutation->transformation.skewX, | ||
| .yy = mutation->transformation.scaleY, | ||
| .x0 = mutation->transformation.transX, | ||
| .y0 = mutation->transformation.transY, | ||
| }; | ||
| cairo_transform(cr, &matrix); | ||
| } break; | ||
| } | ||
| } | ||
| } | ||
| cairo_translate(cr, -self->geometry.x, -self->geometry.y); | ||
| gboolean result = | ||
| GTK_WIDGET_CLASS(fl_clipping_view_parent_class)->draw(widget, cr); | ||
| cairo_restore(cr); | ||
| return result; | ||
| } | ||
|
|
||
| static void fl_clipping_view_constructed(GObject* object) { | ||
| gtk_event_box_set_visible_window(GTK_EVENT_BOX(object), TRUE); | ||
| } | ||
|
|
||
| static void fl_clipping_view_class_init(FlClippingViewClass* klass) { | ||
| GObjectClass* gobject_class = G_OBJECT_CLASS(klass); | ||
| gobject_class->constructed = fl_clipping_view_constructed; | ||
| gobject_class->dispose = fl_clipping_view_dispose; | ||
|
|
||
| GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass); | ||
| widget_class->draw = fl_clipping_view_draw; | ||
| widget_class->size_allocate = fl_clipping_view_size_allocate; | ||
| } | ||
|
|
||
| static void fl_clipping_view_init(FlClippingView* self) {} | ||
|
|
||
| GtkWidget* fl_clipping_view_new() { | ||
| return GTK_WIDGET(g_object_new(fl_clipping_view_get_type(), nullptr)); | ||
| } | ||
|
|
||
| void fl_clipping_view_reset(FlClippingView* self, | ||
| GtkWidget* child, | ||
| GdkRectangle* geometry, | ||
| GPtrArray* mutations) { | ||
| g_return_if_fail(FL_IS_CLIPPING_VIEW(self)); | ||
| g_return_if_fail(mutations != nullptr); | ||
|
|
||
| GtkWidget* old_child = gtk_bin_get_child(GTK_BIN(self)); | ||
| if (old_child != child) { | ||
| if (old_child) { | ||
| gtk_container_remove(GTK_CONTAINER(self), old_child); | ||
| } | ||
|
|
||
| g_object_ref(child); | ||
| gtk_container_add(GTK_CONTAINER(self), child); | ||
| } | ||
| self->geometry = *geometry; | ||
| g_clear_pointer(&self->mutations, g_ptr_array_unref); | ||
| self->mutations = g_ptr_array_ref(mutations); | ||
|
|
||
| for (guint i = 0; i < mutations->len; i++) { | ||
| FlutterPlatformViewMutation* mutation = | ||
| reinterpret_cast<FlutterPlatformViewMutation*>( | ||
| self->mutations->pdata[i]); | ||
| if (mutation->type == kFlutterPlatformViewMutationTypeOpacity) { | ||
| gtk_widget_set_opacity(child, mutation->opacity); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_CLIPPING_VIEW_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_LINUX_FL_CLIPPING_VIEW_H_ | ||
|
|
||
| #include <gtk/gtk.h> | ||
|
|
||
| #include <glib-object.h> | ||
|
|
||
| G_BEGIN_DECLS | ||
|
|
||
| G_DECLARE_FINAL_TYPE(FlClippingView, | ||
| fl_clipping_view, | ||
| FL, | ||
| CLIPPING_VIEW, | ||
| GtkEventBox) | ||
|
|
||
| /** | ||
| * FlClippingView: | ||
| * | ||
| * #FlClippingView is a GTK widget that applies clipping mutations set by | ||
| * Framework side to child platform view. | ||
| */ | ||
|
|
||
| /** | ||
| * fl_clipping_view_new: | ||
| * | ||
| * Creates a new #FlClippingView widget. | ||
| * | ||
| * Returns: the newly created #FlClippingView widget. | ||
| */ | ||
| GtkWidget* fl_clipping_view_new(); | ||
|
|
||
| /** | ||
| * fl_clipping_view_reset: | ||
| * @clipping_view: an #FlClippingView. | ||
| * @child: widget to apply mutators. | ||
| * @geometry: geometry of widget. | ||
| * @mutations: the clipping mutations to be applied. | ||
huanghongxun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * Reset child widget and its mutations. | ||
| */ | ||
| void fl_clipping_view_reset(FlClippingView* clipping_view, | ||
| GtkWidget* child, | ||
| GdkRectangle* geometry, | ||
| GPtrArray* mutations); | ||
|
|
||
| G_END_DECLS | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_CLIPPING_VIEW_H_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.