forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoomChild.jsm
88 lines (75 loc) · 2.22 KB
/
ZoomChild.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["ZoomChild"];
class ZoomChild extends JSWindowActorChild {
constructor() {
super();
this._cache = {
fullZoom: NaN,
textZoom: NaN,
};
}
get fullZoom() {
return this._cache.fullZoom;
}
get textZoom() {
return this._cache.textZoom;
}
set fullZoom(value) {
this._cache.fullZoom = value;
this._markupViewer.fullZoom = value;
}
set textZoom(value) {
this._cache.textZoom = value;
this._markupViewer.textZoom = value;
}
refreshFullZoom() {
return this._refreshZoomValue("fullZoom");
}
refreshTextZoom() {
return this._refreshZoomValue("textZoom");
}
/**
* Retrieves specified zoom property value from markupViewer and refreshes
* cache if needed.
* @param valueName Either 'fullZoom' or 'textZoom'.
* @returns Returns true if cached value was actually refreshed.
* @private
*/
_refreshZoomValue(valueName) {
let actualZoomValue = this._markupViewer[valueName];
// Round to remove any floating-point error.
actualZoomValue = Number(actualZoomValue.toFixed(2));
if (actualZoomValue != this._cache[valueName]) {
this._cache[valueName] = actualZoomValue;
return true;
}
return false;
}
get _markupViewer() {
return this.docShell.contentViewer;
}
receiveMessage(message) {
if (message.name == "FullZoom") {
this.fullZoom = message.data.value;
} else if (message.name == "TextZoom") {
this.textZoom = message.data.value;
}
}
handleEvent(event) {
if (event.type == "FullZoomChange") {
if (this.refreshFullZoom()) {
this.sendAsyncMessage("FullZoomChange", { value: this.fullZoom });
}
} else if (event.type == "TextZoomChange") {
if (this.refreshTextZoom()) {
this.sendAsyncMessage("TextZoomChange", { value: this.textZoom });
}
} else if (event.type == "ZoomChangeUsingMouseWheel") {
this.sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
}
}
}