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.ade.containerpage.client; 029 030import org.opencms.gwt.client.util.CmsDomUtil; 031 032import com.google.gwt.core.client.GWT; 033import com.google.gwt.event.dom.client.LoadEvent; 034import com.google.gwt.event.dom.client.LoadHandler; 035import com.google.gwt.uibinder.client.UiBinder; 036import com.google.gwt.uibinder.client.UiField; 037import com.google.gwt.user.client.ui.Composite; 038import com.google.gwt.user.client.ui.Frame; 039import com.google.gwt.user.client.ui.Panel; 040import com.google.gwt.user.client.ui.Widget; 041 042/** 043 * Container widget for the iframe in which the template variant is shown.<p> 044 */ 045public class CmsClientVariantFrame extends Composite { 046 047 /** UiBinder interface for this class. */ 048 interface I_CmsClientVariantFrameUiBinder extends UiBinder<Widget, CmsClientVariantFrame> { 049 // empty, for uibinder 050 } 051 052 /** UiBinder for this class. */ 053 private static I_CmsClientVariantFrameUiBinder uiBinder = GWT.create(I_CmsClientVariantFrameUiBinder.class); 054 055 /** The iframe for the template variant. */ 056 protected Frame m_iframe; 057 058 /** The iframe container. */ 059 @UiField 060 protected Panel m_iframeContainer; 061 062 /** Placeholder widget which is displayed until the iframe is loaded. */ 063 @UiField 064 protected Widget m_iframePlaceholder; 065 066 /** 067 * Creates a new instance.<p> 068 * 069 * @param url the URL for the client variant 070 * @param width the width 071 * @param height the height 072 * @param containerpageHandler the container page handler 073 */ 074 public CmsClientVariantFrame( 075 String url, 076 final int width, 077 final int height, 078 final CmsContainerpageHandler containerpageHandler) { 079 080 initWidget(uiBinder.createAndBindUi(this)); 081 m_iframe = new Frame(); 082 m_iframe.getElement().getStyle().setVisibility(com.google.gwt.dom.client.Style.Visibility.HIDDEN); 083 m_iframe.setUrl(url); 084 m_iframeContainer.setWidth(width + "px"); 085 m_iframeContainer.setHeight(height + "px"); 086 m_iframe.setWidth("100%"); 087 m_iframe.setHeight("100%"); 088 m_iframe.addLoadHandler(new LoadHandler() { 089 090 public void onLoad(LoadEvent event) { 091 092 m_iframePlaceholder.removeFromParent(); 093 m_iframe.getElement().getStyle().setVisibility(com.google.gwt.dom.client.Style.Visibility.VISIBLE); 094 containerpageHandler.deactivateSelection(); 095 // on mobile devices scroll bars are not shown, 096 // in case the content height is greater than the configured screen height 097 // increase the screen width by the measured scroll bar width to simulate the configured width 098 int contentHeight = CmsDomUtil.getIFrameContentHeight(m_iframe.getElement()); 099 if (contentHeight > height) { 100 int scrollBarWidth = CmsDomUtil.getScrollbarWidth(); 101 if (scrollBarWidth > 0) { 102 m_iframeContainer.setWidth((width + scrollBarWidth) + "px"); 103 } 104 } 105 } 106 }); 107 m_iframeContainer.add(m_iframe); 108 } 109 110 /** 111 * Gets the iframe container.<p> 112 * 113 * @return the iframe container 114 */ 115 public Panel getIframeContainer() { 116 117 return m_iframeContainer; 118 } 119 120}