1/* 2 * Copyright (C) 2012 Igalia S.L. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#include "config.h" 21#include "WebKitPrivate.h" 22 23#include "ErrorsGtk.h" 24#include "WebEvent.h" 25#include "WebKitError.h" 26#include <gdk/gdk.h> 27 28unsigned wkEventModifiersToGdkModifiers(WKEventModifiers wkModifiers) 29{ 30 unsigned modifiers = 0; 31 if (wkModifiers & kWKEventModifiersShiftKey) 32 modifiers |= GDK_SHIFT_MASK; 33 if (wkModifiers & kWKEventModifiersControlKey) 34 modifiers |= GDK_CONTROL_MASK; 35 if (wkModifiers & kWKEventModifiersAltKey) 36 modifiers |= GDK_MOD1_MASK; 37 if (wkModifiers & kWKEventModifiersMetaKey) 38 modifiers |= GDK_META_MASK; 39 return modifiers; 40} 41 42unsigned toGdkModifiers(WebKit::WebEvent::Modifiers wkModifiers) 43{ 44 unsigned modifiers = 0; 45 if (wkModifiers & WebKit::WebEvent::Modifiers::ShiftKey) 46 modifiers |= GDK_SHIFT_MASK; 47 if (wkModifiers & WebKit::WebEvent::Modifiers::ControlKey) 48 modifiers |= GDK_CONTROL_MASK; 49 if (wkModifiers & WebKit::WebEvent::Modifiers::AltKey) 50 modifiers |= GDK_MOD1_MASK; 51 if (wkModifiers & WebKit::WebEvent::Modifiers::MetaKey) 52 modifiers |= GDK_META_MASK; 53 return modifiers; 54} 55 56WebKitNavigationType toWebKitNavigationType(WebCore::NavigationType type) 57{ 58 switch (type) { 59 case WebCore::NavigationType::NavigationTypeLinkClicked: 60 return WEBKIT_NAVIGATION_TYPE_LINK_CLICKED; 61 case WebCore::NavigationType::NavigationTypeFormSubmitted: 62 return WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED; 63 case WebCore::NavigationType::NavigationTypeBackForward: 64 return WEBKIT_NAVIGATION_TYPE_BACK_FORWARD; 65 case WebCore::NavigationType::NavigationTypeReload: 66 return WEBKIT_NAVIGATION_TYPE_RELOAD; 67 case WebCore::NavigationType::NavigationTypeFormResubmitted: 68 return WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED; 69 case WebCore::NavigationType::NavigationTypeOther: 70 return WEBKIT_NAVIGATION_TYPE_OTHER; 71 default: 72 ASSERT_NOT_REACHED(); 73 return WEBKIT_NAVIGATION_TYPE_OTHER; 74 } 75} 76 77unsigned toWebKitMouseButton(WebKit::WebMouseEvent::Button button) 78{ 79 switch (button) { 80 case WebKit::WebMouseEvent::Button::NoButton: 81 return 0; 82 case WebKit::WebMouseEvent::Button::LeftButton: 83 return 1; 84 case WebKit::WebMouseEvent::Button::MiddleButton: 85 return 2; 86 case WebKit::WebMouseEvent::Button::RightButton: 87 return 3; 88 } 89 ASSERT_NOT_REACHED(); 90 return 0; 91} 92 93unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton wkButton) 94{ 95 switch (wkButton) { 96 case kWKEventMouseButtonNoButton: 97 return 0; 98 case kWKEventMouseButtonLeftButton: 99 return 1; 100 case kWKEventMouseButtonMiddleButton: 101 return 2; 102 case kWKEventMouseButtonRightButton: 103 return 3; 104 } 105 ASSERT_NOT_REACHED(); 106 return 0; 107} 108 109unsigned toWebKitError(unsigned webCoreError) 110{ 111 switch (webCoreError) { 112 case WebCore::NetworkErrorFailed: 113 return WEBKIT_NETWORK_ERROR_FAILED; 114 case WebCore::NetworkErrorTransport: 115 return WEBKIT_NETWORK_ERROR_TRANSPORT; 116 case WebCore::NetworkErrorUnknownProtocol: 117 return WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL; 118 case WebCore::NetworkErrorCancelled: 119 return WEBKIT_NETWORK_ERROR_CANCELLED; 120 case WebCore::NetworkErrorFileDoesNotExist: 121 return WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST; 122 case WebCore::PolicyErrorFailed: 123 return WEBKIT_POLICY_ERROR_FAILED; 124 case WebCore::PolicyErrorCannotShowMimeType: 125 return WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE; 126 case WebCore::PolicyErrorCannotShowURL: 127 return WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI; 128 case WebCore::PolicyErrorFrameLoadInterruptedByPolicyChange: 129 return WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE; 130 case WebCore::PolicyErrorCannotUseRestrictedPort: 131 return WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT; 132 case WebCore::PluginErrorFailed: 133 return WEBKIT_PLUGIN_ERROR_FAILED; 134 case WebCore::PluginErrorCannotFindPlugin: 135 return WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN; 136 case WebCore::PluginErrorCannotLoadPlugin: 137 return WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN; 138 case WebCore::PluginErrorJavaUnavailable: 139 return WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE; 140 case WebCore::PluginErrorConnectionCancelled: 141 return WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED; 142 case WebCore::PluginErrorWillHandleLoad: 143 return WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD; 144 case WebCore::DownloadErrorNetwork: 145 return WEBKIT_DOWNLOAD_ERROR_NETWORK; 146 case WebCore::DownloadErrorCancelledByUser: 147 return WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER; 148 case WebCore::DownloadErrorDestination: 149 return WEBKIT_DOWNLOAD_ERROR_DESTINATION; 150 case WebCore::PrintErrorGeneral: 151 return WEBKIT_PRINT_ERROR_GENERAL; 152 case WebCore::PrintErrorPrinterNotFound: 153 return WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND; 154 case WebCore::PrintErrorInvalidPageRange: 155 return WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE; 156 default: 157 // This may be a user app defined error, which needs to be passed as-is. 158 return webCoreError; 159 } 160} 161 162unsigned toWebCoreError(unsigned webKitError) 163{ 164 switch (webKitError) { 165 case WEBKIT_NETWORK_ERROR_FAILED: 166 return WebCore::NetworkErrorFailed; 167 case WEBKIT_NETWORK_ERROR_TRANSPORT: 168 return WebCore::NetworkErrorTransport; 169 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL: 170 return WebCore::NetworkErrorUnknownProtocol; 171 case WEBKIT_NETWORK_ERROR_CANCELLED: 172 return WebCore::NetworkErrorCancelled; 173 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST: 174 return WebCore::NetworkErrorFileDoesNotExist; 175 case WEBKIT_POLICY_ERROR_FAILED: 176 return WebCore::PolicyErrorFailed; 177 case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE: 178 return WebCore::PolicyErrorCannotShowMimeType; 179 case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI: 180 return WebCore::PolicyErrorCannotShowURL; 181 case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE: 182 return WebCore::PolicyErrorFrameLoadInterruptedByPolicyChange; 183 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT: 184 return WebCore::PolicyErrorCannotUseRestrictedPort; 185 case WEBKIT_PLUGIN_ERROR_FAILED: 186 return WebCore::PluginErrorFailed; 187 case WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN: 188 return WebCore::PluginErrorCannotFindPlugin; 189 case WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN: 190 return WebCore::PluginErrorCannotLoadPlugin; 191 case WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE: 192 return WebCore::PluginErrorJavaUnavailable; 193 case WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED: 194 return WebCore::PluginErrorConnectionCancelled; 195 case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD: 196 return WebCore::PluginErrorWillHandleLoad; 197 case WEBKIT_DOWNLOAD_ERROR_NETWORK: 198 return WebCore::DownloadErrorNetwork; 199 case WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER: 200 return WebCore::DownloadErrorCancelledByUser; 201 case WEBKIT_DOWNLOAD_ERROR_DESTINATION: 202 return WebCore::DownloadErrorDestination; 203 case WEBKIT_PRINT_ERROR_GENERAL: 204 return WebCore::PrintErrorGeneral; 205 case WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND: 206 return WebCore::PrintErrorPrinterNotFound; 207 case WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE: 208 return WebCore::PrintErrorInvalidPageRange; 209 default: 210 // This may be a user app defined error, which needs to be passed as-is. 211 return webKitError; 212 } 213} 214