hand_tool.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var grabToPan = require('./grab_to_pan.js');
  17. var preferences = require('./preferences.js');
  18. var uiUtils = require('./ui_utils.js');
  19. var GrabToPan = grabToPan.GrabToPan;
  20. var Preferences = preferences.Preferences;
  21. var localized = uiUtils.localized;
  22. var HandTool = function HandToolClosure() {
  23. function HandTool(options) {
  24. this.container = options.container;
  25. this.eventBus = options.eventBus;
  26. this.wasActive = false;
  27. this.handTool = new GrabToPan({
  28. element: this.container,
  29. onActiveChanged: function (isActive) {
  30. this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
  31. }.bind(this)
  32. });
  33. this.eventBus.on('togglehandtool', this.toggle.bind(this));
  34. Promise.all([localized, Preferences.get('enableHandToolOnLoad')]).then(function resolved(values) {
  35. if (values[1] === true) {
  36. this.handTool.activate();
  37. }
  38. }.bind(this)).catch(function rejected(reason) {});
  39. this.eventBus.on('presentationmodechanged', function (e) {
  40. if (e.switchInProgress) {
  41. return;
  42. }
  43. if (e.active) {
  44. this.enterPresentationMode();
  45. } else {
  46. this.exitPresentationMode();
  47. }
  48. }.bind(this));
  49. }
  50. HandTool.prototype = {
  51. get isActive() {
  52. return !!this.handTool.active;
  53. },
  54. toggle: function HandTool_toggle() {
  55. this.handTool.toggle();
  56. },
  57. enterPresentationMode: function HandTool_enterPresentationMode() {
  58. if (this.isActive) {
  59. this.wasActive = true;
  60. this.handTool.deactivate();
  61. }
  62. },
  63. exitPresentationMode: function HandTool_exitPresentationMode() {
  64. if (this.wasActive) {
  65. this.wasActive = false;
  66. this.handTool.activate();
  67. }
  68. }
  69. };
  70. return HandTool;
  71. }();
  72. exports.HandTool = HandTool;