Skip to content

Instantly share code, notes, and snippets.

@evanw
Created November 28, 2013 19:33
Show Gist options
  • Save evanw/7697112 to your computer and use it in GitHub Desktop.
Save evanw/7697112 to your computer and use it in GitHub Desktop.
PNaCl bug with RequestFilteringInputEvents
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
struct HelloTutorialInstance : pp::Instance {
HelloTutorialInstance(PP_Instance instance) : pp::Instance(instance) {
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
}
virtual bool HandleInputEvent(const pp::InputEvent &event) {
switch (event.GetType()) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
if (pp::MouseInputEvent(event).GetPosition().x() < 50) {
PostMessage("YUP");
return true;
}
PostMessage("NOPE");
return false;
default:
return false;
}
}
};
struct HelloTutorialModule : pp::Module {
HelloTutorialModule() : pp::Module() {}
virtual pp::Instance *CreateInstance(PP_Instance instance) {
return new HelloTutorialInstance(instance);
}
};
namespace pp {
Module *CreateModule() {
return new HelloTutorialModule();
}
}
<h2>PNaCl Event Filtering Demo</h2>
<p>
This tests the RequestFilteringInputEvents() method from the Pepper C++ API.
According to the <a href="https://google-developers.appspot.com/native-client/dev/peppercpp/classpp_1_1_instance">pp::Instance Class Reference</a>, returning true from HandleInputEvent() will prevent the event from bubbling up to enclosing DOM elements.
This is broken in Chrome 33.0.1722.0 canary (the events will always bubble regardless).
</p>
<div id="listener">
<div id="debug">Loading...</div>
<div id="bubble">Click on left half to prevent bubbling, right half to allow bubbling</div>
<script>
listener.addEventListener('load', function() { debug.textContent = 'Success'; }, true);
listener.addEventListener('error', function() { debug.textContent = 'Error'; }, true);
listener.addEventListener('message', function(e) { debug.textContent = 'Message from C++: ' + e.data; }, true);
listener.addEventListener('mousedown', function(e) { bubble.textContent = 'mousedown bubble ' + (e.pageX - pnacl.offsetLeft) + ' ' + (e.pageY - pnacl.offsetTop); }, false);
</script>
<embed id="pnacl" width="100" height="100" src="filtering.nmf" type="application/x-pnacl" style="border:1px solid black;" />
</div>
{
"program": {
"portable": {
"pnacl-translate": {
"url": "filtering.pexe"
}
}
}
}
SDK = ~/nacl_sdk/pepper_canary
build:
$(SDK)/toolchain/mac_pnacl/bin/pnacl-clang++ -o filtering.bc filtering.cpp -O2 -I $(SDK)/include -L $(SDK)/lib/pnacl/Release -lppapi_cpp -lppapi
$(SDK)/toolchain/mac_pnacl/bin/pnacl-finalize -o filtering.pexe filtering.bc
@gliheng
Copy link

gliheng commented Jan 20, 2016

It looks like this is not fixed yet. Need confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment