Failing to get form from FormControl

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Failing to get form from FormControl

Antônio Gomes-2
Guys,

I am facing the following problem on my embedded application:

I have an VirtualKeyboard component (based on minimo's one -  
http://lxr.mozilla.org/mozilla1.8/source/minimo/components/softkb/nsSoftKeyBoard.cpp),
that listens to DOMEvent and pops up the environment's virtual keyboard
in cases when an editable form gets focus.

It work for most of cases, however when I tried it on gmail's chat it's
failed to get nsIDOMHTMLFormElement from formControl. I am doing like
these :

<quoted>

NS_IMETHODIMP
nsSoftKeyBoard::HandleEvent(nsIDOMEvent* aEvent) {
*
 if* (!aEvent) *return* NS_OK;

 nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
 nsCOMPtr<nsIDOMEventTarget> target;
 nsevent->GetOriginalTarget(getter_AddRefs(target));
 nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);

 if (!targetContent ||
!targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL))
   return NS_OK;

 nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
 if (!formControl)
   return NS_OK;

 PRInt32 controlType = formControl->GetType();

 if (controlType != NS_FORM_TEXTAREA     &&  controlType !=
NS_FORM_INPUT_TEXT &&
   controlType != NS_FORM_INPUT_PASSWORD &&  controlType !=
NS_FORM_INPUT_FILE)
   return NS_OK;

 // FIXME: debugging printfs
 if (controlType == NS_FORM_TEXTAREA)  printf ("[vkb] textarea\n");
 if (controlType == NS_FORM_INPUT_TEXT) printf ("[vkb] input_text \n");
 if (controlType == NS_FORM_INPUT_PASSWORD) printf ("[vkb] input_passwd\n");
 if (controlType == NS_FORM_INPUT_FILE) printf ("[vkb] input_file\n");

 // I AM FAILING HERE ALTHOUGH IT PRINTS ''[vkb] textarea" (see
above), SO WHY WOULD IT FAIL IF I AM A TEXTAREA ??
 // MINIMO VKB DiFFS FROM MINE AT THIS POINT ...
 nsCOMPtr <nsIDOMHTMLFormElement> focusedHTMLFormElement;
 formControl->GetForm(getter_AddRefs(focusedHTMLFormElement));

 if (!focusedHTMLFormElement) {
   NS_ASSERTION (PR_TRUE, "[vkb] nsSoftKeyBoard::HandleEvent
focusedHTMLFormElement == NULL");
   return NS_ERROR_UNEXPECTED;
 }

(...)


So although FormControl says it a NS_FORM_TEXTAREA (see bunch of printfs
above), it fails to nsIDOMHTMLFormElement.

This problem occurs only on gmails chat, which is defined as following
(from the html source):


...
<tr>
<td align=center id="[hidden email]
<mailto:[hidden email]>" class=wackinputopen
style="border: none;">
<div style="margin-left: 2px; margin-right: 1px;"">
<textarea (... lots here) onkeypress=... onfocus=... >
</textarea>
</div>
</td>
</tr>
...

This div that is handling onkeypress() events might the problem ? Any
suggestion of how could I get it working ? Workarounds ?

Thanks

regards

--Antonio Gomes
Nokia Technology Institute
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Boris Zbarsky
Antônio Gomes wrote:
> nsCOMPtr <nsIDOMHTMLFormElement> focusedHTMLFormElement;
> formControl->GetForm(getter_AddRefs(focusedHTMLFormElement));

Is the form control actually in a form?

> <div style="margin-left: 2px; margin-right: 1px;"">
> <textarea (... lots here) onkeypress=... onfocus=... >
> </textarea>

So the textarea is not in a form....

Where is the problem?  You ask for a form, there isn't one, so null is returned...

-Boris
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Antônio Gomes-2
Hi Boris,

>> nsCOMPtr <nsIDOMHTMLFormElement> focusedHTMLFormElement;
>> formControl->GetForm(getter_AddRefs(focusedHTMLFormElement));
>
>
> Is the form control actually in a form?

I supposed it is, once GetType returns NS_FORM_TEXTAREA.

>
>> <div style="margin-left: 2px; margin-right: 1px;"">
>> <textarea (... lots here) onkeypress=... onfocus=... >
>> </textarea>
>
>
> So the textarea is not in a form....
>
> Where is the problem?  You ask for a form, there isn't one, so null is
> returned...
>
I see. But even not being a form, it works as an input for the user,
right ? If so, in my case I'll have to handle this as such (like poping
up the virtial keyboard for the user). How could I get this textarea
element ? Can I edit its content manually ?

Thanks again for your time.

--Antonio Gomes
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Boris Zbarsky
In reply to this post by Boris Zbarsky
Antônio Gomes wrote:
>> Is the form control actually in a form?
>
> I supposed it is, once GetType returns NS_FORM_TEXTAREA.

That's just the type of the control.  It doesn't depend on where the control is.

> I see. But even not being a form, it works as an input for the user,
> right ?

Sure.

> If so, in my case I'll have to handle this as such (like poping
> up the virtial keyboard for the user). How could I get this textarea
> element ?

Er...  You already have the textarea element.  It's the target of the event.

-Boris
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Antônio Gomes-2
ext Boris Zbarsky wrote:

> Antônio Gomes wrote:
>
>>> Is the form control actually in a form?
>>
>>
>> I supposed it is, once GetType returns NS_FORM_TEXTAREA.
>
>
> That's just the type of the control.  It doesn't depend on where the
> control is.
>
>> I see. But even not being a form, it works as an input for the user,
>> right ?
>
>
> Sure.
>
>> If so, in my case I'll have to handle this as such (like poping up
>> the virtial keyboard for the user). How could I get this textarea
>> element ?
>
>
> Er...  You already have the textarea element.  It's the target of the
> event.
>

I see, but I'd like to query it to something else in order to change its
content, just like I am doing for 'common' forms
(nsIDOMHTMLFormElement). If I could do so, I'd be identifying I
handlening such case, otherwise it could be a problem ...

regards

--Antonio Gomes
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Boris Zbarsky
In reply to this post by Boris Zbarsky
Antônio Gomes wrote:
> I see, but I'd like to query it to something else in order to change its
> content, just like I am doing for 'common' forms
> (nsIDOMHTMLFormElement).

An nsIDOMHTMLFormElement is a <form> element.  You have a <textarea> element.
The two are unrelated, pretty much.

I'm not sure what you mean by "query it to something else in order to change its
content".

-Boris
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Antônio Gomes-2
ext Boris Zbarsky wrote:

> Antônio Gomes wrote:
>
>> I see, but I'd like to query it to something else in order to change
>> its content, just like I am doing for 'common' forms
>> (nsIDOMHTMLFormElement).
>
>
> An nsIDOMHTMLFormElement is a <form> element.  You have a <textarea>
> element. The two are unrelated, pretty much.
>
ok, they are unrelated, but which interface I'd have to query from the
target of the event in order to make somthing like


(...)
thatMyQueredTextArea->SetValue (NS_LITERAL_STRING("my text has to show
me")) // like for common forms
(...)

> I'm not sure what you mean by "query it to something else in order to
> change its
> content".
>
Sorry, I meant something like 'SetValue' (content showed I mean).

Thanks again

--Antonio Gomes
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Boris Zbarsky
In reply to this post by Boris Zbarsky
Antônio Gomes wrote:
> ok, they are unrelated, but which interface I'd have to query from the
> target of the event in order to make somthing like
>
> (...)
> thatMyQueredTextArea->SetValue (NS_LITERAL_STRING("my text has to show
> me")) // like for common forms
> (...)

nsIDOMHTMLInputElement or nsIDOMHTMLTextAreaElement or nsIDOMHTMLSelectElement,
depending on what sort of control you're working with...

All of this is documented in the DOM HTML spec, for what it's worth.

-Boris
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout
Reply | Threaded
Open this post in threaded view
|

Re: Failing to get form from FormControl

Antônio Gomes-2
ext Boris Zbarsky wrote:

> Antônio Gomes wrote:
>
>> ok, they are unrelated, but which interface I'd have to query from
>> the target of the event in order to make somthing like
>>
>> (...)
>> thatMyQueredTextArea->SetValue (NS_LITERAL_STRING("my text has to
>> show me")) // like for common forms
>> (...)
>
>
> nsIDOMHTMLInputElement or nsIDOMHTMLTextAreaElement or
> nsIDOMHTMLSelectElement, depending on what sort of control you're
> working with...
>
> All of this is documented in the DOM HTML spec, for what it's worth.
>
Got it.

Thanks bz

--Antonio Gomes
_______________________________________________
dev-tech-layout mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-layout