Commit 46cd8bae authored by john's avatar john

Avoiding add signal into the EmailRow, but translate seems hard to do since...

Avoiding add signal into the EmailRow, but translate seems hard to do since the webview is in the inside of message.
parent 720fa65e
......@@ -421,7 +421,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
public signal void view_source();
/** Fired when a internal link is activated */
public signal void internal_link_activated(uint y);
public signal void internal_link_activated(int y);
/** Fired when the user selects text in a message. */
internal signal void body_selection_changed(bool has_selection);
......
......@@ -327,15 +327,10 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
public ConversationEmail view { get; private set; }
/** Fired when a internal link is activated */
public signal void internal_link_activated(EmailRow view, uint y);
public EmailRow(ConversationEmail view) {
base(view.email);
this.view = view;
add(view);
connect_email_signals(view);
}
public override async void expand()
......@@ -363,12 +358,6 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
}
private void connect_email_signals(ConversationEmail email) {
email.internal_link_activated.connect((y) => {
internal_link_activated(this, y);
});
}
}
......@@ -916,6 +905,10 @@ 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.body_selection_changed.connect((email, has_selection) => {
this.body_selected_view = has_selection ? email : null;
});
......@@ -941,8 +934,6 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
email_added(view);
row.internal_link_activated.connect(on_internal_link_activated);
return row;
}
......@@ -1187,7 +1178,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
}
private void on_internal_link_activated(EmailRow row, uint y) {
private void on_internal_link_activated(EmailRow row, int y) {
scroll_to_anchor(row, y);
}
......
......@@ -263,7 +263,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
public signal void link_activated(string link);
/** Fired when the user clicks a internal link in the email. */
public signal void internal_link_activated(uint y);
public signal void internal_link_activated(int y);
/** Fired when the user requests remote images be loaded. */
public signal void flag_remote_images();
......@@ -1169,10 +1169,20 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
if (link.contains(INTERNAL_ANCHOR_PREFIX)) {
long start = INTERNAL_ANCHOR_PREFIX.length;
long end = link.length;
this.web_view.get_anchor_target_y.begin(link.substring(start, end - start), (obj, res) => {
uint y = this.web_view.get_anchor_target_y.end(res);
internal_link_activated(y);
});
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");
}
} catch (Error err) {
debug("Failed to get anchor destination");
}
});
} else {
link_activated(link);
}
......
......@@ -99,11 +99,11 @@ public class ConversationWebView : ClientWebView {
/**
* Returns the y value for a element, by its id
*/
public async uint? get_anchor_target_y(string id) throws Error {
public async int? get_anchor_target_y(string anchor_body) throws Error {
WebKit.JavascriptResult result = yield call(
Geary.JS.callable("geary.getAnchorTargetY").string(id), null
Geary.JS.callable("geary.getAnchorTargetY").string(anchor_body), null
);
return (uint) WebKitUtil.to_number(result);
return (int) WebKitUtil.to_number(result);
}
/**
......
......@@ -244,9 +244,21 @@ ConversationPageState.prototype = {
}
return value;
},
getAnchorTargetY: function(id) {
let anchorTarget = document.getElementById(id);
return anchorTarget.getBoundingClientRect().top+document.documentElement.scrollTop;
getAnchorTargetY: function(anchor) {
let targetById = document.getElementById(anchor);
let targetByName = document.getElementsByName(anchor);
let finalTarget = null;
if (targetById != null) {
finalTarget = targetById;
} else if (targetByNmae.length > 0) {
finalTarget = targetByName[0];
}
if (finalTarget != null) {
return finalTarget.getBoundingClientRect().top +
document.documentElement.scrollTop;
} else {
return -1;
}
},
linkClicked: function(link) {
let cancelClick = false;
......
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