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 00053 CPOpacityRequiresFilterFeature = 1 << 23; 00054 00055 var USER_AGENT = ""; 00056 00057 PLATFORM_ENGINE = CPUnknownBrowserEngine, 00058 PLATFORM_FEATURES = 0; 00059 00060 if (typeof window != "undfined" && typeof window.navigator != "undefined") 00061 USER_AGENT = window.navigator.userAgent; 00062 00063 // Opera 00064 if (window.opera) 00065 { 00066 PLATFORM_ENGINE = CPOperaBrowserEngine; 00067 00068 PLATFORM_FEATURES |= CPJavaScriptCanvasDrawFeature; 00069 } 00070 00071 // Internet Explorer 00072 else if (window.attachEvent) // Must follow Opera check. 00073 { 00074 PLATFORM_ENGINE = CPInternetExplorerBrowserEngine; 00075 00076 // Features we can only be sure of with IE (no known independent tests) 00077 PLATFORM_FEATURES |= CPVMLFeature; 00078 PLATFORM_FEATURES |= CPJavascriptRemedialKeySupport; 00079 PLATFORM_FEATURES |= CPJavaScriptShadowFeature; 00080 00081 PLATFORM_FEATURES |= CPOpacityRequiresFilterFeature; 00082 } 00083 00084 // WebKit 00085 else if (USER_AGENT.indexOf("AppleWebKit/") != -1) 00086 { 00087 PLATFORM_ENGINE = CPWebKitBrowserEngine; 00088 00089 // Features we can only be sure of with WebKit (no known independent tests) 00090 PLATFORM_FEATURES |= CPCSSRGBAFeature; 00091 PLATFORM_FEATURES |= CPHTMLContentEditableFeature; 00092 PLATFORM_FEATURES |= CPJavascriptClipboardEventsFeature; 00093 PLATFORM_FEATURES |= CPJavascriptClipboardAccessFeature; 00094 PLATFORM_FEATURES |= CPJavaScriptShadowFeature; 00095 00096 var versionStart = USER_AGENT.indexOf("AppleWebKit/") + "AppleWebKit/".length, 00097 versionEnd = USER_AGENT.indexOf(" ", versionStart), 00098 version = parseFloat(USER_AGENT.substring(versionStart, versionEnd), 10); 00099 00100 if(USER_AGENT.indexOf("Plainview") == -1 && version >= 525.14 || USER_AGENT.indexOf("Chrome") != -1) 00101 PLATFORM_FEATURES |= CPJavascriptRemedialKeySupport; 00102 } 00103 00104 // KHTML 00105 else if (USER_AGENT.indexOf("KHTML") != -1) // Must follow WebKit check. 00106 { 00107 PLATFORM_ENGINE = CPKHTMLBrowserEngine; 00108 } 00109 00110 // Gecko 00111 else if (USER_AGENT.indexOf("Gecko") != -1) // Must follow KHTML check. 00112 { 00113 PLATFORM_ENGINE = CPGeckoBrowserEngine; 00114 00115 PLATFORM_FEATURES |= CPJavaScriptCanvasDrawFeature; 00116 00117 var index = USER_AGENT.indexOf("Firefox"), 00118 version = (index == -1) ? 2.0 : parseFloat(USER_AGENT.substring(index+"Firefox".length+1)); 00119 00120 if (version >= 3.0) 00121 PLATFORM_FEATURES |= CPCSSRGBAFeature; 00122 } 00123 00124 // Feature Specific Checks 00125 if (typeof document != "undefined") 00126 { 00127 var canvasElement = document.createElement("canvas"); 00128 // Detect Canvas Support 00129 if (canvasElement && canvasElement.getContext) 00130 { 00131 PLATFORM_FEATURES |= CPHTMLCanvasFeature; 00132 00133 // Detect Canvas setTransform/transform support 00134 var context = document.createElement("canvas").getContext("2d"); 00135 00136 if (context && context.setTransform && context.transform) 00137 PLATFORM_FEATURES |= CPJavaScriptCanvasTransformFeature; 00138 } 00139 00140 var DOMElement = document.createElement("div"); 00141 00142 // Detect whether we have innerText or textContent (or neither) 00143 if (DOMElement.innerText != undefined) 00144 PLATFORM_FEATURES |= CPJavascriptInnerTextFeature; 00145 else if (DOMElement.textContent != undefined) 00146 PLATFORM_FEATURES |= CPJavascriptTextContentFeature; 00147 } 00148 00149 function CPFeatureIsCompatible(aFeature) 00150 { 00151 return PLATFORM_FEATURES & aFeature; 00152 } 00153 00154 function CPBrowserIsEngine(anEngine) 00155 { 00156 return PLATFORM_ENGINE == anEngine; 00157 } 00158 00159 if (USER_AGENT.indexOf("Mac") != -1) 00160 { 00161 CPPlatformActionKeyMask = CPCommandKeyMask; 00162 00163 CPUndoKeyEquivalent = @"Z"; 00164 CPRedoKeyEquivalent = @"Z"; 00165 00166 CPUndoKeyEquivalentModifierMask = CPCommandKeyMask; 00167 CPRedoKeyEquivalentModifierMask = CPCommandKeyMask | CPShiftKeyMask; 00168 } 00169 else 00170 { 00171 CPPlatformActionKeyMask = CPControlKeyMask; 00172 00173 CPUndoKeyEquivalent = @"Z"; 00174 CPRedoKeyEquivalent = @"Y"; 00175 00176 CPUndoKeyEquivalentModifierMask = CPControlKeyMask; 00177 CPRedoKeyEquivalentModifierMask = CPControlKeyMask; 00178 }