Title: [87823] trunk/Source/WebKit/gtk
- Revision
- 87823
- Author
- x...@webkit.org
- Date
- 2011-06-01 10:41:25 -0700 (Wed, 01 Jun 2011)
Log Message
2011-06-01 Xan Lopez <xlo...@igalia.com>
Reviewed by Martin Robinson.
[GTK] Utility methods for UA spellchecking
https://bugs.webkit.org/show_bug.cgi?id=61788
Adds a couple of utility methods needed to implement some aspects
of spell checking support in a browser.
* webkit/webkitwebframe.cpp:
(webkit_web_frame_replace_selection): method to replace the current
selection with a string of text.
(webkit_web_frame_get_range_for_word_around_caret): returns the DOM
range for the word where the caret/selection currently is.
* webkit/webkitwebframe.h: declare new methods.
Modified Paths
Diff
Modified: trunk/Source/WebKit/gtk/ChangeLog (87822 => 87823)
--- trunk/Source/WebKit/gtk/ChangeLog 2011-06-01 17:36:56 UTC (rev 87822)
+++ trunk/Source/WebKit/gtk/ChangeLog 2011-06-01 17:41:25 UTC (rev 87823)
@@ -1,3 +1,20 @@
+2011-06-01 Xan Lopez <xlo...@igalia.com>
+
+ Reviewed by Martin Robinson.
+
+ [GTK] Utility methods for UA spellchecking
+ https://bugs.webkit.org/show_bug.cgi?id=61788
+
+ Adds a couple of utility methods needed to implement some aspects
+ of spell checking support in a browser.
+
+ * webkit/webkitwebframe.cpp:
+ (webkit_web_frame_replace_selection): method to replace the current
+ selection with a string of text.
+ (webkit_web_frame_get_range_for_word_around_caret): returns the DOM
+ range for the word where the caret/selection currently is.
+ * webkit/webkitwebframe.h: declare new methods.
+
2011-05-31 Martin Robinson <mrobin...@igalia.com>
Reviewed by Gustavo Noronha Silva.
Modified: trunk/Source/WebKit/gtk/webkit/webkitwebframe.cpp (87822 => 87823)
--- trunk/Source/WebKit/gtk/webkit/webkitwebframe.cpp 2011-06-01 17:36:56 UTC (rev 87822)
+++ trunk/Source/WebKit/gtk/webkit/webkitwebframe.cpp 2011-06-01 17:41:25 UTC (rev 87823)
@@ -31,10 +31,12 @@
#include "AccessibilityObjectWrapperAtk.h"
#include "AnimationController.h"
#include "DOMObjectCache.h"
+#include "DocumentFragment.h"
#include "DocumentLoader.h"
#include "DocumentLoaderGtk.h"
#include "FrameLoader.h"
#include "FrameLoaderClientGtk.h"
+#include "FrameSelection.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "GCController.h"
@@ -49,8 +51,12 @@
#include "RenderListItem.h"
#include "RenderTreeAsText.h"
#include "RenderView.h"
+#include "ReplaceSelectionCommand.h"
#include "ScriptController.h"
#include "SubstituteData.h"
+#include "TextIterator.h"
+#include "markup.h"
+#include "webkit/WebKitDOMRangePrivate.h"
#include "webkitenumtypes.h"
#include "webkitglobalsprivate.h"
#include "webkitmarshal.h"
@@ -974,6 +980,51 @@
return kitNew(loader->response());
}
+/**
+ * webkit_web_frame_replace_selection:
+ * @frame: a #WebKitWeFrame
+ * @text: the text to insert in place of the current selection
+ *
+ * Replaces the current selection in @frame, if any, with @text.
+ *
+ * Since: 1.5.1
+ **/
+void webkit_web_frame_replace_selection(WebKitWebFrame* frame, const char* text)
+{
+ Frame* coreFrame = core(frame);
+ RefPtr<DocumentFragment> fragment = createFragmentFromText(
+ coreFrame->selection()->toNormalizedRange().get(), text);
+ applyCommand(ReplaceSelectionCommand::create(coreFrame->document(), fragment.get(),
+ ReplaceSelectionCommand::SmartReplace | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting));
+}
+
+/**
+ * webkit_web_frame_get_range_for_word_around_caret:
+ * @frame: a #WebKitWebFrame
+ *
+ * Returns a #WebKitDOMRange for the word where the caret is currently
+ * positioned.
+ *
+ * Returns: a #WebKitDOMRange spanning the word where the caret
+ * currently is positioned. If there is no caret %NULL will be
+ * returned.
+ *
+ * Since: 1.5.1.
+ **/
+WebKitDOMRange* webkit_web_frame_get_range_for_word_around_caret(WebKitWebFrame* frame)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
+
+ Frame* coreFrame = core(frame);
+ FrameSelection* selection = coreFrame->selection();
+ if (selection->isNone() || selection->isRange())
+ return 0;
+ VisibleSelection visibleSelection(selection->selection().visibleStart());
+ visibleSelection.expandUsingGranularity(WordGranularity);
+
+ return kit(visibleSelection.firstRange().get());
+}
+
namespace WebKit {
WebKitWebView* getViewFromFrame(WebKitWebFrame* frame)
Modified: trunk/Source/WebKit/gtk/webkit/webkitwebframe.h (87822 => 87823)
--- trunk/Source/WebKit/gtk/webkit/webkitwebframe.h 2011-06-01 17:36:56 UTC (rev 87822)
+++ trunk/Source/WebKit/gtk/webkit/webkitwebframe.h 2011-06-01 17:41:25 UTC (rev 87823)
@@ -27,6 +27,7 @@
#include <_javascript_Core/JSBase.h>
#include <webkit/webkitdefines.h>
+#include <webkit/webkitdomdefines.h>
#include <webkit/webkitnetworkrequest.h>
#include <webkit/webkitwebdatasource.h>
@@ -175,6 +176,13 @@
WEBKIT_API WebKitNetworkResponse*
webkit_web_frame_get_network_response (WebKitWebFrame *frame);
+WEBKIT_API void
+webkit_web_frame_replace_selection (WebKitWebFrame *frame,
+ const char *text);
+
+WEBKIT_API WebKitDOMRange*
+webkit_web_frame_get_range_for_word_around_caret (WebKitWebFrame *frame);
+
G_END_DECLS
#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes