Commit 7a37a465 authored by john's avatar john

Fix serveral things for the MR

parent 15f50cf5
......@@ -692,13 +692,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
update_email_state();
}
/**
* Get the summary's height of the primary message
*/
public int get_summary_height() {
return this.primary_message.get_summary_height();
}
/**
* Returns user-selected body HTML from a message, if any.
*/
......@@ -767,7 +760,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
view.flag_remote_images.connect(on_flag_remote_images);
view.remember_remote_images.connect(on_remember_remote_images);
view.internal_link_activated.connect((y) => {
internal_link_activated(y);
internal_link_activated(y);
});
view.web_view.internal_resource_loaded.connect(on_resource_loaded);
view.web_view.content_loaded.connect(on_content_loaded);
......
......@@ -907,10 +907,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
);
view.mark_email.connect(on_mark_email);
view.mark_email_from_here.connect(on_mark_email_from_here);
view.internal_link_activated.connect((y) => {
EmailRow row = get_email_row_by_id(view.email.id);
on_internal_link_activated(row, y);
});
view.internal_link_activated.connect(on_internal_link_activated);
view.body_selection_changed.connect((email, has_selection) => {
this.body_selected_view = has_selection ? email : null;
});
......@@ -965,20 +962,14 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
Gtk.Allocation? alloc = null;
row.get_allocation(out alloc);
int x = 0, y = 0;
ConversationWebView web_view = row.view.primary_message.web_view;
web_view.translate_coordinates(row, x, anchor_y, out x, out y);
Gtk.Adjustment adj = get_adjustment();
int page_size = (int) adj.get_page_size();
y = alloc.y + y;
adj.set_value(y);
int summary_height = row.view.get_summary_height();
int y = 0;
int necessary_y_offset = summary_height + anchor_y;
if (necessary_y_offset <= page_size) {
//The anchor can be seen with in the page, just scroll to the row.
scroll_to(row);
} else {
//The anchor require further scrolling
y = alloc.y + necessary_y_offset;
adj.set_value(y);
}
}
/**
......@@ -1180,7 +1171,8 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
}
private void on_internal_link_activated(EmailRow row, int y) {
private void on_internal_link_activated(ConversationEmail email, int y) {
EmailRow row = get_email_row_by_id(email.email.id);
scroll_to_anchor(row, y);
}
......
......@@ -359,9 +359,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
this.web_view.get_inspector().show();
});
add_action(ACTION_OPEN_LINK, true, VariantType.STRING)
.activate.connect((param) => {
on_link_activated(param.get_string());
});
.activate.connect(on_link_activated);
add_action(ACTION_SAVE_IMAGE, true, new VariantType("(sms)"))
.activate.connect(on_save_image);
add_action(ACTION_SEARCH_FROM, true, VariantType.STRING)
......@@ -448,7 +446,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
this.web_view.context_menu.connect(on_context_menu);
this.web_view.deceptive_link_clicked.connect(on_deceptive_link_clicked);
this.web_view.link_activated.connect(on_link_activated);
this.web_view.link_activated.connect((link) => {
on_link_activated(new GLib.Variant("s", link));
});
this.web_view.mouse_target_changed.connect(on_mouse_target_changed);
this.web_view.notify["is-loading"].connect(on_is_loading_notify);
this.web_view.resource_load_started.connect(on_resource_load_started);
......@@ -603,11 +603,6 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
this.progress_pulse.reset();
}
/** Get the height of the summary part */
public int get_summary_height() {
return summary.get_allocated_height();
}
/**
* Starts loading the avatar for the message's sender.
*/
......@@ -1165,21 +1160,22 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
});
}
private void on_link_activated(string link) {
if (link.contains(INTERNAL_ANCHOR_PREFIX)) {
private void on_link_activated(GLib.Variant? param) {
string link = param.get_string();
if (link.has_prefix(INTERNAL_ANCHOR_PREFIX)) {
long start = INTERNAL_ANCHOR_PREFIX.length;
long end = link.length;
string anchor_body = link.substring(start, end - start);
this.web_view.get_anchor_target_y.begin(anchor_body, (obj, res) => {
try {
int y = this.web_view.get_anchor_target_y.end(res);
//Workaround for JS.Error does not work well with primitive type.
if (y > 0) {
internal_link_activated(y);
} else {
debug("Failed to get anchor destination");
debug("Failed to get anchor destination");
}
} catch (Error err) {
} catch (GLib.Error err) {
debug("Failed to get anchor destination");
}
});
......
......@@ -99,9 +99,11 @@ public class ConversationWebView : ClientWebView {
/**
* Returns the y value for a element, by its id
*/
public async int? get_anchor_target_y(string anchor_body) throws Error {
public async int? get_anchor_target_y(string anchor_body)
throws GLib.Error {
WebKit.JavascriptResult result = yield call(
Geary.JS.callable("geary.getAnchorTargetY").string(anchor_body), null
Geary.JS.callable("geary.getAnchorTargetY")
.string(anchor_body), null
);
return (int) WebKitUtil.to_number(result);
}
......
......@@ -245,16 +245,15 @@ ConversationPageState.prototype = {
return value;
},
getAnchorTargetY: function(anchor) {
let targetById = document.getElementById(anchor);
let targetByName = document.getElementsByName(anchor);
let finalTarget = null;
if (targetById != null) {
finalTarget = targetById;
} else if (targetByName.length > 0) {
finalTarget = targetByName[0];
let target = document.getElementById(anchor);
if (target == null) {
target = document.getElementsByName(anchor);
if (target.length > 0) {
target = target[0];
}
}
if (finalTarget != null) {
return finalTarget.getBoundingClientRect().top +
if (target != null) {
return target.getBoundingClientRect().top +
document.documentElement.scrollTop;
} else {
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment