aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/client.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-07-23 12:47:42 -0700
committerAlex Yatskov <alex@foosoft.net>2016-07-23 12:47:42 -0700
commita889e1ffaa8b64b18a5b8416db1838ab497f52d6 (patch)
treeda033f74d7a5b6d5b7e487085989a2c8d2a3e702 /ext/fg/js/client.js
parent6099de71d86b923e1bc76b32833a7ccfcab73692 (diff)
WIP
Diffstat (limited to 'ext/fg/js/client.js')
-rw-r--r--ext/fg/js/client.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index 16ee0b24..46e4683e 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -19,17 +19,17 @@
class Client {
constructor() {
- this.popup = new Popup();
- this.audio = {};
- this.lastMousePos = null;
- this.lastTextSource = null;
- this.activateKey = 16;
- this.activateBtn = 2;
- this.enabled = false;
- this.options = {};
- this.definitions = null;
- this.sequence = 0;
- this.fgRoot = chrome.extension.getURL('fg');
+ this.popup = new Popup();
+ this.audio = {};
+ this.lastMousePos = null;
+ this.lastTextSource = null;
+ this.activateKey = 16;
+ this.activateBtn = 2;
+ this.enabled = false;
+ this.options = {};
+ this.definitions = null;
+ this.sequence = 0;
+ this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
window.addEventListener('message', this.onFrameMessage.bind(this));
@@ -88,7 +88,17 @@ class Client {
}
textSourceFromPoint(point) {
- return Range.fromPoint(point);
+ const element = document.elementFromPoint(point.x, point.y);
+ if (element !== null && element.nodeName === 'IMG') {
+ return new ImageSource(element);
+ }
+
+ const range = document.caretRangeFromPoint(point.x, point.y);
+ if (range !== null) {
+ return new RangeSource(range);
+ }
+
+ return null;
}
searchAt(point) {