[gnome-builder/wip/gtk4-port] libde/webkit: add IdeWebkitPage and libide-webkit.h



commit f1023cf54790830c26c1aa73067fba8126e82424
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 25 22:42:06 2022 -0700

    libde/webkit: add IdeWebkitPage and libide-webkit.h
    
    The goal here is to move some of our webkit bits out into a helper so that
    we can break html-preview into multiple plugins.

 meson.build                                   |   2 +
 src/libide/webkit/ide-webkit-page.c           | 105 ++++++++++++++++++++++++++
 src/libide/webkit/ide-webkit-page.h           |  40 ++++++++++
 src/libide/webkit/ide-webkit-page.ui          |  11 +++
 src/libide/webkit/libide-webkit.gresource.xml |   1 +
 src/libide/webkit/libide-webkit.h             |  27 +++++++
 src/libide/webkit/meson.build                 |  31 +++++++-
 7 files changed, 215 insertions(+), 2 deletions(-)
---
diff --git a/meson.build b/meson.build
index e730da409..50de9a847 100644
--- a/meson.build
+++ b/meson.build
@@ -102,6 +102,8 @@ status += [
   '',
   'Help Docs ............. : @0@'.format(get_option('help')),
   'API Docs .............. : @0@'.format(get_option('docs')),
+  '',
+  'WebKit ................ : @0@'.format(get_option('webkit').enabled()),
   '', ''
 ]
 
diff --git a/src/libide/webkit/ide-webkit-page.c b/src/libide/webkit/ide-webkit-page.c
new file mode 100644
index 000000000..0f3078eac
--- /dev/null
+++ b/src/libide/webkit/ide-webkit-page.c
@@ -0,0 +1,105 @@
+/* ide-webkit-page.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-webkit-page"
+
+#include "config.h"
+
+#include <webkit2/webkit2.h>
+
+#include "ide-webkit-page.h"
+
+typedef struct
+{
+  WebKitWebView *webview;
+} IdeWebkitPagePrivate;
+
+enum {
+  PROP_0,
+  N_PROPS
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeWebkitPage, ide_webkit_page, IDE_TYPE_PAGE)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_webkit_page_dispose (GObject *object)
+{
+  G_OBJECT_CLASS (ide_webkit_page_parent_class)->dispose (object);
+}
+
+static void
+ide_webkit_page_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  IdeWebkitPage *self = IDE_WEBKIT_PAGE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_webkit_page_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  IdeWebkitPage *self = IDE_WEBKIT_PAGE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_webkit_page_class_init (IdeWebkitPageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_webkit_page_dispose;
+  object_class->get_property = ide_webkit_page_get_property;
+  object_class->set_property = ide_webkit_page_set_property;
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/webkit/ide-webkit-page.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, webview);
+
+  g_type_ensure (WEBKIT_TYPE_WEB_VIEW);
+}
+
+static void
+ide_webkit_page_init (IdeWebkitPage *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+IdeWebkitPage *
+ide_webkit_page_new (void)
+{
+  return g_object_new (IDE_TYPE_WEBKIT_PAGE, NULL);
+}
diff --git a/src/libide/webkit/ide-webkit-page.h b/src/libide/webkit/ide-webkit-page.h
new file mode 100644
index 000000000..6e18fea50
--- /dev/null
+++ b/src/libide/webkit/ide-webkit-page.h
@@ -0,0 +1,40 @@
+/* ide-webkit-page.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_WEBKIT_PAGE (ide_webkit_page_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeWebkitPage, ide_webkit_page, IDE, WEBKIT_PAGE, IdePage)
+
+struct _IdeWebkitPageClass
+{
+  IdePageClass parent_class;
+};
+
+IDE_AVAILABLE_IN_ALL
+IdeWebkitPage *ide_webkit_page_new (void);
+
+G_END_DECLS
diff --git a/src/libide/webkit/ide-webkit-page.ui b/src/libide/webkit/ide-webkit-page.ui
new file mode 100644
index 000000000..39e4ee290
--- /dev/null
+++ b/src/libide/webkit/ide-webkit-page.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeWebkitPage" parent="IdePage">
+    <child>
+      <object class="WebKitWebView" id="webview">
+        <property name="hexpand">true</property>
+        <property name="vexpand">true</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/libide/webkit/libide-webkit.gresource.xml b/src/libide/webkit/libide-webkit.gresource.xml
index f1621dbaa..ee10c7d54 100644
--- a/src/libide/webkit/libide-webkit.gresource.xml
+++ b/src/libide/webkit/libide-webkit.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/plugins/webkit">
     <file>webkit.plugin</file>
+    <file preprocess="xml-stripblanks">ide-webkit-page.ui</file>
   </gresource>
 </gresources>
diff --git a/src/libide/webkit/libide-webkit.h b/src/libide/webkit/libide-webkit.h
new file mode 100644
index 000000000..9bde8d723
--- /dev/null
+++ b/src/libide/webkit/libide-webkit.h
@@ -0,0 +1,27 @@
+/* libide-webkit.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-gui.h>
+
+#define IDE_WEBKIT_INSIDE
+# include "ide-webkit-page.h"
+#undef IDE_WEBKIT_INSIDE
diff --git a/src/libide/webkit/meson.build b/src/libide/webkit/meson.build
index e1457270f..21fa7e101 100644
--- a/src/libide/webkit/meson.build
+++ b/src/libide/webkit/meson.build
@@ -2,14 +2,31 @@ libwebkit_dep = dependency('webkit2gtk-5.0', required: false)
 
 if libwebkit_dep.found()
 
+libide_webkit_header_dir = join_paths(libide_header_dir, 'webkit')
+libide_webkit_header_subdir = join_paths(libide_header_subdir, 'webkit')
+libide_include_directories += include_directories('.')
+
 #
 # Sources
 #
 
-libide_webkit_sources = [
+libide_webkit_private_sources = [
   'ide-webkit-plugin.c',
 ]
 
+#
+# Public API Headers
+#
+
+libide_webkit_public_headers = [
+  'libide-webkit.h',
+  'ide-webkit-page.h',
+]
+
+libide_webkit_public_sources = [
+  'ide-webkit-page.c',
+]
+
 #
 # Generated Resource Files
 #
@@ -20,7 +37,8 @@ libide_webkit_resources = gnome.compile_resources(
   c_name: 'ide_webkit',
 )
 libide_webkit_generated_headers = [libide_webkit_resources[1]]
-libide_webkit_sources += libide_webkit_resources
+
+libide_webkit_sources = libide_webkit_resources + libide_webkit_public_sources + 
libide_webkit_private_sources
 
 #
 # Dependencies
@@ -29,6 +47,7 @@ libide_webkit_sources += libide_webkit_resources
 libide_webkit_deps = [
   libwebkit_dep,
   libpeas_dep,
+  libide_gui_dep,
 ]
 
 #
@@ -47,4 +66,12 @@ libide_webkit_dep = declare_dependency(
               sources: libide_webkit_generated_headers,
 )
 
+gnome_builder_private_sources += files(libide_webkit_private_sources)
+gnome_builder_public_sources += files(libide_webkit_public_sources)
+gnome_builder_public_headers += files(libide_webkit_public_headers)
+gnome_builder_include_subdirs += libide_webkit_header_subdir
+gnome_builder_gir_extra_args += ['--c-include=libide-webkit.h', '-DIDE_WEBKIT_COMPILATION']
+
+install_headers(libide_webkit_public_headers, subdir: libide_webkit_header_subdir)
+
 endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]