00001 /* 00002 * CPCompatibility.j 00003 * AppKit 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2008, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 @import "CPEvent.j" 00024 00025 // Browser Engines 00026 CPUnknownBrowserEngine = 0; 00027 CPGeckoBrowserEngine = 1; 00028 CPInternetExplorerBrowserEngine = 2; 00029 CPKHTMLBrowserEngine = 3; 00030 CPOperaBrowserEngine = 4; 00031 CPWebKitBrowserEngine = 5; 00032 00033 // Features 00034 CPCSSRGBAFeature = 1 << 5; 00035 00036 CPHTMLCanvasFeature = 1 << 6; 00037 CPHTMLContentEditableFeature = 1 << 7; 00038 00039 CPJavascriptInnerTextFeature = 1 << 8; 00040 CPJavascriptTextContentFeature = 1 << 9; 00041 CPJavascriptClipboardEventsFeature = 1 << 10; 00042 CPJavascriptClipboardAccessFeature = 1 << 11; 00043 CPJavaScriptCanvasDrawFeature = 1 << 12; 00044 CPJavaScriptCanvasTransformFeature = 1 << 13; 00045 00046 CPVMLFeature = 1 << 14; 00047 00048 CPJavascriptRemedialKeySupport = 1 << 15; 00049 CPJavaScriptShadowFeature = 1 << 20; 00050 00051 CPJavaScriptNegativeMouseWheelValues = 1 << 22; 00052 CPJavaScriptMouseWheelValues_8_15 = 1 << 23 00053 00054 CPOpacityRequiresFilterFeature = 1 << 24; 00055 00056 //Internet explorer does not allow dynamically changing the type of an input element 00057 CPInputTypeCanBeChangedFeature = 1 << 25; 00058 00059 00060 00061 var USER_AGENT = "", 00062 PLATFORM_ENGINE = CPUnknownBrowserEngine, 00063 PLATFORM_FEATURES = 0; 00064 00065 // default these features to true 00066 00067 PLATFORM_FEATURES |= CPInputTypeCanBeChangedFeature; 00068 00069 if (typeof window != "undfined" && typeof window.navigator != "undefined") 00070 USER_AGENT = window.navigator.userAgent; 00071 00072 // Opera 00073 if (window.opera) 00074 { 00075 PLATFORM_ENGINE = CPOperaBrowserEngine; 00076 00077 PLATFORM_FEATURES |= CPJavaScriptCanvasDrawFeature; 00078 } 00079 00080 // Internet Explorer 00081 else if (window.attachEvent) // Must follow Opera check. 00082 { 00083 PLATFORM_ENGINE = CPInternetExplorerBrowserEngine; 00084 00085 // Features we can only be sure of with IE (no known independent tests) 00086 PLATFORM_FEATURES |= CPVMLFeature; 00087 PLATFORM_FEATURES |= CPJavascriptRemedialKeySupport; 00088 PLATFORM_FEATURES |= CPJavaScriptShadowFeature; 00089 00090 PLATFORM_FEATURES |= CPOpacityRequiresFilterFeature; 00091 00092 PLATFORM_FEATURES &= ~CPInputTypeCanBeChangedFeature; 00093 } 00094 00095 // WebKit 00096 else if (USER_AGENT.indexOf("AppleWebKit/") != -1) 00097 { 00098 PLATFORM_ENGINE = CPWebKitBrowserEngine; 00099 00100 // Features we can only be sure of with WebKit (no known independent tests) 00101 PLATFORM_FEATURES |= CPCSSRGBAFeature; 00102 PLATFORM_FEATURES |= CPHTMLContentEditableFeature; 00103 PLATFORM_FEATURES |= CPJavascriptClipboardEventsFeature; 00104 PLATFORM_FEATURES |= CPJavascriptClipboardAccessFeature; 00105 PLATFORM_FEATURES |= CPJavaScriptShadowFeature; 00106 00107 var versionStart = USER_AGENT.indexOf("AppleWebKit/") + "AppleWebKit/".length, 00108 versionEnd = USER_AGENT.indexOf(" ", versionStart), 00109 version = parseFloat(USER_AGENT.substring(versionStart, versionEnd), 10); 00110 00111 if(USER_AGENT.indexOf("Plainview") == -1 && version >= 525.14 || USER_AGENT.indexOf("Chrome") != -1) 00112 PLATFORM_FEATURES |= CPJavascriptRemedialKeySupport; 00113 } 00114 00115 // KHTML 00116 else if (USER_AGENT.indexOf("KHTML") != -1) // Must follow WebKit check. 00117 { 00118 PLATFORM_ENGINE = CPKHTMLBrowserEngine; 00119 } 00120 00121 // Gecko 00122 else if (USER_AGENT.indexOf("Gecko") !== -1) // Must follow KHTML check. 00123 { 00124 PLATFORM_ENGINE = CPGeckoBrowserEngine; 00125 00126 PLATFORM_FEATURES |= CPJavaScriptCanvasDrawFeature; 00127 00128 var index = USER_AGENT.indexOf("Firefox"), 00129 version = (index === -1) ? 2.0 : parseFloat(USER_AGENT.substring(index + "Firefox".length + 1)); 00130 00131 if (version >= 3.0) 00132 PLATFORM_FEATURES |= CPCSSRGBAFeature; 00133 00134 if (version < 3.0) 00135 PLATFORM_FEATURES |= CPJavaScriptMouseWheelValues_8_15; 00136 } 00137 00138 // Feature Specific Checks 00139 if (typeof document != "undefined") 00140 { 00141 var canvasElement = document.createElement("canvas"); 00142 // Detect Canvas Support 00143 if (canvasElement && canvasElement.getContext) 00144 { 00145 PLATFORM_FEATURES |= CPHTMLCanvasFeature; 00146 00147 // Detect Canvas setTransform/transform support 00148 var context = document.createElement("canvas").getContext("2d"); 00149 00150 if (context && context.setTransform && context.transform) 00151 PLATFORM_FEATURES |= CPJavaScriptCanvasTransformFeature; 00152 } 00153 00154 var DOMElement = document.createElement("div"); 00155 00156 // Detect whether we have innerText or textContent (or neither) 00157 if (DOMElement.innerText != undefined) 00158 PLATFORM_FEATURES |= CPJavascriptInnerTextFeature; 00159 else if (DOMElement.textContent != undefined) 00160 PLATFORM_FEATURES |= CPJavascriptTextContentFeature; 00161 } 00162 00163 function CPFeatureIsCompatible(aFeature) 00164 { 00165 return PLATFORM_FEATURES & aFeature; 00166 } 00167 00168 function CPBrowserIsEngine(anEngine) 00169 { 00170 return PLATFORM_ENGINE == anEngine; 00171 } 00172 00173 if (USER_AGENT.indexOf("Mac") != -1) 00174 { 00175 CPPlatformActionKeyMask = CPCommandKeyMask; 00176 00177 CPUndoKeyEquivalent = @"Z"; 00178 CPRedoKeyEquivalent = @"Z"; 00179 00180 CPUndoKeyEquivalentModifierMask = CPCommandKeyMask; 00181 CPRedoKeyEquivalentModifierMask = CPCommandKeyMask | CPShiftKeyMask; 00182 } 00183 else 00184 { 00185 CPPlatformActionKeyMask = CPControlKeyMask; 00186 00187 CPUndoKeyEquivalent = @"Z"; 00188 CPRedoKeyEquivalent = @"Y"; 00189 00190 CPUndoKeyEquivalentModifierMask = CPControlKeyMask; 00191 CPRedoKeyEquivalentModifierMask = CPControlKeyMask; 00192 }