diff options
Diffstat (limited to 'chromium/chrome/browser/resources/pdf/ink')
-rw-r--r-- | chromium/chrome/browser/resources/pdf/ink/externs.js | 74 | ||||
-rw-r--r-- | chromium/chrome/browser/resources/pdf/ink/index.html | 2 | ||||
-rw-r--r-- | chromium/chrome/browser/resources/pdf/ink/ink_api.js | 100 |
3 files changed, 23 insertions, 153 deletions
diff --git a/chromium/chrome/browser/resources/pdf/ink/externs.js b/chromium/chrome/browser/resources/pdf/ink/externs.js deleted file mode 100644 index 8af66dfc91f..00000000000 --- a/chromium/chrome/browser/resources/pdf/ink/externs.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview We don't rely on any of these types but they are missing - * from the Ink extern file currently and need to be defined somewhere. - * @externs - */ - -var ink = {}; // eslint-disable-line no-var -ink.proto.scene_change = {}; - -/** @constructor */ -ink.proto.Snapshot = function() {}; - -/** @constructor */ -ink.proto.Command = function() {}; - -/** @constructor */ -ink.proto.MutationPacket = function() {}; - -/** @constructor */ -ink.proto.SetCallbackFlags = function() {}; - -/** @constructor */ -ink.proto.ToolEvent = function() {}; - -/** @constructor */ -ink.Box = function() {}; - -/** @constructor */ -ink.Model = function() {}; - -/** @constructor */ -ink.ElementListener = function() {}; - -/** @constructor */ -ink.proto.scene_change.SceneChangeEvent = function() {}; - -const goog = {}; -goog.events = {}; -goog.disposable = {}; -goog.math = {}; -goog.ui = {}; -goog.html = {}; -goog.proto2 = {}; - -/** @constructor */ -goog.events.EventTarget = function() {}; - -/** @interface */ -goog.disposable.IDisposable = function() {}; - -/** @interface */ -goog.events.Listenable = function() {}; - -/** @constructor */ -goog.math.Size = function() {}; - -/** @constructor */ -goog.events.Event = function() {}; - -/** @constructor */ -goog.proto2.Message = function() {}; - -/** - * @extends {goog.events.EventTarget} - * @constructor - */ -goog.ui.Component = function() {}; - -/** @constructor */ -goog.html.SafeUrl = function() {}; diff --git a/chromium/chrome/browser/resources/pdf/ink/index.html b/chromium/chrome/browser/resources/pdf/ink/index.html index 61d5e7e077b..07f64d813e6 100644 --- a/chromium/chrome/browser/resources/pdf/ink/index.html +++ b/chromium/chrome/browser/resources/pdf/ink/index.html @@ -1,5 +1,5 @@ <!DOCTYPE html> -<script src="glcore_wasm_bootstrap_compiled.js"></script> +<script src="ink_loader.js"></script> <script src="ink_lib_binary.js"></script> <script src="ink_api.js"></script> <style> diff --git a/chromium/chrome/browser/resources/pdf/ink/ink_api.js b/chromium/chrome/browser/resources/pdf/ink/ink_api.js index c394b630077..5d4a4d72a83 100644 --- a/chromium/chrome/browser/resources/pdf/ink/ink_api.js +++ b/chromium/chrome/browser/resources/pdf/ink/ink_api.js @@ -3,36 +3,19 @@ // found in the LICENSE file. /** - * @typedef {{ - * canUndo: boolean, - * canRedo: boolean, - * }} - */ -let UndoState; - -/** * Wraps the Ink component with an API that can be called * across an IFrame boundary. */ class InkAPI { - /** @param {!ink.embed.EmbedComponent} embed */ - constructor(embed) { - this.embed_ = embed; - this.brush_ = ink.BrushModel.getInstance(embed); + /** @param {!drawings.Canvas} canvas */ + constructor(canvas) { + this.canvas_ = canvas; this.camera_ = null; } - /** @param {function(!UndoState)} listener */ + /** @param {function(!drawings.UndoState)} listener */ addUndoStateListener(listener) { - /** @param {!ink.UndoStateChangeEvent} e */ - function wrapper(e) { - listener({ - canUndo: e.getCanUndo(), - canRedo: e.getCanRedo(), - }); - } - - this.embed_.addEventListener(ink.UndoStateChangeEvent.EVENT_TYPE, wrapper); + this.canvas_.addUndoRedoListener(listener); } /** @@ -42,109 +25,70 @@ class InkAPI { // We change the type from ArrayBuffer to Uint8Array due to the consequences // of the buffer being passed across the iframe boundary. This realm has a // different ArrayBuffer constructor than `buffer`. - // TODO(dstockwell): Update Ink to allow Uint8Array here. - this.embed_.setPDF( - /** @type {!ArrayBuffer} */ ( - /** @type {!*} */ (new Uint8Array(buffer)))); + this.canvas_.setPDF(new Uint8Array(buffer)); } /** - * @return {!Promise<Uint8Array>} + * @return {!Uint8Array} */ getPDF() { - return this.embed_.getPDF(); + return this.canvas_.getPDF(); } /** * @return {!Uint8Array} */ getPDFDestructive() { - return this.embed_.getPDFDestructive(); + return this.canvas_.getPDFDestructive(); } async setCamera(camera) { this.camera_ = camera; - this.embed_.setCamera(camera); + this.canvas_.setCamera(camera); // Wait for the next task to avoid a race where Ink drops the camera value // when the canvas is rotated in low-latency mode. - setTimeout(() => this.embed_.setCamera(this.camera_), 0); + setTimeout(() => this.canvas_.setCamera(this.camera_), 0); } /** @param {AnnotationTool} tool */ setAnnotationTool(tool) { - const shape = { - eraser: 'MAGIC_ERASE', - pen: 'INKPEN', - highlighter: 'SMART_HIGHLIGHTER_TOOL', - }[tool.tool]; - this.brush_.setShape(shape); - if (tool.tool !== 'eraser') { - this.brush_.setColor(/** @type {string} */ (tool.color)); - } - this.brush_.setStrokeWidth(tool.size); + this.canvas_.setTool(tool); } flush() { - return new Promise(resolve => this.embed_.flush(resolve)); + return this.canvas_.flush(); } /** @param {string} hexColor */ setOutOfBoundsColor(hexColor) { - this.embed_.setOutOfBoundsColor(ink.Color.fromString(hexColor)); + this.canvas_.setOutOfBoundsColor(hexColor); } /** @param {string} url */ setBorderImage(url) { - this.embed_.setBorderImage(url); + this.canvas_.setBorderImage(url); } /** @param {number} spacing in points */ setPageSpacing(spacing) { - this.embed_.setVerticalPageLayout(spacing); + this.canvas_.setVerticalPageLayout(spacing); } - dispatchPointerEvent(type, init) { - const engine = document.querySelector('#ink-engine'); - const match = engine.style.transform.match(/(\d+)deg/); - const rotation = match ? Number(match[1]) : 0; - let offsetX = init.clientX; - let offsetY = init.clientY; - // If Ink's canvas has been re-orientated away from 0, we must transform - // the event's offsetX and offsetY to correspond with the rotation and - // offset applied. - if ([90, 180, 270].includes(rotation)) { - const width = window.innerWidth; - const height = window.innerHeight; - const matrix = new DOMMatrix(); - matrix.translateSelf(width / 2, height / 2); - matrix.rotateSelf(0, 0, -rotation); - matrix.translateSelf(-width / 2, -height / 2); - const result = matrix.transformPoint({x: offsetX, y: offsetY}); - offsetX = result.x - engine.offsetLeft; - offsetY = result.y - engine.offsetTop; - } - - const event = new PointerEvent(type, init); - // Ink uses offsetX and offsetY, but we can only override them, not pass - // as part of the init. - Object.defineProperty(event, 'offsetX', {value: offsetX}); - Object.defineProperty(event, 'offsetY', {value: offsetY}); - engine.dispatchEvent(event); + dispatchPointerEvent(evt) { + this.canvas_.dispatchInput(evt); } undo() { - this.embed_.undo(); + this.canvas_.undo(); } redo() { - this.embed_.redo(); + this.canvas_.redo(); } } /** @return {Promise<InkAPI>} */ window.initInk = async function() { - const config = new ink.embed.Config(); - const embed = await ink.embed.EmbedComponent.execute(config); - embed.assignFlag(ink.proto.Flag.ENABLE_HOST_CAMERA_CONTROL, true); - return new InkAPI(embed); + const canvas = await drawings.Canvas.execute(document.body); + return new InkAPI(canvas); }; |