• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
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
16export function mockInputMonitor() {
17  const touches = [{
18    force: 1.67,
19    globalX: 122,
20    globalY: 3654,
21    localX: 0,
22    localY: 0,
23    size: 2.03
24  }];
25  const changedTouches = [{
26    force: 1.67,
27    globalX: 122,
28    globalY: 3654,
29    localX: 0,
30    localY: 0,
31    size: 2.03
32  }];
33  const pressedButtons = [10, 11 , 12, 13, 14];
34  global.systemplugin.multimodalInput = {};
35  global.systemplugin.multimodalInput.inputMonitor = {
36    on: function (...args) {
37      console.warn('multimodalInput.inputMonitor.on interface mocked in the Previewer. How this interface works on the' +
38        ' Previewer may be different from that on a real device.');
39      clearInterval(this.offInputMonitor);
40      delete this.offInputMonitor;
41      this.offInputMonitor = setInterval(() => {
42        const len = args.length;
43        if (len !== 2 || typeof args[0] !== 'string' || typeof args[len - 1] !== 'function') {
44          console.warn('multimodalInput.inputMonitor.on param invalid.');
45          return;
46        }
47        if (args[0] !== 'touch' && args[0] !== 'mouse') {
48          console.warn('multimodalInput.inputMonitor.on first param should be touch or mouse.');
49          return;
50        }
51        const value = {};
52        value.type = 'up';
53        value.timestamp = 318878;
54        value.deviceId = 0;
55        value.touches = touches;
56        value.changedTouches = changedTouches;
57        const mouse = {};
58        mouse.type = 'move';
59        mouse.pressedButtons = pressedButtons;
60        mouse.displayId = 20;
61        mouse.targetWindowId = 21;
62        mouse.agentWindowId = 22;
63        mouse.localX = 450;
64        mouse.localY = 736;
65        mouse.globalX = 450;
66        mouse.globalY = 784;
67        mouse.timestamp = 55670246;
68        mouse.axisVerticalValue = 15;
69        mouse.axisHorizontalValue = 20;
70        if (args[0] === 'touch') {
71          console.warn('multimodalInput.inputMonitor.on touch callback.');
72          args[len - 1].call(this, value);
73        } else if (args[0] === 'mouse') {
74          console.warn('multimodalInput.inputMonitor.on mouse callback.');
75          args[len - 1].call(this, mouse);
76        }
77      }, 1000);
78    },
79
80    off: function (...args) {
81      console.warn('multimodalInput.inputMonitor.off interface mocked in the Previewer. How this interface works on the' +
82        ' Previewer may be different from that on a real device.');
83      clearInterval(this.offInputMonitor);
84      delete this.offInputMonitor;
85    }
86  };
87}
88
89