pdf_cursor_tools.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFCursorTools = exports.CursorTool = undefined;
  27. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  28. var _grab_to_pan = require('./grab_to_pan');
  29. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30. var CursorTool = {
  31. SELECT: 0,
  32. HAND: 1,
  33. ZOOM: 2
  34. };
  35. var PDFCursorTools = function () {
  36. function PDFCursorTools(_ref) {
  37. var _this = this;
  38. var container = _ref.container,
  39. eventBus = _ref.eventBus,
  40. preferences = _ref.preferences;
  41. _classCallCheck(this, PDFCursorTools);
  42. this.container = container;
  43. this.eventBus = eventBus;
  44. this.active = CursorTool.SELECT;
  45. this.activeBeforePresentationMode = null;
  46. this.handTool = new _grab_to_pan.GrabToPan({ element: this.container });
  47. this._addEventListeners();
  48. preferences.get('cursorToolOnLoad').then(function (value) {
  49. _this.switchTool(value);
  50. }).catch(function () {});
  51. }
  52. _createClass(PDFCursorTools, [{
  53. key: 'switchTool',
  54. value: function switchTool(tool) {
  55. var _this2 = this;
  56. if (this.activeBeforePresentationMode !== null) {
  57. return;
  58. }
  59. if (tool === this.active) {
  60. return;
  61. }
  62. var disableActiveTool = function disableActiveTool() {
  63. switch (_this2.active) {
  64. case CursorTool.SELECT:
  65. break;
  66. case CursorTool.HAND:
  67. _this2.handTool.deactivate();
  68. break;
  69. case CursorTool.ZOOM:
  70. }
  71. };
  72. switch (tool) {
  73. case CursorTool.SELECT:
  74. disableActiveTool();
  75. break;
  76. case CursorTool.HAND:
  77. disableActiveTool();
  78. this.handTool.activate();
  79. break;
  80. case CursorTool.ZOOM:
  81. default:
  82. console.error('switchTool: "' + tool + '" is an unsupported value.');
  83. return;
  84. }
  85. this.active = tool;
  86. this._dispatchEvent();
  87. }
  88. }, {
  89. key: '_dispatchEvent',
  90. value: function _dispatchEvent() {
  91. this.eventBus.dispatch('cursortoolchanged', {
  92. source: this,
  93. tool: this.active
  94. });
  95. }
  96. }, {
  97. key: '_addEventListeners',
  98. value: function _addEventListeners() {
  99. var _this3 = this;
  100. this.eventBus.on('switchcursortool', function (evt) {
  101. _this3.switchTool(evt.tool);
  102. });
  103. this.eventBus.on('presentationmodechanged', function (evt) {
  104. if (evt.switchInProgress) {
  105. return;
  106. }
  107. var previouslyActive = void 0;
  108. if (evt.active) {
  109. previouslyActive = _this3.active;
  110. _this3.switchTool(CursorTool.SELECT);
  111. _this3.activeBeforePresentationMode = previouslyActive;
  112. } else {
  113. previouslyActive = _this3.activeBeforePresentationMode;
  114. _this3.activeBeforePresentationMode = null;
  115. _this3.switchTool(previouslyActive);
  116. }
  117. });
  118. }
  119. }, {
  120. key: 'activeTool',
  121. get: function get() {
  122. return this.active;
  123. }
  124. }]);
  125. return PDFCursorTools;
  126. }();
  127. exports.CursorTool = CursorTool;
  128. exports.PDFCursorTools = PDFCursorTools;