001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.css2;
042:
043: import java.net.URL;
044: import org.netbeans.modules.visualweb.api.designer.Designer.Box;
045:
046: import org.openide.util.NbBundle;
047: import org.w3c.dom.Element;
048:
049: import org.netbeans.modules.visualweb.designer.WebForm;
050: import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
051: import org.netbeans.modules.visualweb.designer.html.HtmlTag;
052:
053: /**
054: * FrameBox represents a <frame> or <iframe> tag
055:
056: * @todo The fact that I'm inlining the body contents is a bit
057: * "hacky"; some CSS properties should be taken from the <frame>,
058: * elements (e.g. position, margin, padding), whereas others
059: * should be taken from the <body> element pointed to by the frame
060: * src.
061: * @todo frameborder, marginwidth, and marginheight are not supported
062: * yet; they should be, similar to the TableBox.
063: *
064: * @author Tor Norbye
065: *
066: */
067: public class FrameBox extends ExternalDocumentBox {
068: /** Use the "getFrameBox" factory method instead */
069: private FrameBox(/*WebForm frameForm,*/WebForm webform,
070: Element element, /*URL url,*/BoxType boxType,
071: boolean inline, boolean replaced) {
072: super (webform.getPane(), /*frameForm,*/webform, element, /*url,*/
073: boxType, inline, replaced);
074: }
075:
076: //private Element body;
077:
078: /** Create a new framebox, or provide one from a cache */
079: public static ContainerBox getFrameBox(CreateContext context,
080: WebForm webform, Element element, BoxType boxType,
081: HtmlTag tag, boolean inline) {
082: // URL src = getContentURL(webform, element);
083: // WebForm frameForm = null;
084: //
085: // if (src != null) {
086: //// frameForm = findForm(webform, src);
087: // frameForm = webform.findExternalForm(src);
088: // }
089:
090: // boolean external = frameForm == WebForm.EXTERNAL;
091: // boolean external = frameForm == null;
092:
093: // if (frameForm == WebForm.EXTERNAL) {
094: // frameForm = null;
095: // }
096:
097: FrameBox box = new FrameBox(/*frameForm,*/webform, element, /*src,*/
098: boxType, inline, tag.isReplacedTag());
099: // box.external = external;
100:
101: WebForm frameForm = box.getExternalForm();
102: if (frameForm != null) {
103: if (context.isVisitedForm(frameForm)) {
104: return new StringBox(webform, element, boxType,
105: NbBundle.getMessage(FrameBox.class,
106: "RecursiveFrame"), null, AUTO, AUTO);
107: }
108:
109: // XXX Moved to designer/jsf/../JsfForm.
110: // //context.visitForm(frameForm);
111: // frameForm.setContextPage(webform);
112: }
113:
114: return box;
115: }
116:
117: protected String getUrlString() {
118: Element element = getElement();
119: return element == null ? null : element
120: .getAttribute(HtmlAttribute.SRC);
121: }
122:
123: /**
124: * Return a URL for the frame content,
125: * or null if it could not be determined.
126: */
127: @Override
128: protected URL getContentURL(WebForm webform, Element element) {
129: String src = element.getAttribute(HtmlAttribute.SRC);
130:
131: if ((src == null) || (src.length() == 0)) {
132: return null;
133: }
134:
135: // return InSyncService.getProvider().resolveUrl(webform.getMarkup().getBase(), webform.getJspDom(), src);
136: return webform.resolveUrl(src);
137: }
138:
139: // public String toString() {
140: // return "FrameBox[" + paramString() + "]";
141: // }
142:
143: /*
144: protected String paramString() {
145: return super.paramString() + ", " + markup;
146: }
147: */
148: public void relayout(FormatContext context) {
149: int oldWidth = width;
150: int oldHeight = height;
151: int oldContentWidth = contentWidth;
152: int oldContentHeight = contentHeight;
153: super .relayout(context);
154: width = oldWidth;
155: height = oldHeight;
156: contentWidth = oldContentWidth;
157: contentHeight = oldContentHeight;
158: }
159:
160: // Override standard methods to give frames special treatment, since
161: // they are "black boxes" as far as the box hierarchy is concerned
162:
163: /** What should the default intrinsic width be? Mozilla 1.6 seems
164: * to use 300x150.
165: */
166: public int getIntrinsicWidth() {
167: return 300;
168: }
169:
170: /** What should the default intrinsic height be? Mozilla 1.6 seems
171: * to use 300x150.
172: */
173: public int getIntrinsicHeight() {
174: return 150;
175: }
176:
177: protected void updateExtents(int px, int py, int depth) {
178: // Override to ensure that we set/clip the extents to the bounding
179: // rectangle of the frame.
180: super .updateExtents(px, py, depth); // do it for the children....the poor children...
181:
182: if (positionedBy != getParent()) {
183: px = positionedBy.getAbsoluteX();
184: py = positionedBy.getAbsoluteY();
185: }
186:
187: px += getX();
188: py += getY();
189:
190: // Box model quirk: my coordinate system is based on the visual
191: // extents of the boxes - e.g. location and size of the border
192: // edge. Because of this, when visually traversing the hierarchy,
193: // I need to add in the margins.
194: px += leftMargin;
195: py += effectiveTopMargin;
196:
197: extentX = px;
198: extentY = py;
199: extentX2 = px + width;
200: extentY2 = py + height;
201: }
202:
203: public int getPrefMinWidth() {
204: return getPrefWidth();
205: }
206:
207: // Override because we don't want to look inside the box; frames
208: // are treated as atomic blocks - they're not breakable
209: public int getPrefWidth() {
210: int result;
211:
212: // if ((contentWidth != AUTO) && (contentWidth != UNINITIALIZED)) {
213: if ((contentWidth != AUTO)
214: && (contentWidth != Box.UNINITIALIZED)) {
215: result = contentWidth;
216: } else {
217: result = getIntrinsicWidth();
218: }
219:
220: result += (leftBorderWidth + leftPadding + rightPadding + rightBorderWidth);
221:
222: if (leftMargin != AUTO) {
223: result += leftMargin;
224: }
225:
226: if (rightMargin != AUTO) {
227: result += rightMargin;
228: }
229:
230: return result;
231: }
232: }
|