001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.client;
029
030import com.google.gwt.dom.client.Document;
031import com.google.gwt.dom.client.IFrameElement;
032import com.vaadin.client.ui.VBrowserFrame;
033
034/**
035 * Extension of the standard browser frame widget which supports setting the name correctly in Chrome.
036 *
037 * <p>The difference from the standard implementation is that here the name attribute is set on the iframe
038 * element before it is inserted into the DOM, which is necessary in Chrome because setting this attribute
039 * in Chrome does not change the corresponding frame window object's 'name' attribute if it already exists.
040 */
041public class CmsVBrowserFrame extends VBrowserFrame {
042
043    /** The name to set on the iframe element. */
044    protected String m_savedName;
045
046    /**
047     * @see com.vaadin.client.ui.VBrowserFrame#setName(java.lang.String)
048     */
049    @Override
050    public void setName(String name) {
051
052        super.setName(name);
053        m_savedName = name;
054    }
055
056    /**
057     * Always creates new iframe inside widget. Will replace previous iframe.
058     *
059     * @return the iframe element
060     */
061    @Override
062    protected IFrameElement createIFrameElement(String src) {
063
064        String name = m_savedName;
065
066        // Remove alt text
067        if (altElement != null) {
068            getElement().removeChild(altElement);
069            altElement = null;
070        }
071
072        // Remove old iframe
073        if (iframe != null) {
074            name = iframe.getAttribute("name");
075            getElement().removeChild(iframe);
076            iframe = null;
077        }
078
079        iframe = Document.get().createIFrameElement();
080        iframe.setSrc(src);
081        iframe.setFrameBorder(0);
082        iframe.setAttribute("width", "100%");
083        iframe.setAttribute("height", "100%");
084
085        iframe.setAttribute("allowTransparency", "true");
086        if (name != null) {
087            iframe.setName(name);
088        }
089
090        getElement().appendChild(iframe);
091        return iframe;
092    }
093
094}