Commit 70b5c87f authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Chromium LUCI CQ

PDF Viewer: Delegate rotation tracking to the plugin

Certain UI elements, such as the thumbnails and the annotations dialog,
require the number of rotations on the PDF content.

Currently, that value is tracked both on the UI and the plugin backend,
but they can go out of sync because:
- The UI value is updated synchronously whenever the rotate button is
clicked.
- The plugin value updates when a rotate request comes from the UI or
the context menu.

Therefore, the true value is held in the plugin, as the rotate requests
from the context menu do not go through the UI.

Furthermore, the number of rotations from the plugin is already sent to
the UI on the 'documentDimensions' message. Use that value instead.

Fixed: 1166590
Change-Id: Ia7fa111ae338a863828fd1196715684301d7b5c3
Bug: 1166590
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630428
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Auto-Submit: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844746}
parent fe0c7a61
...@@ -546,21 +546,24 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -546,21 +546,24 @@ export class PDFViewerElement extends PDFViewerBaseElement {
this.currentController.setTwoUpView(false); this.currentController.setTwoUpView(false);
this.twoUpViewEnabled_ = false; this.twoUpViewEnabled_ = false;
} }
if (this.isRotated_()) {
const rotations = this.viewport.getClockwiseRotations(); const rotations = this.viewport.getClockwiseRotations();
switch (rotations) { switch (rotations) {
case 1: case 0:
super.rotateCounterclockwise(); break;
break; case 1:
case 2: this.rotateCounterclockwise();
super.rotateCounterclockwise(); break;
super.rotateCounterclockwise(); case 2:
break; this.rotateCounterclockwise();
case 3: this.rotateCounterclockwise();
super.rotateClockwise(); break;
break; case 3:
} this.rotateClockwise();
this.clockwiseRotations_ = 0; break;
default:
assertNotReached('Invalid rotations count: ' + rotations);
break;
} }
} }
...@@ -844,10 +847,12 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -844,10 +847,12 @@ export class PDFViewerElement extends PDFViewerBaseElement {
this.viewport.documentHasScrollbars(), this.viewport.scrollbarWidth); this.viewport.documentHasScrollbars(), this.viewport.scrollbarWidth);
} }
// Update the page indicator. // Update toolbar elements.
if (this.toolbarEnabled_) { if (this.toolbarEnabled_) {
const visiblePage = this.viewport.getMostVisiblePage(); const visiblePage = this.viewport.getMostVisiblePage();
this.pageNo_ = visiblePage + 1; this.pageNo_ = visiblePage + 1;
this.clockwiseRotations_ = this.viewport.getClockwiseRotations();
} }
this.currentController.viewportChanged(); this.currentController.viewportChanged();
...@@ -1333,18 +1338,6 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1333,18 +1338,6 @@ export class PDFViewerElement extends PDFViewerBaseElement {
isRotated_() { isRotated_() {
return this.clockwiseRotations_ !== 0; return this.clockwiseRotations_ !== 0;
} }
/** @override */
rotateClockwise() {
super.rotateClockwise();
this.clockwiseRotations_ = this.viewport.getClockwiseRotations();
}
/** @override */
rotateCounterclockwise() {
super.rotateCounterclockwise();
this.clockwiseRotations_ = this.viewport.getClockwiseRotations();
}
} }
/** /**
......
...@@ -640,14 +640,12 @@ export class PDFViewerBaseElement extends PolymerElement { ...@@ -640,14 +640,12 @@ export class PDFViewerBaseElement extends PolymerElement {
/** @protected */ /** @protected */
rotateClockwise() { rotateClockwise() {
record(UserAction.ROTATE); record(UserAction.ROTATE);
this.viewport_.rotateClockwise();
this.currentController.rotateClockwise(); this.currentController.rotateClockwise();
} }
/** @protected */ /** @protected */
rotateCounterclockwise() { rotateCounterclockwise() {
record(UserAction.ROTATE); record(UserAction.ROTATE);
this.viewport_.rotateCounterclockwise();
this.currentController.rotateCounterclockwise(); this.currentController.rotateCounterclockwise();
} }
......
...@@ -149,9 +149,6 @@ export class Viewport { ...@@ -149,9 +149,6 @@ export class Viewport {
/** @private {?Point} */ /** @private {?Point} */
this.firstPinchCenterInFrame_ = null; this.firstPinchCenterInFrame_ = null;
/** @private {number} */
this.rotations_ = 0;
/** @private {?Point} */ /** @private {?Point} */
this.oldCenterInContent_ = null; this.oldCenterInContent_ = null;
...@@ -228,28 +225,13 @@ export class Viewport { ...@@ -228,28 +225,13 @@ export class Viewport {
this.userInitiatedCallback_ = userInitiatedCallback; this.userInitiatedCallback_ = userInitiatedCallback;
} }
rotateClockwise() {
this.rotateBySteps_(1);
}
rotateCounterclockwise() {
this.rotateBySteps_(3);
}
/**
* @param {number} n The number of clockwise 90-degree rotations to increment
* by.
*/
rotateBySteps_(n) {
this.rotations_ = (this.rotations_ + n) % 4;
}
/** /**
* @return {number} The number of clockwise 90-degree rotations that have been * @return {number} The number of clockwise 90-degree rotations that have been
* applied. * applied.
*/ */
getClockwiseRotations() { getClockwiseRotations() {
return this.rotations_; const options = this.getLayoutOptions();
return options ? options.defaultPageOrientation : 0;
} }
/** @return {boolean} Whether viewport is in two-up view mode. */ /** @return {boolean} Whether viewport is in two-up view mode. */
...@@ -299,7 +281,7 @@ export class Viewport { ...@@ -299,7 +281,7 @@ export class Viewport {
const matrix = new DOMMatrix(); const matrix = new DOMMatrix();
const rotation = this.rotations_ * 90; const rotation = this.getClockwiseRotations() * 90;
// Set origin for rotation. // Set origin for rotation.
if (rotation === 90) { if (rotation === 90) {
matrix.translateSelf(width, 0); matrix.translateSelf(width, 0);
......
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