<commit_before>/*
 * File   : $Source: /alkacon/cvs/opencms/src-modules/org/opencms/gwt/client/util/impl/Attic/DocumentStyleImpl.java,v $
 * Date   : $Date: 2010/03/16 08:22:33 $
 * Version: $Revision: 1.3 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.util.impl;

import com.google.gwt.dom.client.Element;

/**
 * Helper class to retrieve the computed style of an element.<p>
 * 
 * This implementation is used for all none MSIE browsers.<p>
 * 
 * @author <NAME>
 * 
 * @version $Revision: 1.3 $
 * 
 * @since 8.0.0
 */
public class DocumentStyleImpl {

    /**
     * Transforms a CSS property name to its javascript property name (font-size >> fontSize).<p>
     * 
     * @param s the property name
     * @return the javascript property name
     */
    protected static native String camelize(String s)/*-{
        return s.replace(/\-(\w)/g, function(all, letter){
        return letter.toUpperCase();
        });
    }-*/;

    /**
     * Returns the computed style of the given element.<p>
     * 
     * @param elem the element
     * @param name the name of the CSS property 
     * @return the currently computed style
     */
    public String getCurrentStyle(Element elem, String name) {

        name = hyphenize(name);
        String propVal = getComputedStyle(elem, name, null);
        if ("opacity".equals(name) && ((propVal == null) || (propVal.trim().length() == 0))) {
            propVal = "1";
        }
        return propVal;
    }

    /**
     * Transforms the CSS style name to the name of the javascript style property.<p>
     * 
     * @param name the name of the CSS property
     * @return the javascript property name
     */
    public String getPropertyName(String name) {

        if ("float".equals(name)) {
            return "cssFloat";
        } else if ("class".equals(name)) {
            return "className";
        } else if ("for".equals(name)) {
            return "htmlFor";
        }
        return camelize(name);
    }

    /**
     * Hyphenizes the given string.<p>
     * 
     * @param name the string to hyphenize
     * @return the result
     */
    protected native String hyphenize(String name) /*-{
        return name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
    }-*/;

    /**
     * Returns the computed style from the DOM object.<p>
     * 
     * @param elem the element object
     * @param name name of the CSS property
     * @param pseudo the pseudo-element to match
     * @return the property value
     */
    private native String getComputedStyle(Element elem, String name, String pseudo) /*-{
        var cStyle = $doc.defaultView.getComputedStyle( elem, pseudo );
        return cStyle ? cStyle.getPropertyValue( name ) : null;
    }-*/;

}<commit_msg>Improved width and height detection.<commit_after>/*
 * File   : $Source: /alkacon/cvs/opencms/src-modules/org/opencms/gwt/client/util/impl/Attic/DocumentStyleImpl.java,v $
 * Date   : $Date: 2010/04/01 06:45:35 $
 * Version: $Revision: 1.4 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.util.impl;

import com.google.gwt.dom.client.Element;

/**
 * Helper class to retrieve the computed style of an element.<p>
 * 
 * This implementation is used for all none MSIE browsers.<p>
 * 
 * @author <NAME>
 * 
 * @version $Revision: 1.4 $
 * 
 * @since 8.0.0
 */
public class DocumentStyleImpl {

    /**
     * Transforms a CSS property name to its javascript property name (font-size >> fontSize).<p>
     * 
     * @param s the property name
     * @return the javascript property name
     */
    protected static native String camelize(String s)/*-{
        return s.replace(/\-(\w)/g, function(all, letter){
        return letter.toUpperCase();
        });
    }-*/;

    /**
     * Returns the computed style of the given element.<p>
     * 
     * @param elem the element
     * @param name the name of the CSS property 
     * @return the currently computed style
     */
    public String getCurrentStyle(Element elem, String name) {

        name = hyphenize(name);
        String propVal = getComputedStyle(elem, name, null);
        if ("opacity".equals(name) && ((propVal == null) || (propVal.trim().length() == 0))) {
            propVal = "1";
        }
        return propVal;
    }

    /**
     * Transforms the CSS style name to the name of the javascript style property.<p>
     * 
     * @param name the name of the CSS property
     * @return the javascript property name
     */
    public String getPropertyName(String name) {

        if ("float".equals(name)) {
            return "cssFloat";
        } else if ("class".equals(name)) {
            return "className";
        } else if ("for".equals(name)) {
            return "htmlFor";
        }
        return camelize(name);
    }

    /**
     * Hyphenizes the given string.<p>
     * 
     * @param name the string to hyphenize
     * @return the result
     */
    protected native String hyphenize(String name) /*-{
        return name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
    }-*/;

    /**
     * Returns the computed style from the DOM object.<p>
     * 
     * @param elem the element object
     * @param name name of the CSS property
     * @param pseudo the pseudo-element to match
     * @return the property value
     */
    private native String getComputedStyle(Element elem, String name, String pseudo) /*-{
        var cStyle = $doc.defaultView.getComputedStyle( elem, pseudo );
        if (cStyle==null){
        return null;
        }
        var value=cStyle.getPropertyValue( name );
        if (value=="auto" && (name=="width" || name=="height")){
        var which = name === "width" ? ["Left", "Right"] : ["Top", "Bottom"];
        function getWH() {
        var val;
        val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
        for (var i=0; i<which.length; i++){
        val -= parseFloat(getComputed( elem, "padding" + which[i])) || 0;
        val -= parseFloat(getComputed( elem, "border" + which[i] + "Width")) || 0;

        }
        return Math.max(0, Math.round(val));
        }
        value= getWH()+"px";
        }

        return value;
    }-*/;

}
{'fraction_non_alphanumeric': 0.11646055949093528, 'fraction_numerical': 0.012006243246488173, 'mean_word_length': 2.5431731178222035, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6720935', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2350, 'n_words': 856}