001    /*
002     * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package asquare.gwt.tk.client.util.impl;
017    
018    public class DomUtilImpl
019    {
020            private static final boolean QUIRKS_MODE = isQuirksMode0();
021            private static final boolean MAC = isMac0();
022            private static final boolean WIN = isWin0();
023            
024            public native int getViewportWidth() /*-{
025                    if (@asquare.gwt.tk.client.util.impl.DomUtilImpl::QUIRKS_MODE)
026                    {
027                            return $doc.body.clientWidth;
028                    }
029                    return $doc.documentElement.clientWidth;
030            }-*/;
031            
032            public native int getViewportHeight() /*-{
033                    if (@asquare.gwt.tk.client.util.impl.DomUtilImpl::QUIRKS_MODE)
034                    {
035                            return $doc.body.clientHeight;
036                    }
037                    return $doc.documentElement.clientHeight;
038            }-*/;
039            
040            public native int getDocumentScrollWidth() /*-{
041                    if (@asquare.gwt.tk.client.util.impl.DomUtilImpl::QUIRKS_MODE)
042                    {
043                            return $doc.body.scrollWidth;
044                    }
045                    return $doc.documentElement.scrollWidth;
046            }-*/;
047            
048            public native int getDocumentScrollHeight() /*-{
049                    if (@asquare.gwt.tk.client.util.impl.DomUtilImpl::QUIRKS_MODE)
050                    {
051                            return $doc.body.scrollHeight;
052                    }
053                    return $doc.documentElement.scrollHeight;
054            }-*/;
055            
056            public boolean isQuirksMode()
057            {
058                    return QUIRKS_MODE;
059            }
060            
061            private static native boolean isQuirksMode0() /*-{
062                    return $doc.compatMode == "BackCompat";
063            }-*/;
064            
065            public boolean isMac()
066            {
067                    return MAC;
068            }
069            
070            private static native boolean isMac0() /*-{
071                    return navigator.userAgent.toLowerCase().indexOf("mac") != -1;
072            }-*/;
073            
074            public boolean isWin()
075            {
076                    return WIN;
077            }
078            
079            private static native boolean isWin0() /*-{
080                    return navigator.userAgent.toLowerCase().indexOf("win") != -1;
081            }-*/;
082    }