Changeset 87823 in webkit


Ignore:
Timestamp:
Jun 1, 2011 10:41:25 AM (13 years ago)
Author:
xan@webkit.org
Message:

2011-06-01 Xan Lopez <xlopez@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.
Location:
trunk/Source/WebKit/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/gtk/ChangeLog

    r87766 r87823  
     12011-06-01  Xan Lopez  <xlopez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Utility methods for UA spellchecking
     6        https://bugs.webkit.org/show_bug.cgi?id=61788
     7
     8        Adds a couple of utility methods needed to implement some aspects
     9        of spell checking support in a browser.
     10
     11        * webkit/webkitwebframe.cpp:
     12        (webkit_web_frame_replace_selection): method to replace the current
     13        selection with a string of text.
     14        (webkit_web_frame_get_range_for_word_around_caret): returns the DOM
     15        range for the word where the caret/selection currently is.
     16        * webkit/webkitwebframe.h: declare new methods.
     17
    1182011-05-31  Martin Robinson  <mrobinson@igalia.com>
    219
  • trunk/Source/WebKit/gtk/webkit/webkitwebframe.cpp

    r82962 r87823  
    3232#include "AnimationController.h"
    3333#include "DOMObjectCache.h"
     34#include "DocumentFragment.h"
    3435#include "DocumentLoader.h"
    3536#include "DocumentLoaderGtk.h"
    3637#include "FrameLoader.h"
    3738#include "FrameLoaderClientGtk.h"
     39#include "FrameSelection.h"
    3840#include "FrameTree.h"
    3941#include "FrameView.h"
     
    5052#include "RenderTreeAsText.h"
    5153#include "RenderView.h"
     54#include "ReplaceSelectionCommand.h"
    5255#include "ScriptController.h"
    5356#include "SubstituteData.h"
     57#include "TextIterator.h"
     58#include "markup.h"
     59#include "webkit/WebKitDOMRangePrivate.h"
    5460#include "webkitenumtypes.h"
    5561#include "webkitglobalsprivate.h"
     
    975981}
    976982
     983/**
     984 * webkit_web_frame_replace_selection:
     985 * @frame: a #WebKitWeFrame
     986 * @text: the text to insert in place of the current selection
     987 *
     988 * Replaces the current selection in @frame, if any, with @text.
     989 *
     990 * Since: 1.5.1
     991 **/
     992void webkit_web_frame_replace_selection(WebKitWebFrame* frame, const char* text)
     993{
     994    Frame* coreFrame = core(frame);
     995    RefPtr<DocumentFragment> fragment = createFragmentFromText(
     996        coreFrame->selection()->toNormalizedRange().get(), text);
     997    applyCommand(ReplaceSelectionCommand::create(coreFrame->document(), fragment.get(),
     998                                                 ReplaceSelectionCommand::SmartReplace | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting));
     999}
     1000
     1001/**
     1002 * webkit_web_frame_get_range_for_word_around_caret:
     1003 * @frame: a #WebKitWebFrame
     1004 *
     1005 * Returns a #WebKitDOMRange for the word where the caret is currently
     1006 * positioned.
     1007 *
     1008 * Returns: a #WebKitDOMRange spanning the word where the caret
     1009 * currently is positioned. If there is no caret %NULL will be
     1010 * returned.
     1011 *
     1012 * Since: 1.5.1.
     1013 **/
     1014WebKitDOMRange* webkit_web_frame_get_range_for_word_around_caret(WebKitWebFrame* frame)
     1015{
     1016    g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
     1017
     1018    Frame* coreFrame = core(frame);
     1019    FrameSelection* selection = coreFrame->selection();
     1020    if (selection->isNone() || selection->isRange())
     1021        return 0;
     1022    VisibleSelection visibleSelection(selection->selection().visibleStart());
     1023    visibleSelection.expandUsingGranularity(WordGranularity);
     1024
     1025    return kit(visibleSelection.firstRange().get());
     1026}
     1027
    9771028namespace WebKit {
    9781029
  • trunk/Source/WebKit/gtk/webkit/webkitwebframe.h

    r51825 r87823  
    2828
    2929#include <webkit/webkitdefines.h>
     30#include <webkit/webkitdomdefines.h>
    3031#include <webkit/webkitnetworkrequest.h>
    3132#include <webkit/webkitwebdatasource.h>
     
    176177webkit_web_frame_get_network_response        (WebKitWebFrame       *frame);
    177178
     179WEBKIT_API void
     180webkit_web_frame_replace_selection           (WebKitWebFrame        *frame,
     181                                              const char            *text);
     182
     183WEBKIT_API WebKitDOMRange*
     184webkit_web_frame_get_range_for_word_around_caret (WebKitWebFrame    *frame);
     185
    178186G_END_DECLS
    179187
Note: See TracChangeset for help on using the changeset viewer.