Commit cb01fafe authored by john's avatar john

成功定位坐标

parent 82c1e640
......@@ -2608,6 +2608,7 @@ public class GearyController : Geary.BaseObject {
});
foreach (ConversationMessage msg_view in view) {
msg_view.link_activated.connect(on_link_activated);
msg_view.internal_link_activated.connect(on_internal_link_activated);
msg_view.save_image.connect((url, alt_text, buf) => {
on_save_image_extended(view, url, alt_text, buf);
});
......@@ -3063,6 +3064,10 @@ public class GearyController : Geary.BaseObject {
}
}
private void on_internal_link_activated(string uri, uint y) {
}
private void on_save_image_extended(ConversationEmail view,
string url,
string? alt_text,
......
......@@ -20,6 +20,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
private const string FROM_CLASS = "geary-from";
private const string MATCH_CLASS = "geary-match";
private const string INTERNAL_ANCHOR_PREFIX = "geary:body#";
private const string REPLACED_CID_TEMPLATE = "replaced_%02u@geary";
private const string REPLACED_IMAGE_CLASS = "geary_replaced_inline_image";
......@@ -261,6 +262,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
/** Fired when the user clicks a link in the email. */
public signal void link_activated(string link);
/** Fired when the user clicks a internal link in the email. */
public signal void internal_link_activated(string link, uint y);
/** Fired when the user requests remote images be loaded. */
public signal void flag_remote_images();
......@@ -445,7 +449,11 @@ 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((link) => {
link_activated(link);
if (link.contains(INTERNAL_ANCHOR_PREFIX)) {
on_internal_link_activated(link);
} else {
link_activated(link);
}
});
this.web_view.mouse_target_changed.connect(on_mouse_target_changed);
this.web_view.notify["is-loading"].connect(on_is_loading_notify);
......@@ -1158,4 +1166,16 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
});
}
private void on_internal_link_activated(string link) {
//internal link handling
debug("Internal Link Handling Not Implentmented Yet");
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);
stdout.printf("The y is %u\n", y);
internal_link_activated(link, y);
});
}
}
......@@ -96,6 +96,16 @@ public class ConversationWebView : ClientWebView {
return WebKitUtil.to_string(result);
}
/**
* Returns the y value for a element, by its id
*/
public async uint? get_anchor_target_y(string id) throws Error {
WebKit.JavascriptResult result = yield call(
Geary.JS.callable("geary.getAnchorTargetY").string(id), null
);
return (uint) WebKitUtil.to_number(result);
}
/**
* Highlights user search terms in the message view.
*
......
......@@ -176,6 +176,7 @@ PageState.prototype = {
window.webkit.messageHandlers.selectionChanged.postMessage(hasSelection);
}
}
};
var geary = new PageState();
......@@ -244,6 +244,10 @@ ConversationPageState.prototype = {
}
return value;
},
getAnchorTargetY: function(id) {
let anchorTarget = document.getElementById(id);
return anchorTarget.getBoundingClientRect().top+document.documentElement.scrollTop;
},
linkClicked: function(link) {
let cancelClick = false;
let href = link.href;
......
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