Changeset 175160 in webkit


Ignore:
Timestamp:
Oct 24, 2014 12:09:57 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Implement is_selected method on WebKitHitTestResult
https://bugs.webkit.org/show_bug.cgi?id=137110

Patch by Marcos Chavarría Teijeiro <chavarria1991@gmail.com> on 2014-10-24
Reviewed by Tim Horton.

Source/WebKit2:

Expose CONTEXT_SELECTION for WebKitHitTestResult.

  • Shared/WebHitTestResult.cpp: Add is_selected field and getter for this field.

(WebKit::WebHitTestResult::Data::Data):
(WebKit::WebHitTestResult::Data::encode):
(WebKit::WebHitTestResult::Data::decode):

  • Shared/WebHitTestResult.h:

(WebKit::WebHitTestResult::isSelected):

  • UIProcess/API/gtk/WebKitHitTestResult.cpp: Add WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION context and method to check it.

(webkitHitTestResultCreate):
(webkitHitTestResultCompare):
(webkit_hit_test_result_context_is_selection):

  • UIProcess/API/gtk/WebKitHitTestResult.h:
  • UIProcess/API/gtk/WebKitWebView.cpp: Modify context-menu callback to set the new context option.

(webkitWebViewPopulateContextMenu):

  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add documentation about new function.

Tools:

Add tests for new context SELECTION on WebKitHitTestResult.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:

(testContextMenuDefaultMenu):

  • TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:

(testWebViewMouseTarget):

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r175159 r175160  
     12014-10-24  Marcos Chavarría Teijeiro  <chavarria1991@gmail.com>
     2
     3        [GTK] Implement is_selected method on WebKitHitTestResult
     4        https://bugs.webkit.org/show_bug.cgi?id=137110
     5
     6        Reviewed by Tim Horton.
     7
     8        Expose CONTEXT_SELECTION for WebKitHitTestResult.
     9
     10        * Shared/WebHitTestResult.cpp: Add is_selected field and getter for this field.
     11        (WebKit::WebHitTestResult::Data::Data):
     12        (WebKit::WebHitTestResult::Data::encode):
     13        (WebKit::WebHitTestResult::Data::decode):
     14        * Shared/WebHitTestResult.h:
     15        (WebKit::WebHitTestResult::isSelected):
     16        * UIProcess/API/gtk/WebKitHitTestResult.cpp: Add WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION context and method to check it.
     17        (webkitHitTestResultCreate):
     18        (webkitHitTestResultCompare):
     19        (webkit_hit_test_result_context_is_selection):
     20        * UIProcess/API/gtk/WebKitHitTestResult.h:
     21        * UIProcess/API/gtk/WebKitWebView.cpp: Modify context-menu callback to set the new context option.
     22        (webkitWebViewPopulateContextMenu):
     23        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add documentation about new function.
     24
    1252014-10-23  Carlos Garcia Campos  <cgarcia@igalia.com>
    226
  • trunk/Source/WebKit2/Shared/WebHitTestResult.cpp

    r161148 r175160  
    5353    , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
    5454    , isScrollbar(hitTestResult.scrollbar())
     55    , isSelected(hitTestResult.isSelected())
    5556{
    5657}
     
    7172    encoder << elementBoundingBox;
    7273    encoder << isScrollbar;
     74    encoder << isSelected;
    7375}
    7476
     
    8385        || !decoder.decode(hitTestResultData.isContentEditable)
    8486        || !decoder.decode(hitTestResultData.elementBoundingBox)
    85         || !decoder.decode(hitTestResultData.isScrollbar))
     87        || !decoder.decode(hitTestResultData.isScrollbar)
     88        || !decoder.decode(hitTestResultData.isSelected))
    8689        return false;
    8790
  • trunk/Source/WebKit2/Shared/WebHitTestResult.h

    r161148 r175160  
    5353        WebCore::IntRect elementBoundingBox;
    5454        bool isScrollbar;
     55        bool isSelected;
    5556
    5657        Data();
     
    8081    bool isScrollbar() const { return m_data.isScrollbar; }
    8182
     83    bool isSelected() const { return m_data.isSelected; }
     84
    8285private:
    8386    explicit WebHitTestResult(const WebHitTestResult::Data& hitTestResultData)
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp

    r170702 r175160  
    241241        context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR;
    242242
     243    if (hitTestResult.isSelected)
     244        context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
     245
    243246    return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
    244247        "context", context,
     
    261264    return webHitTestResult.isContentEditable == webkit_hit_test_result_context_is_editable(hitTestResult)
    262265        && webHitTestResult.isScrollbar == webkit_hit_test_result_context_is_scrollbar(hitTestResult)
     266        && webHitTestResult.isSelected == webkit_hit_test_result_context_is_selection(hitTestResult)
    263267        && stringIsEqualToCString(webHitTestResult.absoluteLinkURL, priv->linkURI)
    264268        && stringIsEqualToCString(webHitTestResult.linkTitle, priv->linkTitle)
     
    352356
    353357/**
     358 * webkit_hit_test_result_context_is_selection:
     359 * @hit_test_result: a #WebKitHitTestResult
     360 *
     361 * Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION flag is present in
     362 * #WebKitHitTestResult:context.
     363 *
     364 * Returns: %TRUE if there's a selected element at the coordinates of the @hit_test_result,
     365 *    or %FALSE otherwise
     366 *
     367 * Since: 2.8
     368 */
     369gboolean webkit_hit_test_result_context_is_selection(WebKitHitTestResult* hitTestResult)
     370{
     371    g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
     372
     373    return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
     374}
     375
     376/**
    354377 * webkit_hit_test_result_get_link_uri:
    355378 * @hit_test_result: a #WebKitHitTestResult
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h

    r150130 r175160  
    4949 * @WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE: an editable element
    5050 * @WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR: a scrollbar element.
     51 * @WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION: a selected element. Since 2.8
    5152 *
    5253 * Enum values with flags representing the context of a #WebKitHitTestResult.
     
    5960    WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA     = 1 << 4,
    6061    WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE  = 1 << 5,
    61     WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR = 1 << 6
     62    WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR = 1 << 6,
     63    WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION = 1 << 7
    6264} WebKitHitTestResultContext;
    6365
     
    9597webkit_hit_test_result_context_is_editable  (WebKitHitTestResult *hit_test_result);
    9698
     99WEBKIT_API gboolean
     100webkit_hit_test_result_context_is_selection (WebKitHitTestResult *hit_test_result);
     101
    97102WEBKIT_API const gchar *
    98103webkit_hit_test_result_get_link_uri         (WebKitHitTestResult *hit_test_result);
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r174861 r175160  
    19121912    data.elementBoundingBox = webHitTestResult->elementBoundingBox();
    19131913    data.isScrollbar = webHitTestResult->isScrollbar();
     1914    data.isSelected = webHitTestResult->isSelected();
    19141915
    19151916    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(data));
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r174105 r175160  
    669669webkit_hit_test_result_context_is_media
    670670webkit_hit_test_result_context_is_editable
     671webkit_hit_test_result_context_is_selection
    671672webkit_hit_test_result_get_link_uri
    672673webkit_hit_test_result_get_link_title
  • trunk/Tools/ChangeLog

    r175142 r175160  
     12014-10-24  Marcos Chavarría Teijeiro  <chavarria1991@gmail.com>
     2
     3        [GTK] Implement is_selected method on WebKitHitTestResult
     4        https://bugs.webkit.org/show_bug.cgi?id=137110
     5
     6        Reviewed by Tim Horton.
     7
     8        Add tests for new context SELECTION on WebKitHitTestResult.
     9
     10        * TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:
     11        (testContextMenuDefaultMenu):
     12        * TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
     13        (testWebViewMouseTarget):
     14
    1152014-10-23  Roger Fong  <roger_fong@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp

    r162599 r175160  
    240240        Video,
    241241        Audio,
    242         Editable
     242        Editable,
     243        Selection
    243244    };
    244245
     
    258259            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    259260            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     261            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    260262            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_BACK, Visible);
    261263            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD, Visible);
     
    268270            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    269271            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     272            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    270273            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK, Visible | Enabled);
    271274            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW, Visible | Enabled);
     
    278281            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    279282            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     283            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    280284            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW, Visible | Enabled);
    281285            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK, Visible | Enabled);
     
    288292            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    289293            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     294            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    290295            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK, Visible | Enabled);
    291296            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW, Visible | Enabled);
     
    303308            g_assert(webkit_hit_test_result_context_is_media(hitTestResult));
    304309            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     310            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    305311            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY, Visible | Enabled);
    306312            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE, Visible);
     
    318324            g_assert(webkit_hit_test_result_context_is_media(hitTestResult));
    319325            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     326            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    320327            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY, Visible | Enabled);
    321328            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE, Visible);
     
    333340            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    334341            g_assert(webkit_hit_test_result_context_is_editable(hitTestResult));
     342            g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    335343            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_CUT, Visible);
    336344            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY, Visible);
     
    344352            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled);
    345353            break;
     354        case Selection:
     355            g_assert(!webkit_hit_test_result_context_is_link(hitTestResult));
     356            g_assert(!webkit_hit_test_result_context_is_image(hitTestResult));
     357            g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
     358            g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     359            g_assert(webkit_hit_test_result_context_is_selection(hitTestResult));
     360            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY, Visible | Enabled);
     361            break;
    346362        default:
    347363            g_assert_not_reached();
     
    367383
    368384    const char* linksHTML =
    369         "<html><body>"
     385        "<html><head>"
     386        " <script>"
     387        "    window.onload = function () {"
     388        "      window.getSelection().removeAllRanges();"
     389        "      var select_range = document.createRange();"
     390        "      select_range.selectNodeContents(document.getElementById('text_to_select'));"
     391        "      window.getSelection().addRange(select_range);"
     392        "    }"
     393        " </script>"
     394        "</head><body>"
    370395        " <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>"
    371396        " <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>"
     
    374399        " <video style='position:absolute; left:1; top:50' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>"
    375400        " <audio style='position:absolute; left:1; top:60' width='50' height='20' controls='controls' preload='none'><source src='track.mp3' type='audio/mp3' /></audio>"
     401        " <p style='position:absolute; left:1; top:90' id='text_to_select'>Lorem ipsum.</p>"
    376402        "</body></html>";
    377403    test->loadHtml(linksHTML, "file:///");
    378404    test->waitUntilLoadFinished();
     405
     406    // Context menu for selection.
     407    // This test should always be the first because any other click removes the selection.
     408    test->m_expectedMenuType = ContextMenuDefaultTest::Selection;
     409    test->showContextMenuAtPositionAndWaitUntilFinished(2, 115);
    379410
    380411    // Context menu for document.
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp

    r170702 r175160  
    510510
    511511    const char* linksHoveredHTML =
    512         "<html><body>"
     512        "<html><head>"
     513        " <script>"
     514        "    window.onload = function () {"
     515        "      window.getSelection().removeAllRanges();"
     516        "      var select_range = document.createRange();"
     517        "      select_range.selectNodeContents(document.getElementById('text_to_select'));"
     518        "      window.getSelection().addRange(select_range);"
     519        "    }"
     520        " </script>"
     521        "</head><body>"
    513522        " <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>"
    514523        " <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>"
     
    517526        " <div style='position:absolute; left:1; top:50; width:30; height:30; overflow:scroll'>&nbsp;</div>"
    518527        " <video style='position:absolute; left:1; top:100' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>"
     528        " <p style='position:absolute; left:1; top:120' id='text_to_select'>Lorem ipsum.</p>"
    519529        "</body></html>";
    520530
     
    528538    g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    529539    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     540    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    530541    g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/");
    531542    g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Title");
     
    539550    g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    540551    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     552    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    541553    g_assert(!test->m_mouseTargetModifiers);
    542554
     
    547559    g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
    548560    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     561    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    549562    g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
    550563    g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef");
     
    558571    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
    559572    g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
     573    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    560574    g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/logo");
    561575    g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef");
     
    571585    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
    572586    g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
     587    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    573588    g_assert_cmpstr(webkit_hit_test_result_get_media_uri(hitTestResult), ==, "file:///movie.ogg");
    574589    g_assert(!test->m_mouseTargetModifiers);
     
    581596    g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
    582597    g_assert(webkit_hit_test_result_context_is_editable(hitTestResult));
     598    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    583599    g_assert(!test->m_mouseTargetModifiers);
    584600
     
    590606    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
    591607    g_assert(webkit_hit_test_result_context_is_scrollbar(hitTestResult));
     608    g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult));
    592609    g_assert(!test->m_mouseTargetModifiers);
     610
     611    // Move over selection.
     612    hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(2, 145);
     613    g_assert(!webkit_hit_test_result_context_is_link(hitTestResult));
     614    g_assert(!webkit_hit_test_result_context_is_image(hitTestResult));
     615    g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
     616    g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
     617    g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
     618    g_assert(webkit_hit_test_result_context_is_selection(hitTestResult));
     619    g_assert(!test->m_mouseTargetModifiers);
     620
    593621}
    594622
Note: See TracChangeset for help on using the changeset viewer.