зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1135593 Make The Reader Mode controls sidebar not affected by page zoom actions r=Gijs
Roll up existing commits Make updateFontSizeButtonControls separate method Differential Revision: https://phabricator.services.mozilla.com/D23147 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
ac54c9333b
Коммит
7feefb5c15
|
@ -267,23 +267,33 @@ var FullZoom = {
|
|||
// Setting & Pref Manipulation
|
||||
|
||||
/**
|
||||
* Reduces the zoom level of the page in the current browser.
|
||||
* If browser in reader mode sends message to reader in order to decrease font size,
|
||||
* Otherwise reduces the zoom level of the page in the current browser.
|
||||
*/
|
||||
async reduce() {
|
||||
ZoomManager.reduce();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
this._ignorePendingZoomAccesses(browser);
|
||||
await this._applyZoomToPref(browser);
|
||||
if (browser.currentURI.spec.startsWith("about:reader")) {
|
||||
browser.messageManager.sendAsyncMessage("Reader:ZoomOut");
|
||||
} else {
|
||||
ZoomManager.reduce();
|
||||
this._ignorePendingZoomAccesses(browser);
|
||||
await this._applyZoomToPref(browser);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Enlarges the zoom level of the page in the current browser.
|
||||
* If browser in reader mode sends message to reader in order to increase font size,
|
||||
* Otherwise enlarges the zoom level of the page in the current browser.
|
||||
*/
|
||||
async enlarge() {
|
||||
ZoomManager.enlarge();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
this._ignorePendingZoomAccesses(browser);
|
||||
await this._applyZoomToPref(browser);
|
||||
if (browser.currentURI.spec.startsWith("about:reader")) {
|
||||
browser.messageManager.sendAsyncMessage("Reader:ZoomIn");
|
||||
} else {
|
||||
ZoomManager.enlarge();
|
||||
this._ignorePendingZoomAccesses(browser);
|
||||
await this._applyZoomToPref(browser);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,8 @@ var AboutReader = function(mm, win, articlePromise) {
|
|||
this._mm.addMessageListener("Reader:AddButton", this);
|
||||
this._mm.addMessageListener("Reader:RemoveButton", this);
|
||||
this._mm.addMessageListener("Reader:GetStoredArticleData", this);
|
||||
this._mm.addMessageListener("Reader:ZoomIn", this);
|
||||
this._mm.addMessageListener("Reader:ZoomOut", this);
|
||||
|
||||
this._docRef = Cu.getWeakReference(doc);
|
||||
this._winRef = Cu.getWeakReference(win);
|
||||
|
@ -151,6 +153,10 @@ AboutReader.prototype = {
|
|||
|
||||
PLATFORM_HAS_CACHE: AppConstants.platform == "android",
|
||||
|
||||
FONT_SIZE_MIN: 1,
|
||||
|
||||
FONT_SIZE_MAX: 9,
|
||||
|
||||
get _doc() {
|
||||
return this._docRef.get();
|
||||
},
|
||||
|
@ -251,6 +257,15 @@ AboutReader.prototype = {
|
|||
}
|
||||
case "Reader:GetStoredArticleData": {
|
||||
this._mm.sendAsyncMessage("Reader:StoredArticleData", { article: this._article });
|
||||
break;
|
||||
}
|
||||
case "Reader:ZoomIn": {
|
||||
this._changeFontSize(+1);
|
||||
break;
|
||||
}
|
||||
case "Reader:ZoomOut": {
|
||||
this._changeFontSize(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -305,6 +320,8 @@ AboutReader.prototype = {
|
|||
this._mm.removeMessageListener("Reader:AddButton", this);
|
||||
this._mm.removeMessageListener("Reader:RemoveButton", this);
|
||||
this._mm.removeMessageListener("Reader:GetStoredArticleData", this);
|
||||
this._mm.removeMessageListener("Reader:ZoomIn", this);
|
||||
this._mm.removeMessageListener("Reader:ZoomOut", this);
|
||||
this._windowUnloaded = true;
|
||||
break;
|
||||
}
|
||||
|
@ -336,48 +353,25 @@ AboutReader.prototype = {
|
|||
},
|
||||
|
||||
_setupFontSizeButtons() {
|
||||
const FONT_SIZE_MIN = 1;
|
||||
const FONT_SIZE_MAX = 9;
|
||||
|
||||
// Sample text shown in Android UI.
|
||||
let sampleText = this._doc.querySelector(".font-size-sample");
|
||||
sampleText.textContent = gStrings.GetStringFromName("aboutReader.fontTypeSample");
|
||||
|
||||
let currentSize = Services.prefs.getIntPref("reader.font_size");
|
||||
currentSize = Math.max(FONT_SIZE_MIN, Math.min(FONT_SIZE_MAX, currentSize));
|
||||
currentSize = Math.max(this.FONT_SIZE_MIN, Math.min(this.FONT_SIZE_MAX, currentSize));
|
||||
|
||||
let plusButton = this._doc.querySelector(".plus-button");
|
||||
let minusButton = this._doc.querySelector(".minus-button");
|
||||
|
||||
function updateControls() {
|
||||
if (currentSize === FONT_SIZE_MIN) {
|
||||
minusButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
minusButton.removeAttribute("disabled");
|
||||
}
|
||||
if (currentSize === FONT_SIZE_MAX) {
|
||||
plusButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
plusButton.removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
|
||||
updateControls();
|
||||
this._setFontSize(currentSize);
|
||||
this._updateFontSizeButtonControls();
|
||||
|
||||
plusButton.addEventListener("click", (event) => {
|
||||
if (!event.isTrusted) {
|
||||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
|
||||
if (currentSize >= FONT_SIZE_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentSize++;
|
||||
updateControls();
|
||||
this._setFontSize(currentSize);
|
||||
this._changeFontSize(+1);
|
||||
}, true);
|
||||
|
||||
minusButton.addEventListener("click", (event) => {
|
||||
|
@ -385,17 +379,36 @@ AboutReader.prototype = {
|
|||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
|
||||
if (currentSize <= FONT_SIZE_MIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentSize--;
|
||||
updateControls();
|
||||
this._setFontSize(currentSize);
|
||||
this._changeFontSize(-1);
|
||||
}, true);
|
||||
},
|
||||
|
||||
_updateFontSizeButtonControls() {
|
||||
let plusButton = this._doc.querySelector(".plus-button");
|
||||
let minusButton = this._doc.querySelector(".minus-button");
|
||||
|
||||
let currentSize = Services.prefs.getIntPref("reader.font_size");
|
||||
|
||||
if (currentSize === this.FONT_SIZE_MIN) {
|
||||
minusButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
minusButton.removeAttribute("disabled");
|
||||
}
|
||||
if (currentSize === this.FONT_SIZE_MAX) {
|
||||
plusButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
plusButton.removeAttribute("disabled");
|
||||
}
|
||||
},
|
||||
|
||||
_changeFontSize(changeAmount) {
|
||||
let currentSize = Services.prefs.getIntPref("reader.font_size");
|
||||
currentSize = Math.max(this.FONT_SIZE_MIN, Math.min(this.FONT_SIZE_MAX, currentSize + changeAmount));
|
||||
|
||||
this._setFontSize(currentSize);
|
||||
this._updateFontSizeButtonControls();
|
||||
},
|
||||
|
||||
_setContentWidth(newContentWidth) {
|
||||
let containerClasses = this._containerElement.classList;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче