Как избежать ContextMenu после долгого нажатия мыши в Firefox OS Simulator

543
Oriol

Я установил чат-приложение в Firefox OS Simulator.

Это приложение добавляет contextmenuпрослушиватели событий, в которых оно позволяет мне удалять отдельные сообщения.

Однако этот прослушиватель событий не позволяет мне выбирать текст в сообщениях.

Мне все равно, как эта проблема решается в сенсорных устройствах. Поскольку я использую ПК, я могу отправить contextmenuпрослушиватель событий, щелкнув правой кнопкой мыши.

Поэтому, когда я удерживаю левую кнопку мыши, я хочу получить красный цвет этого contextmenuсобытия, но все же иметь возможность выделять текст.

0

2 ответа на вопрос

0
Oriol

This behavior is not a bug, it's intended as a feature:

Simulate touch events on desktop

If you still want to disable it, follow those steps:

  1. Open the profile folder of Firefox:
    1. Go to about:support
    2. Find the "Application Basics" section
    3. Find the "Profile Folder" entry in the table
    4. Click the "Show Folder" button
  2. Go to the extensions subfolder
  3. Find the folder of your simulator, e.g. fxos_2_2_simulator@mozilla.org
  4. Go to b2g/modules/devtools subfolders
  5. Open the touch-events.js file with a proper text editor
  6. Find the sendContextMenu function:

    sendContextMenu: function teh_sendContextMenu(target, x, y, delay) { let doc = target.ownerDocument; let evt = doc.createEvent('MouseEvent'); evt.initMouseEvent('contextmenu', true, true, doc.defaultView, 0, x, y, x, y, false, false, false, false, 0, null); let content = this.getContent(target); let timeout = content.setTimeout((function contextMenu() { target.dispatchEvent(evt); this.cancelClick = true; }).bind(this), delay); return timeout; }, 
  7. Comment this line to avoid dispatching the event:

    // target.dispatchEvent(evt); 
  8. Restart the Simulator

Note it's important to only prevent the dispatch of the event instead of not calling sendContextMenu. Otherwise, the click wouldn't be cancelled (this.cancelClick = true), so text selection wouldn't work properly.

0
Oriol

This is a per app solution:

  1. Find the path to the app. It will be something like

    [Firefox profile]\extensions\[Firefox OS Simulator]\profile\webapps\[ID]\application.zip 
  2. Backup and extract it

  3. Find the JS file which adds the contextmenu event listener.

    Probably, it will be something like

    someThing.addEventListener('contextmenu', function handler(event) { // ... }); 
  4. Filter out the left mouse button:

    someThing.addEventListener('contextmenu', function handler(event) { if(evt.button === 0) return; // ... }); 
  5. Make sure the Simulator is closed

  6. Insert the modified file at the right place of application.zip.

Похожие вопросы