⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 271206 in webkit


Ignore:
Timestamp:
Jan 6, 2021, 11:31:01 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Modernize WebContextMenu
https://bugs.webkit.org/show_bug.cgi?id=219969

Patch by Alex Christensen <achristensen@webkit.org> on 2021-01-06
Reviewed by Tim Horton.

This is old code, complete with a raw pointer.
Use references instead of pointers where possible,
and WeakPtr instead of a raw pointer.

  • WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:

(WKBundlePageClickMenuItem):
(WKBundlePageCopyContextMenuItems):

  • WebProcess/WebCoreSupport/WebContextMenuClient.cpp:

(WebKit::WebContextMenuClient::showContextMenu):

  • WebProcess/WebPage/WebContextMenu.cpp:

(WebKit::WebContextMenu::WebContextMenu):

  • WebProcess/WebPage/WebContextMenu.h:

(WebKit::WebContextMenu::create):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::contextMenu):
(WebKit::WebPage::contextMenuAtPointInWindow):
(WebKit::handleContextMenuEvent):
(WebKit::WebPage::contextMenuForKeyEvent):

Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271205 r271206  
     12021-01-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Modernize WebContextMenu
     4        https://bugs.webkit.org/show_bug.cgi?id=219969
     5
     6        Reviewed by Tim Horton.
     7
     8        This is old code, complete with a raw pointer.
     9        Use references instead of pointers where possible,
     10        and WeakPtr instead of a raw pointer.
     11
     12        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
     13        (WKBundlePageClickMenuItem):
     14        (WKBundlePageCopyContextMenuItems):
     15        * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
     16        (WebKit::WebContextMenuClient::showContextMenu):
     17        * WebProcess/WebPage/WebContextMenu.cpp:
     18        (WebKit::WebContextMenu::WebContextMenu):
     19        * WebProcess/WebPage/WebContextMenu.h:
     20        (WebKit::WebContextMenu::create):
     21        * WebProcess/WebPage/WebPage.cpp:
     22        (WebKit::WebPage::contextMenu):
     23        (WebKit::WebPage::contextMenuAtPointInWindow):
     24        (WebKit::handleContextMenuEvent):
     25        (WebKit::WebPage::contextMenuForKeyEvent):
     26
    1272021-01-06  Sihui Liu  <sihui_liu@appe.com>
    228
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp

    r270647 r271206  
    182182{
    183183#if ENABLE(CONTEXT_MENUS)
    184     WebKit::toImpl(pageRef)->contextMenu()->itemSelected(WebKit::toImpl(item)->data());
     184    WebKit::toImpl(pageRef)->contextMenu().itemSelected(WebKit::toImpl(item)->data());
    185185#else
    186186    UNUSED_PARAM(pageRef);
     
    207207{
    208208#if ENABLE(CONTEXT_MENUS)
    209     WebKit::WebContextMenu* contextMenu = WebKit::toImpl(pageRef)->contextMenu();
    210 
    211     return WebKit::toAPI(&contextMenuItems(*contextMenu).leakRef());
     209    auto& contextMenu = WebKit::toImpl(pageRef)->contextMenu();
     210
     211    return WebKit::toAPI(&contextMenuItems(contextMenu).leakRef());
    212212#else
    213213    UNUSED_PARAM(pageRef);
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.cpp

    r271124 r271206  
    9696void WebContextMenuClient::showContextMenu()
    9797{
    98     m_page->contextMenu()->show();
     98    m_page->contextMenu().show();
    9999}
    100100
  • trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp

    r255106 r271206  
    4141using namespace WebCore;
    4242
    43 WebContextMenu::WebContextMenu(WebPage* page)
    44     : m_page(page)
     43WebContextMenu::WebContextMenu(WebPage& page)
     44    : m_page(makeWeakPtr(page))
    4545{
    4646}
  • trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.h

    r204466 r271206  
    1919 */
    2020
    21 #ifndef WebContextMenu_h
    22 #define WebContextMenu_h
     21#pragma once
    2322
    2423#if ENABLE(CONTEXT_MENUS)
     
    2827#include <wtf/RefCounted.h>
    2928#include <wtf/RefPtr.h>
     29#include <wtf/WeakPtr.h>
    3030
    3131namespace WebCore {
     
    4040class WebContextMenu : public RefCounted<WebContextMenu> {
    4141public:
    42     static Ref<WebContextMenu> create(WebPage* page)
     42    static Ref<WebContextMenu> create(WebPage& page)
    4343    {
    4444        return adoptRef(*new WebContextMenu(page));
     
    5252
    5353private:
    54     WebContextMenu(WebPage*);
     54    WebContextMenu(WebPage&);
    5555    void menuItemsWithUserData(Vector<WebContextMenuItemData>&, RefPtr<API::Object>&) const;
    5656
    57     WebPage* m_page;
     57    WeakPtr<WebPage> m_page;
    5858};
    5959
     
    6161
    6262#endif // ENABLE(CONTEXT_MENUS)
    63 #endif // WebPopupMenu_h
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r271194 r271206  
    25882588
    25892589#if ENABLE(CONTEXT_MENUS)
    2590 WebContextMenu* WebPage::contextMenu()
     2590WebContextMenu& WebPage::contextMenu()
    25912591{
    25922592    if (!m_contextMenu)
    2593         m_contextMenu = WebContextMenu::create(this);
    2594     return m_contextMenu.get();
     2593        m_contextMenu = WebContextMenu::create(*this);
     2594    return *m_contextMenu;
    25952595}
    25962596
     
    26032603    corePage()->userInputBridge().handleMousePressEvent(mousePressEvent);
    26042604    bool handled = corePage()->userInputBridge().handleContextMenuEvent(mousePressEvent, corePage()->mainFrame());
    2605     auto* menu = handled ? contextMenu() : nullptr;
     2605    auto* menu = handled ? &contextMenu() : nullptr;
    26062606    PlatformMouseEvent mouseReleaseEvent(point, point, RightButton, PlatformEvent::MouseReleased, 1, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, WebCore::NoTap);
    26072607    corePage()->userInputBridge().handleMouseReleaseEvent(mouseReleaseEvent);
     
    27512751#if ENABLE(CONTEXT_MENUS)
    27522752    if (handled)
    2753         page->contextMenu()->show();
     2753        page->contextMenu().show();
    27542754#endif
    27552755    return handled;
     
    27662766#if ENABLE(CONTEXT_MENUS)
    27672767    if (handled)
    2768         contextMenu()->show();
     2768        contextMenu().show();
    27692769#else
    27702770    UNUSED_PARAM(handled);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r271201 r271206  
    820820
    821821#if ENABLE(CONTEXT_MENUS)
    822     WebContextMenu* contextMenu();
     822    WebContextMenu& contextMenu();
    823823    WebContextMenu* contextMenuAtPointInWindow(const WebCore::IntPoint&);
    824824#endif
Note: See TracChangeset for help on using the changeset viewer.