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.gwt.client.util.impl;
029
030import com.google.gwt.dom.client.Element;
031
032/**
033 * Helper class to retrieve the computed style of an element.<p>
034 *
035 * This implementation is used for MSIE 9 browsers.<p>
036 *
037 * @since 8.0.0
038 */
039public class DocumentStyleImplIE9 extends DocumentStyleImpl {
040
041    /**
042     * Transforms the CSS style name to the name of the javascript style property.<p>
043     *
044     * @param name the name of the CSS property
045     * @return the javascript property name
046     */
047    @Override
048    public String getPropertyName(String name) {
049
050        if ("float".equals(name)) {
051            return "styleFloat";
052        } else if ("class".equals(name)) {
053            return "className";
054        } else if ("for".equals(name)) {
055            return "htmlFor";
056        }
057        return name;
058    }
059
060    /**
061     * @see org.opencms.gwt.client.util.impl.DocumentStyleImpl#getComputedStyle(com.google.gwt.dom.client.Element, java.lang.String)
062     */
063    @Override
064    protected native String getComputedStyle(Element elem, String name) /*-{
065                                                                        function getComputed(elem, name) {
066                                                                        var style = elem.style;
067                                                                        var camelCase = name.replace(/\-(\w)/g, function(all, letter) {
068                                                                        return letter.toUpperCase();
069                                                                        });
070                                                                        var ret = "";
071                                                                        if (elem.currentStyle != null) {
072                                                                        ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
073                                                                        // From the awesome hack by Dean Edwards
074                                                                        // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
075                                                                        // If we're not dealing with a regular pixel number
076                                                                        // but a number that has a weird ending, we need to convert it to pixels
077                                                                        if (!/^\d+(px)?$/i.test(ret) && /^\d/.test(ret)) {
078                                                                        // Remember the original values
079                                                                        var left = style.left, rsLeft = elem.runtimeStyle.left;
080                                                                        // Put in the new values to get a computed value out
081                                                                        elem.runtimeStyle.left = elem.currentStyle.left;
082                                                                        style.left = ret || 0;
083                                                                        ret = style.pixelLeft + "px";
084                                                                        // Revert the changed values
085                                                                        style.left = left;
086                                                                        elem.runtimeStyle.left = rsLeft;
087                                                                        }
088                                                                        }
089                                                                        return ret;
090                                                                        }
091
092                                                                        if (name === "width" || name === "height") {
093
094                                                                        var which = name === "width" ? [ "Left", "Right" ] : [ "Top",
095                                                                        "Bottom" ];
096                                                                        function getWH() {
097                                                                        var val;
098                                                                        val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
099                                                                        for ( var i = 0; i < which.length; i++) {
100                                                                        val -= parseFloat(getComputed(elem, "padding" + which[i])) || 0;
101                                                                        val -= parseFloat(getComputed(elem, "border" + which[i]
102                                                                        + "Width")) || 0;
103
104                                                                        }
105                                                                        return Math.max(0, Math.round(val));
106                                                                        }
107                                                                        return getWH() + "px";
108                                                                        }
109
110                                                                        return "" + getComputed(elem, name);
111                                                                        }-*/;
112}