Commit b8e99dbb authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

PDF Viewer cleanup: Remove unnecessary private static members.

These made sense in a pre-JS module world. Now that PDF viewer uses
JS modules, they can simply be defined within the scope of the module
to become truly private, as opposed to only be private from Closure
Compiler's perspective.

Bug: None
Change-Id: If3073e38263890e04e6d6e7937ba68959c396d8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2615671
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841257}
parent 1bf046db
...@@ -102,7 +102,7 @@ export class GestureDetector { ...@@ -102,7 +102,7 @@ export class GestureDetector {
this.pinchStartEvent_ = event; this.pinchStartEvent_ = event;
this.lastEvent_ = event; this.lastEvent_ = event;
this.notify_('pinchstart', {center: GestureDetector.center_(event)}); this.notify_('pinchstart', {center: center(event)});
} }
/** /**
...@@ -120,27 +120,23 @@ export class GestureDetector { ...@@ -120,27 +120,23 @@ export class GestureDetector {
// Check if the pinch ends with the current event. // Check if the pinch ends with the current event.
if (event.touches.length < 2 || if (event.touches.length < 2 ||
lastEvent.touches.length !== event.touches.length) { lastEvent.touches.length !== event.touches.length) {
const startScaleRatio = const startScaleRatio = pinchScaleRatio(lastEvent, this.pinchStartEvent_);
GestureDetector.pinchScaleRatio_(lastEvent, this.pinchStartEvent_);
const center = GestureDetector.center_(lastEvent);
this.pinchStartEvent_ = null; this.pinchStartEvent_ = null;
this.lastEvent_ = null; this.lastEvent_ = null;
this.notify_('pinchend', { this.notify_('pinchend', {
startScaleRatio: startScaleRatio, startScaleRatio: startScaleRatio,
center: center, center: center(lastEvent),
}); });
return; return;
} }
const scaleRatio = GestureDetector.pinchScaleRatio_(event, lastEvent); const scaleRatio = pinchScaleRatio(event, lastEvent);
const startScaleRatio = const startScaleRatio = pinchScaleRatio(event, this.pinchStartEvent_);
GestureDetector.pinchScaleRatio_(event, this.pinchStartEvent_);
const center = GestureDetector.center_(event);
this.notify_('pinchupdate', { this.notify_('pinchupdate', {
scaleRatio: scaleRatio, scaleRatio: scaleRatio,
direction: scaleRatio > 1.0 ? 'in' : 'out', direction: scaleRatio > 1.0 ? 'in' : 'out',
startScaleRatio: startScaleRatio, startScaleRatio: startScaleRatio,
center: center, center: center(event),
}); });
this.lastEvent_ = event; this.lastEvent_ = event;
...@@ -222,50 +218,47 @@ export class GestureDetector { ...@@ -222,50 +218,47 @@ export class GestureDetector {
e.preventDefault(); e.preventDefault();
} }
} }
}
/** /**
* Computes the change in scale between this touch event * Computes the change in scale between this touch event
* and a previous one. * and a previous one.
* @param {!TouchEvent} event Latest touch event on the element. * @param {!TouchEvent} event Latest touch event on the element.
* @param {!TouchEvent} prevEvent A previous touch event on the element. * @param {!TouchEvent} prevEvent A previous touch event on the element.
* @return {?number} The ratio of the scale of this event and the * @return {?number} The ratio of the scale of this event and the
* scale of the previous one. * scale of the previous one.
* @private */
*/ function pinchScaleRatio(event, prevEvent) {
static pinchScaleRatio_(event, prevEvent) { const distance1 = distance(prevEvent);
const distance1 = GestureDetector.distance_(prevEvent); const distance2 = distance(event);
const distance2 = GestureDetector.distance_(event); return distance1 === 0 ? null : distance2 / distance1;
return distance1 === 0 ? null : distance2 / distance1; }
}
/** /**
* Computes the distance between fingers. * Computes the distance between fingers.
* @param {!TouchEvent} event Touch event with at least 2 touch points. * @param {!TouchEvent} event Touch event with at least 2 touch points.
* @return {number} Distance between touch[0] and touch[1]. * @return {number} Distance between touch[0] and touch[1].
* @private */
*/ function distance(event) {
static distance_(event) { const touch1 = event.touches[0];
const touch1 = event.touches[0]; const touch2 = event.touches[1];
const touch2 = event.touches[1]; const dx = touch1.clientX - touch2.clientX;
const dx = touch1.clientX - touch2.clientX; const dy = touch1.clientY - touch2.clientY;
const dy = touch1.clientY - touch2.clientY; return Math.sqrt(dx * dx + dy * dy);
return Math.sqrt(dx * dx + dy * dy); }
}
/** /**
* Computes the midpoint between fingers. * Computes the midpoint between fingers.
* @param {!TouchEvent} event Touch event with at least 2 touch points. * @param {!TouchEvent} event Touch event with at least 2 touch points.
* @return {!Point} Midpoint between touch[0] and touch[1]. * @return {!Point} Midpoint between touch[0] and touch[1].
* @private */
*/ function center(event) {
static center_(event) { const touch1 = event.touches[0];
const touch1 = event.touches[0]; const touch2 = event.touches[1];
const touch2 = event.touches[1]; return {
return { x: (touch1.clientX + touch2.clientX) / 2,
x: (touch1.clientX + touch2.clientX) / 2, y: (touch1.clientY + touch2.clientY) / 2
y: (touch1.clientY + touch2.clientY) / 2 };
};
}
} }
// Export on |window| such that scripts injected from pdf_extension_test.cc can // Export on |window| such that scripts injected from pdf_extension_test.cc can
......
...@@ -47,8 +47,8 @@ export class PDFMetrics { ...@@ -47,8 +47,8 @@ export class PDFMetrics {
if (!chrome.metricsPrivate) { if (!chrome.metricsPrivate) {
return; return;
} }
if (!PDFMetrics.actionsMetric_) { if (!actionsMetric) {
PDFMetrics.actionsMetric_ = { actionsMetric = {
'metricName': 'PDF.Actions', 'metricName': 'PDF.Actions',
'type': chrome.metricsPrivate.MetricTypeType.HISTOGRAM_LOG, 'type': chrome.metricsPrivate.MetricTypeType.HISTOGRAM_LOG,
'min': 1, 'min': 1,
...@@ -56,28 +56,27 @@ export class PDFMetrics { ...@@ -56,28 +56,27 @@ export class PDFMetrics {
'buckets': UserAction.NUMBER_OF_ACTIONS + 1 'buckets': UserAction.NUMBER_OF_ACTIONS + 1
}; };
} }
chrome.metricsPrivate.recordValue(PDFMetrics.actionsMetric_, action); chrome.metricsPrivate.recordValue(actionsMetric, action);
if (PDFMetrics.firstMap_.has(action)) { if (firstMap.has(action)) {
const firstAction = PDFMetrics.firstMap_.get(action); const firstAction = firstMap.get(action);
if (!PDFMetrics.firstActionRecorded_.has(firstAction)) { if (!firstActionRecorded.has(firstAction)) {
chrome.metricsPrivate.recordValue( chrome.metricsPrivate.recordValue(actionsMetric, firstAction);
PDFMetrics.actionsMetric_, firstAction); firstActionRecorded.add(firstAction);
PDFMetrics.firstActionRecorded_.add(firstAction);
} }
} }
} }
static resetForTesting() { static resetForTesting() {
PDFMetrics.firstActionRecorded_.clear(); firstActionRecorded.clear();
PDFMetrics.actionsMetric_ = null; actionsMetric = null;
} }
} }
/** @private {?chrome.metricsPrivate.MetricType} */ /** @type {?chrome.metricsPrivate.MetricType} */
PDFMetrics.actionsMetric_ = null; let actionsMetric = null;
/** @private {Set} */ /** @type {!Set<!UserAction>} */
PDFMetrics.firstActionRecorded_ = new Set(); const firstActionRecorded = new Set();
// Keep in sync with enums.xml. // Keep in sync with enums.xml.
// Do not change the numeric values or reuse them since these numbers are // Do not change the numeric values or reuse them since these numbers are
...@@ -218,8 +217,8 @@ export const UserAction = { ...@@ -218,8 +217,8 @@ export const UserAction = {
// Map from UserAction to the 'FIRST' action. These metrics are recorded // Map from UserAction to the 'FIRST' action. These metrics are recorded
// by PDFMetrics.log the first time each corresponding action occurs. // by PDFMetrics.log the first time each corresponding action occurs.
/** @private Map<number, number> */ /** @type {!Map<!UserAction, !UserAction>} */
PDFMetrics.firstMap_ = new Map([ const firstMap = new Map([
[ [
UserAction.ROTATE, UserAction.ROTATE,
UserAction.ROTATE_FIRST, UserAction.ROTATE_FIRST,
......
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