Changeset 226602 in webkit


Ignore:
Timestamp:
Jan 8, 2018 5:53:29 PM (6 years ago)
Author:
achristensen@apple.com
Message:

Pass around Vector<Ref<WebContextMenuItem>> instead of WKArrayRef or Vector<WebContextMenuItemData>
https://bugs.webkit.org/show_bug.cgi?id=181419

Reviewed by Tim Horton.

Passing a WKArrayRef to an API object is messy and was preventing me from moving things around and making ObjC SPI.
No change in behavior. Just using different layering abstractions for the same data.

  • UIProcess/API/C/WKContextMenuListener.cpp:

(WKContextMenuListenerUseContextMenuItems):

  • UIProcess/WebContextMenuListenerProxy.cpp:

(WebKit::WebContextMenuListenerProxy::useContextMenuItems):

  • UIProcess/WebContextMenuListenerProxy.h:
  • UIProcess/WebContextMenuProxy.h:
  • UIProcess/mac/WebContextMenuProxyMac.h:
  • UIProcess/mac/WebContextMenuProxyMac.mm:

(WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
(WebKit::WebContextMenuProxyMac::showContextMenu):

Location:
trunk/Source/WebKit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r226542 r226602  
     12018-01-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Pass around Vector<Ref<WebContextMenuItem>> instead of WKArrayRef or Vector<WebContextMenuItemData>
     4        https://bugs.webkit.org/show_bug.cgi?id=181419
     5
     6        Reviewed by Tim Horton.
     7
     8        Passing a WKArrayRef to an API object is messy and was preventing me from moving things around and making ObjC SPI.
     9        No change in behavior.  Just using different layering abstractions for the same data.
     10
     11        * UIProcess/API/C/WKContextMenuListener.cpp:
     12        (WKContextMenuListenerUseContextMenuItems):
     13        * UIProcess/WebContextMenuListenerProxy.cpp:
     14        (WebKit::WebContextMenuListenerProxy::useContextMenuItems):
     15        * UIProcess/WebContextMenuListenerProxy.h:
     16        * UIProcess/WebContextMenuProxy.h:
     17        * UIProcess/mac/WebContextMenuProxyMac.h:
     18        * UIProcess/mac/WebContextMenuProxyMac.mm:
     19        (WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
     20        (WebKit::WebContextMenuProxyMac::showContextMenu):
     21
    1222018-01-08  John Wilander  <wilander@apple.com>
    223
  • trunk/Source/WebKit/UIProcess/API/C/WKContextMenuListener.cpp

    r207558 r226602  
    2727#include "WKContextMenuListener.h"
    2828
     29#include "APIArray.h"
    2930#include "WKAPICast.h"
     31#include "WebContextMenuItem.h"
    3032#include "WebContextMenuListenerProxy.h"
    3133
     
    4143}
    4244
    43 void WKContextMenuListenerUseContextMenuItems(WKContextMenuListenerRef listenerRef, WKArrayRef items)
     45void WKContextMenuListenerUseContextMenuItems(WKContextMenuListenerRef listenerRef, WKArrayRef arrayRef)
    4446{
    4547#if ENABLE(CONTEXT_MENUS)
    46     toImpl(listenerRef)->useContextMenuItems(items);
     48    RefPtr<API::Array> array = toImpl(arrayRef);
     49    size_t newSize = array ? array->size() : 0;
     50    Vector<Ref<WebContextMenuItem>> items;
     51    items.reserveInitialCapacity(newSize);
     52    for (size_t i = 0; i < newSize; ++i) {
     53        WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
     54        if (!item)
     55            continue;
     56       
     57        items.uncheckedAppend(*item);
     58    }
     59
     60    toImpl(listenerRef)->useContextMenuItems(WTFMove(items));
    4761#else
    4862    UNUSED_PARAM(listenerRef);
  • trunk/Source/WebKit/UIProcess/WebContextMenuListenerProxy.cpp

    r226323 r226602  
    4848}
    4949
    50 void WebContextMenuListenerProxy::useContextMenuItems(WKArrayRef items)
     50void WebContextMenuListenerProxy::useContextMenuItems(Vector<Ref<WebContextMenuItem>>&& items)
    5151{
    5252    if (!m_contextMenuMac)
    5353        return;
    5454
    55     RefPtr<API::Array> array = toImpl(items);
    56     size_t newSize = array ? array->size() : 0;
    57     Vector<WebContextMenuItemData> dataItems;
    58     dataItems.reserveInitialCapacity(newSize);
    59     for (size_t i = 0; i < newSize; ++i) {
    60         WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
    61         if (!item)
    62             continue;
    63 
    64         dataItems.uncheckedAppend(item->data());
    65     }
    66 
    67     m_contextMenuMac->showContextMenuWithItems(WTFMove(dataItems));
     55    m_contextMenuMac->showContextMenuWithItems(WTFMove(items));
    6856}
    6957
  • trunk/Source/WebKit/UIProcess/WebContextMenuListenerProxy.h

    r216794 r226602  
    4545    virtual ~WebContextMenuListenerProxy();
    4646
    47     void useContextMenuItems(WKArrayRef items);
     47    void useContextMenuItems(Vector<Ref<WebContextMenuItem>>&&);
    4848
    4949    void invalidate();
  • trunk/Source/WebKit/UIProcess/WebContextMenuProxy.h

    r226323 r226602  
    4242    virtual void show() = 0;
    4343
    44     virtual void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) = 0;
     44    virtual void showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>&) = 0;
    4545
    4646protected:
  • trunk/Source/WebKit/UIProcess/gtk/WebContextMenuProxyGtk.cpp

    r226323 r226602  
    176176}
    177177
    178 void WebContextMenuProxyGtk::showContextMenuWithItems(Vector<WebContextMenuItemData>&&)
     178void WebContextMenuProxyGtk::showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>&)
    179179{
    180180}
  • trunk/Source/WebKit/UIProcess/gtk/WebContextMenuProxyGtk.h

    r226323 r226602  
    5656    WebContextMenuProxyGtk(GtkWidget*, WebPageProxy&, ContextMenuContextData&&, const UserData&);
    5757    void show() override;
    58     void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) override;
     58    void showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>&) override;
    5959    void append(GMenu*, const WebContextMenuItemGlib&);
    6060    GRefPtr<GMenu> buildMenu(const Vector<WebContextMenuItemGlib>&);
  • trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.h

    r226323 r226602  
    5555
    5656    void contextMenuItemSelected(const WebContextMenuItemData&);
    57     void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) override;
     57    void showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>&) override;
    5858
    5959#if ENABLE(SERVICE_CONTROLS)
  • trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm

    r226323 r226602  
    452452}
    453453
    454 void WebContextMenuProxyMac::showContextMenuWithItems(Vector<WebContextMenuItemData>&& items)
    455 {
    456     auto menu = createContextMenuFromItems(items);
     454void WebContextMenuProxyMac::showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>& items)
     455{
     456    Vector<WebContextMenuItemData> data;
     457    data.reserveInitialCapacity(items.size());
     458    for (auto& item : items)
     459        data.uncheckedAppend(item->data());
     460   
     461    auto menu = createContextMenuFromItems(data);
    457462    [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
    458463    m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData(), m_userData.object());
     
    494499        return;
    495500
    496     Vector<WebContextMenuItemData> items;
    497     for (auto& item : (useProposedItems ? proposedAPIItems : clientItems))
    498         items.append(item->data());
    499 
     501    auto&& items = WTFMove(useProposedItems ? proposedAPIItems : clientItems);
     502   
    500503    if (items.isEmpty())
    501504        return;
    502505
    503     showContextMenuWithItems(WTFMove(items));
     506    showContextMenuWithItems(items);
    504507}
    505508
  • trunk/Source/WebKit/UIProcess/wpe/WebContextMenuProxyWPE.h

    r226323 r226602  
    3737    }
    3838
    39     void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) final { }
     39    void showContextMenuWithItems(const Vector<Ref<WebContextMenuItem>>&) final { }
    4040    void show() final { };
    4141
Note: See TracChangeset for help on using the changeset viewer.