package com.skystrider.subtabs.client.gwtUtils;
import java.util.ArrayList;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Frame;
/**
* A {...@link com.google.gwt.user.client.ui.Frame} that has a 'name'
associated
* with it. This allows the frame to be the target of a
* {...@link com.google.gwt.user.client.ui.FormPanel}
*
* <h3>CSS Style Rules</h3>
* <ul class='css'>
* <li>.gwt-Frame { }</li>
* </ul>
*/
public class MyNamedFrame extends Frame {
private ArrayList<LoadHandler> loadHandlers = null;
// Used inside JSNI, so please don't delete this field just because
// your compiler or IDE says it's unused.
@SuppressWarnings("unused")
private static JavaScriptObject PATTERN_NAME;
static {
if (GWT.isClient()) {
initStatics();
}
}
/**
* Creates an HTML IFRAME element with a src and name.
*
* @param src the src of the frame
* @param name the name of the frame, which must contain at least
one
* non-whitespace character and must not contain reserved
HTML markup
* characters such as '<code><</code>', '<code>></
code>',
* or '<code>&</code>'
* @return the newly-created element
* @throws IllegalArgumentException if the supplied name is not
allowed
*/
private static IFrameElement createIFrame(String src, String name)
{
if (name == null || !isValidName(name.trim())) {
throw new IllegalArgumentException(
"expecting one or more non-whitespace chars with no '<',
'>', or '&'");
}
// Use innerHTML to implicitly create the <iframe>. This is
necessary
// because most browsers will not respect a dynamically-set
iframe name.
Element div = DOM.createDiv();
String onload = "onload=\"if(!event){event = window.event;}
this.myonload(event);\"";
div.setInnerHTML("<iframe src=\"" + src + "\" name='" + name + "'
" + onload + ">");
return div.getFirstChild().cast();
}
private static native void initStatics() /*-{
@com.google.gwt.user.client.ui.NamedFrame::PATTERN_NAME = /^[^<>&
\'\"]+$/;
}-*/;
/**
* @param name the specified frame name to be checked
* @return <code>true</code> if the name is valid, <code>false</
code> if
* not
*/
private static native boolean isValidName(String name) /*-{
return
@com.google.gwt.user.client.ui.NamedFrame::PATTERN_NAME.test(name);
}-*/;
/**
* Constructs a frame with the given name.
*
* @param name the name of the frame, which must contain at least
one
* non-whitespace character and must not contain reserved
HTML markup
* characters such as '<code><</code>', '<code>></
code>',
* or '<code>&</code>'
*
* @throws IllegalArgumentException if the supplied name is not
allowed
*/
public MyNamedFrame(String name) {
// Setting a src prevents mixed-content warnings.
//
http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
super(createIFrame("javascript:''", name));
setStyleName("gwt-Frame");
setMyOnload(this.getElement().cast(), this);
}
/**
* Gets the name associated with this frame.
*
* @return the frame's name
*/
public String getName() {
return DOM.getElementProperty(getElement(), "name");
}
public void addLoadHandler(LoadHandler handler) {
if(loadHandlers == null){
loadHandlers = new ArrayList<LoadHandler>();
}
loadHandlers.add(handler);
}
public interface LoadHandler {
void onLoad(Event event);
}
public native void setMyOnload(JavaScriptObject elm, MyNamedFrame
frame)/*-{
elm.myonload = function(event){
[email protected]::onload(Lcom/
google/gwt/user/client/Event;)(event);
};
}-*/;
public void onload(Event event)
{
for (LoadHandler handler : loadHandlers) {
handler.onLoad(event);
}
}
}
On May 20, 12:13 am, Sky <[email protected]> wrote:
> Just in case you ever wanted to have a handler for the <iframe>'s
> onload event:
>
> import com.google.gwt.event.dom.client.HasLoadHandlers;
> import com.google.gwt.event.dom.client.LoadEvent;
> import com.google.gwt.event.dom.client.LoadHandler;
> import com.google.gwt.event.shared.HandlerRegistration;
> import com.google.gwt.user.client.ui.NamedFrame;
>
> public classMyNamedFrameextends NamedFrame implements
> HasLoadHandlers {
>
> publicMyNamedFrame(String name) {
> super(name);
> }
>
> @Override
> public HandlerRegistration addLoadHandler(LoadHandler handler) {
> return addDomHandler(handler, LoadEvent.getType());
> }
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.