Commits

Rune Halvorsen committed 946504a

Use event listeners for higher granularity than handler system. Dispatch both mouse down and up rather than just clicks

Comments (0)

Files changed (1)

src/screenwatcher/screenwatcher.js

       ['img',
           'id', 'screenwatcher-image',
           'style', 'border: solid thin black',
-          'src', 'http://www.opera.com/bitmaps/common/opera-footer.gif',
-          'handler', 'clicked-browser-screenshot'
+          'src', 'http://www.opera.com/bitmaps/common/opera-footer.gif'
       ],
       'class', 'padding'
     ]);
   this.createView = function(container)
   {
     container.clearAndRender(this._template_main());
+
+    if (settings['browser-window-viewer'].get('forward-screenshot-clicks')) {
+      var img = document.getElementById("screenwatcher-image");
+      img.addEventListener("mousedown", function(e) { self._onImageMouseDown(e) }, false);
+      img.addEventListener("mouseup", function(e) { self._onImageMouseUp(e) }, false);
+    }
     this._requestUpdate();
   }
 
     this._requestScreenshot();
   }
 
-  this._forwardClick = function(x, y)
+    this._forwardMouse = function(x, y, button)
   {
-    opera.postError("Clicking " + x + "/" + y);
+    button = button || 0;
     window.services.exec.requestSendMouseAction(
-      tagManager.set_callback(this, this._onForwardClick),
-      [runtimes.getActiveWindowId(), x, y, 3]
+      tagManager.set_callback(this, this._onForwardMouse),
+      [runtimes.getActiveWindowId(), x, y, button]
     );
   }
 
-  this._onForwardClick = function(status, msg)
+  this._onForwardMouse = function(status, msg)
   {
     this._requestUpdate();
   }
 
-  this._onImageClick = function(evt, target)
+  this._onImageMouseUp = function(evt, target)
   {
-    if (settings['browser-window-viewer'].get('forward-screenshot-clicks'))
-    {
-      this._forwardClick(_current_image_metrics.left + evt.offsetX, _current_image_metrics.top + evt.offsetY);
-    }
+    this._forwardMouse(_current_image_metrics.left + evt.offsetX, _current_image_metrics.top + evt.offsetY, 2);
   }
 
+  this._onImageMouseDown = function(evt, target)
+  {
+    this._forwardMouse(_current_image_metrics.left + evt.offsetX, _current_image_metrics.top + evt.offsetY, 1);
+  }
+
+
   new Settings
   (
     'browser-window-viewer',
     self._requestUpdate();
   }
 
-  eventHandlers.click['clicked-browser-screenshot'] = function(event, target)
-  {
-    self._onImageClick(event, target);
-  }
-
-
   messages.addListener('setting-changed', function(msg) {
     if (msg.id == id &&
         msg.key == 'auto-reload-browser-window' &&