001: /*
002: * MyGWT Widget Library
003: * Copyright(c) 2007, MyGWT.
004: * licensing@mygwt.net
005: *
006: * http://mygwt.net/license
007: */
008: package net.mygwt.ui.client.widget;
009:
010: import java.util.Stack;
011:
012: import net.mygwt.ui.client.MyGWT;
013:
014: import com.google.gwt.user.client.DOM;
015: import com.google.gwt.user.client.Element;
016: import com.google.gwt.user.client.ui.Widget;
017:
018: /**
019: * Displays an iframe under a element to stop IE bleed through and applet
020: * related issues.
021: */
022: public class FramePanel extends Widget {
023:
024: private static Stack frameStack = new Stack();
025:
026: /**
027: * Returns a frame panel from the stack.
028: *
029: * @return the frame panel
030: */
031: public static FramePanel pop() {
032: FramePanel panel = frameStack.size() > 0 ? (FramePanel) frameStack
033: .pop()
034: : null;
035: if (panel == null) {
036: panel = new FramePanel();
037: }
038: return panel;
039: }
040:
041: /**
042: * Pushes a panel back onto the stack.
043: *
044: * @param panel the panel
045: */
046: public static void push(FramePanel panel) {
047: frameStack.push(panel);
048: }
049:
050: /**
051: * Creates a new frame panel.
052: */
053: private FramePanel() {
054: Element frame = DOM.createIFrame();
055: setElement(frame);
056: if (MyGWT.isIE && MyGWT.isSecure) {
057: DOM.setElementProperty(getElement(), "src",
058: MyGWT.SSL_SECURE_URL);
059: }
060: }
061:
062: /**
063: * Removes the panel.
064: *
065: * @param element the parent element
066: */
067: public native void onHide(Element element) /*-{
068: var frame = this.@com.google.gwt.user.client.ui.UIObject::element;
069: frame.parentNode.removeChild(frame);
070: }-*/;
071:
072: /**
073: * Displays the panel behind the given element.
074: *
075: * @param element the element
076: */
077: public void onShow(Element element) {
078: if (MyGWT.isIE) {
079: bindIE(element, getElement());
080: } else {
081: bindOther(element, getElement());
082: }
083: }
084:
085: /**
086: * Displays the panel behind the given element.
087: *
088: * @param element the element
089: * @param zIndex the z index
090: */
091: public void onShow(Element element, int zIndex) {
092: onShow(element);
093: setZIndex(zIndex);
094: }
095:
096: /**
097: * Sets the z-index of the panel.
098: *
099: * @param index the z index
100: */
101: public void setZIndex(int index) {
102: index = Math.max(1, index);
103: if (MyGWT.isIE) {
104: setZIndexIE(index);
105: } else {
106: DOM.setIntStyleAttribute(getElement(), "zIndex", index);
107: }
108: }
109:
110: public void sync(Element element) {
111: if (MyGWT.isIE) {
112: syncIE(element, getElement());
113: } else {
114: syncOther(element, getElement());
115: }
116: }
117:
118: private native void bindIE(Element parent, Element frame) /*-{
119: frame.scrolling = 'no';
120: frame.frameBorder = 0;
121: frame.style.position = 'absolute';
122: frame.className = 'my-frame-panel';
123: parent.__frame = frame;
124: frame.__parent = parent;
125: frame.style.setExpression('left', parent.offsetLeft);
126: frame.style.setExpression('top', parent.offsetTop);
127: frame.style.setExpression('width', parent.offsetWidth);
128: frame.style.setExpression('height', parent.offsetHeight);
129: parent.parentElement.insertBefore(frame, parent);
130: }-*/;
131:
132: private native void bindOther(Element parent, Element frame) /*-{
133: frame.scrolling = 'no';
134: frame.frameBorder = 0;
135: frame.style.position = 'absolute';
136: frame.className = 'my-frame-panel';
137: parent.__frame = frame;
138: frame.__parent = parent;
139: frame.style.left = parent.offsetLeft + 'px';
140: frame.style.top = parent.offsetTop + 'px';
141: frame.style.width = parent.offsetWidth + 'px';
142: frame.style.height = parent.offsetHeight + 'px';
143: parent.parentNode.insertBefore(frame, parent);
144: }-*/;
145:
146: private native void setZIndexIE(int index) /*-{
147: var frame = this.@com.google.gwt.user.client.ui.UIObject::element;
148: frame.style.setExpression('zIndex', index);
149: }-*/;
150:
151: private native void syncIE(Element parent, Element frame) /*-{
152: frame.style.setExpression('left', parent.offsetLeft);
153: frame.style.setExpression('top', parent.offsetTop);
154: frame.style.setExpression('width', parent.offsetWidth);
155: frame.style.setExpression('height', parent.offsetHeight);
156: }-*/;
157:
158: private native void syncOther(Element parent, Element frame) /*-{
159: frame.style.left = parent.offsetLeft + 'px';
160: frame.style.top = parent.offsetTop + 'px';
161: frame.style.width = parent.offsetWidth + 'px';
162: frame.style.height = parent.offsetHeight + 'px';
163: }-*/;
164:
165: }
|