[geary/wip/713739-inline: 17/37] Fix scrolling and resizing of webview in overlay
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/713739-inline: 17/37] Fix scrolling and resizing of webview in overlay
- Date: Tue, 20 May 2014 20:17:05 +0000 (UTC)
commit 53d23717e2b2734c89a5fda31e2d67790271ca0d
Author: Robert Schroll <rschroll gmail com>
Date: Wed May 14 17:47:16 2014 -0700
Fix scrolling and resizing of webview in overlay
The webview doesn't properly shrink down unless the overlay implements
Scrollable. But this keeps the overlaid widgets from scrolling with the
webview, so we adjust their position based on the location of the
scrollbars.
src/CMakeLists.txt | 1 +
src/client/composer/composer-embed.vala | 6 +-
src/client/composer/scrollable-overlay.vala | 57 ++++++++++++++++++++
.../conversation-viewer/conversation-viewer.vala | 7 +--
4 files changed, 63 insertions(+), 8 deletions(-)
---
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1753a60..5f339a8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -330,6 +330,7 @@ client/composer/composer-window.vala
client/composer/contact-entry-completion.vala
client/composer/contact-list-store.vala
client/composer/email-entry.vala
+client/composer/scrollable-overlay.vala
client/composer/webview-edit-fixer.vala
client/conversation-list/conversation-list-cell-renderer.vala
diff --git a/src/client/composer/composer-embed.vala b/src/client/composer/composer-embed.vala
index f9af0da..d5f5a35 100644
--- a/src/client/composer/composer-embed.vala
+++ b/src/client/composer/composer-embed.vala
@@ -89,13 +89,13 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
close();
}
- public bool set_position(ref Gdk.Rectangle allocation) {
+ public bool set_position(ref Gdk.Rectangle allocation, double hscroll, double vscroll) {
WebKit.DOM.Element embed =
conversation_viewer.web_view.get_dom_document().get_element_by_id(embed_id);
if (embed == null)
return false;
- allocation.x = (int) (embed.offset_left + embed.client_left);
- allocation.y = (int) (embed.offset_top + embed.client_top);
+ allocation.x = (int) (embed.offset_left + embed.client_left) - (int) hscroll;
+ allocation.y = (int) (embed.offset_top + embed.client_top) - (int) vscroll;
allocation.width = (int) embed.client_width;
allocation.height = (int) embed.client_height;
return true;
diff --git a/src/client/composer/scrollable-overlay.vala b/src/client/composer/scrollable-overlay.vala
new file mode 100644
index 0000000..811ce3e
--- /dev/null
+++ b/src/client/composer/scrollable-overlay.vala
@@ -0,0 +1,57 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public class ScrollableOverlay : Gtk.Overlay, Gtk.Scrollable {
+
+ private Gtk.Scrollable main_child;
+
+ public Gtk.Adjustment hadjustment {
+ get; set;
+ }
+
+ public Gtk.Adjustment vadjustment {
+ get; set;
+ }
+
+ public Gtk.ScrollablePolicy hscroll_policy {
+ get; set;
+ }
+
+ public Gtk.ScrollablePolicy vscroll_policy {
+ get; set;
+ }
+
+ public ScrollableOverlay(Gtk.Scrollable main_child) {
+ this.main_child = main_child;
+ add((Gtk.Widget) main_child);
+
+ bind_property("hadjustment", main_child, "hadjustment",
+ BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
+ bind_property("vadjustment", main_child, "vadjustment",
+ BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
+ bind_property("hscroll_policy", main_child, "hscroll_policy",
+ BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
+ bind_property("vscroll_policy", main_child, "vscroll_policy",
+ BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
+
+ realize.connect(() => {
+ vadjustment.value_changed.connect(on_scroll);
+ hadjustment.value_changed.connect(on_scroll);
+ });
+ get_child_position.connect(on_child_position);
+ }
+
+ private bool on_child_position(Gtk.Widget widget, Gdk.Rectangle allocation) {
+ double hscroll = hadjustment.value,
+ vscroll = vadjustment.value;
+ return ((ComposerEmbed) widget).set_position(ref allocation, hscroll, vscroll);
+ }
+
+ private void on_scroll() {
+ queue_resize();
+ }
+}
+
diff --git a/src/client/conversation-viewer/conversation-viewer.vala
b/src/client/conversation-viewer/conversation-viewer.vala
index 1954c6c..613e73c 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -127,7 +127,7 @@ public class ConversationViewer : Gtk.Box {
private Gtk.Label message_overlay_label;
// Overlay containing any inline composers.
- public Gtk.Overlay compose_overlay;
+ public ScrollableOverlay compose_overlay;
// Maps emails to their corresponding elements.
private Gee.HashMap<Geary.EmailIdentifier, WebKit.DOM.HTMLElement> email_to_element = new
@@ -189,10 +189,7 @@ public class ConversationViewer : Gtk.Box {
web_view.link_selected.connect((link) => { link_selected(link); });
- compose_overlay = new Gtk.Overlay();
- compose_overlay.add(web_view);
- compose_overlay.get_child_position.connect((widget, allocation) =>
- { return ((ComposerEmbed) widget).set_position(ref allocation); } );
+ compose_overlay = new ScrollableOverlay(web_view);
Gtk.ScrolledWindow conversation_viewer_scrolled = new Gtk.ScrolledWindow(null, null);
conversation_viewer_scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]