diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-03-12 14:11:15 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-03-12 14:11:15 +0100 |
commit | dd91e772430dc294e3bf478c119ef8d43c0a3358 (patch) | |
tree | 6f33ce4d5872a5691e0291eb45bf6ab373a5f567 /Source/WebKit2/UIProcess/API/gtk | |
parent | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (diff) | |
download | qtwebkit-dd91e772430dc294e3bf478c119ef8d43c0a3358.tar.gz |
Imported WebKit commit 3db4eb1820ac8fb03065d7ea73a4d9db1e8fea1a (http://svn.webkit.org/repository/webkit/trunk@110422)
This includes build fixes for the latest qtbase/qtdeclarative as well as the final QML2 API.
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk')
28 files changed, 1627 insertions, 234 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp index c3ad3f764..9fadbeab5 100644 --- a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp @@ -242,6 +242,11 @@ void PageClientImpl::exitAcceleratedCompositingMode() { notImplemented(); } + +void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&) +{ + notImplemented(); +} #endif // USE(ACCELERATED_COMPOSITING) void PageClientImpl::didCommitLoadForMainFrame(bool useCustomRepresentation) diff --git a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h index 291ba212b..6a1cb2459 100644 --- a/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h +++ b/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h @@ -92,6 +92,7 @@ private: #if USE(ACCELERATED_COMPOSITING) virtual void enterAcceleratedCompositingMode(const LayerTreeContext&); virtual void exitAcceleratedCompositingMode(); + virtual void updateAcceleratedCompositingMode(const LayerTreeContext&); #endif virtual void didCommitLoadForMainFrame(bool useCustomRepresentation); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h b/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h index 8c3eec2a4..96bcb4ea2 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h @@ -33,6 +33,8 @@ #include <glib.h> typedef struct _WebKitPrintOperation WebKitPrintOperation; +typedef struct _WebKitFindController WebKitFindController; +typedef struct _WebKitWebView WebKitWebView; #ifdef G_OS_WIN32 # ifdef BUILDING_WEBKIT diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp index 4d4eba18d..018f08d3d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp @@ -169,18 +169,14 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) * This signal is emitted after response is received, * every time new data has been written to the destination. It's * useful to know the progress of the download operation. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. */ signals[RECEIVED_DATA] = g_signal_new("received-data", G_TYPE_FROM_CLASS(objectClass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitDownloadClass, received_data), - g_signal_accumulator_true_handled, NULL, - webkit_marshal_BOOLEAN__UINT64, - G_TYPE_BOOLEAN, 1, + 0, 0, 0, + webkit_marshal_VOID__UINT64, + G_TYPE_NONE, 1, G_TYPE_UINT64); /** @@ -189,18 +185,14 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) * * This signal is emitted when download finishes successfully or due to an error. * In case of errors #WebKitDownload::failed signal is emitted before this one. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. */ signals[FINISHED] = g_signal_new("finished", G_TYPE_FROM_CLASS(objectClass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitDownloadClass, finished), - g_signal_accumulator_true_handled, NULL, - webkit_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); + 0, 0, 0, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); /** * WebKitDownload::failed: @@ -213,18 +205,14 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) * with webkit_download_cancel(), this signal is emitted with error * %WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER. The download operation finishes * after an error and #WebKitDownload::finished signal is emitted after this one. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. */ signals[FAILED] = g_signal_new("failed", G_TYPE_FROM_CLASS(objectClass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitDownloadClass, failed), - g_signal_accumulator_true_handled, NULL, - webkit_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, 1, + 0, 0, 0, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); /** @@ -258,17 +246,13 @@ static void webkit_download_class_init(WebKitDownloadClass* downloadClass) * This signal is emitted after #WebKitDownload::decide-destination and before * #WebKitDownload::received-data to notify that destination file has been * created successfully at @destination. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. */ signals[CREATED_DESTINATION] = g_signal_new("created-destination", G_TYPE_FROM_CLASS(objectClass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitDownloadClass, created_destination), - g_signal_accumulator_true_handled, NULL, - webkit_marshal_BOOLEAN__STRING, + 0, 0, 0, + g_cclosure_marshal_VOID__STRING, G_TYPE_BOOLEAN, 1, G_TYPE_STRING); @@ -304,8 +288,7 @@ void webkitDownloadNotifyProgress(WebKitDownload* download, guint64 bytesReceive download->priv->timer.set(g_timer_new()); priv->currentSize += bytesReceived; - gboolean returnValue; - g_signal_emit(download, signals[RECEIVED_DATA], 0, bytesReceived, &returnValue); + g_signal_emit(download, signals[RECEIVED_DATA], 0, bytesReceived); // Throttle progress notification to not consume high amounts of // CPU on fast links, except when the last notification occured @@ -333,9 +316,9 @@ void webkitDownloadFailed(WebKitDownload* download, const ResourceError& resourc resourceError.localizedDescription().utf8().data())); if (download->priv->timer) g_timer_stop(download->priv->timer.get()); - gboolean returnValue; - g_signal_emit(download, signals[FAILED], 0, webError.get(), &returnValue); - g_signal_emit(download, signals[FINISHED], 0, &returnValue); + + g_signal_emit(download, signals[FAILED], 0, webError.get()); + g_signal_emit(download, signals[FINISHED], 0, NULL); } void webkitDownloadCancelled(WebKitDownload* download) @@ -356,8 +339,7 @@ void webkitDownloadFinished(WebKitDownload* download) } if (download->priv->timer) g_timer_stop(download->priv->timer.get()); - gboolean returnValue; - g_signal_emit(download, signals[FINISHED], 0, &returnValue); + g_signal_emit(download, signals[FINISHED], 0, NULL); } CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h index e200fec53..b6c51fea5 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h @@ -50,15 +50,8 @@ struct _WebKitDownload { struct _WebKitDownloadClass { GObjectClass parent_class; - gboolean (* received_data) (WebKitDownload *download, - guint64 data_length); - gboolean (* finished) (WebKitDownload *download); - gboolean (* failed) (WebKitDownload *download, - GError *error); gboolean (* decide_destination) (WebKitDownload *download, const gchar *suggested_filename); - gboolean (* created_destination) (WebKitDownload *download, - const gchar *destination); }; WEBKIT_API GType diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp new file mode 100644 index 000000000..360137e16 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp @@ -0,0 +1,475 @@ +/* + * 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 "WebKitFindController.h" + +#include "WebKitEnumTypes.h" +#include "WebKitPrivate.h" +#include "WebKitWebViewBasePrivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/CString.h> + +using namespace WebCore; + +enum { + FOUND_TEXT, + FAILED_TO_FIND_TEXT, + COUNTED_MATCHES, + + LAST_SIGNAL +}; + +enum { + PROP_0, + + PROP_TEXT, + PROP_OPTIONS, + PROP_MAX_MATCH_COUNT, + PROP_WEB_VIEW +}; + +typedef enum { + FindOperation, + CountOperation +} WebKitFindControllerOperation; + +struct _WebKitFindControllerPrivate { + CString searchText; + uint32_t findOptions; + unsigned maxMatchCount; + WebKitWebView* webView; +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + +G_DEFINE_TYPE(WebKitFindController, webkit_find_controller, G_TYPE_OBJECT) + +COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE, kWKFindOptionsCaseInsensitive); +COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, kWKFindOptionsAtWordStarts); +COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, kWKFindOptionsTreatMedialCapitalAsWordStart); +COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_BACKWARDS, kWKFindOptionsBackwards); +COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_FIND_OPTIONS_WRAP_AROUND, kWKFindOptionsWrapAround); + +static void didFindString(WKPageRef page, WKStringRef string, unsigned matchCount, const void* clientInfo) +{ + g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[FOUND_TEXT], 0, matchCount); +} + +static void didFailToFindString(WKPageRef page, WKStringRef string, const void* clientInfo) +{ + g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[FAILED_TO_FIND_TEXT], 0); +} + +static void didCountStringMatches(WKPageRef page, WKStringRef string, unsigned matchCount, const void* clientInfo) +{ + g_signal_emit(WEBKIT_FIND_CONTROLLER(clientInfo), signals[COUNTED_MATCHES], 0, matchCount); +} + +static void webkit_find_controller_init(WebKitFindController* findController) +{ + WebKitFindControllerPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(findController, WEBKIT_TYPE_FIND_CONTROLLER, WebKitFindControllerPrivate); + findController->priv = priv; + new (priv) WebKitFindControllerPrivate(); +} + +static WKPageRef inline getWKPageFromWebKitWebView(WebKitWebView* webView) +{ + return toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); +} + +static void webkitFindControllerConstructed(GObject* object) +{ + WebKitFindController* findController = WEBKIT_FIND_CONTROLLER(object); + WKPageFindClient wkFindClient = { + kWKPageFindClientCurrentVersion, + findController, // clientInfo + didFindString, + didFailToFindString, + didCountStringMatches + }; + + WKPageSetPageFindClient(getWKPageFromWebKitWebView(findController->priv->webView), &wkFindClient); +} + +static void webkitFindControllerGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitFindController* findController = WEBKIT_FIND_CONTROLLER(object); + + switch (propId) { + case PROP_TEXT: + g_value_set_string(value, webkit_find_controller_get_search_text(findController)); + break; + case PROP_OPTIONS: + g_value_set_uint(value, webkit_find_controller_get_options(findController)); + break; + case PROP_MAX_MATCH_COUNT: + g_value_set_uint(value, webkit_find_controller_get_max_match_count(findController)); + break; + case PROP_WEB_VIEW: + g_value_set_object(value, webkit_find_controller_get_web_view(findController)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkitFindControllerSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) +{ + WebKitFindController* findController = WEBKIT_FIND_CONTROLLER(object); + + switch (propId) { + case PROP_WEB_VIEW: + findController->priv->webView = WEBKIT_WEB_VIEW(g_value_get_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkitFindControllerFinalize(GObject* object) +{ + WEBKIT_FIND_CONTROLLER(object)->priv->~WebKitFindControllerPrivate(); + G_OBJECT_CLASS(webkit_find_controller_parent_class)->finalize(object); +} + +static void webkit_find_controller_class_init(WebKitFindControllerClass* findClass) +{ + GObjectClass* gObjectClass = G_OBJECT_CLASS(findClass); + + gObjectClass->constructed = webkitFindControllerConstructed; + gObjectClass->get_property = webkitFindControllerGetProperty; + gObjectClass->set_property = webkitFindControllerSetProperty; + gObjectClass->finalize = webkitFindControllerFinalize; + + g_type_class_add_private(findClass, sizeof(WebKitFindControllerPrivate)); + + /** + * WebKitFindController:text: + * + * The current search text for this #WebKitFindController. + */ + g_object_class_install_property(gObjectClass, + PROP_TEXT, + g_param_spec_string("text", + _("Search text"), + _("Text to search for in the view"), + 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitFindController:options: + * + * The options to be used in the search operation. + */ + g_object_class_install_property(gObjectClass, + PROP_OPTIONS, + g_param_spec_flags("options", + _("Search Options"), + _("Search options to be used in the search operation"), + WEBKIT_TYPE_FIND_OPTIONS, + WEBKIT_FIND_OPTIONS_NONE, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitFindController:max-match-count: + * + * The maximum number of matches to report for a given search. + */ + g_object_class_install_property(gObjectClass, + PROP_MAX_MATCH_COUNT, + g_param_spec_uint("max-match-count", + _("Maximum matches count"), + _("The maximum number of matches in a given text to report"), + 0, G_MAXUINT, 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitFindController:web-view: + * + * The #WebKitWebView this controller is associated to. + */ + g_object_class_install_property(gObjectClass, + PROP_WEB_VIEW, + g_param_spec_object("web-view", + _("WebView"), + _("The WebView associated with this find controller"), + WEBKIT_TYPE_WEB_VIEW, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitFindController::found-text: + * @find_controller: the #WebKitFindController + * @match_count: the number of matches found of the search text + * + * This signal is emitted when a given text is found in the web + * page text. It will be issued if the text is found + * asynchronously after a call to webkit_find_controller_search(), + * webkit_find_controller_search_next() or + * webkit_find_controller_search_previous(). + */ + signals[FOUND_TEXT] = + g_signal_new("found-text", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); + + /** + * WebKitFindController::failed-to-find-text: + * @find_controller: the #WebKitFindController + * + * This signal is emitted when a search operation does not find + * any result for the given text. It will be issued if the text + * is not found asynchronously after a call to + * webkit_find_controller_search(), webkit_find_controller_search_next() + * or webkit_find_controller_search_previous(). + */ + signals[FAILED_TO_FIND_TEXT] = + g_signal_new("failed-to-find-text", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitFindController::counted-matches: + * @find_controller: the #WebKitFindController + * @match_count: the number of matches of the search text + * + * This signal is emitted when the #WebKitFindController has + * counted the number of matches for a given text after a call + * to webkit_find_controller_count_matches(). + */ + signals[COUNTED_MATCHES] = + g_signal_new("counted-matches", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); +} + +/** + * webkit_find_controller_get_search_text: + * @find_controller: the #WebKitFindController + * + * Gets the text that @find_controller is currently searching + * for. This text is passed to either + * webkit_find_controller_search() or + * webkit_find_controller_count_matches(). + * + * Returns: the text to look for in the #WebKitWebView. + */ +const char* webkit_find_controller_get_search_text(WebKitFindController* findController) +{ + g_return_val_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController), 0); + + return findController->priv->searchText.data(); +} + +/** + * webkit_find_controller_get_options: + * @find_controller: the #WebKitFindController + * + * Gets a bitmask containing the #WebKitFindOptions associated with + * the current search. + * + * Returns: a bitmask containing the #WebKitFindOptions associated + * with the current search. + */ +guint32 webkit_find_controller_get_options(WebKitFindController* findController) +{ + g_return_val_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController), WEBKIT_FIND_OPTIONS_NONE); + + return findController->priv->findOptions; +} + +/** + * webkit_find_controller_get_max_match_count: + * @find_controller: the #WebKitFindController + * + * Gets the maximum number of matches to report during a text + * lookup. This number is passed as the last argument of + * webkit_find_controller_search() or + * webkit_find_controller_count_matches(). + * + * Returns: the maximum number of matches to report. + */ +guint webkit_find_controller_get_max_match_count(WebKitFindController* findController) +{ + g_return_val_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController), 0); + + return findController->priv->maxMatchCount; +} + +/** + * webkit_find_controller_get_web_view: + * @find_controller: the #WebKitFindController + * + * Gets the #WebKitWebView this find controller is associated to. Do + * not unref the returned instance as it belongs to the + * #WebKitFindController. + * + * Returns: (transfer none): the #WebKitWebView. + */ +WebKitWebView* webkit_find_controller_get_web_view(WebKitFindController* findController) +{ + g_return_val_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController), 0); + + return findController->priv->webView; +} + +static void webKitFindControllerPerform(WebKitFindController* findController, WebKitFindControllerOperation operation) +{ + WKFindOptions wkFindOptions = static_cast<WKFindOptions>(findController->priv->findOptions); + WKRetainPtr<WKStringRef> wkSearchText(AdoptWK, WKStringCreateWithUTF8CString(findController->priv->searchText.data())); + WKPageRef wkPage = getWKPageFromWebKitWebView(findController->priv->webView); + + if (operation == FindOperation) { + // Unconditionally highlight text matches. WK1 API was forcing + // clients to enable/disable highlighting. Since most of them + // (all?) where using highlighting we decided to simplify the + // WK2 API and unconditionally show highlights. + wkFindOptions = static_cast<WKFindOptions>(findController->priv->findOptions | kWKFindOptionsShowHighlight); + WKPageFindString(wkPage, wkSearchText.get(), wkFindOptions, findController->priv->maxMatchCount); + return; + } + + WKPageCountStringMatches(wkPage, wkSearchText.get(), wkFindOptions, findController->priv->maxMatchCount); +} + +static inline void webKitFindControllerSetSearchData(WebKitFindController* findController, const gchar* searchText, guint32 findOptions, guint maxMatchCount) +{ + findController->priv->searchText = searchText; + findController->priv->findOptions = findOptions; + findController->priv->maxMatchCount = maxMatchCount; +} + +/** + * webkit_find_controller_search: + * @find_controller: the #WebKitFindController + * @search_text: the text to look for + * @find_options: a bitmask with the #WebKitFindOptions used in the search + * @max_match_count: the maximum number of matches allowed in the search + * + * Looks for @search_text in the #WebKitWebView associated with + * @find_controller since the beginning of the document highlighting + * up to @max_match_count matches. The outcome of the search will be + * asynchronously provided by the #WebKitFindController::found-text + * and #WebKitFindController::failed-to-find-text signals. + * + * To look for the next or previous occurrences of the same text + * with the same find options use webkit_find_controller_search_next() + * and/or webkit_find_controller_search_previous(). The + * #WebKitFindController will use the same text and options for the + * following searches unless they are modified by another call to this + * method. + * + * Note that if the number of matches is higher than @max_match_count + * then #WebKitFindController::found-text will report %G_MAXUINT matches + * instead of the actual number. + * + * Callers should call webkit_find_controller_search_finish() to + * finish the current search operation. + */ +void webkit_find_controller_search(WebKitFindController* findController, const gchar* searchText, guint findOptions, guint maxMatchCount) +{ + g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); + g_return_if_fail(searchText); + + webKitFindControllerSetSearchData(findController, searchText, findOptions, maxMatchCount); + webKitFindControllerPerform(findController, FindOperation); +} + +/** + * webkit_find_controller_search_next: + * @find_controller: the #WebKitFindController + * + * Looks for the next occurrence of the search text. + * + * Calling this method before webkit_find_controller_search() or + * webkit_find_controller_count_matches() is a programming error. + */ +void webkit_find_controller_search_next(WebKitFindController* findController) +{ + g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); + + findController->priv->findOptions = findController->priv->findOptions & ~WEBKIT_FIND_OPTIONS_BACKWARDS; + webKitFindControllerPerform(findController, FindOperation); +} + +/** + * webkit_find_controller_search_previous: + * @find_controller: the #WebKitFindController + * + * Looks for the previous occurrence of the search text. + * + * Calling this method before webkit_find_controller_search() or + * webkit_find_controller_count_matches() is a programming error. + */ +void webkit_find_controller_search_previous(WebKitFindController* findController) +{ + g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); + + findController->priv->findOptions = findController->priv->findOptions | WEBKIT_FIND_OPTIONS_BACKWARDS; + webKitFindControllerPerform(findController, FindOperation); +} + +/** + * webkit_find_controller_count_matches: + * @find_controller: the #WebKitFindController + * @search_text: the text to look for + * @find_options: a bitmask with the #WebKitFindOptions used in the search + * @max_match_count: the maximum number of matches allowed in the search + * + * Counts the number of matches for @search_text found in the + * #WebKitWebView with the provided @find_options. The number of + * matches will be provided by the + * #WebKitFindController::counted-matches signal. + */ +void webkit_find_controller_count_matches(WebKitFindController* findController, const gchar* searchText, guint32 findOptions, guint maxMatchCount) +{ + g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); + g_return_if_fail(searchText); + + webKitFindControllerSetSearchData(findController, searchText, findOptions, maxMatchCount); + webKitFindControllerPerform(findController, CountOperation); +} + +/** + * webkit_find_controller_search_finish: + * @find_controller: a #WebKitFindController + * + * Finishes a find operation started by + * webkit_find_controller_search(). It will basically unhighlight + * every text match found. + * + * This method will be typically called when the search UI is + * closed/hidden by the client application. + */ +void webkit_find_controller_search_finish(WebKitFindController* findController) +{ + g_return_if_fail(WEBKIT_IS_FIND_CONTROLLER(findController)); + + WKPageHideFindUI(getWKPageFromWebKitWebView(findController->priv->webView)); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h new file mode 100644 index 000000000..3a47f99d4 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitFindController_h +#define WebKitFindController_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_FIND_CONTROLLER (webkit_find_controller_get_type()) +#define WEBKIT_FIND_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_FIND_CONTROLLER, WebKitFindController)) +#define WEBKIT_FIND_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_FIND_CONTROLLER, WebKitFindControllerClass)) +#define WEBKIT_IS_FIND_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_FIND_CONTROLLER)) +#define WEBKIT_IS_FIND_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_FIND_CONTROLLER)) +#define WEBKIT_FIND_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_FIND_CONTROLLER, WebKitFindControllerClass)) + +typedef struct _WebKitFindControllerPrivate WebKitFindControllerPrivate; +typedef struct _WebKitFindControllerClass WebKitFindControllerClass; + +/** + * WebKitFindOptions: + * @WEBKIT_FIND_OPTIONS_NONE: no search flags, this means a case + * sensitive, no wrap, forward only search. + * @WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE: case insensitive search. + * @WEBKIT_FIND_OPTIONS_AT_WORD_STARTS: search text only at the + * begining of the words. + * @WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START: treat + * capital letters in the middle of words as word start. + * @WEBKIT_FIND_OPTIONS_BACKWARDS: search backwards. + * @WEBKIT_FIND_OPTIONS_WRAP_AROUND: if not present search will stop + * at the end of the document. + * + * Enum values used to specify search options. + */ +typedef enum { + WEBKIT_FIND_OPTIONS_NONE, + + WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE = 1 << 0, + WEBKIT_FIND_OPTIONS_AT_WORD_STARTS = 1 << 1, + WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, + WEBKIT_FIND_OPTIONS_BACKWARDS = 1 << 3, + WEBKIT_FIND_OPTIONS_WRAP_AROUND = 1 << 4, +} WebKitFindOptions; + +struct _WebKitFindController { + GObject parent; + + /*< private >*/ + WebKitFindControllerPrivate *priv; +}; + +struct _WebKitFindControllerClass { + GObjectClass parent_class; +}; + +WEBKIT_API GType +webkit_find_controller_get_type (void); + +WEBKIT_API void +webkit_find_controller_search (WebKitFindController *find_controller, + const gchar *search_text, + guint32 find_options, + guint max_match_count); + +WEBKIT_API void +webkit_find_controller_search_finish (WebKitFindController *find_controller); + +WEBKIT_API void +webkit_find_controller_search_next (WebKitFindController *find_controller); + +WEBKIT_API void +webkit_find_controller_search_previous (WebKitFindController *find_controller); + +WEBKIT_API void +webkit_find_controller_count_matches (WebKitFindController *find_controller, + const gchar *search_text, + guint32 find_options, + guint max_match_count); + +WEBKIT_API const gchar * +webkit_find_controller_get_search_text (WebKitFindController *find_controller); + +WEBKIT_API guint32 +webkit_find_controller_get_options (WebKitFindController *find_controller); + +WEBKIT_API guint +webkit_find_controller_get_max_match_count (WebKitFindController *find_controller); + +WEBKIT_API WebKitWebView * +webkit_find_controller_get_web_view (WebKitFindController *find_controller); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp index 94d13eab2..e40fde76e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp @@ -38,7 +38,7 @@ using namespace WebKit; * @See_also: #WebKitPolicyDecision, #WebKitWebView * * WebKitNavigationPolicyDecision represents a policy decision for events associated with - * navigations. If the value of WebKitNavigationPolicyDecision:mouse-button is not 0, then + * navigations. If the value of #WebKitNavigationPolicyDecision:mouse-button is not 0, then * the navigation was triggered by a mouse event. */ @@ -143,7 +143,7 @@ static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyD * * If the navigation associated with this policy decision was originally * triggered by a mouse event, this property contains a bitmask of various - * GdkModifierType values describing the modifiers used for that click. + * #GdkModifierType values describing the modifiers used for that click. * If the navigation was not triggered by a mouse event or no modifiers * were active, the value of this property will be zero. */ @@ -248,7 +248,7 @@ WebKitURIRequest* webkit_navigation_policy_decision_get_request(WebKitNavigation * * Gets the value of the #WebKitNavigationPolicyDecision:frame-name property. * - * Returns: The name of the new frame this navigation action targets or %NULL + * Returns: The name of the new frame this navigation action targets or %NULL */ const char* webkit_navigation_policy_decision_get_frame_name(WebKitNavigationPolicyDecision* decision) { diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp index a20ccb2a6..d79d40149 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp @@ -367,7 +367,7 @@ void webkit_print_operation_set_page_setup(WebKitPrintOperation* printOperation, * the user. This method returns when the print dialog is closed. * If the print dialog is cancelled %WEBKIT_PRINT_OPERATION_RESPONSE_CANCEL * is returned. If the user clicks on the print button, %WEBKIT_PRINT_OPERATION_RESPONSE_PRINT - * is returned and the print operation starts. In this case, the WebKitPrintOperation::finished + * is returned and the print operation starts. In this case, the #WebKitPrintOperation::finished * signal is emitted when the operation finishes. * If the print dialog is not cancelled current print settings and page setup of @print_operation * are updated with options selected by the user when Print button is pressed in print dialog. @@ -394,7 +394,7 @@ WebKitPrintOperationResponse webkit_print_operation_run_dialog(WebKitPrintOperat * are not set with webkit_print_operation_set_print_settings() and * webkit_print_operation_set_page_setup(), the default options will be used * and the print job will be sent to the default printer. - * The WebKitPrintOperation::finished signal is emitted when the printing + * The #WebKitPrintOperation::finished signal is emitted when the printing * operation finishes. */ void webkit_print_operation_print(WebKitPrintOperation* printOperation) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h index 43d26cc85..e785c3638 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h @@ -28,7 +28,9 @@ #include <WebKit2/WKAPICast.h> #include <WebKit2/WKDownload.h> +#include <WebKit2/WKFindOptions.h> #include <WebKit2/WKRetainPtr.h> +#include <WebKit2/WKString.h> #include <WebKit2/WebKit2.h> #include <glib.h> #include <wtf/Assertions.h> diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp new file mode 100644 index 000000000..863665d71 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.cpp @@ -0,0 +1,126 @@ +/* + * 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 "WebKitScriptDialog.h" + +#include "WebKitScriptDialogPrivate.h" + +static WebKitScriptDialog* webkitScriptDialogCopy(WebKitScriptDialog* dialog) +{ + WebKitScriptDialog* copy = g_slice_new0(WebKitScriptDialog); + new (copy) WebKitScriptDialog(dialog); + return copy; +} + +static void webkitScriptDialogFree(WebKitScriptDialog* dialog) +{ + dialog->~WebKitScriptDialog(); + g_slice_free(WebKitScriptDialog, dialog); +} + +G_DEFINE_BOXED_TYPE(WebKitScriptDialog, webkit_script_dialog, webkitScriptDialogCopy, webkitScriptDialogFree) + +/** + * webkit_script_dialog_get_dialog_type: + * @dialog: a #WebKitScriptDialog + * + * Get the dialog type of a #WebKitScriptDialog. + * + * Returns: the #WebKitScriptDialogType of @dialog + */ +WebKitScriptDialogType webkit_script_dialog_get_dialog_type(WebKitScriptDialog* dialog) +{ + g_return_val_if_fail(dialog, WEBKIT_SCRIPT_DIALOG_ALERT); + + return static_cast<WebKitScriptDialogType>(dialog->type); +} + +/** + * webkit_script_dialog_get_message: + * @dialog: a #WebKitScriptDialog + * + * Get the message of a #WebKitScriptDialog. + * + * Returns: the message of @dialog. + */ +const char* webkit_script_dialog_get_message(WebKitScriptDialog* dialog) +{ + g_return_val_if_fail(dialog, 0); + + return dialog->message.data(); +} + +/** + * webkit_script_dialog_confirm_set_confirmed: + * @dialog: a #WebKitScriptDialog + * @confirmed: whether user confirmed the dialog + * + * This method is used for %WEBKIT_SCRIPT_DIALOG_CONFIRM dialogs when + * #WebKitWebView::script-dialog signal is emitted to set whether the user + * confirmed the dialog or not. The default implementation of #WebKitWebView::script-dialog + * signal sets %TRUE when the OK button is clicked and %FALSE otherwise. + * It's an error to use this method with a #WebKitScriptDialog that is not of type + * %WEBKIT_SCRIPT_DIALOG_CONFIRM. + */ +void webkit_script_dialog_confirm_set_confirmed(WebKitScriptDialog* dialog, gboolean confirmed) +{ + g_return_if_fail(dialog); + g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_CONFIRM); + + dialog->confirmed = confirmed; +} + +/** + * webkit_script_dialog_prompt_get_default_text: + * @dialog: a #WebKitScriptDialog + * + * Get the default text of a #WebKitScriptDialog of type %WEBKIT_SCRIPT_DIALOG_PROMPT. + * It's an error to use this method with a #WebKitScriptDialog that is not of type + * %WEBKIT_SCRIPT_DIALOG_PROMPT. + * + * Returns: the default text of @dialog + */ +const char* webkit_script_dialog_prompt_get_default_text(WebKitScriptDialog* dialog) +{ + g_return_val_if_fail(dialog, 0); + g_return_val_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_PROMPT, 0); + + return dialog->defaultText.data(); +} + +/** + * webkit_script_dialog_prompt_set_text: + * @dialog: a #WebKitScriptDialog + * @text: the text to set + * + * This method is used for %WEBKIT_SCRIPT_DIALOG_PROMPT dialogs when + * #WebKitWebView::script-dialog signal is emitted to set the text + * entered by the user. The default implementation of #WebKitWebView::script-dialog + * signal sets the text of the entry form when OK button is clicked, otherwise %NULL is set. + * It's an error to use this method with a #WebKitScriptDialog that is not of type + * %WEBKIT_SCRIPT_DIALOG_PROMPT. + */ +void webkit_script_dialog_prompt_set_text(WebKitScriptDialog* dialog, const char* text) +{ + g_return_if_fail(dialog); + g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_PROMPT); + + dialog->text = text; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h new file mode 100644 index 000000000..cf88535ad --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialog.h @@ -0,0 +1,75 @@ +/* + * 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 WebKitScriptDialog_h +#define WebKitScriptDialog_h + +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_SCRIPT_DIALOG (webkit_script_dialog_get_type()) + +typedef struct _WebKitScriptDialog WebKitScriptDialog; + +/** + * WebKitScriptDialogType: + * @WEBKIT_SCRIPT_DIALOG_ALERT: Alert script dialog, used to show a + * message to the user. + * @WEBKIT_SCRIPT_DIALOG_CONFIRM: Confirm script dialog, used to ask + * confirmation to the user. + * @WEBKIT_SCRIPT_DIALOG_PROMPT: Prompt script dialog, used to ask + * information to the user. + * + * Enum values used for determining the type of #WebKitScriptDialog + */ +typedef enum { + WEBKIT_SCRIPT_DIALOG_ALERT, + WEBKIT_SCRIPT_DIALOG_CONFIRM, + WEBKIT_SCRIPT_DIALOG_PROMPT +} WebKitScriptDialogType; + +WEBKIT_API GType +webkit_script_dialog_get_type (void); + +WEBKIT_API WebKitScriptDialogType +webkit_script_dialog_get_dialog_type (WebKitScriptDialog *dialog); + +WEBKIT_API const gchar * +webkit_script_dialog_get_message (WebKitScriptDialog *dialog); + +WEBKIT_API void +webkit_script_dialog_confirm_set_confirmed (WebKitScriptDialog *dialog, + gboolean confirmed); + +WEBKIT_API const gchar * +webkit_script_dialog_prompt_get_default_text (WebKitScriptDialog *dialog); + +WEBKIT_API void +webkit_script_dialog_prompt_set_text (WebKitScriptDialog *dialog, + const gchar *text); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialogPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialogPrivate.h new file mode 100644 index 000000000..5f1a43d94 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitScriptDialogPrivate.h @@ -0,0 +1,60 @@ +/* + * 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 WebKitScriptDialogPrivate_h +#define WebKitScriptDialogPrivate_h + +#include "WebKitScriptDialog.h" +#include <wtf/text/CString.h> + +struct _WebKitScriptDialog { + _WebKitScriptDialog(unsigned type, const CString& message) + : type(type) + , message(message) + , confirmed(false) + { + } + + _WebKitScriptDialog(unsigned type, const CString& message, const CString& defaultText) + : type(type) + , message(message) + , defaultText(defaultText) + , confirmed(false) + { + ASSERT(type == WEBKIT_SCRIPT_DIALOG_PROMPT); + } + + _WebKitScriptDialog(WebKitScriptDialog* dialog) + : type(dialog->type) + , message(dialog->message) + , defaultText(dialog->defaultText) + , confirmed(dialog->confirmed) + , text(dialog->text) + { + } + + unsigned type; + CString message; + CString defaultText; + + bool confirmed; + CString text; +}; + +#endif // WebKitScriptDialogPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp index c1c4a970b..b4b267d1b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp @@ -46,6 +46,7 @@ struct _WebKitSettingsPrivate { CString fantasyFontFamily; CString pictographFontFamily; CString defaultCharset; + bool zoomTextOnly; }; /** @@ -103,7 +104,8 @@ enum { PROP_ENABLE_FULLSCREEN, PROP_PRINT_BACKGROUNDS, PROP_ENABLE_WEBAUDIO, - PROP_ENABLE_WEBGL + PROP_ENABLE_WEBGL, + PROP_ZOOM_TEXT_ONLY }; static void webKitSettingsSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) @@ -210,6 +212,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu case PROP_ENABLE_WEBGL: webkit_settings_set_enable_webgl(settings, g_value_get_boolean(value)); break; + case PROP_ZOOM_TEXT_ONLY: + webkit_settings_set_zoom_text_only(settings, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -320,6 +325,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val case PROP_ENABLE_WEBGL: g_value_set_boolean(value, webkit_settings_get_enable_webgl(settings)); break; + case PROP_ZOOM_TEXT_ONLY: + g_value_set_boolean(value, webkit_settings_get_zoom_text_only(settings)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -816,6 +824,22 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass) FALSE, readWriteConstructParamFlags)); + /** + * WebKitSettings:zoom-text-only: + * + * Whether #WebKitWebView:zoom-level affects only the + * text of the page or all the contents. Other contents containing text + * like form controls will be also affected by zoom factor when + * this property is enabled. + */ + g_object_class_install_property(gObjectClass, + PROP_ZOOM_TEXT_ONLY, + g_param_spec_boolean("zoom-text-only", + _("Zoom Text Only"), + _("Whether zoom level of web view changes only the text size"), + FALSE, + readWriteConstructParamFlags)); + g_type_class_add_private(klass, sizeof(WebKitSettingsPrivate)); } @@ -2073,3 +2097,39 @@ void webkit_settings_set_enable_webgl(WebKitSettings* settings, gboolean enabled WKPreferencesSetWebGLEnabled(priv->preferences.get(), enabled); g_object_notify(G_OBJECT(settings), "enable-webgl"); } + +/** + * webkit_settings_set_zoom_text_only: + * @settings: a #WebKitSettings + * @zoom_text_only: Value to be set + * + * Set the #WebKitSettings:zoom-text-only property. + */ +void webkit_settings_set_zoom_text_only(WebKitSettings* settings, gboolean zoomTextOnly) +{ + g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); + + WebKitSettingsPrivate* priv = settings->priv; + if (priv->zoomTextOnly == zoomTextOnly) + return; + + priv->zoomTextOnly = zoomTextOnly; + g_object_notify(G_OBJECT(settings), "zoom-text-only"); +} + +/** + * webkit_settings_get_zoom_text_only: + * @settings: a #WebKitSettings + * + * Get the #WebKitSettings:zoom-text-only property. + * + * Returns: %TRUE If zoom level of the view should only affect the text + * or %FALSE if all view contents should be scaled. + */ +gboolean webkit_settings_get_zoom_text_only(WebKitSettings* settings) +{ + g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE); + + return settings->priv->zoomTextOnly; +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h index b22ba00ff..25a78aca3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h @@ -307,6 +307,13 @@ WEBKIT_API void webkit_settings_set_enable_webgl (WebKitSettings *settings, gboolean enabled); +WEBKIT_API void +webkit_settings_set_zoom_text_only (WebKitSettings *settings, + gboolean zoom_text_only); + +WEBKIT_API gboolean +webkit_settings_get_zoom_text_only (WebKitSettings *settings); + 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 be590ff33..4f17d4669 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -30,6 +30,7 @@ #include "WebKitPolicyClient.h" #include "WebKitPrintOperationPrivate.h" #include "WebKitPrivate.h" +#include "WebKitScriptDialogPrivate.h" #include "WebKitSettingsPrivate.h" #include "WebKitUIClient.h" #include "WebKitWebContextPrivate.h" @@ -55,9 +56,7 @@ enum { READY_TO_SHOW, CLOSE, - SCRIPT_ALERT, - SCRIPT_CONFIRM, - SCRIPT_PROMPT, + SCRIPT_DIALOG, DECIDE_POLICY, @@ -78,13 +77,20 @@ enum { PROP_ZOOM_LEVEL }; +typedef enum { + NotReplacingContent, + WillReplaceContent, + ReplacingContent, + DidReplaceContent +} ReplaceContentStatus; + struct _WebKitWebViewPrivate { WebKitWebContext* context; CString title; CString customTextEncoding; double estimatedLoadProgress; CString activeURI; - bool replacingContent; + ReplaceContentStatus replaceContentStatus; GRefPtr<WebKitBackForwardList> backForwardList; GRefPtr<WebKitSettings> settings; @@ -92,6 +98,8 @@ struct _WebKitWebViewPrivate { GRefPtr<WebKitHitTestResult> mouseTargetHitTestResult; unsigned mouseTargetModifiers; + + GRefPtr<WebKitFindController> findController; }; static guint signals[LAST_SIGNAL] = { 0, }; @@ -128,39 +136,56 @@ static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, Gt return dialog; } -static gboolean webkitWebViewScriptAlert(WebKitWebView* webView, const char* message) +static gboolean webkitWebViewScriptDialog(WebKitWebView* webView, WebKitScriptDialog* scriptDialog) { - GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, message); - gtk_dialog_run(GTK_DIALOG(dialog)); + GtkWidget* dialog = 0; + + switch (scriptDialog->type) { + case WEBKIT_SCRIPT_DIALOG_ALERT: + dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, scriptDialog->message.data()); + gtk_dialog_run(GTK_DIALOG(dialog)); + break; + case WEBKIT_SCRIPT_DIALOG_CONFIRM: + dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data()); + scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK; + break; + case WEBKIT_SCRIPT_DIALOG_PROMPT: + dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data()); + GtkWidget* entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(entry), scriptDialog->defaultText.data()); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry); + gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); + gtk_widget_show(entry); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) + scriptDialog->text = gtk_entry_get_text(GTK_ENTRY(entry)); + break; + } + gtk_widget_destroy(dialog); + return TRUE; } -static gboolean webkitWebViewScriptConfirm(WebKitWebView* webView, const char* message, gboolean* confirmed) +static gboolean webkitWebViewDecidePolicy(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType) { - GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message); - *confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK; - gtk_widget_destroy(dialog); + webkit_policy_decision_use(decision); return TRUE; } -static gboolean webkitWebViewScriptPrompt(WebKitWebView* webView, const char* message, const char* defaultText, char** text) +static void zoomTextOnlyChanged(WebKitSettings* settings, GParamSpec*, WebKitWebView* webView) { - GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message); - GtkWidget* entry = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(entry), defaultText); - gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry); - gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); - gtk_widget_show(entry); - - *text = (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) ? g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))) : 0; - return TRUE; + WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); + gboolean zoomTextOnly = webkit_settings_get_zoom_text_only(settings); + gdouble pageZoomLevel = zoomTextOnly ? 1 : WKPageGetTextZoomFactor(wkPage); + gdouble textZoomLevel = zoomTextOnly ? WKPageGetPageZoomFactor(wkPage) : 1; + WKPageSetPageAndTextZoomFactors(wkPage, pageZoomLevel, textZoomLevel); } -static gboolean webkitWebViewDecidePolicy(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType) +static void webkitWebViewSetSettings(WebKitWebView* webView, WebKitSettings* settings, WKPageRef wkPage) { - webkit_policy_decision_use(decision); - return TRUE; + webView->priv->settings = settings; + webkitSettingsAttachSettingsToPage(webView->priv->settings.get(), wkPage); + g_signal_connect(settings, "notify::zoom-text-only", G_CALLBACK(zoomTextOnlyChanged), webView); } static void webkitWebViewConstructed(GObject* object) @@ -180,8 +205,9 @@ static void webkitWebViewConstructed(GObject* object) WebPageProxy* page = webkitWebViewBaseGetPage(webViewBase); priv->backForwardList = adoptGRef(webkitBackForwardListCreate(WKPageGetBackForwardList(toAPI(page)))); - priv->settings = adoptGRef(webkit_settings_new()); - webkitSettingsAttachSettingsToPage(priv->settings.get(), toAPI(page)); + + GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new()); + webkitWebViewSetSettings(webView, settings.get(), toAPI(page)); } static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) @@ -262,9 +288,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) webViewClass->load_failed = webkitWebViewLoadFail; webViewClass->create = webkitWebViewCreate; - webViewClass->script_alert = webkitWebViewScriptAlert; - webViewClass->script_confirm = webkitWebViewScriptConfirm; - webViewClass->script_prompt = webkitWebViewScriptPrompt; + webViewClass->script_dialog = webkitWebViewScriptDialog; webViewClass->decide_policy = webkitWebViewDecidePolicy; g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate)); @@ -494,75 +518,40 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) G_TYPE_NONE, 0); /** - * WebKitWebView::script-alert: - * @web_view: the #WebKitWebView on which the signal is emitted - * @message: the message text - * - * Emitted when JavaScript code calls <function>window.alert</function>. If the - * signal is not handled a message dialog with a single Close button will be - * shown with the message text. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. - */ - signals[SCRIPT_ALERT] = - g_signal_new("script-alert", - G_TYPE_FROM_CLASS(webViewClass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, script_alert), - g_signal_accumulator_true_handled, 0, - webkit_marshal_BOOLEAN__STRING, - G_TYPE_BOOLEAN, 1, - G_TYPE_STRING); - - /** - * WebKitWebView::script-confirm: - * @web_view: the #WebKitWebView on which the signal is emitted - * @message: the message text - * @confirmed: (out): return location for confirm dialog response - * - * Emitted when JavaScript code calls <function>confirm</function>. If the - * signal is not handled a message dialog with OK and Cancel buttons will be - * shown with the message text. If OK button is clicked @confirmed will be - * set to %TRUE, otherwise it will be %FALSE. - * - * Returns: %TRUE to stop other handlers from being invoked for the event. - * %FALSE to propagate the event further. - */ - signals[SCRIPT_CONFIRM] = - g_signal_new("script-confirm", - G_TYPE_FROM_CLASS(webViewClass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm), - g_signal_accumulator_true_handled, 0, - webkit_marshal_BOOLEAN__STRING_POINTER, - G_TYPE_BOOLEAN, 2, - G_TYPE_STRING, G_TYPE_POINTER); - - /** - * WebKitWebView::script-prompt: + * WebKitWebView::script-dialog: * @web_view: the #WebKitWebView on which the signal is emitted - * @message: the message text - * @default (allow-none): the default text - * @text: (out): return location for prompt dialog text response + * @dialog: the #WebKitScriptDialog to show * - * Emitted when JavaScript code calls <function>prompt</function>. If the - * signal is not handled a message dialog with OK and Cancel buttons and - * a text entry will be shown with the message text. If OK button is clicked - * @text will contain the text entered by the user, otherwise it will be %NULL. + * Emitted when JavaScript code calls <function>window.alert</function>, + * <function>window.confirm</function> or <function>window.prompt</function>. + * The @dialog parameter should be used to build the dialog. + * If the signal is not handled a different dialog will be built and shown depending + * on the dialog type: + * <itemizedlist> + * <listitem><para> + * %WEBKIT_SCRIPT_DIALOG_ALERT: message dialog with a single Close button. + * </para></listitem> + * <listitem><para> + * %WEBKIT_SCRIPT_DIALOG_CONFIRM: message dialog with OK and Cancel buttons. + * </para></listitem> + * <listitem><para> + * %WEBKIT_SCRIPT_DIALOG_PROMPT: message dialog with OK and Cancel buttons and + * a text entry with the default text. + * </para></listitem> + * </itemizedlist> * * Returns: %TRUE to stop other handlers from being invoked for the event. * %FALSE to propagate the event further. */ - signals[SCRIPT_PROMPT] = - g_signal_new("script-prompt", - G_TYPE_FROM_CLASS(webViewClass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt), - g_signal_accumulator_true_handled, 0, - webkit_marshal_BOOLEAN__STRING_STRING_POINTER, - G_TYPE_BOOLEAN, 3, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + signals[SCRIPT_DIALOG] = + g_signal_new("script-dialog", + G_TYPE_FROM_CLASS(webViewClass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, script_dialog), + g_signal_accumulator_true_handled, 0, + webkit_marshal_BOOLEAN__BOXED, + G_TYPE_BOOLEAN, 1, + WEBKIT_TYPE_SCRIPT_DIALOG | G_SIGNAL_TYPE_STATIC_SCOPE); /** * WebKitWebView::decide-policy: @@ -679,14 +668,30 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) WEBKIT_TYPE_PRINT_OPERATION); } -void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) +static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent) { - if (webView->priv->replacingContent) { + if (webView->priv->replaceContentStatus == ReplacingContent) { if (loadEvent == WEBKIT_LOAD_FINISHED) - webView->priv->replacingContent = false; - return; + webView->priv->replaceContentStatus = DidReplaceContent; + return true; + } + + if (loadEvent == WEBKIT_LOAD_STARTED) { + if (webView->priv->replaceContentStatus == WillReplaceContent) { + webView->priv->replaceContentStatus = ReplacingContent; + return true; + } + webView->priv->replaceContentStatus = NotReplacingContent; } + return false; +} + +void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) +{ + if (updateReplaceContentStatus(webView, loadEvent)) + return; + if (loadEvent != WEBKIT_LOAD_FINISHED) webkitWebViewUpdateURI(webView); g_signal_emit(webView, signals[LOAD_CHANGED], 0, loadEvent); @@ -694,7 +699,7 @@ void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error) { - if (webView->priv->replacingContent) + if (webView->priv->replaceContentStatus == ReplacingContent) return; gboolean returnValue; @@ -714,7 +719,7 @@ void webkitWebViewSetTitle(WebKitWebView* webView, const CString& title) void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress) { - if (webView->priv->replacingContent) + if (webView->priv->replaceContentStatus != NotReplacingContent) return; if (webView->priv->estimatedLoadProgress == estimatedLoadProgress) @@ -763,23 +768,25 @@ void webkitWebViewClosePage(WebKitWebView* webView) void webkitWebViewRunJavaScriptAlert(WebKitWebView* webView, const CString& message) { + WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_ALERT, message); gboolean returnValue; - g_signal_emit(webView, signals[SCRIPT_ALERT], 0, message.data(), &returnValue); + g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue); } bool webkitWebViewRunJavaScriptConfirm(WebKitWebView* webView, const CString& message) { - gboolean returnValue, confirmed; - g_signal_emit(webView, signals[SCRIPT_CONFIRM], 0, message.data(), &confirmed, &returnValue); - return confirmed; + WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_CONFIRM, message); + gboolean returnValue; + g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue); + return dialog.confirmed; } WKStringRef webkitWebViewRunJavaScriptPrompt(WebKitWebView* webView, const CString& message, const CString& defaultText) { + WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_PROMPT, message, defaultText); gboolean returnValue; - GOwnPtr<char> text; - g_signal_emit(webView, signals[SCRIPT_PROMPT], 0, message.data(), defaultText.data(), &text.outPtr(), &returnValue); - return text ? WKStringCreateWithUTF8CString(text.get()) : 0; + g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue); + return dialog.text.isNull() ? 0 : WKStringCreateWithUTF8CString(dialog.text.data()); } void webkitWebViewMakePolicyDecision(WebKitWebView* webView, WebKitPolicyDecisionType type, WebKitPolicyDecision* decision) @@ -965,7 +972,7 @@ void webkit_web_view_replace_content(WebKitWebView* webView, const gchar* conten g_return_if_fail(content); g_return_if_fail(contentURI); - webView->priv->replacingContent = true; + webView->priv->replaceContentStatus = WillReplaceContent; WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content)); WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI)); @@ -1279,8 +1286,8 @@ void webkit_web_view_set_settings(WebKitWebView* webView, WebKitSettings* settin if (webView->priv->settings == settings) return; - webView->priv->settings = settings; - webkitSettingsAttachSettingsToPage(settings, toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)))); + g_signal_handlers_disconnect_by_func(webView->priv->settings.get(), reinterpret_cast<gpointer>(zoomTextOnlyChanged), webView); + webkitWebViewSetSettings(webView, settings, toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)))); } /** @@ -1338,11 +1345,14 @@ void webkit_web_view_set_zoom_level(WebKitWebView* webView, gdouble zoomLevel) { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); - if (WKPageGetPageZoomFactor(wkPage) == zoomLevel) + if (webkit_web_view_get_zoom_level(webView) == zoomLevel) return; - WKPageSetPageZoomFactor(wkPage, zoomLevel); + WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); + if (webkit_settings_get_zoom_text_only(webView->priv->settings.get())) + WKPageSetTextZoomFactor(wkPage, zoomLevel); + else + WKPageSetPageZoomFactor(wkPage, zoomLevel); g_object_notify(G_OBJECT(webView), "zoom-level"); } @@ -1360,10 +1370,10 @@ gdouble webkit_web_view_get_zoom_level(WebKitWebView* webView) g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1); WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); - return WKPageGetPageZoomFactor(wkPage); + gboolean zoomTextOnly = webkit_settings_get_zoom_text_only(webView->priv->settings.get()); + return zoomTextOnly ? WKPageGetTextZoomFactor(wkPage) : WKPageGetPageZoomFactor(wkPage); } - static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context) { GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context)); @@ -1436,3 +1446,23 @@ void webkit_web_view_execute_editing_command(WebKitWebView* webView, const char* WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command)); WKPageExecuteCommand(toAPI(page), wkCommand.get()); } + +/** + * webkit_web_view_get_find_controller: + * @web_view: the #WebKitWebView + * + * Gets the #WebKitFindController that will allow the caller to query + * the #WebKitWebView for the text to look for. + * + * Returns: (transfer none): the #WebKitFindController associated to + * this particular #WebKitWebView. + */ +WebKitFindController* webkit_web_view_get_find_controller(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + if (!webView->priv->findController) + webView->priv->findController = adoptGRef(WEBKIT_FIND_CONTROLLER(g_object_new(WEBKIT_TYPE_FIND_CONTROLLER, "web-view", webView, NULL))); + + return webView->priv->findController.get(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index a1b21420b..fb4c48a2d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -30,7 +30,9 @@ #include <webkit2/WebKitBackForwardList.h> #include <webkit2/WebKitDefines.h> +#include <webkit2/WebKitFindController.h> #include <webkit2/WebKitHitTestResult.h> +#include <webkit2/WebKitScriptDialog.h> #include <webkit2/WebKitSettings.h> #include <webkit2/WebKitURIRequest.h> #include <webkit2/WebKitWebContext.h> @@ -47,7 +49,6 @@ G_BEGIN_DECLS #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; @@ -77,7 +78,7 @@ typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate; * or to block the transfer of resources entirely. * * Enum values used for determining the type of a policy decision during - * WebKitWebView::decide-policy. + * #WebKitWebView::decide-policy. */ typedef enum { WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION, @@ -86,7 +87,7 @@ typedef enum { } WebKitPolicyDecisionType; /** - * WebKitLoadEvent + * WebKitLoadEvent: * @WEBKIT_LOAD_STARTED: A new load request has been made. * No data has been received yet, empty structures have * been allocated to perform the load; the load may still @@ -99,6 +100,9 @@ typedef enum { * load is being performed. * @WEBKIT_LOAD_FINISHED: Load completed. All resources are done loading * or there was an error during the load operation. + * + * Enum values used to denote the different events that happen during a + * #WebKitWebView load operation. */ typedef enum { WEBKIT_LOAD_STARTED, @@ -128,15 +132,9 @@ struct _WebKitWebViewClass { void (* ready_to_show) (WebKitWebView *web_view); void (* close) (WebKitWebView *web_view); - gboolean (* script_alert) (WebKitWebView *web_view, - const gchar *message); - gboolean (* script_confirm) (WebKitWebView *web_view, - const gchar *message, - gboolean *confirmed); - gboolean (* script_prompt) (WebKitWebView *web_view, - const gchar *message, - const gchar *default_text, - gchar **text); + gboolean (* script_dialog) (WebKitWebView *web_view, + WebKitScriptDialog *dialog); + gboolean (* decide_policy) (WebKitWebView *web_view, WebKitPolicyDecision *decision, WebKitPolicyDecisionType type); @@ -265,6 +263,10 @@ webkit_web_view_can_execute_editing_command_finish (WebKitWebView *w WEBKIT_API void webkit_web_view_execute_editing_command (WebKitWebView *web_view, const gchar *command); + +WEBKIT_API WebKitFindController * +webkit_web_view_get_find_controller (WebKitWebView *web_view); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml index 5cd859dad..4a9cc798c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml @@ -27,6 +27,7 @@ <xi:include href="xml/WebKitHitTestResult.xml"/> <xi:include href="xml/WebKitPrintOperation.xml"/> <xi:include href="xml/WebKitError.xml"/> + <xi:include href="xml/WebKitFindController.xml"/> </chapter> <index id="index-all"> diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt index 5bfc129b2..a8f54083a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt @@ -49,6 +49,8 @@ webkit_web_context_get_type WebKitWebView WebKitLoadEvent WebKitPolicyDecisionType +WebKitScriptDialog +WebKitScriptDialogType <SUBSECTION Editing Commands> WEBKIT_EDITING_COMMAND_CUT @@ -86,6 +88,12 @@ 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 +webkit_web_view_get_find_controller +webkit_script_dialog_get_dialog_type +webkit_script_dialog_get_message +webkit_script_dialog_confirm_set_confirmed +webkit_script_dialog_prompt_get_default_text +webkit_script_dialog_prompt_set_text <SUBSECTION Standard> WebKitWebViewClass @@ -95,9 +103,11 @@ WEBKIT_TYPE_WEB_VIEW WEBKIT_WEB_VIEW_CLASS WEBKIT_IS_WEB_VIEW_CLASS WEBKIT_WEB_VIEW_GET_CLASS +WEBKIT_TYPE_SCRIPT_DIALOG <SUBSECTION Private> webkit_web_view_get_type +webkit_script_dialog_get_type WebKitWebViewPrivate </SECTION> @@ -220,6 +230,8 @@ webkit_settings_get_enable_webaudio webkit_settings_set_enable_webaudio webkit_settings_get_enable_webgl webkit_settings_set_enable_webgl +webkit_settings_get_zoom_text_only +webkit_settings_set_zoom_text_only <SUBSECTION Standard> WebKitSettingsClass @@ -461,3 +473,30 @@ webkit_policy_error_quark webkit_download_error_quark </SECTION> +<SECTION> +<FILE>WebKitFindController</FILE> +WebKitFindController +WebKitFindOptions +webkit_find_controller_search +webkit_find_controller_search_finish +webkit_find_controller_search_next +webkit_find_controller_search_previous +webkit_find_controller_get_search_text +webkit_find_controller_count_matches +webkit_find_controller_get_options +webkit_find_controller_get_max_match_count +webkit_find_controller_get_web_view + +<SUBSECTION Standard> +WebKitFindControllerClass +WEBKIT_TYPE_FIND_CONTROLLER +WEBKIT_FIND_CONTROLLER +WEBKIT_IS_FIND_CONTROLLER +WEBKIT_FIND_CONTROLLER_CLASS +WEBKIT_IS_FIND_CONTROLLER_CLASS +WEBKIT_FIND_CONTROLLER_GET_CLASS + +<SUBSECTION Private> +WebKitFindControllerPrivate +webkit_find_controller_get_type +</SECTION> diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types index cba2df42c..8e8d7b13a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types @@ -9,4 +9,5 @@ webkit_uri_response_get_type webkit_uri_request_get_type webkit_window_properties_get_type webkit_download_get_type - +webkit_find_controller_get_type +webkit_script_dialog_get_type diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am index 35ece6845..6adb2d5cd 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am +++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am @@ -1,15 +1,16 @@ if ENABLE_WEBKIT2 TEST_PROGS += \ - Programs/WebKit2APITests/TestWebKitWebContext \ - Programs/WebKit2APITests/TestWebKitWebView \ - Programs/WebKit2APITests/TestLoaderClient \ - Programs/WebKit2APITests/TestWebKitSettings \ Programs/WebKit2APITests/TestBackForwardList \ Programs/WebKit2APITests/TestDownloads \ + Programs/WebKit2APITests/TestLoaderClient \ + Programs/WebKit2APITests/TestPrinting \ + Programs/WebKit2APITests/TestWebKitFindController \ Programs/WebKit2APITests/TestWebKitPolicyClient \ - Programs/WebKit2APITests/TestWebViewEditor \ - Programs/WebKit2APITests/TestPrinting + Programs/WebKit2APITests/TestWebKitSettings \ + Programs/WebKit2APITests/TestWebKitWebContext \ + Programs/WebKit2APITests/TestWebKitWebView \ + Programs/WebKit2APITests/TestWebViewEditor noinst_PROGRAMS += $(TEST_PROGS) @@ -128,4 +129,10 @@ Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS) Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags) +Programs_WebKit2APITests_TestWebKitFindController_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp +Programs_WebKit2APITests_TestWebKitFindController_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitFindController_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitFindController_LDFLAGS = $(webkit2_tests_ldflags) + endif # ENABLE_WEBKIT2 diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp new file mode 100644 index 000000000..ae9ff2f7a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp @@ -0,0 +1,379 @@ +/* + * 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 "LoadTrackingTest.h" +#include <gtk/gtk.h> +#include <webkit2/webkit2.h> +#include <wtf/gobject/GRefPtr.h> + +static const char* testString = "<html><body>first testing second testing secondHalf</body></html>"; + +class FindControllerTest: public WebViewTest { +public: + MAKE_GLIB_TEST_FIXTURE(FindControllerTest); + + FindControllerTest() + : m_findController(webkit_web_view_get_find_controller(m_webView)) + , m_runFindUntilCompletion(false) + { + assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_findController.get())); + } + + ~FindControllerTest() + { + if (m_findController) + g_signal_handlers_disconnect_matched(m_findController.get(), G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); + } + + void find(const char* searchText, guint32 findOptions, guint maxMatchCount) + { + g_signal_connect(m_findController.get(), "found-text", G_CALLBACK(foundTextCallback), this); + g_signal_connect(m_findController.get(), "failed-to-find-text", G_CALLBACK(failedToFindTextCallback), this); + webkit_find_controller_search(m_findController.get(), searchText, findOptions, maxMatchCount); + } + + void count(const char* searchText, guint32 findOptions, guint maxMatchCount) + { + g_signal_connect(m_findController.get(), "counted-matches", G_CALLBACK(countedMatchesCallback), this); + webkit_find_controller_count_matches(m_findController.get(), searchText, findOptions, maxMatchCount); + } + + void waitUntilFindFinished() + { + m_runFindUntilCompletion = true; + g_main_loop_run(m_mainLoop); + } + + void waitUntilWebViewDrawSignal() + { + g_signal_connect_after(m_webView, "draw", G_CALLBACK(webViewDraw), this); + g_main_loop_run(m_mainLoop); + } + + GRefPtr<WebKitFindController> m_findController; + bool m_textFound; + unsigned m_matchCount; + +private: + bool m_runFindUntilCompletion; + + static void webViewDraw(GtkWidget *widget, cairo_t *cr, FindControllerTest* test) + { + g_main_loop_quit(test->m_mainLoop); + g_signal_handlers_disconnect_matched(widget, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, test); + } + + static void foundTextCallback(WebKitFindController*, guint matchCount, FindControllerTest* test) + { + test->m_textFound = true; + test->m_matchCount = matchCount; + if (test->m_runFindUntilCompletion) + g_main_loop_quit(test->m_mainLoop); + } + + static void failedToFindTextCallback(WebKitFindController*, FindControllerTest* test) + { + test->m_textFound = false; + if (test->m_runFindUntilCompletion) + g_main_loop_quit(test->m_mainLoop); + } + + static void countedMatchesCallback(WebKitFindController*, guint matchCount, FindControllerTest* test) + { + test->m_matchCount = matchCount; + if (test->m_runFindUntilCompletion) + g_main_loop_quit(test->m_mainLoop); + } +}; + +static void testFindControllerTextFound(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); +} + +static void testFindControllerTextNotFound(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("notFound", WEBKIT_FIND_OPTIONS_NONE, 1); + test->waitUntilFindFinished(); + + g_assert(!test->m_textFound); +} + +static void testFindControllerMatchCount(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_matchCount == 2); + g_assert(test->m_textFound); +} + +static void testFindControllerMaxMatchCount(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); + test->waitUntilFindFinished(); + + g_assert(test->m_matchCount == G_MAXUINT); + g_assert(test->m_textFound); +} + +static void testFindControllerNext(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + g_assert(test->m_matchCount == 2); + + webkit_find_controller_search_next(test->m_findController.get()); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + g_assert(test->m_matchCount == 2); + g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); + + webkit_find_controller_search_next(test->m_findController.get()); + test->waitUntilFindFinished(); + + g_assert(!test->m_textFound); + g_assert(test->m_matchCount == 2); + g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); +} + +static void testFindControllerPrevious(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_matchCount == 2); + g_assert(test->m_textFound); + + webkit_find_controller_search_next(test->m_findController.get()); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + g_assert(test->m_matchCount == 2); + g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); + + webkit_find_controller_search_previous(test->m_findController.get()); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + g_assert(test->m_matchCount == 2); + g_assert(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS); +} + +static void testFindControllerCountedMatches(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->count("testing", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_matchCount == 2); + + test->count("first", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_matchCount == 1); + + test->count("notFound", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(!test->m_matchCount); +} + +static void testFindControllerOptions(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->find("Testing", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(!test->m_textFound); + + test->find("Testing", WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + + test->find("esting", WEBKIT_FIND_OPTIONS_NONE, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + + test->find("esting", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, 2); + test->waitUntilFindFinished(); + + g_assert(!test->m_textFound); + + test->find("Half", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, 2); + test->waitUntilFindFinished(); + + g_assert(!test->m_textFound); + + test->find("Half", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS | WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, 2); + test->waitUntilFindFinished(); + + g_assert(test->m_textFound); + + test->find("testing", WEBKIT_FIND_OPTIONS_WRAP_AROUND, 3); + test->waitUntilFindFinished(); + g_assert(test->m_textFound); + + webkit_find_controller_search_next(test->m_findController.get()); + test->waitUntilFindFinished(); + g_assert(test->m_textFound); + + webkit_find_controller_search_next(test->m_findController.get()); + test->waitUntilFindFinished(); + g_assert(test->m_textFound); +} + +static gboolean gdkPixbufEqual(GdkPixbuf* firstPixbuf, GdkPixbuf* secondPixbuf) +{ + if (gdk_pixbuf_get_bits_per_sample(firstPixbuf) != gdk_pixbuf_get_bits_per_sample(secondPixbuf) + || gdk_pixbuf_get_has_alpha(firstPixbuf) != gdk_pixbuf_get_has_alpha(secondPixbuf) + || gdk_pixbuf_get_height(firstPixbuf) != gdk_pixbuf_get_height(secondPixbuf) + || gdk_pixbuf_get_n_channels(firstPixbuf) != gdk_pixbuf_get_n_channels(secondPixbuf) + || gdk_pixbuf_get_rowstride(firstPixbuf) != gdk_pixbuf_get_rowstride(secondPixbuf) + || gdk_pixbuf_get_width(firstPixbuf) != gdk_pixbuf_get_width(secondPixbuf)) + return FALSE; + + int pixbufRowstride = gdk_pixbuf_get_rowstride(firstPixbuf); + int pixbufHeight = gdk_pixbuf_get_height(firstPixbuf); + int pixbufWidth = gdk_pixbuf_get_width(firstPixbuf); + int numberOfChannels = gdk_pixbuf_get_n_channels(firstPixbuf); + int bitsPerSample = gdk_pixbuf_get_bits_per_sample(firstPixbuf); + + // Last row can be of different length. Taken from gdk-pixbuf documentation. + int totalLength = (pixbufHeight - 1) * pixbufRowstride \ + + pixbufWidth * ((numberOfChannels * bitsPerSample + 7) / 8); + + guchar* firstPixels = gdk_pixbuf_get_pixels(firstPixbuf); + guchar* secondPixels = gdk_pixbuf_get_pixels(secondPixbuf); + for (int i = 0; i < totalLength; i++) + if (firstPixels[i] != secondPixels[i]) + return FALSE; + + return TRUE; +} + +static void testFindControllerHide(FindControllerTest* test, gconstpointer) +{ + test->loadHtml(testString, 0); + test->waitUntilLoadFinished(); + + test->showInWindowAndWaitUntilMapped(); + int allocatedHeight = gtk_widget_get_allocated_height(GTK_WIDGET(test->m_webView)); + int allocatedWidth = gtk_widget_get_allocated_width(GTK_WIDGET(test->m_webView)); + GdkWindow* webViewGdkWindow = gtk_widget_get_window(GTK_WIDGET(test->m_webView)); + g_assert(webViewGdkWindow); + + test->waitUntilWebViewDrawSignal(); + GRefPtr<GdkPixbuf> originalPixbuf = gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth); + g_assert(originalPixbuf); + + test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); + test->waitUntilFindFinished(); + g_assert(test->m_textFound); + + test->waitUntilWebViewDrawSignal(); + GRefPtr<GdkPixbuf> highlightPixbuf = gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth); + g_assert(highlightPixbuf); + g_assert(!gdkPixbufEqual(originalPixbuf.get(), highlightPixbuf.get())); + +#if (0) + // Requires http://webkit.org/b/77747 to be fixed + WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView); + webkit_find_controller_search_finish(findController); + webkit_web_view_execute_editing_command(test->m_webView, "Unselect"); + + test->waitUntilWebViewDrawSignal(); + GRefPtr<GdkPixbuf> unhighlightPixbuf = gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth); + g_assert(unhighlightPixbuf); + g_assert(gdkPixbufEqual(originalPixbuf.get(), unhighlightPixbuf.get())); +#endif +} + +static void testFindControllerInstance(FindControllerTest* test, gconstpointer) +{ + WebKitFindController* findController1 = webkit_web_view_get_find_controller(test->m_webView); + WebKitFindController* findController2 = webkit_web_view_get_find_controller(test->m_webView); + + g_assert(findController1 == findController2); +} + +static void testFindControllerGetters(FindControllerTest* test, gconstpointer) +{ + const char* searchText = "testing"; + guint maxMatchCount = 1; + guint32 findOptions = WEBKIT_FIND_OPTIONS_WRAP_AROUND | WEBKIT_FIND_OPTIONS_AT_WORD_STARTS; + WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView); + + webkit_find_controller_search(findController, searchText, findOptions, maxMatchCount); + g_assert(webkit_find_controller_get_web_view(findController) == test->m_webView); + g_assert(!g_strcmp0(webkit_find_controller_get_search_text(findController), searchText)); + g_assert(webkit_find_controller_get_max_match_count(findController) == maxMatchCount); + g_assert(webkit_find_controller_get_options(findController) == findOptions); +} + +void beforeAll() +{ + FindControllerTest::add("WebKitFindController", "getters", testFindControllerGetters); + FindControllerTest::add("WebKitFindController", "instance", testFindControllerInstance); + FindControllerTest::add("WebKitFindController", "text-found", testFindControllerTextFound); + FindControllerTest::add("WebKitFindController", "text-not-found", testFindControllerTextNotFound); + FindControllerTest::add("WebKitFindController", "match-count", testFindControllerMatchCount); + FindControllerTest::add("WebKitFindController", "max-match-count", testFindControllerMaxMatchCount); + FindControllerTest::add("WebKitFindController", "next", testFindControllerNext); + FindControllerTest::add("WebKitFindController", "previous", testFindControllerPrevious); + FindControllerTest::add("WebKitFindController", "counted-matches", testFindControllerCountedMatches); + FindControllerTest::add("WebKitFindController", "options", testFindControllerOptions); + FindControllerTest::add("WebKitFindController", "hide", testFindControllerHide); +} + +void afterAll() +{ +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp index a3ce7dece..03c5f2fe8 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp @@ -199,6 +199,11 @@ static void testWebKitSettings(Test*, gconstpointer) webkit_settings_set_enable_webgl(settings, TRUE); g_assert(webkit_settings_get_enable_webgl(settings)); + // Zoom text only is disabled by default. + g_assert(!webkit_settings_get_zoom_text_only(settings)); + webkit_settings_set_zoom_text_only(settings, TRUE); + g_assert(webkit_settings_get_zoom_text_only(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 47da98eb3..bfeda169f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp @@ -71,24 +71,22 @@ static void testWebViewSettings(WebViewTest* test, gconstpointer) g_assert(webkit_settings_get_enable_javascript(settings)); } -static void replaceContentTitleChangedCallback(WebViewTest* test) +static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test) { - g_main_loop_quit(test->m_mainLoop); -} - -static void replaceContentLoadCallback() -{ - g_assert_not_reached(); + // There might be an event from a previous load, + // but never a WEBKIT_LOAD_STARTED after webkit_web_view_replace_content(). + g_assert_cmpint(loadEvent, !=, WEBKIT_LOAD_STARTED); } static void testWebViewReplaceContent(WebViewTest* test, gconstpointer) { - g_signal_connect_swapped(test->m_webView, "notify::title", G_CALLBACK(replaceContentTitleChangedCallback), test); + test->loadHtml("<html><head><title>Replace Content Test</title></head><body>Content to replace</body></html>", 0); + test->waitUntilTitleChangedTo("Replace Content Test"); + g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test); - g_signal_connect(test->m_webView, "load-failed", G_CALLBACK(replaceContentLoadCallback), test); - test->replaceContent("<html><head><title>Content Replaced</title></head><body>New Content</body></html>", + test->replaceContent("<html><body onload='document.title=\"Content Replaced\"'>New Content</body></html>", "http://foo.com/bar", 0); - g_main_loop_run(test->m_mainLoop); + test->waitUntilTitleChangedTo("Content Replaced"); } static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; @@ -106,12 +104,6 @@ public: Close }; - enum ScriptType { - Alert, - Confirm, - Prompt - }; - class WindowProperties { public: WindowProperties() @@ -226,43 +218,52 @@ public: return newWebView; } - static gboolean scriptAlert(WebKitWebView*, const char* message, UIClientTest* test) + void scriptAlert(WebKitScriptDialog* dialog) { - switch (test->m_scriptType) { - case UIClientTest::Alert: - g_assert_cmpstr(message, ==, kAlertDialogMessage); + switch (m_scriptDialogType) { + case WEBKIT_SCRIPT_DIALOG_ALERT: + g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kAlertDialogMessage); break; - case UIClientTest::Confirm: - g_assert(test->m_scriptDialogConfirmed); - g_assert_cmpstr(message, ==, "confirmed"); + case WEBKIT_SCRIPT_DIALOG_CONFIRM: + g_assert(m_scriptDialogConfirmed); + g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, "confirmed"); break; - case UIClientTest::Prompt: - g_assert_cmpstr(message, ==, kPromptDialogReturnedText); + case WEBKIT_SCRIPT_DIALOG_PROMPT: + g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kPromptDialogReturnedText); break; } - g_main_loop_quit(test->m_mainLoop); - - return TRUE; + g_main_loop_quit(m_mainLoop); } - static gboolean scriptConfirm(WebKitWebView*, const char* message, gboolean* confirmed, UIClientTest* test) + void scriptConfirm(WebKitScriptDialog* dialog) { - g_assert_cmpstr(message, ==, kConfirmDialogMessage); - g_assert(confirmed); - test->m_scriptDialogConfirmed = !test->m_scriptDialogConfirmed; - *confirmed = test->m_scriptDialogConfirmed; + g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kConfirmDialogMessage); + m_scriptDialogConfirmed = !m_scriptDialogConfirmed; + webkit_script_dialog_confirm_set_confirmed(dialog, m_scriptDialogConfirmed); + } - return TRUE; + void scriptPrompt(WebKitScriptDialog* dialog) + { + g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kPromptDialogMessage); + g_assert_cmpstr(webkit_script_dialog_prompt_get_default_text(dialog), ==, "default"); + webkit_script_dialog_prompt_set_text(dialog, kPromptDialogReturnedText); } - static gboolean scriptPrompt(WebKitWebView*, const char* message, const char* defaultText, char **text, UIClientTest* test) + static gboolean scriptDialog(WebKitWebView*, WebKitScriptDialog* dialog, UIClientTest* test) { - g_assert_cmpstr(message, ==, kPromptDialogMessage); - g_assert_cmpstr(defaultText, ==, "default"); - g_assert(text); - *text = g_strdup(kPromptDialogReturnedText); + switch (webkit_script_dialog_get_dialog_type(dialog)) { + case WEBKIT_SCRIPT_DIALOG_ALERT: + test->scriptAlert(dialog); + break; + case WEBKIT_SCRIPT_DIALOG_CONFIRM: + test->scriptConfirm(dialog); + break; + case WEBKIT_SCRIPT_DIALOG_PROMPT: + test->scriptPrompt(dialog); + break; + } return TRUE; } @@ -278,15 +279,13 @@ public: } UIClientTest() - : m_scriptType(Alert) + : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT) , m_scriptDialogConfirmed(true) , m_mouseTargetModifiers(0) { webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE); g_signal_connect(m_webView, "create", G_CALLBACK(viewCreate), this); - g_signal_connect(m_webView, "script-alert", G_CALLBACK(scriptAlert), this); - g_signal_connect(m_webView, "script-confirm", G_CALLBACK(scriptConfirm), this); - g_signal_connect(m_webView, "script-prompt", G_CALLBACK(scriptPrompt), this); + g_signal_connect(m_webView, "script-dialog", G_CALLBACK(scriptDialog), this); g_signal_connect(m_webView, "mouse-target-changed", G_CALLBACK(mouseTargetChanged), this); } @@ -313,7 +312,7 @@ public: } Vector<WebViewEvents> m_webViewEvents; - ScriptType m_scriptType; + WebKitScriptDialogType m_scriptDialogType; bool m_scriptDialogConfirmed; WindowProperties m_windowProperties; HashSet<WTF::String> m_windowPropertiesChanged; @@ -340,19 +339,19 @@ static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer) static const char* jsConfirmFormat = "do { confirmed = confirm('%s'); } while (!confirmed); alert('confirmed');"; static const char* jsPromptFormat = "alert(prompt('%s', 'default'));"; - test->m_scriptType = UIClientTest::Alert; + test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_ALERT; GOwnPtr<char> alertDialogMessage(g_strdup_printf(jsAlertFormat, kAlertDialogMessage)); GOwnPtr<char> alertHTML(g_strdup_printf(htmlOnLoadFormat, alertDialogMessage.get())); test->loadHtml(alertHTML.get(), 0); test->waitUntilMainLoopFinishes(); - test->m_scriptType = UIClientTest::Confirm; + test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_CONFIRM; GOwnPtr<char> confirmDialogMessage(g_strdup_printf(jsConfirmFormat, kConfirmDialogMessage)); GOwnPtr<char> confirmHTML(g_strdup_printf(htmlOnLoadFormat, confirmDialogMessage.get())); test->loadHtml(confirmHTML.get(), 0); test->waitUntilMainLoopFinishes(); - test->m_scriptType = UIClientTest::Prompt; + test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_PROMPT; GOwnPtr<char> promptDialogMessage(g_strdup_printf(jsPromptFormat, kPromptDialogMessage)); GOwnPtr<char> promptHTML(g_strdup_printf(htmlOnLoadFormat, promptDialogMessage.get())); test->loadHtml(promptHTML.get(), 0); @@ -447,6 +446,10 @@ static void testWebViewZoomLevel(WebViewTest* test, gconstpointer) g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 1); webkit_web_view_set_zoom_level(test->m_webView, 2.5); g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 2.5); + + webkit_settings_set_zoom_text_only(webkit_web_view_get_settings(test->m_webView), TRUE); + // The zoom level shouldn't change when zoom-text-only setting changes. + g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 2.5); } void beforeAll() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp index 00d3b3e20..31de72911 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp @@ -136,6 +136,28 @@ void WebViewTest::waitUntilLoadFinished() g_main_loop_run(m_mainLoop); } +static void titleChanged(WebKitWebView* webView, GParamSpec*, WebViewTest* test) +{ + if (!test->m_expectedTitle.isNull() && test->m_expectedTitle != webkit_web_view_get_title(webView)) + return; + + g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(titleChanged), test); + g_main_loop_quit(test->m_mainLoop); +} + +void WebViewTest::waitUntilTitleChangedTo(const char* expectedTitle) +{ + m_expectedTitle = expectedTitle; + g_signal_connect(m_webView, "notify::title", G_CALLBACK(titleChanged), this); + g_main_loop_run(m_mainLoop); + m_expectedTitle = CString(); +} + +void WebViewTest::waitUntilTitleChanged() +{ + waitUntilTitleChangedTo(0); +} + static gboolean parentWindowMapped(GtkWidget* widget, GdkEvent*, WebViewTest* test) { g_signal_handlers_disconnect_by_func(widget, reinterpret_cast<void*>(parentWindowMapped), test); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h index 95a569cd6..01f468562 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h @@ -42,6 +42,8 @@ public: void wait(double seconds); void waitUntilLoadFinished(); + void waitUntilTitleChangedTo(const char* expectedTitle); + void waitUntilTitleChanged(); void showInWindowAndWaitUntilMapped(); void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0); @@ -50,6 +52,7 @@ public: GMainLoop* m_mainLoop; CString m_activeURI; GtkWidget* m_parentWindow; + CString m_expectedTitle; }; #endif // WebViewTest_h diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h index f78b873a3..0a807bc3d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h @@ -30,8 +30,10 @@ #include <webkit2/WebKitEditingCommands.h> #include <webkit2/WebKitEnumTypes.h> #include <webkit2/WebKitError.h> +#include <webkit2/WebKitFindController.h> #include <webkit2/WebKitHitTestResult.h> #include <webkit2/WebKitPrintOperation.h> +#include <webkit2/WebKitScriptDialog.h> #include <webkit2/WebKitSettings.h> #include <webkit2/WebKitURIRequest.h> #include <webkit2/WebKitURIResponse.h> diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list b/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list index 77d269a75..5f7356039 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list @@ -1,15 +1,10 @@ +BOOLEAN:BOXED BOOLEAN:ENUM,STRING,POINTER BOOLEAN:OBJECT BOOLEAN:OBJECT,ENUM -BOOLEAN:OBJECT,STRING,POINTER -BOOLEAN:POINTER BOOLEAN:STRING -BOOLEAN:STRING,POINTER -BOOLEAN:STRING,STRING,POINTER -BOOLEAN:UINT64 -BOOLEAN:VOID OBJECT:VOID -VOID:ENUM VOID:OBJECT,UINT VOID:OBJECT,POINTER +VOID:UINT64 |