diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
commit | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (patch) | |
tree | 52599cd0ab782b1768e23ad176f7618f98333cb6 /Source/WebKit2/UIProcess/API | |
parent | cd44dc59cdfc39534aef4d417e9f3c412e3be139 (diff) | |
download | qtwebkit-03e12282df9aa1e1fb05a8b90f1cfc2e08764cec.tar.gz |
Imported WebKit commit e09a82039aa4273ab318b71122e92d8e5f233525 (http://svn.webkit.org/repository/webkit/trunk@107223)
Diffstat (limited to 'Source/WebKit2/UIProcess/API')
59 files changed, 1375 insertions, 530 deletions
diff --git a/Source/WebKit2/UIProcess/API/C/WKNotification.cpp b/Source/WebKit2/UIProcess/API/C/WKNotification.cpp index db7d1f02f..634aa9824 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotification.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKNotification.cpp @@ -47,6 +47,11 @@ WKStringRef WKNotificationCopyBody(WKNotificationRef notification) return toCopiedAPI(toImpl(notification)->body()); } +WKStringRef WKNotificationCopyIconURL(WKNotificationRef notification) +{ + return toCopiedAPI(toImpl(notification)->iconURL()); +} + WKSecurityOriginRef WKNotificationGetSecurityOrigin(WKNotificationRef notification) { return toAPI(toImpl(notification)->origin()); diff --git a/Source/WebKit2/UIProcess/API/C/WKNotification.h b/Source/WebKit2/UIProcess/API/C/WKNotification.h index 07311af3f..7c2723896 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotification.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotification.h @@ -36,6 +36,7 @@ WK_EXPORT WKTypeID WKNotificationGetTypeID(); WK_EXPORT WKStringRef WKNotificationCopyTitle(WKNotificationRef notification); WK_EXPORT WKStringRef WKNotificationCopyBody(WKNotificationRef notification); +WK_EXPORT WKStringRef WKNotificationCopyIconURL(WKNotificationRef notification); WK_EXPORT WKSecurityOriginRef WKNotificationGetSecurityOrigin(WKNotificationRef notification); WK_EXPORT uint64_t WKNotificationGetID(WKNotificationRef notification); diff --git a/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h b/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h index 42a4beb92..bc99ec9b0 100644 --- a/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h +++ b/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h @@ -38,6 +38,7 @@ typedef void (*WKNotificationProviderDidDestroyNotificationCallback)(WKNotificat typedef void (*WKNotificationProviderAddNotificationManagerCallback)(WKNotificationManagerRef manager, const void* clientInfo); typedef void (*WKNotificationProviderRemoveNotificationManagerCallback)(WKNotificationManagerRef manager, const void* clientInfo); typedef WKDictionaryRef (*WKNotificationProviderNotificationPermissionsCallback)(const void* clientInfo); +typedef void (*WKNotificationProviderClearNotificationsCallback)(WKArrayRef notificationIDs, const void* clientInfo); struct WKNotificationProvider { int version; @@ -48,6 +49,7 @@ struct WKNotificationProvider { WKNotificationProviderAddNotificationManagerCallback addNotificationManager; WKNotificationProviderRemoveNotificationManagerCallback removeNotificationManager; WKNotificationProviderNotificationPermissionsCallback notificationPermissions; + WKNotificationProviderClearNotificationsCallback clearNotifications; }; typedef struct WKNotificationProvider WKNotificationProvider; diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp index 60e7b7264..521e6d4a0 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp @@ -52,6 +52,12 @@ WKPreferencesRef WKPreferencesCreateWithIdentifier(WKStringRef identifierRef) return toAPI(preferences.release().leakRef()); } +WKPreferencesRef WKPreferencesCreateCopy(WKPreferencesRef preferencesRef) +{ + RefPtr<WebPreferences> preferences = WebPreferences::create(*toImpl(preferencesRef)); + return toAPI(preferences.release().leakRef()); +} + void WKPreferencesSetJavaScriptEnabled(WKPreferencesRef preferencesRef, bool javaScriptEnabled) { toImpl(preferencesRef)->setJavaScriptEnabled(javaScriptEnabled); diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h b/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h index 3208c6ea3..9153ccab8 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h @@ -52,6 +52,9 @@ enum WKEditableLinkBehavior { }; typedef enum WKEditableLinkBehavior WKEditableLinkBehavior; +// Creates a copy with no identifier. +WK_EXPORT WKPreferencesRef WKPreferencesCreateCopy(WKPreferencesRef); + // Defaults to kWKFontSmoothingLevelWindows on Windows, kWKFontSmoothingLevelMedium on other platforms. WK_EXPORT void WKPreferencesSetFontSmoothingLevel(WKPreferencesRef, WKFontSmoothingLevel); WK_EXPORT WKFontSmoothingLevel WKPreferencesGetFontSmoothingLevel(WKPreferencesRef); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h b/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h new file mode 100644 index 000000000..f85bf31bd --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitEditingCommands_h +#define WebKitEditingCommands_h + +G_BEGIN_DECLS + +/** + * WEBKIT_EDITING_COMMAND_CUT: + * + * The cut clipboard command. Copies the current selection inside + * a #WebKitWebView to the clipboard and deletes the selected content. + * You can check whether it's possible to execute the command with + * webkit_web_view_can_execute_editing_command(). In general it's + * possible to cut to the clipboard when the #WebKitWebView content is + * editable and there is an active selection. + */ +#define WEBKIT_EDITING_COMMAND_CUT "Cut" + +/** + * WEBKIT_EDITING_COMMAND_COPY: + * + * The copy clipboard command. Copies the current selection inside + * a #WebKitWebView to the clipboard. + * You can check whether it's possible to execute the command with + * webkit_web_view_can_execute_editing_command(). In general it's + * possible to copy to the clipboard when there is an active selection + * inside the #WebKitWebView. + */ +#define WEBKIT_EDITING_COMMAND_COPY "Copy" + +/** + * WEBKIT_EDITING_COMMAND_PASTE: + * + * The paste clipboard command. Pastes the contents of the clipboard to + * a #WebKitWebView. + * You can check whether it's possible to execute the command with + * webkit_web_view_can_execute_editing_command(). In general it's possible + * to paste from the clipboard when the #WebKitWebView content is editable + * and clipboard is not empty. + */ +#define WEBKIT_EDITING_COMMAND_PASTE "Paste" + + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp index 61757d428..87fe90799 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp @@ -23,6 +23,7 @@ #include "WebKitNavigationPolicyDecisionPrivate.h" #include "WebKitPolicyDecision.h" #include "WebKitPrivate.h" +#include "WebKitResponsePolicyDecisionPrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" #include <wtf/gobject/GRefPtr.h> @@ -57,6 +58,15 @@ static void decidePolicyForNewWindowActionCallback(WKPageRef page, WKFrameRef fr WEBKIT_POLICY_DECISION(decision.get())); } +static void decidePolicyForResponseCallback(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo) +{ + GRefPtr<WebKitResponsePolicyDecision> decision = + adoptGRef(webkitResponsePolicyDecisionCreate(request, response, listener)); + webkitWebViewMakePolicyDecision(WEBKIT_WEB_VIEW(clientInfo), + WEBKIT_POLICY_DECISION_TYPE_RESPONSE, + WEBKIT_POLICY_DECISION(decision.get())); +} + void attachPolicyClientToPage(WebKitWebView* webView) { WKPagePolicyClient policyClient = { @@ -64,7 +74,7 @@ void attachPolicyClientToPage(WebKitWebView* webView) webView, // clientInfo decidePolicyForNavigationActionCallback, decidePolicyForNewWindowActionCallback, - 0, // decidePolicyForResponseCallback, + decidePolicyForResponseCallback, 0, // unableToImplementPolicy }; WKPageSetPagePolicyClient(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))), &policyClient); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h index 13280d600..c44d877e0 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h @@ -33,9 +33,9 @@ #include <glib.h> #include <wtf/Assertions.h> -#define WEBKIT_PARAM_READABLE (static_cast<GParamFlags>(G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) -#define WEBKIT_PARAM_WRITABLE (static_cast<GParamFlags>(G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) -#define WEBKIT_PARAM_READWRITE (static_cast<GParamFlags>(G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_READABLE (static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_WRITABLE (static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_READWRITE (static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)) #define COMPILE_ASSERT_MATCHING_ENUM(webkitName, webcoreName) \ COMPILE_ASSERT(int(webkitName) == int(webcoreName), mismatchingEnums) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp new file mode 100644 index 000000000..adfcdfdd7 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitResponsePolicyDecision.h" + +#include "WebKitPolicyDecisionPrivate.h" +#include "WebKitPrivate.h" +#include "WebKitURIRequestPrivate.h" +#include "WebKitURIResponsePrivate.h" +#include "WebURLRequest.h" +#include "WebURLResponse.h" +#include <glib/gi18n-lib.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/CString.h> + +using namespace WebKit; + +/** + * SECTION: WebKitResponsePolicyDecision + * @Short_description: A policy decision for resource responses + * @Title: WebKitResponsePolicyDecision + * @See_also: #WebKitPolicyDecision, #WebKitWebView + * + * WebKitResponsePolicyDecision represents a policy decision for a + * resource response, whether from the network or the local system. + * A very common usecase for these types of decision is deciding + * whether or not to download a particular resource or to load it + * normally. + */ +G_DEFINE_TYPE(WebKitResponsePolicyDecision, webkit_response_policy_decision, WEBKIT_TYPE_POLICY_DECISION) + +struct _WebKitResponsePolicyDecisionPrivate { + GRefPtr<WebKitURIRequest> request; + GRefPtr<WebKitURIResponse> response; +}; + +enum { + PROP_0, + PROP_REQUEST, + PROP_RESPONSE, +}; + +static void webkit_response_policy_decision_init(WebKitResponsePolicyDecision* decision) +{ + decision->priv = G_TYPE_INSTANCE_GET_PRIVATE(decision, WEBKIT_TYPE_RESPONSE_POLICY_DECISION, WebKitResponsePolicyDecisionPrivate); + new (decision->priv) WebKitResponsePolicyDecisionPrivate(); +} + +static void webkitResponsePolicyDecisionFinalize(GObject* object) +{ + WEBKIT_RESPONSE_POLICY_DECISION(object)->priv->~WebKitResponsePolicyDecisionPrivate(); + G_OBJECT_CLASS(webkit_response_policy_decision_parent_class)->finalize(object); +} + +static void webkitResponsePolicyDecisionGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitResponsePolicyDecision* decision = WEBKIT_RESPONSE_POLICY_DECISION(object); + switch (propId) { + case PROP_REQUEST: + g_value_set_object(value, webkit_response_policy_decision_get_request(decision)); + break; + case PROP_RESPONSE: + g_value_set_object(value, webkit_response_policy_decision_get_response(decision)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + break; + } +} + +static void webkit_response_policy_decision_class_init(WebKitResponsePolicyDecisionClass* decisionClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(decisionClass); + objectClass->finalize = webkitResponsePolicyDecisionFinalize; + objectClass->get_property = webkitResponsePolicyDecisionGetProperty; + g_type_class_add_private(decisionClass, sizeof(WebKitResponsePolicyDecisionPrivate)); + + /** + * WebKitResponsePolicyDecision:request: + * + * This property contains the #WebKitURIRequest associated with this + * policy decision. + */ + g_object_class_install_property(objectClass, + PROP_REQUEST, + g_param_spec_object("request", + _("Response URI request"), + _("The URI request that is associated with this policy decision"), + WEBKIT_TYPE_URI_REQUEST, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitResponsePolicyDecision:response: + * + * This property contains the #WebKitURIResponse associated with this + * policy decision. + */ + g_object_class_install_property(objectClass, + PROP_REQUEST, + g_param_spec_object("response", + _("URI response"), + _("The URI response that is associated with this policy decision"), + WEBKIT_TYPE_URI_REQUEST, + WEBKIT_PARAM_READABLE)); + +} + +/** + * webkit_response_policy_decision_get_request: + * @decision: a #WebKitResponsePolicyDecision + * + * Gets the value of the #WebKitResponsePolicyDecision:request property. + * + * Returns: (transfer none): The URI request that is associated with this policy decision. + */ +WebKitURIRequest* webkit_response_policy_decision_get_request(WebKitResponsePolicyDecision* decision) +{ + g_return_val_if_fail(WEBKIT_IS_RESPONSE_POLICY_DECISION(decision), 0); + return decision->priv->request.get(); +} + +/** + * webkit_response_policy_decision_get_response: + * @decision: a #WebKitResponsePolicyDecision + * + * Gets the value of the #WebKitResponsePolicyDecision:response property. + * + * Returns: (transfer none): The URI response that is associated with this policy decision. + */ +WebKitURIResponse* webkit_response_policy_decision_get_response(WebKitResponsePolicyDecision* decision) +{ + g_return_val_if_fail(WEBKIT_IS_RESPONSE_POLICY_DECISION(decision), 0); + return decision->priv->response.get(); +} + +WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(WKURLRequestRef request, WKURLResponseRef response, WKFramePolicyListenerRef listener) +{ + WebKitResponsePolicyDecision* decision = WEBKIT_RESPONSE_POLICY_DECISION(g_object_new(WEBKIT_TYPE_RESPONSE_POLICY_DECISION, NULL)); + decision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(toImpl(request)->resourceRequest())); + decision->priv->response = adoptGRef(webkitURIResponseCreateForResourceResponse(toImpl(response)->resourceResponse())); + webkitPolicyDecisionSetListener(WEBKIT_POLICY_DECISION(decision), listener); + return decision; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.h b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.h new file mode 100644 index 000000000..7653fcc14 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitResponsePolicyDecision_h +#define WebKitResponsePolicyDecision_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitPolicyDecision.h> +#include <webkit2/WebKitURIResponse.h> +#include <webkit2/WebKitURIRequest.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_RESPONSE_POLICY_DECISION (webkit_response_policy_decision_get_type()) +#define WEBKIT_RESPONSE_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_RESPONSE_POLICY_DECISION, WebKitResponsePolicyDecision)) +#define WEBKIT_RESPONSE_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_RESPONSE_POLICY_DECISION, WebKitResponsePolicyDecisionClass)) +#define WEBKIT_IS_RESPONSE_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_RESPONSE_POLICY_DECISION)) +#define WEBKIT_IS_RESPONSE_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_RESPONSE_POLICY_DECISION)) +#define WEBKIT_RESPONSE_POLICY_DECISION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_RESPONSE_POLICY_DECISION, WebKitResponsePolicyDecisionClass)) + +typedef struct _WebKitResponsePolicyDecision WebKitResponsePolicyDecision; +typedef struct _WebKitResponsePolicyDecisionClass WebKitResponsePolicyDecisionClass; +typedef struct _WebKitResponsePolicyDecisionPrivate WebKitResponsePolicyDecisionPrivate; + +struct _WebKitResponsePolicyDecision { + WebKitPolicyDecision parent; + + /*< private >*/ + WebKitResponsePolicyDecisionPrivate *priv; +}; + +struct _WebKitResponsePolicyDecisionClass { + WebKitPolicyDecisionClass parent_class; +}; + +WEBKIT_API GType +webkit_response_policy_decision_get_type (void); + +WEBKIT_API WebKitURIRequest * +webkit_response_policy_decision_get_request (WebKitResponsePolicyDecision *decision); + +WEBKIT_API WebKitURIResponse * +webkit_response_policy_decision_get_response (WebKitResponsePolicyDecision *decision); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h new file mode 100644 index 000000000..b508aa525 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitResponsePolicyDecisionPrivate_h +#define WebKitResponsePolicyDecisionPrivate_h + +#include "WebKitPrivate.h" +#include "WebKitResponsePolicyDecision.h" + +WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(WKURLRequestRef, WKURLResponseRef, WKFramePolicyListenerRef); + +#endif // WebKitResponsePolicyDecisionPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp index 06418613d..774f17190 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp @@ -101,7 +101,8 @@ enum { PROP_ENABLE_DNS_PREFETCHING, PROP_ENABLE_CARET_BROWSING, PROP_ENABLE_FULLSCREEN, - PROP_PRINT_BACKGROUNDS + PROP_PRINT_BACKGROUNDS, + PROP_ENABLE_WEBAUDIO }; static void webKitSettingsSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) @@ -202,6 +203,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu case PROP_PRINT_BACKGROUNDS: webkit_settings_set_print_backgrounds(settings, g_value_get_boolean(value)); break; + case PROP_ENABLE_WEBAUDIO: + webkit_settings_set_enable_webaudio(settings, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -306,6 +310,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val case PROP_PRINT_BACKGROUNDS: g_value_set_boolean(value, webkit_settings_get_print_backgrounds(settings)); break; + case PROP_ENABLE_WEBAUDIO: + g_value_set_boolean(value, webkit_settings_get_enable_webaudio(settings)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -768,6 +775,25 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass) TRUE, readWriteConstructParamFlags)); + /** + * WebKitSettings:enable-webaudio: + * + * + * Enable or disable support for WebAudio on pages. WebAudio is an + * experimental proposal for allowing web pages to generate Audio + * WAVE data from JavaScript. The standard is currently a + * work-in-progress by the W3C Audio Working Group. + * + * See also https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html + */ + g_object_class_install_property(gObjectClass, + PROP_ENABLE_WEBAUDIO, + g_param_spec_boolean("enable-webaudio", + _("Enable WebAudio"), + _("Whether WebAudio content should be handled"), + FALSE, + readWriteConstructParamFlags)); + g_type_class_add_private(klass, sizeof(WebKitSettingsPrivate)); } @@ -1955,3 +1981,38 @@ void webkit_settings_set_print_backgrounds(WebKitSettings* settings, gboolean pr WKPreferencesSetShouldPrintBackgrounds(priv->preferences.get(), printBackgrounds); g_object_notify(G_OBJECT(settings), "print-backgrounds"); } + +/** + * webkit_settings_get_enable_webaudio: + * @settings: a #WebKitSettings + * + * Get the #WebKitSettings:enable-webaudio property. + * + * Returns: %TRUE If webaudio support is enabled or %FALSE otherwise. + */ +gboolean webkit_settings_get_enable_webaudio(WebKitSettings* settings) +{ + g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE); + + return WKPreferencesGetWebAudioEnabled(settings->priv->preferences.get()); +} + +/** + * webkit_settings_set_enable_webaudio: + * @settings: a #WebKitSettings + * @enabled: Value to be set + * + * Set the #WebKitSettings:enable-webaudio property. + */ +void webkit_settings_set_enable_webaudio(WebKitSettings* settings, gboolean enabled) +{ + g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); + + WebKitSettingsPrivate* priv = settings->priv; + bool currentValue = WKPreferencesGetWebAudioEnabled(priv->preferences.get()); + if (currentValue == enabled) + return; + + WKPreferencesSetWebAudioEnabled(priv->preferences.get(), enabled); + g_object_notify(G_OBJECT(settings), "enable-webaudio"); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h index a6769fc0e..27cb7c75a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h @@ -293,6 +293,13 @@ WEBKIT_API void webkit_settings_set_print_backgrounds (WebKitSettings *settings, gboolean print_backgrounds); +WEBKIT_API gboolean +webkit_settings_get_enable_webaudio (WebKitSettings *settings); + +WEBKIT_API void +webkit_settings_set_enable_webaudio (WebKitSettings *settings, + gboolean enabled); + G_END_DECLS #endif /* WebKitSettings_h */ diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index fcaa2db1d..c3accccbb 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -27,13 +27,13 @@ #include "WebKitLoaderClient.h" #include "WebKitMarshal.h" #include "WebKitPolicyClient.h" +#include "WebKitPrivate.h" #include "WebKitSettingsPrivate.h" #include "WebKitUIClient.h" #include "WebKitWebContextPrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" #include "WebKitWindowPropertiesPrivate.h" -#include "WebKitPrivate.h" #include "WebPageProxy.h" #include <WebCore/DragIcon.h> #include <WebCore/GtkUtilities.h> @@ -180,9 +180,11 @@ static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue WebKitWebView* webView = WEBKIT_WEB_VIEW(object); switch (propId) { - case PROP_WEB_CONTEXT: - webView->priv->context = WEBKIT_WEB_CONTEXT(g_value_get_object(value)); + case PROP_WEB_CONTEXT: { + gpointer webContext = g_value_get_object(value); + webView->priv->context = webContext ? WEBKIT_WEB_CONTEXT(webContext) : webkit_web_context_get_default(); break; + } case PROP_ZOOM_LEVEL: webkit_web_view_set_zoom_level(webView, g_value_get_double(value)); break; @@ -554,9 +556,9 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); /** - * WebKitPolicyClient::decide-policy + * WebKitWebView::decide-policy: * @web_view: the #WebKitWebView on which the signal is emitted - * @decision: the #WebKitNavigationPolicyDecision + * @decision: the #WebKitPolicyDecision * @decision_type: a #WebKitPolicyDecisionType denoting the type of @decision * * This signal is emitted when WebKit is requesting the client to decide a policy @@ -1267,3 +1269,77 @@ gdouble webkit_web_view_get_zoom_level(WebKitWebView* webView) WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); return WKPageGetPageZoomFactor(wkPage); } + + +static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context) +{ + GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context)); + g_simple_async_result_set_op_res_gboolean(result.get(), isEnabled); + g_simple_async_result_complete(result.get()); +} + +/** + * webkit_web_view_can_execute_editing_command: + * @web_view: a #WebKitWebView + * @command: the command to check + * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied + * @user_data: (closure): the data to pass to callback function + * + * Asynchronously execute the given editing command. + * + * When the operation is finished, @callback will be called. You can then call + * webkit_web_view_can_execute_editing_command_finish() to get the result of the operation. + */ +void webkit_web_view_can_execute_editing_command(WebKitWebView* webView, const char* command, GAsyncReadyCallback callback, gpointer userData) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(command); + + GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(webView), callback, userData, + reinterpret_cast<gpointer>(webkit_web_view_can_execute_editing_command)); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command)); + WKPageValidateCommand(toAPI(page), wkCommand.get(), result, didValidateCommand); +} + +/** + * webkit_web_view_can_execute_editing_command_finish: + * @web_view: a #WebKitWebView + * @result: a #GAsyncResult + * @error: return location for error or %NULL to ignore + * + * Finish an asynchronous operation started with webkit_web_view_can_execute_editing_command(). + * + * Returns: %TRUE if a selection can be cut or %FALSE otherwise + */ +gboolean webkit_web_view_can_execute_editing_command_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE); + + GSimpleAsyncResult* simple = G_SIMPLE_ASYNC_RESULT(result); + g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == webkit_web_view_can_execute_editing_command); + + if (g_simple_async_result_propagate_error(simple, error)) + return FALSE; + return g_simple_async_result_get_op_res_gboolean(simple); +} + +/** + * webkit_web_view_execute_editing_command: + * @web_view: a #WebKitWebView + * @command: the command to execute + * + * Request to execute the given @command for @web_view. You can use + * webkit_web_view_can_execute_editing_command() to check whether + * it's possible to execute the command. + */ +void webkit_web_view_execute_editing_command(WebKitWebView* webView, const char* command) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(command); + + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command)); + WKPageExecuteCommand(toAPI(page), wkCommand.get()); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index 697fcdc80..d4768e3b6 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -39,6 +39,17 @@ G_BEGIN_DECLS +#define WEBKIT_TYPE_WEB_VIEW (webkit_web_view_get_type()) +#define WEBKIT_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView)) +#define WEBKIT_IS_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW)) +#define WEBKIT_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) +#define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_VIEW)) +#define WEBKIT_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) + +typedef struct _WebKitWebView WebKitWebView; +typedef struct _WebKitWebViewClass WebKitWebViewClass; +typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate; + /** * WebKitPolicyDecisionType: * @WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: This type of policy decision @@ -73,17 +84,6 @@ typedef enum { WEBKIT_POLICY_DECISION_TYPE_RESPONSE, } WebKitPolicyDecisionType; -#define WEBKIT_TYPE_WEB_VIEW (webkit_web_view_get_type()) -#define WEBKIT_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView)) -#define WEBKIT_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) -#define WEBKIT_IS_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW)) -#define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_VIEW)) -#define WEBKIT_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) - -typedef struct _WebKitWebView WebKitWebView; -typedef struct _WebKitWebViewClass WebKitWebViewClass; -typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate; - /** * WebKitLoadEvent * @WEBKIT_LOAD_STARTED: A new load request has been made. @@ -152,99 +152,113 @@ struct _WebKitWebViewClass { }; WEBKIT_API GType -webkit_web_view_get_type (void); +webkit_web_view_get_type (void); WEBKIT_API GtkWidget * -webkit_web_view_new (void); +webkit_web_view_new (void); WEBKIT_API GtkWidget * -webkit_web_view_new_with_context (WebKitWebContext *context); +webkit_web_view_new_with_context (WebKitWebContext *context); WEBKIT_API WebKitWebContext * -webkit_web_view_get_context (WebKitWebView *web_view); +webkit_web_view_get_context (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_load_uri (WebKitWebView *web_view, - const gchar *uri); +webkit_web_view_load_uri (WebKitWebView *web_view, + const gchar *uri); WEBKIT_API void -webkit_web_view_load_html (WebKitWebView *web_view, - const gchar *content, - const gchar *base_uri); +webkit_web_view_load_html (WebKitWebView *web_view, + const gchar *content, + const gchar *base_uri); WEBKIT_API void -webkit_web_view_load_plain_text (WebKitWebView *web_view, - const gchar *plain_text); +webkit_web_view_load_plain_text (WebKitWebView *web_view, + const gchar *plain_text); WEBKIT_API void -webkit_web_view_load_request (WebKitWebView *web_view, - WebKitURIRequest *request); +webkit_web_view_load_request (WebKitWebView *web_view, + WebKitURIRequest *request); WEBKIT_API void -webkit_web_view_stop_loading (WebKitWebView *web_view); +webkit_web_view_stop_loading (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_replace_content (WebKitWebView *web_view, - const gchar *content, - const gchar *content_uri, - const gchar *base_uri); +webkit_web_view_replace_content (WebKitWebView *web_view, + const gchar *content, + const gchar *content_uri, + const gchar *base_uri); WEBKIT_API const gchar * -webkit_web_view_get_title (WebKitWebView *web_view); +webkit_web_view_get_title (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_reload (WebKitWebView *web_view); +webkit_web_view_reload (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_reload_bypass_cache (WebKitWebView *web_view); +webkit_web_view_reload_bypass_cache (WebKitWebView *web_view); WEBKIT_API gdouble -webkit_web_view_get_estimated_load_progress (WebKitWebView *web_view); +webkit_web_view_get_estimated_load_progress (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_back (WebKitWebView *web_view); +webkit_web_view_go_back (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_can_go_back (WebKitWebView *web_view); +webkit_web_view_can_go_back (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_forward (WebKitWebView *web_view); +webkit_web_view_go_forward (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_can_go_forward (WebKitWebView *web_view); +webkit_web_view_can_go_forward (WebKitWebView *web_view); WEBKIT_API WebKitBackForwardList * -webkit_web_view_get_back_forward_list (WebKitWebView *web_view); +webkit_web_view_get_back_forward_list (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_to_back_forward_list_item (WebKitWebView *web_view, - WebKitBackForwardListItem *list_item); +webkit_web_view_go_to_back_forward_list_item (WebKitWebView *web_view, + WebKitBackForwardListItem *list_item); WEBKIT_API const gchar * -webkit_web_view_get_uri (WebKitWebView *web_view); +webkit_web_view_get_uri (WebKitWebView *web_view); WEBKIT_API const gchar * -webkit_web_view_get_custom_charset (WebKitWebView *web_view); +webkit_web_view_get_custom_charset (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_set_custom_charset (WebKitWebView *web_view, - const gchar *charset); +webkit_web_view_set_custom_charset (WebKitWebView *web_view, + const gchar *charset); WEBKIT_API void -webkit_web_view_set_settings (WebKitWebView *web_view, - WebKitSettings *settings); +webkit_web_view_set_settings (WebKitWebView *web_view, + WebKitSettings *settings); WEBKIT_API WebKitSettings * -webkit_web_view_get_settings (WebKitWebView *web_view); +webkit_web_view_get_settings (WebKitWebView *web_view); WEBKIT_API WebKitWindowProperties * -webkit_web_view_get_window_properties (WebKitWebView *web_view); +webkit_web_view_get_window_properties (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_set_zoom_level (WebKitWebView *web_view, - gdouble zoom_level); +webkit_web_view_set_zoom_level (WebKitWebView *web_view, + gdouble zoom_level); WEBKIT_API gdouble -webkit_web_view_get_zoom_level (WebKitWebView *web_view); +webkit_web_view_get_zoom_level (WebKitWebView *web_view); + +WEBKIT_API void +webkit_web_view_can_execute_editing_command (WebKitWebView *web_view, + const gchar *command, + GAsyncReadyCallback callback, + gpointer user_data); +WEBKIT_API gboolean +webkit_web_view_can_execute_editing_command_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); + +WEBKIT_API void +webkit_web_view_execute_editing_command (WebKitWebView *web_view, + const gchar *command); G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp index d9ccaa32a..adcc34ae3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp @@ -71,6 +71,7 @@ struct _WebKitWebViewBasePrivate { DragIcon dragIcon; IntSize resizerSize; GRefPtr<AtkObject> accessible; + bool needsResizeOnMap; }; G_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER) @@ -202,20 +203,43 @@ static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr) return FALSE; } +static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase, GtkAllocation* allocation) +{ + WebKitWebViewBasePrivate* priv = webViewBase->priv; + + if (priv->pageProxy->drawingArea()) + priv->pageProxy->drawingArea()->setSize(IntSize(allocation->width, allocation->height), IntSize()); + + GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(webViewBase)); + if (widgetIsOnscreenToplevelWindow(toplevel)) + webkitWebViewBaseNotifyResizerSizeForWindow(webViewBase, GTK_WINDOW(toplevel)); +} + static void webkitWebViewBaseSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { + GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation); + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); - WebKitWebViewBasePrivate* priv = webViewBase->priv; + if (!gtk_widget_get_mapped(GTK_WIDGET(webViewBase)) && !webViewBase->priv->pageProxy->drawingArea()->size().isEmpty()) { + webViewBase->priv->needsResizeOnMap = true; + return; + } + resizeWebKitWebViewBaseFromAllocation(webViewBase, allocation); +} + +static void webkitWebViewBaseMap(GtkWidget* widget) +{ + GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->map(widget); - if (!priv->pageProxy->drawingArea()) + WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); + if (!webViewBase->priv->needsResizeOnMap) return; - GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation); - priv->pageProxy->drawingArea()->setSize(IntSize(allocation->width, allocation->height), IntSize()); + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + resizeWebKitWebViewBaseFromAllocation(webViewBase, &allocation); + webViewBase->priv->needsResizeOnMap = false; - GtkWidget* toplevel = gtk_widget_get_toplevel(widget); - if (widgetIsOnscreenToplevelWindow(toplevel)) - webkitWebViewBaseNotifyResizerSizeForWindow(webViewBase, GTK_WINDOW(toplevel)); } static gboolean webkitWebViewBaseFocusInEvent(GtkWidget* widget, GdkEventFocus* event) @@ -454,6 +478,7 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie widgetClass->realize = webkitWebViewBaseRealize; widgetClass->draw = webkitWebViewBaseDraw; widgetClass->size_allocate = webkitWebViewBaseSizeAllocate; + widgetClass->map = webkitWebViewBaseMap; widgetClass->focus_in_event = webkitWebViewBaseFocusInEvent; widgetClass->focus_out_event = webkitWebViewBaseFocusOutEvent; widgetClass->key_press_event = webkitWebViewBaseKeyPressEvent; diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp index b170c82c9..413890203 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp @@ -38,7 +38,7 @@ * scrollbar, statusbar, locationbar should be visible to the user, * and the request to show the #WebKitWebView fullscreen. * - * The #WebKitWebView:ready-to-show signal handler is the proper place + * The #WebKitWebView::ready-to-show signal handler is the proper place * to apply the initial window properties. Then you can monitor the * #WebKitWindowProperties by connecting to ::notify signal. * diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml index c6f943ab2..af0cdae7c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml @@ -23,6 +23,7 @@ <xi:include href="xml/WebKitDownload.xml"/> <xi:include href="xml/WebKitPolicyDecision.xml"/> <xi:include href="xml/WebKitNavigationPolicyDecision.xml"/> + <xi:include href="xml/WebKitResponsePolicyDecision.xml"/> <xi:include href="xml/WebKitError.xml"/> </chapter> diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt index ef44b2bed..52cd89ee7 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt @@ -49,6 +49,13 @@ webkit_web_context_get_type WebKitWebView WebKitLoadEvent WebKitPolicyDecisionType + +<SUBSECTION Editing Commands> +WEBKIT_EDITING_COMMAND_CUT +WEBKIT_EDITING_COMMAND_COPY +WEBKIT_EDITING_COMMAND_PASTE + +<SUBSECTION> webkit_web_view_new webkit_web_view_new_with_context webkit_web_view_get_context @@ -76,6 +83,9 @@ webkit_web_view_get_settings webkit_web_view_get_window_properties webkit_web_view_set_zoom_level webkit_web_view_get_zoom_level +webkit_web_view_can_execute_editing_command +webkit_web_view_can_execute_editing_command_finish +webkit_web_view_execute_editing_command <SUBSECTION Standard> WebKitWebViewClass @@ -206,6 +216,8 @@ webkit_settings_get_enable_fullscreen webkit_settings_set_enable_fullscreen webkit_settings_get_print_backgrounds webkit_settings_set_print_backgrounds +webkit_settings_get_enable_webaudio +webkit_settings_set_enable_webaudio <SUBSECTION Standard> WebKitSettingsClass @@ -358,6 +370,26 @@ webkit_navigation_policy_decision_get_type </SECTION> <SECTION> +<FILE>WebKitResponsePolicyDecision</FILE> +WebKitResponsePolicyDecision +webkit_response_policy_decision_get_request +webkit_response_policy_decision_get_response + +<SUBSECTION Standard> +WebKitResponsePolicyDecisionClass +WEBKIT_TYPE_RESPONSE_POLICY_DECISION +WEBKIT_RESPONSE_POLICY_DECISION +WEBKIT_IS_RESPONSE_POLICY_DECISION +WEBKIT_RESPONSE_POLICY_DECISION_CLASS +WEBKIT_IS_RESPONSE_POLICY_DECISION_CLASS +WEBKIT_RESPONSE_POLICY_DECISION_GET_CLASS + +<SUBSECTION Private> +WebKitResponsePolicyDecisionPrivate +webkit_response_policy_decision_get_type +</SECTION> + +<SECTION> <FILE>WebKitError</FILE> WEBKIT_NETWORK_ERROR WEBKIT_PLUGIN_ERROR diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am index 175a149e4..7241b9980 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am +++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am @@ -5,7 +5,8 @@ TEST_PROGS += \ Programs/WebKit2APITests/TestWebKitSettings \ Programs/WebKit2APITests/TestBackForwardList \ Programs/WebKit2APITests/TestDownloads \ - Programs/WebKit2APITests/TestWebKitPolicyClient + Programs/WebKit2APITests/TestWebKitPolicyClient \ + Programs/WebKit2APITests/TestWebViewEditor noinst_PROGRAMS += $(TEST_PROGS) @@ -111,3 +112,9 @@ Programs_WebKit2APITests_TestDownloads_SOURCES = \ Programs_WebKit2APITests_TestDownloads_CPPFLAGS = $(webkit2_tests_cppflags) Programs_WebKit2APITests_TestDownloads_LDADD = $(webkit2_tests_ldadd) Programs_WebKit2APITests_TestDownloads_LDFLAGS = $(webkit2_tests_ldflags) + +Programs_WebKit2APITests_TestWebViewEditor_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp +Programs_WebKit2APITests_TestWebViewEditor_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebViewEditor_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebViewEditor_LDFLAGS = $(webkit2_tests_ldflags) diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp index 9eb08575d..a35c8745b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp @@ -110,8 +110,6 @@ void LoadTrackingTest::provisionalLoadReceivedServerRedirect() void LoadTrackingTest::provisionalLoadFailed(const gchar* failingURI, GError* error) { m_loadEvents.append(ProvisionalLoadFailed); - if (m_runLoadUntilCompletion) - g_main_loop_quit(m_mainLoop); } void LoadTrackingTest::loadCommitted() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp index cc657cc64..e70e391ff 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp @@ -19,8 +19,8 @@ #include "config.h" -#include "LoadTrackingTest.h" #include "WebKitTestServer.h" +#include "WebViewTest.h" #include <gtk/gtk.h> #include <libsoup/soup.h> #include <string.h> @@ -46,7 +46,7 @@ static void serverCallback(SoupServer* server, SoupMessage* msg, const char* pat soup_message_body_complete(msg->response_body); } -class BackForwardListTest: public LoadTrackingTest { +class BackForwardListTest: public WebViewTest { public: MAKE_GLIB_TEST_FIXTURE(BackForwardListTest); @@ -130,7 +130,7 @@ public: void waitUntilLoadFinished() { m_hasChanged = false; - LoadTrackingTest::waitUntilLoadFinished(); + WebViewTest::waitUntilLoadFinished(); g_assert(m_hasChanged); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h index 631096a76..39a2000ac 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h @@ -20,9 +20,9 @@ #ifndef TestMain_h #define TestMain_h -#include <glib-object.h> #include <JavaScriptCore/GOwnPtr.h> #include <JavaScriptCore/HashSet.h> +#include <glib-object.h> #define MAKE_GLIB_TEST_FIXTURE(ClassName) \ static void setUp(ClassName* fixture, gconstpointer data) \ @@ -39,8 +39,7 @@ g_test_add(testPath.get(), ClassName, 0, ClassName::setUp, testFunc, ClassName::tearDown); \ } -class Test -{ +class Test { public: MAKE_GLIB_TEST_FIXTURE(Test); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp index 7cbe4e7f9..9f6ce7819 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp @@ -20,9 +20,12 @@ #include "config.h" #include "LoadTrackingTest.h" +#include "WebKitTestServer.h" #include <wtf/gobject/GRefPtr.h> #include <wtf/text/CString.h> +static WebKitTestServer* kServer; + class PolicyClientTest: public LoadTrackingTest { public: MAKE_GLIB_TEST_FIXTURE(PolicyClientTest); @@ -142,6 +145,37 @@ static void testNavigationPolicy(PolicyClientTest* test, gconstpointer) g_assert_cmpint(test->m_loadEvents.size(), ==, 0); } +static void testResponsePolicy(PolicyClientTest* test, gconstpointer) +{ + test->m_policyDecisionTypeFilter = WEBKIT_POLICY_DECISION_TYPE_RESPONSE; + + test->m_policyDecisionResponse = PolicyClientTest::Use; + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilLoadFinished(); + g_assert_cmpint(test->m_loadEvents.size(), ==, 3); + g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); + g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); + + test->m_respondToPolicyDecisionAsynchronously = true; + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilLoadFinished(); + g_assert_cmpint(test->m_loadEvents.size(), ==, 3); + g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); + g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); + + test->m_respondToPolicyDecisionAsynchronously = false; + test->m_policyDecisionResponse = PolicyClientTest::Ignore; + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilLoadFinished(); + + g_assert_cmpint(test->m_loadEvents.size(), ==, 3); + g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::ProvisionalLoadFailed); + g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); +} + struct CreateCallbackData { bool triedToOpenWindow; GMainLoop* mainLoop; @@ -191,12 +225,31 @@ static void testNewWindowPolicy(PolicyClientTest* test, gconstpointer) g_assert(!data.triedToOpenWindow); } +static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) +{ + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(message, SOUP_STATUS_OK); + + static const char* responseString = "<html><body>Testing!</body></html>"; + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); + soup_message_body_complete(message->response_body); +} + void beforeAll() { + kServer = new WebKitTestServer(); + kServer->run(serverCallback); + PolicyClientTest::add("WebKitPolicyClient", "navigation-policy", testNavigationPolicy); + PolicyClientTest::add("WebKitPolicyClient", "response-policy", testResponsePolicy); PolicyClientTest::add("WebKitPolicyClient", "new-window-policy", testNewWindowPolicy); } void afterAll() { + delete kServer; } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp index cce7e1fe7..0ecea5604 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp @@ -189,6 +189,11 @@ static void testWebKitSettings(Test*, gconstpointer) webkit_settings_set_print_backgrounds(settings, FALSE); g_assert(!webkit_settings_get_print_backgrounds(settings)); + // WebAudio is disabled by default. + g_assert(!webkit_settings_get_enable_webaudio(settings)); + webkit_settings_set_enable_webaudio(settings, TRUE); + g_assert(webkit_settings_get_enable_webaudio(settings)); + g_object_unref(G_OBJECT(settings)); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp index 16375ed20..3d59ee917 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp @@ -26,6 +26,10 @@ static void testWebViewDefaultContext(WebViewTest* test, gconstpointer) { g_assert(webkit_web_view_get_context(test->m_webView) == webkit_web_context_get_default()); + + // Check that a web view created with g_object_new has the default context. + GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL)); + g_assert(webkit_web_view_get_context(webView.get()) == webkit_web_context_get_default()); } static void testWebViewCustomCharset(WebViewTest* test, gconstpointer) diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp new file mode 100644 index 000000000..644584a3e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebViewTest.h" +#include <wtf/gobject/GRefPtr.h> + +class EditorTest: public WebViewTest { +public: + MAKE_GLIB_TEST_FIXTURE(EditorTest); + + static const unsigned int kClipboardWaitTimeout = 50; + static const unsigned int kClipboardWaitMaxTries = 2; + + EditorTest() + : m_clipboard(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)) + , m_canExecuteEditingCommand(false) + , m_triesCount(0) + { + gtk_clipboard_clear(m_clipboard); + } + + static void canExecuteEditingCommandReadyCallback(GObject*, GAsyncResult* result, EditorTest* test) + { + GOwnPtr<GError> error; + test->m_canExecuteEditingCommand = webkit_web_view_can_execute_editing_command_finish(test->m_webView, result, &error.outPtr()); + g_assert(!error.get()); + g_main_loop_quit(test->m_mainLoop); + } + + bool canExecuteEditingCommand(const char* command) + { + m_canExecuteEditingCommand = false; + webkit_web_view_can_execute_editing_command(m_webView, command, reinterpret_cast<GAsyncReadyCallback>(canExecuteEditingCommandReadyCallback), this); + g_main_loop_run(m_mainLoop); + return m_canExecuteEditingCommand; + } + + static gboolean waitForClipboardText(EditorTest* test) + { + test->m_triesCount++; + if (gtk_clipboard_wait_is_text_available(test->m_clipboard) || test->m_triesCount > kClipboardWaitMaxTries) { + g_main_loop_quit(test->m_mainLoop); + return FALSE; + } + + return TRUE; + } + + void copyClipboard() + { + webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_COPY); + // There's no way to know when the selection has been copied to + // the clipboard, so use a timeout source to query the clipboard. + m_triesCount = 0; + g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this); + g_main_loop_run(m_mainLoop); + } + + GtkClipboard* m_clipboard; + bool m_canExecuteEditingCommand; + size_t m_triesCount; +}; + +static void testWebViewEditorCutCopyPasteNonEditable(EditorTest* test, gconstpointer) +{ + static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">" + "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" + "<script>document.getSelection().collapse();\n" + "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" + "</script></body></html>"; + + // Nothing loaded yet. + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); + + test->loadHtml(selectedSpanHTML, 0); + test->waitUntilLoadFinished(); + + g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); + // It's not possible to cut and paste when content is not editable + // even if there's a selection. + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); + + test->copyClipboard(); + GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); + g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); +} + +static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer) +{ + static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">" + "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy.</span>" + "<script>document.getSelection().collapse();\n" + "document.getSelection().selectAllChildren(document.getElementById('mainspan'));\n" + "</script></body></html>"; + + // Nothing loaded yet. + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); + g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); + + test->loadHtml(selectedSpanHTML, 0); + test->waitUntilLoadFinished(); + + // There's a selection. + g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); + g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); + g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); + + test->copyClipboard(); + GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); + g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy."); +} + +void beforeAll() +{ + EditorTest::add("WebKitWebView", "cut-copy-paste/non-editable", testWebViewEditorCutCopyPasteNonEditable); + EditorTest::add("WebKitWebView", "cut-copy-paste/editable", testWebViewEditorCutCopyPasteEditable); +} + +void afterAll() +{ +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp index 099eabda5..20895eccb 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp @@ -116,3 +116,17 @@ void WebViewTest::wait(double seconds) g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(testLoadTimeoutFinishLoop), m_mainLoop); g_main_loop_run(m_mainLoop); } + +static void loadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test) +{ + if (loadEvent != WEBKIT_LOAD_FINISHED) + return; + g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadChanged), test); + g_main_loop_quit(test->m_mainLoop); +} + +void WebViewTest::waitUntilLoadFinished() +{ + g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChanged), this); + g_main_loop_run(m_mainLoop); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h index 882e8b224..4ad6fa648 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h @@ -41,6 +41,7 @@ public: void goToBackForwardListItem(WebKitBackForwardListItem*); void wait(double seconds); + void waitUntilLoadFinished(); WebKitWebView* m_webView; GMainLoop* m_mainLoop; diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h index e9d892b54..78e53d508 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h @@ -27,6 +27,7 @@ #include <webkit2/WebKitBackForwardListItem.h> #include <webkit2/WebKitDefines.h> #include <webkit2/WebKitDownload.h> +#include <webkit2/WebKitEditingCommands.h> #include <webkit2/WebKitEnumTypes.h> #include <webkit2/WebKitError.h> #include <webkit2/WebKitSettings.h> diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm index 7d21e9b7f..728f0e56f 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKView.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm @@ -1709,7 +1709,7 @@ static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard, - (void)_updateWindowVisibility { - _data->_page->updateWindowIsVisible(![[self window] isMiniaturized]); + _data->_page->updateWindowIsVisible([[self window] isVisible]); } - (BOOL)_ownsWindowGrowBox @@ -1924,6 +1924,7 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl // we hide it first and then update the active state. _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible); _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive); + [self _updateWindowVisibility]; } - (void)_windowDidOrderOnScreen:(NSNotification *)notification @@ -1932,6 +1933,7 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl // we update the active state first and then make it visible. _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive); _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible); + [self _updateWindowVisibility]; } - (void)_windowDidChangeBackingProperties:(NSNotification *)notification @@ -2279,12 +2281,12 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I - (NSRect)_convertToDeviceSpace:(NSRect)rect { - return toDeviceSpace(rect, [self window], _data->_page->deviceScaleFactor()); + return toDeviceSpace(rect, [self window]); } - (NSRect)_convertToUserSpace:(NSRect)rect { - return toUserSpace(rect, [self window], _data->_page->deviceScaleFactor()); + return toUserSpace(rect, [self window]); } // Any non-zero value will do, but using something recognizable might help us debug some day. @@ -2734,6 +2736,7 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I _data->_pageClient = PageClientImpl::create(self); _data->_page = toImpl(contextRef)->createWebPage(_data->_pageClient.get(), toImpl(pageGroupRef)); _data->_page->initializeWebPage(); + _data->_page->setIntrinsicDeviceScaleFactor([self _intrinsicDeviceScaleFactor]); #if ENABLE(FULLSCREEN_API) _data->_page->fullScreenManager()->setWebView(self); #endif diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp index 206ba2522..22c6703c4 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp @@ -46,31 +46,13 @@ QQuickWebPage::~QQuickWebPage() delete d; } -QtSGUpdateQueue *QQuickWebPage::sceneGraphUpdateQueue() const -{ - return &d->sgUpdateQueue; -} - -void QQuickWebPage::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) -{ - QQuickItem::geometryChanged(newGeometry, oldGeometry); - - if (!d->useTraditionalDesktopBehaviour) - return; - - if (newGeometry.size() != oldGeometry.size()) - d->setDrawingAreaSize(newGeometry.size().toSize()); -} - QQuickWebPagePrivate::QQuickWebPagePrivate(QQuickWebPage* q, QQuickWebView* viewportItem) : q(q) , viewportItem(viewportItem) , webPageProxy(0) - , sgUpdateQueue(q) , paintingIsInitialized(false) , m_paintNode(0) - , contentScale(1) - , useTraditionalDesktopBehaviour(false) + , contentsScale(1) { } @@ -112,7 +94,7 @@ void QQuickWebPagePrivate::paintToCurrentGLContext() return; QTransform transform = q->itemTransform(0, 0); - transform.scale(contentScale, contentScale); + transform.scale(contentsScale, contentsScale); float opacity = computeEffectiveOpacity(q); QRectF clipRect = q->parentItem()->mapRectToScene(q->parentItem()->boundingRect()); @@ -220,47 +202,37 @@ QSGNode* QQuickWebPage::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) return proxyNode; } -bool QQuickWebPage::usesTraditionalDesktopBehaviour() const -{ - return d->useTraditionalDesktopBehaviour; -} - -void QQuickWebPage::setUsesTraditionalDesktopBehaviour(bool enable) -{ - d->useTraditionalDesktopBehaviour = enable; -} - QtWebPageEventHandler* QQuickWebPage::eventHandler() const { return d->eventHandler.data(); } -void QQuickWebPage::setContentSize(const QSizeF& size) +void QQuickWebPage::setContentsSize(const QSizeF& size) { - if (size.isEmpty() || d->contentSize == size) + if (size.isEmpty() || d->contentsSize == size) return; - d->contentSize = size; + d->contentsSize = size; d->updateSize(); - d->setDrawingAreaSize(d->contentSize.toSize()); + d->setDrawingAreaSize(d->contentsSize.toSize()); } -const QSizeF& QQuickWebPage::contentSize() const +const QSizeF& QQuickWebPage::contentsSize() const { - return d->contentSize; + return d->contentsSize; } -void QQuickWebPage::setContentScale(qreal scale) +void QQuickWebPage::setContentsScale(qreal scale) { ASSERT(scale > 0); - d->contentScale = scale; + d->contentsScale = scale; d->updateSize(); } -qreal QQuickWebPage::contentScale() const +qreal QQuickWebPage::contentsScale() const { - ASSERT(d->contentScale > 0); - return d->contentScale; + ASSERT(d->contentsScale > 0); + return d->contentsScale; } QTransform QQuickWebPage::transformFromItem() const @@ -270,12 +242,12 @@ QTransform QQuickWebPage::transformFromItem() const QTransform QQuickWebPage::transformToItem() const { - return QTransform(d->contentScale, 0, 0, 0, d->contentScale, 0, x(), y(), 1); + return QTransform(d->contentsScale, 0, 0, 0, d->contentsScale, 0, x(), y(), 1); } void QQuickWebPagePrivate::updateSize() { - QSizeF scaledSize = contentSize * contentScale; + QSizeF scaledSize = contentsSize * contentsScale; q->setSize(scaledSize); } diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p.h index bf44b9dc7..9d791ac25 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p.h @@ -31,34 +31,23 @@ class QQuickWebView; class QtWebPageEventHandler; class QWebPreferences; -namespace WebKit { -class QtSGUpdateQueue; -} - class QWEBKIT_EXPORT QQuickWebPage : public QQuickItem { Q_OBJECT public: QQuickWebPage(QQuickWebView* view = 0); virtual ~QQuickWebPage(); - void setContentSize(const QSizeF& size); - const QSizeF& contentSize() const; - void setContentScale(qreal); - qreal contentScale() const; + void setContentsSize(const QSizeF& size); + const QSizeF& contentsSize() const; + void setContentsScale(qreal); + qreal contentsScale() const; QTransform transformFromItem() const; QTransform transformToItem() const; - bool usesTraditionalDesktopBehaviour() const; - void setUsesTraditionalDesktopBehaviour(bool enable); - QtWebPageEventHandler* eventHandler() const; - // Internal. To be removed soon. - WebKit::QtSGUpdateQueue* sceneGraphUpdateQueue() const; - protected: - virtual void geometryChanged(const QRectF&, const QRectF&); virtual QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*); private: diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h index 0c17aa5b5..dfd223dbe 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h @@ -21,7 +21,6 @@ #ifndef qquickwebpage_p_p_h #define qquickwebpage_p_p_h -#include "QtSGUpdateQueue.h" #include "qquickwebpage_p.h" #include <QTransform> @@ -50,13 +49,11 @@ public: QQuickWebPage* const q; QQuickWebView* const viewportItem; WebKit::WebPageProxy* webPageProxy; - WebKit::QtSGUpdateQueue sgUpdateQueue; bool paintingIsInitialized; QSGNode* m_paintNode; - QSizeF contentSize; - qreal contentScale; - bool useTraditionalDesktopBehaviour; + QSizeF contentsSize; + qreal contentsScale; }; #endif // qquickwebpage_p_p_h diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp index 5712ca593..7ea6d347c 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp @@ -55,6 +55,15 @@ using namespace WebCore; +static bool s_flickableViewportEnabled = true; + +static QQuickWebViewPrivate* createPrivateObject(QQuickWebView* publicObject) +{ + if (s_flickableViewportEnabled) + return new QQuickWebViewFlickablePrivate(publicObject); + return new QQuickWebViewLegacyPrivate(publicObject); +} + QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport) : q_ptr(viewport) , alertDialog(0) @@ -63,9 +72,6 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport) , authenticationDialog(0) , certificateVerificationDialog(0) , itemSelector(0) - , postTransitionState(adoptPtr(new PostTransitionState(this))) - , isTransitioningToNewPage(false) - , pageIsSuspended(false) , m_navigatorQtObjectEnabled(false) , m_renderToOffscreenBuffer(false) { @@ -76,8 +82,6 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport) QQuickWebViewPrivate::~QQuickWebViewPrivate() { - if (interactionEngine) - interactionEngine->disconnect(); webPageProxy->close(); } @@ -106,15 +110,11 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa QObject::connect(q_ptr, SIGNAL(urlChanged(QUrl)), iconDatabase, SLOT(requestIconForPageURL(QUrl))); // Any page setting should preferrable be set before creating the page. - setUseTraditionalDesktopBehaviour(false); webPageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(true); webPageProxy->pageGroup()->preferences()->setForceCompositingMode(true); pageClient.initialize(q_ptr, pageViewPrivate->eventHandler.data(), &undoController); webPageProxy->initializeWebPage(); - - // Trigger setting of correct visibility flags after everything was allocated and initialized. - _q_onVisibleChanged(); } void QQuickWebViewPrivate::enableMouseEvents() @@ -131,30 +131,11 @@ void QQuickWebViewPrivate::disableMouseEvents() q->setAcceptHoverEvents(false); } -void QQuickWebViewPrivate::initializeDesktop(QQuickWebView* viewport) -{ - if (interactionEngine) { - QObject::disconnect(interactionEngine.data(), SIGNAL(contentSuspendRequested()), viewport, SLOT(_q_suspend())); - QObject::disconnect(interactionEngine.data(), SIGNAL(contentResumeRequested()), viewport, SLOT(_q_resume())); - QObject::disconnect(interactionEngine.data(), SIGNAL(viewportTrajectoryVectorChanged(const QPointF&)), viewport, SLOT(_q_viewportTrajectoryVectorChanged(const QPointF&))); - QObject::disconnect(interactionEngine.data(), SIGNAL(visibleContentRectAndScaleChanged()), viewport, SLOT(_q_updateVisibleContentRectAndScale())); - } - interactionEngine.reset(0); - pageView->d->eventHandler->setViewportInteractionEngine(0); - enableMouseEvents(); - updateDesktopViewportSize(); -} - -void QQuickWebViewPrivate::initializeTouch(QQuickWebView* viewport) +void QQuickWebViewPrivate::loadDidSucceed() { - interactionEngine.reset(new QtViewportInteractionEngine(viewport, pageView.data())); - pageView->d->eventHandler->setViewportInteractionEngine(interactionEngine.data()); - disableMouseEvents(); - QObject::connect(interactionEngine.data(), SIGNAL(contentSuspendRequested()), viewport, SLOT(_q_suspend())); - QObject::connect(interactionEngine.data(), SIGNAL(contentResumeRequested()), viewport, SLOT(_q_resume())); - QObject::connect(interactionEngine.data(), SIGNAL(viewportTrajectoryVectorChanged(const QPointF&)), viewport, SLOT(_q_viewportTrajectoryVectorChanged(const QPointF&))); - QObject::connect(interactionEngine.data(), SIGNAL(visibleContentRectAndScaleChanged()), viewport, SLOT(_q_updateVisibleContentRectAndScale())); - updateTouchViewportSize(); + Q_Q(QQuickWebView); + emit q->navigationStateChanged(); + emit q->loadSucceeded(); } void QQuickWebViewPrivate::setNeedsDisplay() @@ -171,28 +152,6 @@ void QQuickWebViewPrivate::setNeedsDisplay() q->page()->update(); } -void QQuickWebViewPrivate::loadDidCommit() -{ - // Due to entering provisional load before committing, we - // might actually be suspended here. - - if (pageView->usesTraditionalDesktopBehaviour()) - return; - - isTransitioningToNewPage = true; -} - -void QQuickWebViewPrivate::didFinishFirstNonEmptyLayout() -{ - if (pageView->usesTraditionalDesktopBehaviour()) - return; - - if (!pageIsSuspended) { - isTransitioningToNewPage = false; - postTransitionState->apply(); - } -} - void QQuickWebViewPrivate::_q_onIconChangedForPageURL(const QUrl& pageURL, const QUrl& iconURL) { Q_Q(QQuickWebView); @@ -202,74 +161,15 @@ void QQuickWebViewPrivate::_q_onIconChangedForPageURL(const QUrl& pageURL, const setIcon(iconURL); } -void QQuickWebViewPrivate::_q_suspend() -{ - pageIsSuspended = true; -} - -void QQuickWebViewPrivate::_q_resume() -{ - pageIsSuspended = false; - - if (isTransitioningToNewPage) { - isTransitioningToNewPage = false; - postTransitionState->apply(); - } - - _q_updateVisibleContentRectAndScale(); -} - -void QQuickWebViewPrivate::didChangeContentsSize(const QSize& newSize) -{ - Q_Q(QQuickWebView); - if (pageView->usesTraditionalDesktopBehaviour()) - return; - - // FIXME: We probably want to handle suspend here as well - if (isTransitioningToNewPage) { - postTransitionState->contentsSize = newSize; - return; - } - - pageView->setContentSize(newSize); - q->m_experimental->viewportInfo()->didUpdateContentsSize(); -} - -void QQuickWebViewPrivate::didChangeViewportProperties(const WebCore::ViewportArguments& args) -{ - if (pageView->usesTraditionalDesktopBehaviour()) - return; - - viewportArguments = args; - - if (isTransitioningToNewPage) - return; - - interactionEngine->applyConstraints(computeViewportConstraints()); -} - void QQuickWebViewPrivate::didChangeBackForwardList() { navigationHistory->d->reset(); } -void QQuickWebViewPrivate::pageDidRequestScroll(const QPoint& pos) -{ - if (pageView->usesTraditionalDesktopBehaviour()) - return; - - if (isTransitioningToNewPage) { - postTransitionState->position = pos; - return; - } - - interactionEngine->pagePositionRequest(pos); -} - void QQuickWebViewPrivate::processDidCrash() { emit q_ptr->navigationStateChanged(); - pageView->d->eventHandler->resetGestureRecognizers(); + pageView->eventHandler()->resetGestureRecognizers(); WebCore::KURL url(WebCore::ParsedURLString, webPageProxy->urlAtProcessExit()); qWarning("WARNING: The web process experienced a crash on '%s'.", qPrintable(QUrl(url).toString(QUrl::RemoveUserInfo))); } @@ -300,24 +200,6 @@ void QQuickWebViewPrivate::handleDownloadRequest(DownloadProxy* download) context->downloadManager()->addDownload(download, downloadItem); } -void QQuickWebViewPrivate::_q_updateVisibleContentRectAndScale() -{ - DrawingAreaProxy* drawingArea = webPageProxy->drawingArea(); - if (!drawingArea) - return; - - Q_Q(QQuickWebView); - const QRectF visibleRectInCSSCoordinates = q->mapRectToWebContent(q->boundingRect()).intersected(pageView->boundingRect()); - float scale = pageView->contentScale(); - - QRect alignedVisibleContentRect = visibleRectInCSSCoordinates.toAlignedRect(); - drawingArea->setVisibleContentsRectAndScale(alignedVisibleContentRect, scale); - - // FIXME: Once we support suspend and resume, this should be delayed until the page is active if the page is suspended. - webPageProxy->setFixedVisibleContentRect(alignedVisibleContentRect); - q->m_experimental->viewportInfo()->didUpdateCurrentScale(); -} - void QQuickWebViewPrivate::_q_viewportTrajectoryVectorChanged(const QPointF& trajectoryVector) { DrawingAreaProxy* drawingArea = webPageProxy->drawingArea(); @@ -342,85 +224,6 @@ void QQuickWebViewPrivate::_q_onReceivedResponseFromDownload(QWebDownloadItem* d emit q->experimental()->downloadRequested(downloadItem); } -void QQuickWebViewPrivate::updateDesktopViewportSize() -{ - Q_Q(QQuickWebView); - QSize viewportSize = q->boundingRect().size().toSize(); - pageView->setWidth(viewportSize.width()); - pageView->setHeight(viewportSize.height()); - // The fixed layout is handled by the FrameView and the drawing area doesn't behave differently - // wether its fixed or not. We still need to tell the drawing area which part of it - // has to be rendered on tiles, and in desktop mode it's all of it. - webPageProxy->drawingArea()->setVisibleContentsRectAndScale(IntRect(IntPoint(), viewportSize), 1); -} - -void QQuickWebViewPrivate::updateTouchViewportSize() -{ - Q_Q(QQuickWebView); - QSize viewportSize = q->boundingRect().size().toSize(); - - if (viewportSize.isEmpty()) - return; - - // Let the WebProcess know about the new viewport size, so that - // it can resize the content accordingly. - webPageProxy->setViewportSize(viewportSize); - - interactionEngine->applyConstraints(computeViewportConstraints()); - _q_updateVisibleContentRectAndScale(); -} - -void QQuickWebViewPrivate::PostTransitionState::apply() -{ - p->interactionEngine->reset(); - p->interactionEngine->applyConstraints(p->computeViewportConstraints()); - p->interactionEngine->pagePositionRequest(position); - - if (contentsSize.isValid()) { - p->pageView->setContentSize(contentsSize); - p->q_ptr->experimental()->viewportInfo()->didUpdateContentsSize(); - } - - position = QPoint(); - contentsSize = QSize(); -} - -QtViewportInteractionEngine::Constraints QQuickWebViewPrivate::computeViewportConstraints() -{ - Q_Q(QQuickWebView); - - QtViewportInteractionEngine::Constraints newConstraints; - QSize availableSize = q->boundingRect().size().toSize(); - - // Return default values for zero sized viewport. - if (availableSize.isEmpty()) - return newConstraints; - - WebPreferences* wkPrefs = webPageProxy->pageGroup()->preferences(); - - // FIXME: Remove later; Hardcode some values for now to make sure the DPI adjustment is being tested. - wkPrefs->setDeviceDPI(240); - wkPrefs->setDeviceWidth(480); - wkPrefs->setDeviceHeight(720); - - int minimumLayoutFallbackWidth = qMax<int>(wkPrefs->layoutFallbackWidth(), availableSize.width()); - - WebCore::ViewportAttributes attr = WebCore::computeViewportAttributes(viewportArguments, minimumLayoutFallbackWidth, wkPrefs->deviceWidth(), wkPrefs->deviceHeight(), wkPrefs->deviceDPI(), availableSize); - WebCore::restrictMinimumScaleFactorToViewportSize(attr, availableSize); - WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(attr); - - newConstraints.initialScale = attr.initialScale; - newConstraints.minimumScale = attr.minimumScale; - newConstraints.maximumScale = attr.maximumScale; - newConstraints.devicePixelRatio = attr.devicePixelRatio; - newConstraints.isUserScalable = !!attr.userScalable; - newConstraints.layoutSize = attr.layoutSize; - - q->m_experimental->viewportInfo()->didUpdateViewportConstraints(); - - return newConstraints; -} - void QQuickWebViewPrivate::runJavaScriptAlert(const QString& alertText) { if (!alertDialog) @@ -565,20 +368,6 @@ void QQuickWebViewPrivate::_q_onOpenPanelFinished(int result) fileDialog = 0; } -void QQuickWebViewPrivate::setUseTraditionalDesktopBehaviour(bool enable) -{ - Q_Q(QQuickWebView); - - // Do not guard, testing for the same value, as we call this from the constructor. - - webPageProxy->setUseFixedLayout(!enable); - pageView->setUsesTraditionalDesktopBehaviour(enable); - if (enable) - initializeDesktop(q); - else - initializeTouch(q); -} - void QQuickWebViewPrivate::setViewInAttachedProperties(QObject* object) { Q_Q(QQuickWebView); @@ -634,6 +423,236 @@ void QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject(const String& emit q_ptr->experimental()->messageReceived(variantMap); } +QQuickWebViewLegacyPrivate::QQuickWebViewLegacyPrivate(QQuickWebView* viewport) + : QQuickWebViewPrivate(viewport) +{ +} + +void QQuickWebViewLegacyPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pageGroupRef) +{ + QQuickWebViewPrivate::initialize(contextRef, pageGroupRef); + enableMouseEvents(); + + // Trigger setting of correct visibility flags after everything was allocated and initialized. + _q_onVisibleChanged(); +} + +void QQuickWebViewLegacyPrivate::updateViewportSize() +{ + Q_Q(QQuickWebView); + QSize viewportSize = q->boundingRect().size().toSize(); + pageView->setContentsSize(viewportSize); + // The fixed layout is handled by the FrameView and the drawing area doesn't behave differently + // whether its fixed or not. We still need to tell the drawing area which part of it + // has to be rendered on tiles, and in desktop mode it's all of it. + webPageProxy->drawingArea()->setVisibleContentsRectAndScale(IntRect(IntPoint(), viewportSize), 1); +} + +QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate(QQuickWebView* viewport) + : QQuickWebViewPrivate(viewport) + , postTransitionState(adoptPtr(new PostTransitionState(this))) + , isTransitioningToNewPage(false) + , pageIsSuspended(true) + , loadSuccessDispatchIsPending(false) +{ +} + +QQuickWebViewFlickablePrivate::~QQuickWebViewFlickablePrivate() +{ + interactionEngine->disconnect(); +} + +void QQuickWebViewFlickablePrivate::initialize(WKContextRef contextRef, WKPageGroupRef pageGroupRef) +{ + QQuickWebViewPrivate::initialize(contextRef, pageGroupRef); + webPageProxy->setUseFixedLayout(true); +} + +void QQuickWebViewFlickablePrivate::onComponentComplete() +{ + Q_Q(QQuickWebView); + interactionEngine.reset(new QtViewportInteractionEngine(q, pageView.data())); + pageView->eventHandler()->setViewportInteractionEngine(interactionEngine.data()); + + QObject::connect(interactionEngine.data(), SIGNAL(contentSuspendRequested()), q, SLOT(_q_suspend())); + QObject::connect(interactionEngine.data(), SIGNAL(contentResumeRequested()), q, SLOT(_q_resume())); + QObject::connect(interactionEngine.data(), SIGNAL(viewportTrajectoryVectorChanged(const QPointF&)), q, SLOT(_q_viewportTrajectoryVectorChanged(const QPointF&))); + QObject::connect(interactionEngine.data(), SIGNAL(visibleContentRectAndScaleChanged()), q, SLOT(_q_updateVisibleContentRectAndScale())); + + _q_resume(); + + if (loadSuccessDispatchIsPending) { + QQuickWebViewPrivate::loadDidSucceed(); + loadSuccessDispatchIsPending = false; + } + + // Trigger setting of correct visibility flags after everything was allocated and initialized. + _q_onVisibleChanged(); +} + +void QQuickWebViewFlickablePrivate::loadDidSucceed() +{ + if (interactionEngine) + QQuickWebViewPrivate::loadDidSucceed(); + else + loadSuccessDispatchIsPending = true; + +} + +void QQuickWebViewFlickablePrivate::loadDidCommit() +{ + // Due to entering provisional load before committing, we + // might actually be suspended here. + + isTransitioningToNewPage = true; +} + +void QQuickWebViewFlickablePrivate::didFinishFirstNonEmptyLayout() +{ + if (!pageIsSuspended) { + isTransitioningToNewPage = false; + postTransitionState->apply(); + } +} + +void QQuickWebViewFlickablePrivate::didChangeViewportProperties(const WebCore::ViewportArguments& args) +{ + viewportArguments = args; + + if (isTransitioningToNewPage) + return; + + interactionEngine->applyConstraints(computeViewportConstraints()); +} + +void QQuickWebViewFlickablePrivate::updateViewportSize() +{ + Q_Q(QQuickWebView); + QSize viewportSize = q->boundingRect().size().toSize(); + + if (viewportSize.isEmpty() || !interactionEngine) + return; + + // Let the WebProcess know about the new viewport size, so that + // it can resize the content accordingly. + webPageProxy->setViewportSize(viewportSize); + + interactionEngine->applyConstraints(computeViewportConstraints()); + _q_updateVisibleContentRectAndScale(); +} + +void QQuickWebViewFlickablePrivate::_q_updateVisibleContentRectAndScale() +{ + DrawingAreaProxy* drawingArea = webPageProxy->drawingArea(); + if (!drawingArea) + return; + + Q_Q(QQuickWebView); + const QRectF visibleRectInCSSCoordinates = q->mapRectToWebContent(q->boundingRect()).intersected(pageView->boundingRect()); + float scale = pageView->contentsScale(); + + QRect alignedVisibleContentRect = visibleRectInCSSCoordinates.toAlignedRect(); + drawingArea->setVisibleContentsRectAndScale(alignedVisibleContentRect, scale); + + // FIXME: Once we support suspend and resume, this should be delayed until the page is active if the page is suspended. + webPageProxy->setFixedVisibleContentRect(alignedVisibleContentRect); + q->experimental()->viewportInfo()->didUpdateCurrentScale(); +} + +void QQuickWebViewFlickablePrivate::_q_suspend() +{ + pageIsSuspended = true; +} + +void QQuickWebViewFlickablePrivate::_q_resume() +{ + if (!interactionEngine) + return; + + pageIsSuspended = false; + + if (isTransitioningToNewPage) { + isTransitioningToNewPage = false; + postTransitionState->apply(); + } + + _q_updateVisibleContentRectAndScale(); +} + +void QQuickWebViewFlickablePrivate::pageDidRequestScroll(const QPoint& pos) +{ + if (isTransitioningToNewPage) { + postTransitionState->position = pos; + return; + } + + interactionEngine->pagePositionRequest(pos); +} + +void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize) +{ + Q_Q(QQuickWebView); + // FIXME: We probably want to handle suspend here as well + if (isTransitioningToNewPage) { + postTransitionState->contentsSize = newSize; + return; + } + + pageView->setContentsSize(newSize); + q->experimental()->viewportInfo()->didUpdateContentsSize(); +} + +QtViewportInteractionEngine::Constraints QQuickWebViewFlickablePrivate::computeViewportConstraints() +{ + Q_Q(QQuickWebView); + + QtViewportInteractionEngine::Constraints newConstraints; + QSize availableSize = q->boundingRect().size().toSize(); + + // Return default values for zero sized viewport. + if (availableSize.isEmpty()) + return newConstraints; + + WebPreferences* wkPrefs = webPageProxy->pageGroup()->preferences(); + + // FIXME: Remove later; Hardcode some values for now to make sure the DPI adjustment is being tested. + wkPrefs->setDeviceDPI(240); + wkPrefs->setDeviceWidth(480); + wkPrefs->setDeviceHeight(720); + + int minimumLayoutFallbackWidth = qMax<int>(wkPrefs->layoutFallbackWidth(), availableSize.width()); + + WebCore::ViewportAttributes attr = WebCore::computeViewportAttributes(viewportArguments, minimumLayoutFallbackWidth, wkPrefs->deviceWidth(), wkPrefs->deviceHeight(), wkPrefs->deviceDPI(), availableSize); + WebCore::restrictMinimumScaleFactorToViewportSize(attr, availableSize); + WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(attr); + + newConstraints.initialScale = attr.initialScale; + newConstraints.minimumScale = attr.minimumScale; + newConstraints.maximumScale = attr.maximumScale; + newConstraints.devicePixelRatio = attr.devicePixelRatio; + newConstraints.isUserScalable = !!attr.userScalable; + newConstraints.layoutSize = attr.layoutSize; + + q->experimental()->viewportInfo()->didUpdateViewportConstraints(); + + return newConstraints; +} + +void QQuickWebViewFlickablePrivate::PostTransitionState::apply() +{ + p->interactionEngine->reset(); + p->interactionEngine->applyConstraints(p->computeViewportConstraints()); + p->interactionEngine->pagePositionRequest(position); + + if (contentsSize.isValid()) { + p->pageView->setContentsSize(contentsSize); + p->q_ptr->experimental()->viewportInfo()->didUpdateContentsSize(); + } + + position = QPoint(); + contentsSize = QSize(); +} + /*! \qmlsignal WebView::onNavigationRequested(request) @@ -674,16 +693,6 @@ QQuickWebViewExperimental::~QQuickWebViewExperimental() { } -void QQuickWebViewExperimental::setUseTraditionalDesktopBehaviour(bool enable) -{ - Q_D(QQuickWebView); - - if (enable == d->pageView->usesTraditionalDesktopBehaviour()) - return; - - d->setUseTraditionalDesktopBehaviour(enable); -} - void QQuickWebViewExperimental::setRenderToOffscreenBuffer(bool enable) { Q_D(QQuickWebView); @@ -696,6 +705,16 @@ bool QQuickWebViewExperimental::renderToOffscreenBuffer() const return d->renderToOffscreenBuffer(); } +void QQuickWebViewExperimental::setFlickableViewportEnabled(bool enable) +{ + s_flickableViewportEnabled = enable; +} + +bool QQuickWebViewExperimental::flickableViewportEnabled() +{ + return s_flickableViewportEnabled; +} + void QQuickWebViewExperimental::postMessage(const QString& message) { Q_D(QQuickWebView); @@ -805,12 +824,6 @@ void QQuickWebViewExperimental::setItemSelector(QDeclarativeComponent* itemSelec emit itemSelectorChanged(); } -bool QQuickWebViewExperimental::useTraditionalDesktopBehaviour() const -{ - Q_D(const QQuickWebView); - return d->pageView->usesTraditionalDesktopBehaviour(); -} - QQuickUrlSchemeDelegate* QQuickWebViewExperimental::schemeDelegates_At(QDeclarativeListProperty<QQuickUrlSchemeDelegate>* property, int index) { const QObjectList children = property->object->children(); @@ -899,7 +912,7 @@ QQuickWebPage* QQuickWebViewExperimental::page() QQuickWebView::QQuickWebView(QQuickItem* parent) : QQuickItem(parent) - , d_ptr(new QQuickWebViewPrivate(this)) + , d_ptr(createPrivateObject(this)) , m_experimental(new QQuickWebViewExperimental(this)) { Q_D(QQuickWebView); @@ -908,7 +921,7 @@ QQuickWebView::QQuickWebView(QQuickItem* parent) QQuickWebView::QQuickWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef, QQuickItem* parent) : QQuickItem(parent) - , d_ptr(new QQuickWebViewPrivate(this)) + , d_ptr(createPrivateObject(this)) , m_experimental(new QQuickWebViewExperimental(this)) { Q_D(QQuickWebView); @@ -1084,12 +1097,17 @@ void QQuickWebView::geometryChanged(const QRectF& newGeometry, const QRectF& old { Q_D(QQuickWebView); QQuickItem::geometryChanged(newGeometry, oldGeometry); - if (newGeometry.size() != oldGeometry.size()) { - if (d->pageView->usesTraditionalDesktopBehaviour()) - d->updateDesktopViewportSize(); - else - d->updateTouchViewportSize(); - } + if (newGeometry.size() != oldGeometry.size()) + d->updateViewportSize(); +} + +void QQuickWebView::componentComplete() +{ + Q_D(QQuickWebView); + QQuickItem::componentComplete(); + + d->onComponentComplete(); + d->updateViewportSize(); } void QQuickWebView::keyPressEvent(QKeyEvent* event) diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h index 7a713d133..69f1cd81b 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h @@ -60,6 +60,10 @@ class QPainter; class QUrl; QT_END_NAMESPACE + +// Instantiating the WebView in C++ is only possible by creating +// a QDeclarativeComponent as the initialization depends on the +// componentComplete method being called. class QWEBKIT_EXPORT QQuickWebView : public QQuickItem { Q_OBJECT Q_PROPERTY(QString title READ title NOTIFY titleChanged) @@ -135,7 +139,7 @@ Q_SIGNALS: protected: virtual void geometryChanged(const QRectF&, const QRectF&); - + virtual void componentComplete(); virtual void keyPressEvent(QKeyEvent*); virtual void keyReleaseEvent(QKeyEvent*); virtual void inputMethodEvent(QInputMethodEvent*); @@ -213,7 +217,6 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject { Q_PROPERTY(QDeclarativeComponent* certificateVerificationDialog READ certificateVerificationDialog WRITE setCertificateVerificationDialog NOTIFY certificateVerificationDialogChanged) Q_PROPERTY(QDeclarativeComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged) Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL) - Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour) Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL) Q_PROPERTY(QDeclarativeListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates) Q_ENUMS(NavigationRequestAction) @@ -238,8 +241,6 @@ public: void setCertificateVerificationDialog(QDeclarativeComponent*); QDeclarativeComponent* itemSelector() const; void setItemSelector(QDeclarativeComponent*); - bool useTraditionalDesktopBehaviour() const; - void setUseTraditionalDesktopBehaviour(bool enable); QWebViewportInfo* viewportInfo(); @@ -258,6 +259,8 @@ public: // C++ only bool renderToOffscreenBuffer() const; void setRenderToOffscreenBuffer(bool enable); + static void setFlickableViewportEnabled(bool enable); + static bool flickableViewportEnabled(); public Q_SLOTS: void goBackTo(int index); diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h index 17a5cf82a..9e27ce322 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h @@ -61,32 +61,29 @@ class QQuickWebViewPrivate { public: static QQuickWebViewPrivate* get(QQuickWebView* q) { return q->d_ptr.data(); } - QQuickWebViewPrivate(QQuickWebView* viewport); virtual ~QQuickWebViewPrivate(); - void initialize(WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0); + virtual void initialize(WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0); - void initializeTouch(QQuickWebView* viewport); - void initializeDesktop(QQuickWebView* viewport); void enableMouseEvents(); void disableMouseEvents(); - void loadDidCommit(); - - void didFinishFirstNonEmptyLayout(); - void didChangeViewportProperties(const WebCore::ViewportArguments& args); + virtual void loadDidSucceed(); + virtual void onComponentComplete() { } + virtual void loadDidCommit() { } + virtual void didFinishFirstNonEmptyLayout() { } + virtual void didChangeViewportProperties(const WebCore::ViewportArguments& args) { } void didChangeBackForwardList(); void setNeedsDisplay(); - void updateDesktopViewportSize(); + virtual QtViewportInteractionEngine* viewportInteractionEngine() { return 0; } + virtual void updateViewportSize() { } void updateTouchViewportSize(); - QtViewportInteractionEngine::Constraints computeViewportConstraints(); - - void _q_updateVisibleContentRectAndScale(); + virtual void _q_updateVisibleContentRectAndScale() { } - void _q_suspend(); - void _q_resume(); + virtual void _q_suspend() { } + virtual void _q_resume() { } void _q_viewportTrajectoryVectorChanged(const QPointF&); void _q_onOpenPanelFilesSelected(); void _q_onOpenPanelFinished(int result); @@ -102,7 +99,6 @@ public: void handleAuthenticationRequiredRequest(const QString& hostname, const QString& realm, const QString& prefilledUsername, QString& username, QString& password); bool handleCertificateVerificationRequest(const QString& hostname); - void setUseTraditionalDesktopBehaviour(bool enable); void setRenderToOffscreenBuffer(bool enable) { m_renderToOffscreenBuffer = enable; } void setViewInAttachedProperties(QObject*); void setIcon(const QUrl&); @@ -114,30 +110,15 @@ public: // PageClient. WebCore::IntSize viewSize() const; void didReceiveMessageFromNavigatorQtObject(const String& message); - void pageDidRequestScroll(const QPoint& pos); - void didChangeContentsSize(const QSize& newSize); + virtual void pageDidRequestScroll(const QPoint& pos) { } + virtual void didChangeContentsSize(const QSize& newSize) { } void processDidCrash(); void didRelaunchProcess(); PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy(); void handleDownloadRequest(DownloadProxy*); -private: - // This class is responsible for collecting and applying all properties - // on the viewport item, when transitioning from page A to page B is finished. - // See more at https://trac.webkit.org/wiki/QtWebKitLayoutInteraction - class PostTransitionState { - public: - PostTransitionState(QQuickWebViewPrivate* parent) - : p(parent) - { } - - void apply(); - - QQuickWebViewPrivate* p; - QSize contentsSize; - QPoint position; - }; - +protected: + QQuickWebViewPrivate(QQuickWebView* viewport); RefPtr<QtWebContext> context; RefPtr<WebKit::WebPageProxy> webPageProxy; @@ -151,8 +132,6 @@ private: QScopedPointer<QtWebPageUIClient> pageUIClient; QScopedPointer<QQuickWebPage> pageView; - QScopedPointer<QtViewportInteractionEngine> interactionEngine; - QQuickWebView* q_ptr; QDeclarativeComponent* alertDialog; @@ -163,15 +142,68 @@ private: QDeclarativeComponent* itemSelector; WebCore::ViewportArguments viewportArguments; - OwnPtr<PostTransitionState> postTransitionState; QFileDialog* fileDialog; WKOpenPanelResultListenerRef openPanelResultListener; - bool isTransitioningToNewPage; - bool pageIsSuspended; bool m_navigatorQtObjectEnabled; bool m_renderToOffscreenBuffer; QUrl m_iconURL; }; +class QQuickWebViewLegacyPrivate : public QQuickWebViewPrivate { + Q_DECLARE_PUBLIC(QQuickWebView) +public: + QQuickWebViewLegacyPrivate(QQuickWebView* viewport); + virtual void initialize(WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0); + + virtual void updateViewportSize(); +}; + +class QQuickWebViewFlickablePrivate : public QQuickWebViewPrivate { + Q_DECLARE_PUBLIC(QQuickWebView) +public: + QQuickWebViewFlickablePrivate(QQuickWebView* viewport); + virtual ~QQuickWebViewFlickablePrivate(); + virtual void initialize(WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0); + + virtual void loadDidSucceed(); + virtual void onComponentComplete(); + virtual void loadDidCommit(); + virtual void didFinishFirstNonEmptyLayout(); + virtual void didChangeViewportProperties(const WebCore::ViewportArguments& args); + virtual QtViewportInteractionEngine* viewportInteractionEngine() { return interactionEngine.data(); } + virtual void updateViewportSize(); + virtual void _q_updateVisibleContentRectAndScale(); + virtual void _q_suspend(); + virtual void _q_resume(); + + virtual void pageDidRequestScroll(const QPoint& pos); + virtual void didChangeContentsSize(const QSize& newSize); + + QtViewportInteractionEngine::Constraints computeViewportConstraints(); + +private: + // This class is responsible for collecting and applying all properties + // on the viewport item, when transitioning from page A to page B is finished. + // See more at https://trac.webkit.org/wiki/QtWebKitLayoutInteraction + class PostTransitionState { + public: + PostTransitionState(QQuickWebViewFlickablePrivate* parent) + : p(parent) + { } + + void apply(); + + QQuickWebViewFlickablePrivate* p; + QSize contentsSize; + QPoint position; + }; + + QScopedPointer<QtViewportInteractionEngine> interactionEngine; + OwnPtr<PostTransitionState> postTransitionState; + bool isTransitioningToNewPage; + bool pageIsSuspended; + bool loadSuccessDispatchIsPending; +}; + #endif // qquickwebview_p_p_h diff --git a/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp b/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp index 735196f86..22863be29 100644 --- a/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo.cpp @@ -38,63 +38,63 @@ QWebViewportInfo::~QWebViewportInfo() QSize QWebViewportInfo::contentsSize() const { - return QSize(m_webViewPrivate->pageView->contentSize().toSize()); + return QSize(m_webViewPrivate->pageView->contentsSize().toSize()); } QVariant QWebViewportInfo::currentScale() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->currentCSSScale(); - return m_webViewPrivate->interactionEngine->currentCSSScale(); + return QtViewportInteractionEngine::Constraints().initialScale; } QVariant QWebViewportInfo::devicePixelRatio() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().devicePixelRatio; - return m_webViewPrivate->interactionEngine->constraints().devicePixelRatio; + return QtViewportInteractionEngine::Constraints().devicePixelRatio; } QVariant QWebViewportInfo::initialScale() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().initialScale; - return m_webViewPrivate->interactionEngine->constraints().initialScale; + return QtViewportInteractionEngine::Constraints().initialScale; } QVariant QWebViewportInfo::minimumScale() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().minimumScale; - return m_webViewPrivate->interactionEngine->constraints().minimumScale; + return QtViewportInteractionEngine::Constraints().minimumScale; } QVariant QWebViewportInfo::maximumScale() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().maximumScale; - return m_webViewPrivate->interactionEngine->constraints().maximumScale; + return QtViewportInteractionEngine::Constraints().maximumScale; } QVariant QWebViewportInfo::isScalable() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().isUserScalable; - return m_webViewPrivate->interactionEngine->constraints().isUserScalable; + return QtViewportInteractionEngine::Constraints().isUserScalable; } QVariant QWebViewportInfo::layoutSize() const { - if (!m_webViewPrivate->interactionEngine) - return QVariant(); + if (QtViewportInteractionEngine* interactionEngine = m_webViewPrivate->viewportInteractionEngine()) + return interactionEngine->constraints().layoutSize; - return m_webViewPrivate->interactionEngine->constraints().layoutSize; + return QVariant(QSize()); } void QWebViewportInfo::didUpdateContentsSize() diff --git a/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h b/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h index e1dea6575..653018221 100644 --- a/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qwebviewportinfo_p.h @@ -29,9 +29,6 @@ #include <QtCore/QVariant> #include <QtDeclarative/QtDeclarative> -namespace WebCore { -class ViewportAttributes; -} class QQuickWebViewPrivate; class QWEBKIT_EXPORT QWebViewportInfo : public QObject { diff --git a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro index 728521f8a..0f0d4f52c 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro @@ -1,2 +1,3 @@ include(../tests.pri) +SOURCES += $${TARGET}.cpp CONFIG += qtwebkit-private diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro new file mode 100644 index 000000000..8b5b3cbb8 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro @@ -0,0 +1,22 @@ +include(../tests.pri) +SOURCES += tst_qmltests.cpp +TARGET = tst_qmltests_DesktopBehavior +OBJECTS_DIR = obj_DesktopBehavior/$$activeBuildConfig() + +CONFIG += qtwebkit-private +CONFIG += warn_on testcase + +QT -= testlib +QT += qmltest + +DEFINES += DISABLE_FLICKABLE_VIEWPORT=1 +# Test the QML files under DesktopBehavior in the source repository. +DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD$${QMAKE_DIR_SEP}DesktopBehavior\\\"\" +DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" + +OTHER_FILES += \ + DesktopBehavior/DesktopWebView.qml \ + DesktopBehavior/tst_linkHovered.qml \ + DesktopBehavior/tst_loadHtml.qml \ + DesktopBehavior/tst_messaging.qml \ + DesktopBehavior/tst_navigationRequested.qml diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/DesktopWebView.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/DesktopWebView.qml deleted file mode 100644 index 4dce0918b..000000000 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/DesktopWebView.qml +++ /dev/null @@ -1,9 +0,0 @@ -import QtQuick 2.0 -import QtWebKit 3.0 -import QtWebKit.experimental 3.0 - -WebView { - id: component - experimental.useTraditionalDesktopBehaviour: true -} - diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_itemSelector.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_itemSelector.qml index 03d68be5b..432416a63 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_itemSelector.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_itemSelector.qml @@ -1,13 +1,11 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 -// FIXME: used because we want to have mouseClick() to open the <select> tag. We can remove this +// FIXME: Moved to Desktop tests because we want to have mouseClick() to open the <select> tag. We can move it back // when TestCase starts supporting touch events, see https://bugreports.qt.nokia.com/browse/QTBUG-23083. -import "../DesktopBehavior" - -DesktopWebView { +WebView { id: webView width: 400 diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_linkHovered.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_linkHovered.qml index c98958319..b8ab29496 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_linkHovered.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_linkHovered.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -DesktopWebView { +WebView { id: webView width: 200 height: 400 diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml index b45b01ac8..9e173d56a 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_loadHtml.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -DesktopWebView { +WebView { id: webView width: 200 height: 400 diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_messaging.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_messaging.qml index 7fcc91a64..eb18a8216 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_messaging.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_messaging.qml @@ -1,10 +1,10 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 Item { - DesktopWebView { + WebView { id: webView property variant lastMessage experimental.preferences.navigatorQtObjectEnabled: true @@ -13,7 +13,7 @@ Item { } } - DesktopWebView { + WebView { id: otherWebView property variant lastMessage experimental.preferences.navigatorQtObjectEnabled: true @@ -22,7 +22,7 @@ Item { } } - DesktopWebView { + WebView { id: disabledWebView property bool receivedMessage experimental.preferences.navigatorQtObjectEnabled: false diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml index 3ef7d5516..169a0273e 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 Item { property int expectedLength: 0 @@ -11,7 +11,7 @@ Item { property url beginUrl: Qt.resolvedUrl("../common/test2.html") property url endUrl: Qt.resolvedUrl("../common/test1.html") - DesktopWebView { + WebView { id: webView width: 200 height: 200 @@ -51,7 +51,7 @@ Item { signalName: "loadSucceeded" } - DesktopWebView { + WebView { id: otherWebView } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro new file mode 100644 index 000000000..8cd15ff4d --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro @@ -0,0 +1,30 @@ +include(../tests.pri) +SOURCES += tst_qmltests.cpp +TARGET = tst_qmltests_WebView +OBJECTS_DIR = obj_WebView/$$activeBuildConfig() + +CONFIG += qtwebkit-private +CONFIG += warn_on testcase + +QT -= testlib +QT += qmltest + +# Test the QML files under WebView in the source repository. +DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD$${QMAKE_DIR_SEP}WebView\\\"\" +DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" + +OTHER_FILES += \ + WebView/tst_favIconLoad.qml \ + WebView/tst_download.qml \ + WebView/tst_geopermission.qml \ + WebView/tst_itemSelector.qml \ + WebView/tst_javaScriptDialogs.qml \ + WebView/tst_loadFail.qml \ + WebView/tst_loadIgnore.qml \ + WebView/tst_loadHtml.qml \ + WebView/tst_loadProgress.qml \ + WebView/tst_loadProgressSignal.qml \ + WebView/tst_preferences.qml \ + WebView/tst_properties.qml \ + WebView/tst_titleChanged.qml \ + WebView/tst_applicationScheme.qml diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml index 239483c5b..8bcb5eccb 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 import Test 1.0 WebView { diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml index 6c25af3bc..f8324a606 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_download.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 WebView { id: webView diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_geopermission.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_geopermission.qml index 697ab085a..fd898a78e 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_geopermission.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_geopermission.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 WebView { id: webView diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml index 56c34abcd..13adb3b2d 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_javaScriptDialogs.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 WebView { id: webView diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_navigationHistory.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_navigationHistory.qml index 68aeeb556..b886e48f3 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_navigationHistory.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_navigationHistory.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 WebView { id: webView diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml index 8bec01418..917b689e6 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebKit 3.0 -import QtWebKit.experimental 3.0 +import QtWebKit.experimental 1.0 Item { WebView { diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro index c8ce87a7f..8ddc4484e 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro @@ -1,32 +1,3 @@ -include(../tests.pri) +TEMPLATE = subdirs -CONFIG += qtwebkit-private -CONFIG += warn_on testcase - -QT -= testlib -QT += qmltest - -# QML files tested are the ones in WebKit source repository. -DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD\\\"\" -DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" - -OTHER_FILES += \ - DesktopBehavior/DesktopWebView.qml \ - DesktopBehavior/tst_linkHovered.qml \ - DesktopBehavior/tst_loadHtml.qml \ - DesktopBehavior/tst_messaging.qml \ - DesktopBehavior/tst_navigationRequested.qml \ - WebView/tst_favIconLoad.qml \ - WebView/tst_download.qml \ - WebView/tst_geopermission.qml \ - WebView/tst_itemSelector.qml \ - WebView/tst_javaScriptDialogs.qml \ - WebView/tst_loadFail.qml \ - WebView/tst_loadIgnore.qml \ - WebView/tst_loadHtml.qml \ - WebView/tst_loadProgress.qml \ - WebView/tst_loadProgressSignal.qml \ - WebView/tst_preferences.qml \ - WebView/tst_properties.qml \ - WebView/tst_titleChanged.qml \ - WebView/tst_applicationScheme.qml +SUBDIRS += DesktopBehavior.pro WebView.pro diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp index 8c8c4b3e6..a80c5c389 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/tst_qmltests.cpp @@ -20,6 +20,7 @@ #include "../bytearraytestdata.h" #include "../util.h" +#include "qquickwebview_p.h" #include <QVarLengthArray> #include <QtQuickTest/quicktest.h> #include <QtWidgets/QApplication> @@ -43,5 +44,9 @@ int main(int argc, char** argv) // This can be removed as soon as we do not use QtWidgets any more. QApplication app(argc, argv); qmlRegisterType<ByteArrayTestData>("Test", 1, 0, "ByteArrayTestData"); + +#ifdef DISABLE_FLICKABLE_VIEWPORT + QQuickWebViewExperimental::setFlickableViewportEnabled(false); +#endif return quick_test_main(argc, argv, "qmltests", 0, QUICK_TEST_SOURCE_DIR); } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro index 728521f8a..25cd8324f 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro @@ -1,2 +1,4 @@ include(../tests.pri) +SOURCES += $${TARGET}.cpp CONFIG += qtwebkit-private +DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp index 1d14d1844..db3f9c977 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp @@ -20,6 +20,7 @@ #include "../testwindow.h" #include "../util.h" +#include <QDeclarativeEngine> #include <QScopedPointer> #include <QtTest/QtTest> #include <qquickwebpage_p.h> @@ -55,19 +56,42 @@ private slots: void multipleWebViews(); private: + void prepareWebViewComponent(); + inline QQuickWebView* newWebView(); inline QQuickWebView* webView() const; QScopedPointer<TestWindow> m_window; + QScopedPointer<QDeclarativeComponent> m_component; }; tst_QQuickWebView::tst_QQuickWebView() { addQtWebProcessToPath(); - qRegisterMetaType<QQuickWebPage*>("QQuickWebPage*"); + prepareWebViewComponent(); +} + +void tst_QQuickWebView::prepareWebViewComponent() +{ + static QDeclarativeEngine* engine = new QDeclarativeEngine(this); + engine->addImportPath(QString::fromUtf8(IMPORT_DIR)); + + m_component.reset(new QDeclarativeComponent(engine, this)); + + m_component->setData(QByteArrayLiteral("import QtQuick 2.0\n" + "import QtWebKit 3.0\n" + "WebView {}") + , QUrl()); +} + +QQuickWebView* tst_QQuickWebView::newWebView() +{ + QObject* viewInstance = m_component->create(); + + return qobject_cast<QQuickWebView*>(viewInstance); } void tst_QQuickWebView::init() { - m_window.reset(new TestWindow(new QQuickWebView())); + m_window.reset(new TestWindow(newWebView())); } void tst_QQuickWebView::cleanup() @@ -277,9 +301,9 @@ void tst_QQuickWebView::multipleWebViewWindows() showWebView(); // This should not crash. - QQuickWebView* webView1 = new QQuickWebView(); + QQuickWebView* webView1 = newWebView(); QScopedPointer<TestWindow> window1(new TestWindow(webView1)); - QQuickWebView* webView2 = new QQuickWebView(); + QQuickWebView* webView2 = newWebView(); QScopedPointer<TestWindow> window2(new TestWindow(webView2)); webView1->setSize(QSizeF(300, 400)); @@ -301,9 +325,9 @@ void tst_QQuickWebView::multipleWebViews() showWebView(); // This should not crash. - QScopedPointer<QQuickWebView> webView1(new QQuickWebView()); + QScopedPointer<QQuickWebView> webView1(newWebView()); webView1->setParentItem(m_window->rootItem()); - QScopedPointer<QQuickWebView> webView2(new QQuickWebView()); + QScopedPointer<QQuickWebView> webView2(newWebView()); webView2->setParentItem(m_window->rootItem()); webView1->setSize(QSizeF(300, 400)); @@ -328,7 +352,7 @@ void tst_QQuickWebView::scrollRequest() // COMPARE with the position requested in the html // Use qRound as that is also used when calculating the position // in WebKit. - int y = -qRound(50 * webView()->page()->contentScale()); + int y = -qRound(50 * webView()->page()->contentsScale()); QVERIFY(webView()->page()->pos().y() == y); } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/tests.pri b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri index 06ff1a0a3..ed91d3942 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/tests.pri +++ b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri @@ -5,8 +5,7 @@ TARGET = tst_$$TARGET HEADERS += ../bytearraytestdata.h -SOURCES += $${TARGET}.cpp \ - ../util.cpp \ +SOURCES += ../util.cpp \ ../bytearraytestdata.cpp INCLUDEPATH += $$PWD |