Commit 844d3498 authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer: Small cleanup in updateUIForViewportChange().

Delegate more logic from pdf-viewer into viewer-zoom-toolbar.

Bug: None
Change-Id: I4a80f895ce26825dc491cd7eb4291afdc4b5292f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285360Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786546}
parent edb144bb
...@@ -116,6 +116,7 @@ js_library("viewer-zoom-toolbar") { ...@@ -116,6 +116,7 @@ js_library("viewer-zoom-toolbar") {
":viewer-zoom-button", ":viewer-zoom-button",
"..:constants", "..:constants",
"//ui/webui/resources/js:assert.m", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:util.m",
] ]
} }
......
...@@ -9,6 +9,7 @@ import './viewer-zoom-button.js'; ...@@ -9,6 +9,7 @@ import './viewer-zoom-button.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {isRTL} from 'chrome://resources/js/util.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {FittingType} from '../constants.js'; import {FittingType} from '../constants.js';
...@@ -161,4 +162,31 @@ Polymer({ ...@@ -161,4 +162,31 @@ Polymer({
this.$['zoom-out-button'].hide(); this.$['zoom-out-button'].hide();
} }
}, },
/**
* Offsets the toolbar position so that it doesn't move if scrollbars appear.
* @param {!{horizontal: boolean, vertical: boolean}} hasScrollbars
* @param {number} scrollbarWidth
*/
shiftForScrollbars(hasScrollbars, scrollbarWidth) {
const verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
const horizontalScrollbarWidth =
hasScrollbars.horizontal ? scrollbarWidth : 0;
// Shift the zoom toolbar to the left by half a scrollbar width. This
// gives a compromise: if there is no scrollbar visible then the toolbar
// will be half a scrollbar width further left than the spec but if there
// is a scrollbar visible it will be half a scrollbar width further right
// than the spec. In RTL layout normally, the zoom toolbar is on the left
// left side, but the scrollbar is still on the right, so this is not
// necessary.
if (!isRTL()) {
this.style.right = -verticalScrollbarWidth + (scrollbarWidth / 2) + 'px';
}
// Having a horizontal scrollbar is much rarer so we don't offset the
// toolbar from the bottom any more than what the spec says. This means
// that when there is a scrollbar visible, it will be a full scrollbar
// width closer to the bottom of the screen than usual, but this is ok.
this.style.bottom = -horizontalScrollbarWidth + 'px';
}
}); });
...@@ -15,7 +15,7 @@ import './pdf_viewer_shared_style.js'; ...@@ -15,7 +15,7 @@ import './pdf_viewer_shared_style.js';
import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js'; import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {hasKeyModifiers, isRTL} from 'chrome://resources/js/util.m.js'; import {hasKeyModifiers} from 'chrome://resources/js/util.m.js';
import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {Bookmark} from './bookmark_type.js'; import {Bookmark} from './bookmark_type.js';
...@@ -596,31 +596,9 @@ class PDFViewerElement extends PDFViewerBaseElement { ...@@ -596,31 +596,9 @@ class PDFViewerElement extends PDFViewerBaseElement {
/** @override */ /** @override */
updateUIForViewportChange() { updateUIForViewportChange() {
// Offset the toolbar position so that it doesn't move if scrollbars appear.
const hasScrollbars = this.viewport.documentHasScrollbars();
const scrollbarWidth = this.viewport.scrollbarWidth;
const verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
const horizontalScrollbarWidth =
hasScrollbars.horizontal ? scrollbarWidth : 0;
if (!this.pdfViewerUpdateEnabled_) { if (!this.pdfViewerUpdateEnabled_) {
// Shift the zoom toolbar to the left by half a scrollbar width. This this.getZoomToolbar_().shiftForScrollbars(
// gives a compromise: if there is no scrollbar visible then the toolbar this.viewport.documentHasScrollbars(), this.viewport.scrollbarWidth);
// will be half a scrollbar width further left than the spec but if there
// is a scrollbar visible it will be half a scrollbar width further right
// than the spec. In RTL layout normally, the zoom toolbar is on the left
// left side, but the scrollbar is still on the right, so this is not
// necessary.
const zoomToolbar = this.getZoomToolbar_();
if (!isRTL()) {
zoomToolbar.style.right =
-verticalScrollbarWidth + (scrollbarWidth / 2) + 'px';
}
// Having a horizontal scrollbar is much rarer so we don't offset the
// toolbar from the bottom any more than what the spec says. This means
// that when there is a scrollbar visible, it will be a full scrollbar
// width closer to the bottom of the screen than usual, but this is ok.
zoomToolbar.style.bottom = -horizontalScrollbarWidth + 'px';
} }
// Update the page indicator. // Update the page indicator.
......
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