Title: [202327] trunk/Tools
Revision
202327
Author
[email protected]
Date
2016-06-22 01:35:03 -0700 (Wed, 22 Jun 2016)

Log Message

[Win] Implement modal dialog support in MiniBrowser.
https://bugs.webkit.org/show_bug.cgi?id=158976

Reviewed by Brent Fulgham.

* MiniBrowser/win/PrintWebUIDelegate.cpp:
(PrintWebUIDelegate::createWebViewWithRequest):
(getHandleFromWebView):
(PrintWebUIDelegate::webViewClose):
(PrintWebUIDelegate::setFrame):
(PrintWebUIDelegate::webViewFrame):
(PrintWebUIDelegate::canRunModal):
(findTopLevelParent):
(PrintWebUIDelegate::runModal):
(PrintWebUIDelegate::createModalDialog):
* MiniBrowser/win/PrintWebUIDelegate.h:
(PrintWebUIDelegate::webViewClose):
(PrintWebUIDelegate::setFrame):
(PrintWebUIDelegate::webViewFrame):
(PrintWebUIDelegate::canRunModal):
(PrintWebUIDelegate::runModal):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (202326 => 202327)


--- trunk/Tools/ChangeLog	2016-06-22 07:48:15 UTC (rev 202326)
+++ trunk/Tools/ChangeLog	2016-06-22 08:35:03 UTC (rev 202327)
@@ -1,5 +1,29 @@
 2016-06-22  Per Arne Vollan  <[email protected]>
 
+        [Win] Implement modal dialog support in MiniBrowser.
+        https://bugs.webkit.org/show_bug.cgi?id=158976
+
+        Reviewed by Brent Fulgham.
+
+        * MiniBrowser/win/PrintWebUIDelegate.cpp:
+        (PrintWebUIDelegate::createWebViewWithRequest):
+        (getHandleFromWebView):
+        (PrintWebUIDelegate::webViewClose):
+        (PrintWebUIDelegate::setFrame):
+        (PrintWebUIDelegate::webViewFrame):
+        (PrintWebUIDelegate::canRunModal):
+        (findTopLevelParent):
+        (PrintWebUIDelegate::runModal):
+        (PrintWebUIDelegate::createModalDialog):
+        * MiniBrowser/win/PrintWebUIDelegate.h:
+        (PrintWebUIDelegate::webViewClose):
+        (PrintWebUIDelegate::setFrame):
+        (PrintWebUIDelegate::webViewFrame):
+        (PrintWebUIDelegate::canRunModal):
+        (PrintWebUIDelegate::runModal):
+
+2016-06-22  Per Arne Vollan  <[email protected]>
+
         window.showModalDialog doesn't work in DumpRenderTree on Windows
         https://bugs.webkit.org/show_bug.cgi?id=53675
 

Modified: trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp (202326 => 202327)


--- trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp	2016-06-22 07:48:15 UTC (rev 202326)
+++ trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp	2016-06-22 08:35:03 UTC (rev 202327)
@@ -27,6 +27,10 @@
 #include "stdafx.h"
 #include "PrintWebUIDelegate.h"
 
+#if USE(CF)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+#include <WebCore/COMPtr.h>
 #include <WebKit/WebKitCOMAPI.h>
 #include <comip.h>
 #include <commctrl.h>
@@ -81,6 +85,54 @@
     return S_OK;
 }
 
+static HWND getHandleFromWebView(IWebView* webView)
+{
+    COMPtr<IWebViewPrivate2> webViewPrivate;
+    HRESULT hr = webView->QueryInterface(&webViewPrivate);
+    if (FAILED(hr))
+        return nullptr;
+
+    HWND webViewWindow = nullptr;
+    hr = webViewPrivate->viewWindow(&webViewWindow);
+    if (FAILED(hr))
+        return nullptr;
+
+    return webViewWindow;
+}
+
+HRESULT PrintWebUIDelegate::webViewClose(_In_opt_ IWebView* webView)
+{
+    HWND hostWindow;
+    HRESULT hr = webView->hostWindow(&hostWindow);
+    if (FAILED(hr))
+        return hr;
+
+    ::DestroyWindow(hostWindow);
+
+    if (hostWindow == m_modalDialogParent)
+        m_modalDialogParent = nullptr;
+
+    return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::setFrame(_In_opt_ IWebView* webView, _In_ RECT* rect)
+{
+    if (m_modalDialogParent)
+        ::MoveWindow(m_modalDialogParent, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, FALSE);
+
+    ::MoveWindow(getHandleFromWebView(webView), 0, 0, rect->right - rect->left, rect->bottom - rect->top, FALSE);
+
+    return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::webViewFrame(_In_opt_ IWebView* webView, _Out_ RECT* rect)
+{
+    if (!::GetWindowRect(getHandleFromWebView(webView), rect))
+        return E_FAIL;
+
+    return S_OK;
+}
+
 HRESULT PrintWebUIDelegate::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
 {
     if (!ppvObject)
@@ -237,10 +289,82 @@
     return S_OK;
 }
 
-HRESULT PrintWebUIDelegate::createModalDialog(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _COM_Outptr_opt_ IWebView** webView)
+HRESULT PrintWebUIDelegate::canRunModal(_In_opt_ IWebView*, _Out_ BOOL* canRunBoolean)
 {
-    if (!webView)
+    if (!canRunBoolean)
         return E_POINTER;
-    *webView = nullptr;
-    return E_NOTIMPL;
+    *canRunBoolean = TRUE;
+    return S_OK;
 }
+
+static HWND findTopLevelParent(HWND window)
+{
+    if (!window)
+        return nullptr;
+
+    HWND current = window;
+    for (HWND parent = GetParent(current); current; current = parent, parent = GetParent(parent)) {
+        if (!parent)
+            return current;
+    }
+    ASSERT_NOT_REACHED();
+    return nullptr;
+}
+
+HRESULT PrintWebUIDelegate::runModal(_In_opt_ IWebView* webView)
+{
+    COMPtr<IWebView> protector(webView);
+
+    auto topLevelParent = findTopLevelParent(::GetWindow(m_modalDialogParent, GW_OWNER));
+
+    ::EnableWindow(topLevelParent, FALSE);
+
+    while (::IsWindow(getHandleFromWebView(webView))) {
+#if USE(CF)
+        CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
+#endif
+        MSG msg;
+        if (!::GetMessage(&msg, 0, 0, 0))
+            break;
+
+        ::TranslateMessage(&msg);
+        ::DispatchMessage(&msg);        
+    }
+
+    ::EnableWindow(topLevelParent, TRUE);
+
+    return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::createModalDialog(_In_opt_ IWebView* sender, _In_opt_ IWebURLRequest* request, _COM_Outptr_opt_ IWebView** newWebView)
+{
+    if (!newWebView)
+        return E_POINTER;
+    
+    COMPtr<IWebView> webView;
+    HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, (void**)&webView);
+    if (FAILED(hr))
+        return hr;
+
+    m_modalDialogParent = ::CreateWindow(L"STATIC", L"ModalDialog", WS_OVERLAPPED | WS_VISIBLE, 0, 0, 0, 0, getHandleFromWebView(sender), nullptr, nullptr, nullptr);
+
+    hr = webView->setHostWindow(m_modalDialogParent);
+    if (FAILED(hr))
+        return hr;
+
+    RECT clientRect = { 0, 0, 0, 0 };
+    hr = webView->initWithFrame(clientRect, 0, _bstr_t(L""));
+    if (FAILED(hr))
+        return hr;
+
+    COMPtr<IWebUIDelegate> uiDelegate;
+    hr = sender->uiDelegate(&uiDelegate);
+    if (FAILED(hr))
+        return hr;
+
+    webView->setUIDelegate(uiDelegate.get());
+
+    *newWebView = webView.leakRef();
+
+    return S_OK;
+}

Modified: trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h (202326 => 202327)


--- trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h	2016-06-22 07:48:15 UTC (rev 202326)
+++ trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h	2016-06-22 08:35:03 UTC (rev 202327)
@@ -40,7 +40,7 @@
 
     virtual HRESULT STDMETHODCALLTYPE createWebViewWithRequest(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _COM_Outptr_opt_ IWebView**);
     virtual HRESULT STDMETHODCALLTYPE webViewShow(_In_opt_ IWebView*) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE webViewClose(_In_opt_ IWebView*) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE webViewClose(_In_opt_ IWebView*);
     virtual HRESULT STDMETHODCALLTYPE webViewFocus(_In_opt_ IWebView*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE webViewUnfocus(_In_opt_ IWebView*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE webViewFirstResponder(_In_opt_ IWebView*, _Out_ HWND*)  { return E_NOTIMPL; }
@@ -53,8 +53,8 @@
     virtual HRESULT STDMETHODCALLTYPE setStatusBarVisible(_In_opt_ IWebView*, BOOL) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE webViewIsResizable(_In_opt_ IWebView*, _Out_ BOOL*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE setResizable(_In_opt_ IWebView*, BOOL) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE setFrame(_In_opt_ IWebView*, _In_ RECT*) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE webViewFrame(_In_opt_ IWebView*, _Out_ RECT*) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE setFrame(_In_opt_ IWebView*, _In_ RECT*);
+    virtual HRESULT STDMETHODCALLTYPE webViewFrame(_In_opt_ IWebView*, _Out_ RECT*);
     virtual HRESULT STDMETHODCALLTYPE setContentRect(_In_opt_ IWebView*, _In_ RECT*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE webViewContentRect(_In_opt_ IWebView*, _Out_ RECT*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE runJavaScriptAlertPanelWithMessage(_In_opt_ IWebView*, _In_ BSTR);
@@ -93,9 +93,9 @@
     virtual HRESULT STDMETHODCALLTYPE drawHeaderInRect(_In_opt_ IWebView*, _In_ RECT*, ULONG_PTR);
     virtual HRESULT STDMETHODCALLTYPE drawFooterInRect(_In_opt_ IWebView*, _In_ RECT*, ULONG_PTR, UINT, UINT);
     virtual HRESULT STDMETHODCALLTYPE webViewPrintingMarginRect(_In_opt_ IWebView*, _Out_ RECT*);
-    virtual HRESULT STDMETHODCALLTYPE canRunModal(_In_opt_ IWebView*, _Out_ BOOL*) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE canRunModal(_In_opt_ IWebView*, _Out_ BOOL*);
     virtual HRESULT STDMETHODCALLTYPE createModalDialog(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _COM_Outptr_opt_ IWebView**);
-    virtual HRESULT STDMETHODCALLTYPE runModal(_In_opt_ IWebView*) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE runModal(_In_opt_ IWebView*);
     virtual HRESULT STDMETHODCALLTYPE isMenuBarVisible(_In_opt_ IWebView*, _Out_ BOOL*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE setMenuBarVisible(_In_opt_ IWebView*, BOOL) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE runDatabaseSizeLimitPrompt(_In_opt_ IWebView*, _In_ BSTR, _In_opt_ IWebFrame*, _Out_ BOOL*) { return E_NOTIMPL; }
@@ -104,6 +104,7 @@
 
 private:
     int m_refCount { 1 };
+    HWND m_modalDialogParent { nullptr };
 };
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to