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

Fix webview scroll #973

Closed
wants to merge 4 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 51 additions & 13 deletions src/MessageList/MessageList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Mail.MessageList : Gtk.Box {

private FolderPopover folder_popover;
private Gtk.ListBox list_box;
private Gtk.ScrolledWindow scrolled_window;
private Gtk.Paned vpaned;
private Gtk.Frame web_view_frame;
private Gee.HashMap<string, MessageListItem> messages;

construct {
Expand Down Expand Up @@ -139,20 +140,57 @@ public class Mail.MessageList : Gtk.Box {
list_box.set_placeholder (placeholder);
list_box.set_sort_func (message_sort_function);

scrolled_window = new Gtk.ScrolledWindow (null, null) {
hscrollbar_policy = NEVER
vpaned = new Gtk.Paned (Gtk.Orientation.VERTICAL);
var scrolled_window = new Gtk.ScrolledWindow (null, null) {
hscrollbar_policy = NEVER,
min_content_height = 120
};

scrolled_window.add (list_box);

// Prevent the focus of the webview causing the ScrolledWindow to scroll
var scrolled_child = scrolled_window.get_child ();
if (scrolled_child is Gtk.Container) {
((Gtk.Container) scrolled_child).set_focus_vadjustment (new Gtk.Adjustment (0, 0, 0, 0, 0, 0));
}
web_view_frame = new Gtk.Frame ("") {
margin_top = 12,
margin_bottom = 12,
margin_start = 12,
margin_end = 12,
shadow_type = Gtk.ShadowType.ETCHED_IN,
no_show_all = true
};

vpaned.pack1 (scrolled_window, false, false);
vpaned.pack2 (web_view_frame, true, true);

orientation = VERTICAL;
add (headerbar);
add (scrolled_window);
add (vpaned);
show_all ();
}

private Gtk.Widget? view_widget = null;
public void row_expand_changed (Mail.MessageListItem row) {
if (view_widget != null) {
web_view_frame.remove (view_widget);
view_widget = null;
}

web_view_frame.hide ();

if (row.expanded) {
var index = 0;
while (list_box.get_row_at_index (index) != null) {
var rw = (Mail.MessageListItem) list_box.get_row_at_index (index);
if (rw != row) {
rw.expanded = false;
}

index++;
}

view_widget = row.web_view;
web_view_frame.add (view_widget);
row.web_view.show_all ();
web_view_frame.show ();
}
}

public void set_conversation (Camel.FolderThreadNode? node) {
Expand Down Expand Up @@ -182,7 +220,7 @@ public class Mail.MessageList : Gtk.Box {
var store = node.message.summary.folder.parent_store;
folder_popover.set_store (store);

var item = new MessageListItem (node.message);
var item = new MessageListItem (node.message, this);
list_box.add (item);
messages.set (node.message.uid, item);
if (node.child != null) {
Expand All @@ -192,7 +230,7 @@ public class Mail.MessageList : Gtk.Box {
var children = list_box.get_children ();
var num_children = children.length ();
if (num_children > 0) {
var child = list_box.get_row_at_index ((int) num_children - 1);
var child = list_box.get_row_at_index (0);
if (child != null && child is MessageListItem) {
var list_item = (MessageListItem) child;
list_item.expanded = true;
Expand All @@ -211,7 +249,7 @@ public class Mail.MessageList : Gtk.Box {
private void go_down (Camel.FolderThreadNode node) {
unowned Camel.FolderThreadNode? current_node = node;
while (current_node != null) {
var item = new MessageListItem (current_node.message);
var item = new MessageListItem (current_node.message, this);
list_box.add (item);
messages.set (current_node.message.uid, item);
if (current_node.next != null) {
Expand Down Expand Up @@ -287,6 +325,6 @@ public class Mail.MessageList : Gtk.Box {
timestamp2 = message2.message_info.date_sent;
}

return (int)(timestamp1 - timestamp2);
return (int)(timestamp2 - timestamp1);
}
}
17 changes: 8 additions & 9 deletions src/MessageList/MessageListItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
public Camel.MessageInfo message_info { get; construct; }
public Camel.MimeMessage? mime_message { get; private set; default = null; }

private Mail.WebView web_view;
public Mail.WebView web_view { get; private set; }
private GLib.Cancellable loading_cancellable;

private Gtk.InfoBar calendar_info_bar;
Expand Down Expand Up @@ -58,18 +58,22 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
} else {
style_context.add_class ("collapsed");
}

message_list.row_expand_changed (this);
}
}

private GLib.Settings settings;
public unowned Mail.MessageList message_list { get; construct; }

public MessageListItem (Camel.MessageInfo message_info) {
public MessageListItem (Camel.MessageInfo message_info, Mail.MessageList message_list) {
Object (
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
message_info: message_info
message_info: message_info,
message_list: message_list
);
}

Expand Down Expand Up @@ -304,11 +308,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
((Gtk.Box) blocked_images_infobar.get_action_area ()).orientation = Gtk.Orientation.VERTICAL;

web_view = new Mail.WebView () {
margin_top = 12,
margin_bottom = 12,
margin_start = 12,
margin_end = 12,
bind_height_to_page_height = true
bind_height_to_page_height = false
};
web_view.mouse_target_changed.connect (on_mouse_target_changed);
web_view.context_menu.connect (on_webview_context_menu);
Expand All @@ -320,7 +320,6 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
secondary_box.add (separator);
secondary_box.add (calendar_info_bar);
secondary_box.add (blocked_images_infobar);
secondary_box.add (web_view);

secondary_revealer = new Gtk.Revealer () {
transition_type = SLIDE_UP
Expand Down