lukt1 wrote:

On your class derived from nsIWebBrowserChrome take a look at OnStateChange () and check your progressStateFlags for STATE_STOP...that should be when the document has finished loading. Then you get hold of the nsIDOMWindow by calling GetDOMWindow () from your aWebProgress that was passed in nwIWebBrowserChrome::OnStateChange (). Then on the nsIDOMWindow you just got, do a QueryInterface on it for your nsIDOMEventTarget. Once you have that you call nsIDOMEventTarget::AddEventListener () for any events you want to receive notifications for.

Make sure to implement nsIWebBrowserChrome::HandleEvent () so you can handle the events you just told Gecko to send you.
Hope this helps.

Niky Williams


Hello!

Thanks to your help I can receive events in my gecko embed app.
But still I dont know how to read values which user writes in input
fields.

For example I have following input field:

<input type="text" id="edit1" value="2">

When I read it by:

nsCOMPtr<nsIDOMNode> domNode;
nsString nodeValue;
....
....
domNode->GetNodeValue(nodeValue);

I always receive default value.
How can I read current value from input field?

lukt1


Ya, I had that same problem too. I could never get what I needed from the nsIDOMNode. I should probably look back into that, but here is how I got around it with my current code...actually, there are 2 ways.

1) Through the nsIDOMEvent if you are wanting to read the value on an event

2) Through the nsIDOMElement if you are just wanting to poll the value.


Okay, to get it through the nsIDOMEvent, you need to get the ID of the element that caused the event. You do this by calling nsIDOMEvent::GetTarget () to get an nsIDOMEventTarget. Then you Query the nsIDOMEventTarget for an nsIDOMHTMLElement. Once you have that, call nsIDOMHTMLElement::GetId () to get the ID of the element that caused the event.

Once you have this, you can use the next method for #1 and #2

Get the nsIWebBrowser from your nsIWebBrowserChrome derived class. Then call nsIWebBrowser::GetContentDOMWindow () to get an nsIDOMWindow. Call nsIDOMWindow::GetDocument () to get an nsIDOMDocument object. Then call nsIDOMDocument::GetElementById () using the ID from the element you want. This will get you an nsIDOMElement. Once you have that, query the object for an nsIDOMHTMLInputElement. Now you can call either nsIDOMHTMLInputElement::SetValue () or nsIDOMHTMLInputElement::GetValue () to get/set what you need.

Hope this helps, and if anyone else knows an easier way, please say something :-)

Niky Williams

_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to