Added for RMB: handling of contextmenu events that happens before mouseup.

Important for Linux (and possibly Mac OS) compatibility.

- postponing contextmenu events after mouseup event, because Linux fires
  contextmenu event after mousedown.
- moved RMB specific code from _isKeyActive to _handleMouseMove, because
  _isKeyActive should not contain any additional logic.
- added some util functions.
- some code shuffling and refactoring.
Minor: removed some whitespaces.