geary/ui/client-web-view.js
Michael James Gratton 766d55e75d Reimplement selection_changed signal for WK2.
Add a "has_selection" param to avoid a second round-trip to the web
process to determine that.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  selection_changed signal, register a JS message handler for the JS
  equivalent hook up firing the signal.

* src/client/web-process/web-process-extension.vala (GearyWebExtension):
  Send a JS selectionChanged message when the page's selection changes.

* src/client/composer/composer-widget.vala,
  src/client/conversation-viewer/conversation-email.vala,
  src/client/conversation-viewer/conversation-message.vala: Uncomment
  code that relied on the WK1 selection_changed signal, use signal param
  rather than DOM calls.

* ui/client-web-view.js: Implement sending the selectionChanged message.
2017-02-01 00:41:43 +11:00

58 lines
1.7 KiB
JavaScript

/*
* Copyright 2016 Michael Gratton <mike@vee.net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
/**
* Application logic for ClientWebView and subclasses.
*/
var PageState = function() {
this.init.apply(this, arguments);
};
PageState.prototype = {
init: function() {
this.allowRemoteImages = false;
this.loaded = false;
var state = this;
var timeoutId = window.setInterval(function() {
state.preferredHeightChanged();
if (state.loaded) {
window.clearTimeout(timeoutId);
}
}, 50);
},
loadRemoteImages: function() {
this.allowRemoteImages = true;
var images = document.getElementsByTagName("IMG");
for (var i = 0; i < images.length; i++) {
var img = images.item(i);
var src = img.src;
img.src = "";
img.src = src;
}
},
remoteImageLoadBlocked: function() {
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
},
preferredHeightChanged: function() {
var height = window.document.documentElement.offsetHeight;
if (height > 0) {
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
height
);
}
},
selectionChanged: function() {
var has_selection = !window.getSelection().isCollapsed;
window.webkit.messageHandlers.selectionChanged.postMessage(has_selection);
}
};
var geary = new PageState();
window.onload = function() {
geary.loaded = true;
};