[Webkit-unassigned] [Bug 60269] New: Ability to add C++ event listeners to html dom elements and dom window
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Thu May 5 08:38:32 PDT 2011
https://bugs.webkit.org/show_bug.cgi?id=60269
Summary: Ability to add C++ event listeners to html dom
elements and dom window
Product: WebKit
Version: 528+ (Nightly build)
Platform: PC
OS/Version: Windows 7
Status: UNCONFIRMED
Severity: Normal
Priority: P2
Component: WebKit API
AssignedTo: webkit-unassigned at lists.webkit.org
ReportedBy: anthony.johnson at flexsim.com
Created an attachment (id=92420)
--> (https://bugs.webkit.org/attachment.cgi?id=92420&action=review)
Patch for adding event listeners
The included patch adds the ability to attach C++ event listeners to an html dom element and to a dom window for the wincairo port.
To give an idea of what I mean, here's some pseudo-code:
// for dom elements
domElement = webFrame->DOMDocument()->getElementById("myelement");
domElement->addEventListener("click", myCPPElementEventListener, false);
// for dom windows
domWindow = webFrame->DOMWindow();
domWindow->addEventListener("focus", myCPPWindowEventListener, false);
Of course, the actual c++ code is a little more involved, but I'll include that as well (minus all the error checking).
// for dom elements
CComPtr<IDOMElement> domDocument;
webFrame->DOMDocument(&domDocument);
CComPtr<IDOMElement> domElement;
domDocument->getElementById("myelement", &domElement);
CComPtr<IDOMEventTarget> target;
domElement->QueryInterface(IID_IDOMEventTarget, &target);
// myCPPElementEventListener is an instantiation of a class I (the end user) define that implements IDOMEventListener
target->addEventListener(TEXT("click"), static_cast<IDOMEventListener*>(myCPPElementEventListener), false);
// for dom windows
CComPtr<IDOMWindow> domWindow;
webFrame->DOMWindow(&domWindow);
CComPtr<IDOMEventTarget> target;
domWindow->QueryInterface(IID_IDOMEventTarget, &target);
// myCPPWindowEventListener is an instantiation of a class I (the end user) define that implements IDOMEventListener
target->addEventListener(TEXT("focus"), static_cast<IDOMEventListener*>(myCPPWindowEventListener), false);
Now, an explanation of my design.
1. I added a class called CPPEventListener, which inherits WebCore::EventListener and is a wrapper for an IDOMEventListener*, passing events on to that user-defined interface. As far as location of the class definition, I defined the class in DOMEventsClasses.h, and defined the methods in DOMEventsClasses.cpp. Not sure if that's the best spot to put it.
2. I filled in the DOMNode::addEventListener() and DOMNode::removeEventListener() methods, which instantiates the CPPEventListener class and adds it to the webcore node's event listeners.
3. I defined a DOMWindow class that implements the IDOMWindow interface as well as the IDOMEventTarget interface, and is a wrapper around WebCore::DOMWindow.
4. I added a DOMWindow() method to the IWebFrame interface and WebFrame class, which instantiates a DOMWindow object and returns its IDOMWindow interface.
Additional points:
- You may want to look at my use of RefPtr in DOMNode::addEventListener(), DOMNode::removeEventListener(), DOMWindow::addEventListener(), and DOMWindow::removeEventListener(). I'm not yet an expert on RefPtr, so I may not have done it in the best-practices method.
- My creation of the CPPEventListener sub-class WebCore::EventListener seems to me to be the most precarious, because I don't know if it's proper to sub-class a WebCore class in a platform-specific port. But that seemed to be the only way I could think of to get it to dispatch events to my own code.
Thanks,
Anthony Johnson
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list