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

Add platform view support for linux #26288

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,12 @@ FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_view.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_view_factory.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_view_private.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_views_plugin.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_views_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_views_plugin_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc
Expand Down Expand Up @@ -2110,6 +2116,8 @@ FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_method_chann
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_method_response.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_pixel_buffer_texture.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_platform_view.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_platform_view_factory.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ _public_headers = [
"public/flutter_linux/fl_method_codec.h",
"public/flutter_linux/fl_method_response.h",
"public/flutter_linux/fl_pixel_buffer_texture.h",
"public/flutter_linux/fl_platform_view.h",
"public/flutter_linux/fl_platform_view_factory.h",
"public/flutter_linux/fl_plugin_registrar.h",
"public/flutter_linux/fl_plugin_registry.h",
"public/flutter_linux/fl_standard_message_codec.h",
Expand Down Expand Up @@ -121,6 +123,9 @@ source_set("flutter_linux_sources") {
"fl_mouse_cursor_plugin.cc",
"fl_pixel_buffer_texture.cc",
"fl_platform_plugin.cc",
"fl_platform_view.cc",
"fl_platform_view_factory.cc",
"fl_platform_views_plugin.cc",
"fl_plugin_registrar.cc",
"fl_plugin_registry.cc",
"fl_renderer.cc",
Expand Down Expand Up @@ -194,6 +199,7 @@ executable("flutter_linux_unittests") {
"fl_method_codec_test.cc",
"fl_method_response_test.cc",
"fl_pixel_buffer_texture_test.cc",
"fl_platform_views_plugin_test.cc",
"fl_plugin_registrar_test.cc",
"fl_standard_message_codec_test.cc",
"fl_standard_method_codec_test.cc",
Expand All @@ -205,6 +211,7 @@ executable("flutter_linux_unittests") {
"testing/mock_binary_messenger_response_handle.cc",
"testing/mock_engine.cc",
"testing/mock_epoxy.cc",
"testing/mock_platform_view.cc",
"testing/mock_plugin_registrar.cc",
"testing/mock_renderer.cc",
"testing/mock_text_input_plugin.cc",
Expand Down
45 changes: 45 additions & 0 deletions shell/platform/linux/fl_platform_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/public/flutter_linux/fl_platform_view_factory.h"

#include "flutter/shell/platform/linux/fl_platform_view_private.h"

#include <gmodule.h>

// Added here to stop the compiler from optimizing this function away.
G_MODULE_EXPORT GType fl_platform_view_get_type();

typedef struct {
GtkTextDirection direction;
} FlPlatformViewPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(FlPlatformView, fl_platform_view, G_TYPE_OBJECT)

static void fl_platform_view_class_init(FlPlatformViewClass* klass) {}

static void fl_platform_view_init(FlPlatformView* self) {}

G_MODULE_EXPORT GtkWidget* fl_platform_view_get_view(FlPlatformView* self) {
g_return_val_if_fail(FL_IS_PLATFORM_VIEW(self), nullptr);

GtkWidget* widget = FL_PLATFORM_VIEW_GET_CLASS(self)->get_view(self);
if (!widget || !GTK_IS_WIDGET(widget)) {
g_critical("fl_platform_view::get_view should return GtkWidget");
return nullptr;
}

FlPlatformViewPrivate* priv = static_cast<FlPlatformViewPrivate*>(
fl_platform_view_get_instance_private(self));
gtk_widget_set_direction(widget, priv->direction);

return widget;
}

void fl_platform_view_set_direction(FlPlatformView* self,
GtkTextDirection direction) {
FlPlatformViewPrivate* priv = static_cast<FlPlatformViewPrivate*>(
fl_platform_view_get_instance_private(self));
priv->direction = direction;
}
39 changes: 39 additions & 0 deletions shell/platform/linux/fl_platform_view_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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/public/flutter_linux/fl_platform_view_factory.h"

#include <gmodule.h>

// Added here to stop the compiler from optimizing this function away.
G_MODULE_EXPORT GType fl_platform_view_factory_get_type();

G_DEFINE_INTERFACE(FlPlatformViewFactory,
fl_platform_view_factory,
G_TYPE_OBJECT)

static void fl_platform_view_factory_default_init(
FlPlatformViewFactoryInterface* iface) {}

G_MODULE_EXPORT FlPlatformView* fl_platform_view_factory_create_platform_view(
FlPlatformViewFactory* self,
int64_t view_identifier,
FlValue* args) {
g_return_val_if_fail(FL_IS_PLATFORM_VIEW_FACTORY(self), nullptr);

return FL_PLATFORM_VIEW_FACTORY_GET_IFACE(self)->create_platform_view(
self, view_identifier, args);
}

G_MODULE_EXPORT FlMessageCodec*
fl_platform_view_factory_get_create_arguments_codec(
FlPlatformViewFactory* self) {
g_return_val_if_fail(FL_IS_PLATFORM_VIEW_FACTORY(self), nullptr);

if (!FL_PLATFORM_VIEW_FACTORY_GET_IFACE(self)->get_create_arguments_codec)
return nullptr;

return FL_PLATFORM_VIEW_FACTORY_GET_IFACE(self)->get_create_arguments_codec(
self);
}
24 changes: 24 additions & 0 deletions shell/platform/linux/fl_platform_view_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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_PLATFORM_VIEW_PRIVATE_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_PLATFORM_VIEW_PRIVATE_H_

#include "flutter/shell/platform/linux/public/flutter_linux/fl_platform_view.h"

G_BEGIN_DECLS

/**
* fl_platform_view_set_direction:
* @platform_view: an #FlPlatformView.
* @direction: new #GtkTextDirection for platform view.
*
* Set text direction.
*/
void fl_platform_view_set_direction(FlPlatformView* platform_view,
GtkTextDirection direction);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_PLATFORM_VIEW_PRIVATE_H_
Loading