KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > FormPanelImpl


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui.impl;
17
18 import com.google.gwt.user.client.Element;
19
20 /**
21  * Implementation class used by {@link com.google.gwt.user.client.ui.FormPanel}.
22  */

23 public class FormPanelImpl {
24
25   /**
26    * Gets the response html from the loaded iframe.
27    *
28    * @param iframe the iframe from which the response html is to be extracted
29    * @return the response html
30    */

31   public native String JavaDoc getContents(Element iframe) /*-{
32     try {
33       // Make sure the iframe's window & document are loaded.
34       if (!iframe.contentWindow || !iframe.contentWindow.document)
35         return null;
36
37       // Get the body's entire inner HTML.
38       return iframe.contentWindow.document.body.innerHTML;
39     } catch (e) {
40       return null;
41     }
42   }-*/
;
43
44   /**
45    * Gets the form element's encoding.
46    *
47    * @param form the form whose encoding is to be retrieved
48    * @return the form's encoding type
49    */

50   public native String JavaDoc getEncoding(Element form) /*-{
51     // We can always get 'enctype', no matter which browser, because we set
52     // both 'encoding' and 'enctype' in setEncoding().
53     return form.enctype;
54   }-*/
;
55
56   /**
57    * Hooks the iframe's onLoad event and the form's onSubmit event.
58    *
59    * @param iframe the iframe whose onLoad event is to be hooked
60    * @param form the form whose onSubmit event is to be hooked
61    * @param listener the listener to receive notification
62    */

63   public native void hookEvents(Element iframe, Element form,
64       FormPanelImplHost listener) /*-{
65     if (iframe) {
66       iframe.onload = function() {
67         // If there is no __formAction yet, this is a spurious onload
68         // generated when the iframe is first added to the DOM.
69         if (!iframe.__formAction)
70           return;
71
72         listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFrameLoad()();
73       };
74     }
75
76     form.onsubmit = function() {
77       // Hang on to the form's action url, needed in the
78       // onload/onreadystatechange handler.
79       if (iframe)
80         iframe.__formAction = form.action;
81       return listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFormSubmit()();
82     };
83   }-*/
;
84
85   /**
86    * Sets the form element's encoding.
87    *
88    * @param form the form whose encoding is to be set
89    * @param encoding the new encoding type
90    */

91   public native void setEncoding(Element form, String JavaDoc encoding) /*-{
92     // To be safe, setting both.
93     form.enctype = encoding;
94     form.encoding = encoding;
95   }-*/
;
96
97   /**
98    * Submits a form.
99    *
100    * @param form the form to be submitted
101    * @param iframe the iframe that is targetted, or <code>null</code>
102    */

103   public native void submit(Element form, Element iframe) /*-{
104     // Hang on to the form's action url, needed in the
105     // onload/onreadystatechange handler.
106     if (iframe)
107       iframe.__formAction = form.action;
108     form.submit();
109   }-*/
;
110
111   /**
112    * Unhooks the iframe's onLoad event.
113    *
114    * @param iframe the iframe whose onLoad event is to be unhooked
115    * @param form the form whose onSubmit event is to be unhooked
116    */

117   public native void unhookEvents(Element iframe, Element form) /*-{
118     if (iframe)
119       iframe.onload = null;
120     form.onsubmit = null;
121   }-*/
;
122 }
123
Popular Tags