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

Changeset 248990 in webkit


Ignore:
Timestamp:
Aug 21, 2019, 6:49:48 PM (7 years ago)
Author:
Fujii Hironori
Message:

[Win][MiniBrowser] Add a progress indicator to the main window
https://bugs.webkit.org/show_bug.cgi?id=200970

Reviewed by Alex Christensen.

  • MiniBrowser/win/BrowserWindow.h: Added BrowserWindowClient class.
  • MiniBrowser/win/MainWindow.cpp:

(MainWindow::init):
(MainWindow::resizeSubViews):
(MainWindow::progressChanged):
(MainWindow::progressFinished):

  • MiniBrowser/win/MainWindow.h: Inherited BrowserWindowClient.

Added m_hProgressIndicator.
(MainWindow::hwnd const): Deleted.
(MainWindow::browserWindow const): Deleted.
(): Deleted.

  • MiniBrowser/win/MiniBrowserWebHost.cpp:

(MiniBrowserWebHost::onNotify):

  • MiniBrowser/win/MiniBrowserWebHost.h:
  • MiniBrowser/win/WebKitBrowserWindow.cpp:

(WebKitBrowserWindow::create):
(WebKitBrowserWindow::WebKitBrowserWindow):
(WebKitBrowserWindow::didChangeIsLoading):
(WebKitBrowserWindow::didChangeEstimatedProgress):
(WebKitBrowserWindow::createNewPage):

  • MiniBrowser/win/WebKitBrowserWindow.h:
  • MiniBrowser/win/WebKitLegacyBrowserWindow.cpp:

(WebKitLegacyBrowserWindow::create):
(WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow):
(WebKitLegacyBrowserWindow::init):

  • MiniBrowser/win/WebKitLegacyBrowserWindow.h:
Location:
trunk/Tools
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r248980 r248990  
     12019-08-21  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [Win][MiniBrowser] Add a progress indicator to the main window
     4        https://bugs.webkit.org/show_bug.cgi?id=200970
     5
     6        Reviewed by Alex Christensen.
     7
     8        * MiniBrowser/win/BrowserWindow.h: Added BrowserWindowClient class.
     9        * MiniBrowser/win/MainWindow.cpp:
     10        (MainWindow::init):
     11        (MainWindow::resizeSubViews):
     12        (MainWindow::progressChanged):
     13        (MainWindow::progressFinished):
     14        * MiniBrowser/win/MainWindow.h: Inherited BrowserWindowClient.
     15        Added m_hProgressIndicator.
     16        (MainWindow::hwnd const): Deleted.
     17        (MainWindow::browserWindow const): Deleted.
     18        (): Deleted.
     19        * MiniBrowser/win/MiniBrowserWebHost.cpp:
     20        (MiniBrowserWebHost::onNotify):
     21        * MiniBrowser/win/MiniBrowserWebHost.h:
     22        * MiniBrowser/win/WebKitBrowserWindow.cpp:
     23        (WebKitBrowserWindow::create):
     24        (WebKitBrowserWindow::WebKitBrowserWindow):
     25        (WebKitBrowserWindow::didChangeIsLoading):
     26        (WebKitBrowserWindow::didChangeEstimatedProgress):
     27        (WebKitBrowserWindow::createNewPage):
     28        * MiniBrowser/win/WebKitBrowserWindow.h:
     29        * MiniBrowser/win/WebKitLegacyBrowserWindow.cpp:
     30        (WebKitLegacyBrowserWindow::create):
     31        (WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow):
     32        (WebKitLegacyBrowserWindow::init):
     33        * MiniBrowser/win/WebKitLegacyBrowserWindow.h:
     34
    1352019-08-21  Ryan Haddad  <ryanhaddad@apple.com>
    236
  • trunk/Tools/MiniBrowser/win/BrowserWindow.h

    r247938 r248990  
    2929#include <wtf/RefCounted.h>
    3030
     31class BrowserWindowClient {
     32public:
     33    virtual void progressChanged(double) = 0;
     34    virtual void progressFinished() = 0;
     35};
     36
    3137class BrowserWindow : public RefCounted<BrowserWindow> {
    3238public:
  • trunk/Tools/MiniBrowser/win/MainWindow.cpp

    r248399 r248990  
    3131#include "WebKitLegacyBrowserWindow.h"
    3232#include <CoreFoundation/CoreFoundation.h>
     33#include <sstream>
    3334
    3435#if ENABLE(WEBKIT)
     
    116117#endif
    117118
    118     float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
    119119    m_hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE  | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_BACKWARD), hInstance, 0);
    120120    m_hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_FORWARD), hInstance, 0);
    121121    m_hReloadButtonWnd = CreateWindow(L"BUTTON", L"↺", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_RELOAD), hInstance, 0);
    122122    m_hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
     123    m_hProgressIndicator = CreateWindow(L"STATIC", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER | SS_CENTERIMAGE, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
    123124
    124125    DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
    125126    SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
    126127
    127     m_browserWindow = factory(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView);
     128    m_browserWindow = factory(*this, m_hMainWnd, m_hURLBarWnd, usesLayeredWebView);
    128129    if (!m_browserWindow)
    129130        return false;
     
    151152    MoveWindow(m_hForwardButtonWnd, width, 0, width, height, TRUE);
    152153    MoveWindow(m_hReloadButtonWnd, width * 2, 0, width, height, TRUE);
    153     MoveWindow(m_hURLBarWnd, width * 3, 0, rcClient.right - width * 3, height, TRUE);
     154    MoveWindow(m_hURLBarWnd, width * 3, 0, rcClient.right - width * 5, height, TRUE);
     155    MoveWindow(m_hProgressIndicator, rcClient.right - width * 2, 0, width * 2, height, TRUE);
    154156
    155157    if (m_browserWindow->usesLayeredWebView() || !m_browserWindow->hwnd())
     
    474476    ::SendMessage(m_hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(m_hURLBarFont), TRUE);
    475477}
     478
     479void MainWindow::progressChanged(double progress)
     480{
     481    std::wostringstream text;
     482    text << static_cast<int>(progress * 100) << L'%';
     483    SetWindowText(m_hProgressIndicator, text.str().c_str());
     484}
     485
     486void MainWindow::progressFinished()
     487{
     488    SetWindowText(m_hProgressIndicator, L"");
     489}
  • trunk/Tools/MiniBrowser/win/MainWindow.h

    r247938 r248990  
    3232#include <wtf/RefPtr.h>
    3333
    34 class MainWindow : public RefCounted<MainWindow> {
     34class MainWindow final : public RefCounted<MainWindow>, public BrowserWindowClient {
    3535public:
    36     using BrowserWindowFactory = std::function<Ref<BrowserWindow>(HWND mainWnd, HWND urlBarWnd, bool usesLayeredWebView)>;
     36    using BrowserWindowFactory = std::function<Ref<BrowserWindow>(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool usesLayeredWebView)>;
    3737
    3838    static Ref<MainWindow> create();
     
    6060    void updateDeviceScaleFactor();
    6161
     62    // BrowserWindowClient
     63    void progressChanged(double) final;
     64    void progressFinished() final;
     65
    6266    HWND m_hMainWnd { nullptr };
    6367    HWND m_hURLBarWnd { nullptr };
     
    6569    HWND m_hForwardButtonWnd { nullptr };
    6670    HWND m_hReloadButtonWnd { nullptr };
     71    HWND m_hProgressIndicator { nullptr };
    6772    HWND m_hCacheWnd { nullptr };
    6873    HGDIOBJ m_hURLBarFont { nullptr };
  • trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp

    r247896 r248990  
    167167    return S_OK;
    168168}
     169
     170HRESULT MiniBrowserWebHost::onNotify(_In_opt_ IWebNotification* notification)
     171{
     172    _bstr_t name;
     173    HRESULT hr = notification->name(name.GetAddress());
     174    if (FAILED(hr))
     175        return hr;
     176    if (name == _bstr_t(WebViewProgressEstimateChangedNotification)) {
     177        IUnknownPtr object;
     178        hr = notification->getObject(&object.GetInterfacePtr());
     179        if (FAILED(hr))
     180            return hr;
     181        IWebViewPtr webView(object);
     182        if (!webView)
     183            return E_NOINTERFACE;
     184        double progress;
     185        hr = webView->estimatedProgress(&progress);
     186        if (FAILED(hr))
     187            return hr;
     188        m_client->m_client.progressChanged(progress);
     189    } else if (name == _bstr_t(WebViewProgressFinishedNotification))
     190        m_client->m_client.progressFinished();
     191   
     192    return S_OK;
     193}
  • trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h

    r239666 r248990  
    3232class WebKitLegacyBrowserWindow;
    3333
    34 class MiniBrowserWebHost : public IWebFrameLoadDelegate, public IWebFrameLoadDelegatePrivate {
     34class MiniBrowserWebHost : public IWebFrameLoadDelegate, public IWebFrameLoadDelegatePrivate, public IWebNotificationObserver {
    3535public:
    3636    MiniBrowserWebHost(WebKitLegacyBrowserWindow* client, HWND urlBar)
     
    7272    virtual HRESULT STDMETHODCALLTYPE didFirstVisuallyNonEmptyLayoutInFrame(_In_opt_ IWebView* sender, _In_opt_ IWebFrame*)  { return S_OK; }
    7373
     74    // IWebNotificationObserver
     75    virtual HRESULT STDMETHODCALLTYPE onNotify(_In_opt_ IWebNotification*);
     76
    7477    void loadURL(_bstr_t&);
    7578
  • trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp

    r248291 r248990  
    105105}
    106106
    107 Ref<BrowserWindow> WebKitBrowserWindow::create(HWND mainWnd, HWND urlBarWnd, bool)
     107Ref<BrowserWindow> WebKitBrowserWindow::create(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool)
    108108{
    109109    auto conf = adoptWK(WKPageConfigurationCreate());
     
    122122    WKPageConfigurationSetContext(conf.get(), context.get());
    123123
    124     return adoptRef(*new WebKitBrowserWindow(conf.get(), mainWnd, urlBarWnd));
    125 }
    126 
    127 WebKitBrowserWindow::WebKitBrowserWindow(WKPageConfigurationRef conf, HWND mainWnd, HWND urlBarWnd)
    128     : m_hMainWnd(mainWnd)
     124    return adoptRef(*new WebKitBrowserWindow(client, conf.get(), mainWnd, urlBarWnd));
     125}
     126
     127WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConfigurationRef conf, HWND mainWnd, HWND urlBarWnd)
     128    : m_client(client)
     129    , m_hMainWnd(mainWnd)
    129130    , m_urlBarWnd(urlBarWnd)
    130131{
     
    153154    stateClient.base.clientInfo = this;
    154155    stateClient.didChangeTitle = didChangeTitle;
     156    stateClient.didChangeIsLoading = didChangeIsLoading;
     157    stateClient.didChangeEstimatedProgress = didChangeEstimatedProgress;
    155158    WKPageSetPageStateClient(page, &stateClient.base);
    156159
     
    307310    std::wstring titleString = createString(title.get()) + L" [WebKit]";
    308311    SetWindowText(thisWindow.m_hMainWnd, titleString.c_str());
     312}
     313
     314void WebKitBrowserWindow::didChangeIsLoading(const void* clientInfo)
     315{
     316    auto& thisWindow = toWebKitBrowserWindow(clientInfo);
     317    auto page = WKViewGetPage(thisWindow.m_view.get());
     318    thisWindow.m_client.progressFinished();
     319}
     320
     321void WebKitBrowserWindow::didChangeEstimatedProgress(const void* clientInfo)
     322{
     323    auto& thisWindow = toWebKitBrowserWindow(clientInfo);
     324    auto page = WKViewGetPage(thisWindow.m_view.get());
     325    thisWindow.m_client.progressChanged(WKPageGetEstimatedProgress(page));
    309326}
    310327
     
    368385{
    369386    auto& newWindow = MainWindow::create().leakRef();
    370     auto factory = [configuration](HWND mainWnd, HWND urlBarWnd, bool) -> auto {
    371         return adoptRef(*new WebKitBrowserWindow(configuration, mainWnd, urlBarWnd));
     387    auto factory = [configuration](BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool) -> auto {
     388        return adoptRef(*new WebKitBrowserWindow(client, configuration, mainWnd, urlBarWnd));
    372389    };
    373390    bool ok = newWindow.init(factory, hInst);
  • trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.h

    r248291 r248990  
    3434class WebKitBrowserWindow : public BrowserWindow {
    3535public:
    36     static Ref<BrowserWindow> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
     36    static Ref<BrowserWindow> create(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
    3737
    3838private:
    39     WebKitBrowserWindow(WKPageConfigurationRef, HWND mainWnd, HWND urlBarWnd);
     39    WebKitBrowserWindow(BrowserWindowClient&, WKPageConfigurationRef, HWND mainWnd, HWND urlBarWnd);
    4040
    4141    HRESULT init() override;
     
    6767
    6868    static void didChangeTitle(const void*);
     69    static void didChangeIsLoading(const void*);
     70    static void didChangeEstimatedProgress(const void*);
    6971    static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
    7072    static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
     
    7274    static void didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr, const void*);
    7375
     76    BrowserWindowClient& m_client;
    7477    WKRetainPtr<WKViewRef> m_view;
    7578    HWND m_hMainWnd { nullptr };
  • trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.cpp

    r248444 r248990  
    5959
    6060typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
    61 
    62 Ref<BrowserWindow> WebKitLegacyBrowserWindow::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
    63 {
    64     return adoptRef(*new WebKitLegacyBrowserWindow(mainWnd, urlBarWnd, useLayeredWebView));
    65 }
    66 
    67 WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
    68     : m_hMainWnd(mainWnd)
     61typedef _com_ptr_t<_com_IIID<IWebNotificationObserver, &__uuidof(IWebNotificationObserver)>> IWebNotificationObserverPtr;
     62typedef _com_ptr_t<_com_IIID<IWebNotificationCenter, &__uuidof(IWebNotificationCenter)>> IWebNotificationCenterPtr;
     63
     64
     65Ref<BrowserWindow> WebKitLegacyBrowserWindow::create(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
     66{
     67    return adoptRef(*new WebKitLegacyBrowserWindow(client, mainWnd, urlBarWnd, useLayeredWebView));
     68}
     69
     70WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
     71    : m_client(client)
     72    , m_hMainWnd(mainWnd)
    6973    , m_hURLBarWnd(urlBarWnd)
    7074    , m_useLayeredWebView(useLayeredWebView)
     
    107111        return hr;
    108112
     113    IWebNotificationCenterPtr notificationCenter;
     114    hr = WebKitCreateInstance(CLSID_WebNotificationCenter, 0, __uuidof(notificationCenter), reinterpret_cast<void**>(&notificationCenter.GetInterfacePtr()));
     115    if (FAILED(hr))
     116        return hr;
     117
     118    IWebNotificationCenterPtr defaultNotificationCenter;
     119    hr = notificationCenter->defaultCenter(&defaultNotificationCenter.GetInterfacePtr());
     120    if (FAILED(hr))
     121        return hr;
     122
    109123    if (!seedInitialDefaultPreferences())
    110124        return E_FAIL;
     
    123137
    124138    hr = setFrameLoadDelegatePrivate(webHost);
     139    if (FAILED(hr))
     140        return hr;
     141
     142    hr = defaultNotificationCenter->addObserver(webHost, _bstr_t(WebViewProgressEstimateChangedNotification), nullptr);
     143    if (FAILED(hr))
     144        return hr;
     145
     146    hr = defaultNotificationCenter->addObserver(webHost, _bstr_t(WebViewProgressFinishedNotification), nullptr);
    125147    if (FAILED(hr))
    126148        return hr;
  • trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.h

    r247938 r248990  
    3232#include <wtf/Ref.h>
    3333
     34typedef _com_ptr_t<_com_IIID<IUnknown, &__uuidof(IUnknown)>> IUnknownPtr;
    3435typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
    3536typedef _com_ptr_t<_com_IIID<IWebView, &__uuidof(IWebView)>> IWebViewPtr;
     
    5152class WebKitLegacyBrowserWindow : public BrowserWindow {
    5253public:
    53     static Ref<BrowserWindow> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
     54    static Ref<BrowserWindow> create(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
    5455
    5556private:
     
    111112    void setPreference(UINT menuID, bool enable);
    112113
    113     WebKitLegacyBrowserWindow(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView);
     114    WebKitLegacyBrowserWindow(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView);
    114115    void subclassForLayeredWindow();
    115116    bool setCacheFolder();
    116117
     118    BrowserWindowClient& m_client;
    117119    std::vector<IWebHistoryItemPtr> m_historyItems;
    118120
Note: See TracChangeset for help on using the changeset viewer.