2013-10-03 05:09:43 +09:00
|
|
|
/* Copyright 2013 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-04-15 00:32:36 +09:00
|
|
|
import { GrabToPan } from './grab_to_pan';
|
|
|
|
import { localized } from './ui_utils';
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2016-04-16 23:47:48 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} HandToolOptions
|
|
|
|
* @property {HTMLDivElement} container - The document container.
|
2016-04-26 07:57:15 +09:00
|
|
|
* @property {EventBus} eventBus - The application event bus.
|
2017-05-08 04:30:07 +09:00
|
|
|
* @property {BasePreferences} preferences - Object for reading/writing
|
|
|
|
* persistent settings.
|
2016-04-16 23:47:48 +09:00
|
|
|
*/
|
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
class HandTool {
|
2016-04-16 23:47:48 +09:00
|
|
|
/**
|
|
|
|
* @param {HandToolOptions} options
|
|
|
|
*/
|
2017-05-08 04:30:07 +09:00
|
|
|
constructor({ container, eventBus, preferences, }) {
|
|
|
|
this.container = container;
|
|
|
|
this.eventBus = eventBus;
|
2016-04-16 23:47:48 +09:00
|
|
|
|
|
|
|
this.wasActive = false;
|
|
|
|
|
2013-10-03 05:09:43 +09:00
|
|
|
this.handTool = new GrabToPan({
|
2016-04-16 23:47:48 +09:00
|
|
|
element: this.container,
|
2017-04-28 19:02:42 +09:00
|
|
|
onActiveChanged: (isActive) => {
|
|
|
|
this.eventBus.dispatch('handtoolchanged', { isActive, });
|
|
|
|
},
|
2013-10-03 05:09:43 +09:00
|
|
|
});
|
2016-04-16 23:47:48 +09:00
|
|
|
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.on('togglehandtool', this.toggle.bind(this));
|
2014-03-17 10:11:41 +09:00
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
let enableOnLoad = preferences.get('enableHandToolOnLoad');
|
|
|
|
Promise.all([localized, enableOnLoad]).then((values) => {
|
2017-04-17 20:21:11 +09:00
|
|
|
if (values[1] === true) {
|
|
|
|
this.handTool.activate();
|
|
|
|
}
|
2017-05-08 04:30:07 +09:00
|
|
|
}).catch(function(reason) {});
|
2016-04-29 05:04:09 +09:00
|
|
|
|
2017-05-05 00:09:50 +09:00
|
|
|
this.eventBus.on('presentationmodechanged', (evt) => {
|
|
|
|
if (evt.switchInProgress) {
|
2016-04-29 05:04:09 +09:00
|
|
|
return;
|
|
|
|
}
|
2017-05-05 00:09:50 +09:00
|
|
|
if (evt.active) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.enterPresentationMode();
|
|
|
|
} else {
|
|
|
|
this.exitPresentationMode();
|
|
|
|
}
|
2017-05-05 00:09:50 +09:00
|
|
|
});
|
2016-04-16 23:47:48 +09:00
|
|
|
}
|
2013-10-03 05:09:43 +09:00
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
get isActive() {
|
|
|
|
return !!this.handTool.active;
|
|
|
|
}
|
2016-04-16 23:47:48 +09:00
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
toggle() {
|
|
|
|
this.handTool.toggle();
|
|
|
|
}
|
2013-10-03 05:09:43 +09:00
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
enterPresentationMode() {
|
|
|
|
if (this.isActive) {
|
|
|
|
this.wasActive = true;
|
|
|
|
this.handTool.deactivate();
|
2013-10-03 05:09:43 +09:00
|
|
|
}
|
2017-05-08 04:30:07 +09:00
|
|
|
}
|
2016-04-16 23:47:48 +09:00
|
|
|
|
2017-05-08 04:30:07 +09:00
|
|
|
exitPresentationMode() {
|
|
|
|
if (this.wasActive) {
|
|
|
|
this.wasActive = false;
|
|
|
|
this.handTool.activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
HandTool,
|
|
|
|
};
|