Reviewed by Adam.
authorkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2007 00:35:08 +0000 (00:35 +0000)
committerkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2007 00:35:08 +0000 (00:35 +0000)
        - Drosera now displays the console window, although it cannot currently
        process JavaScript.

        * Drosera/win/DebuggerClient.cpp: Shows the console window.
        (registerConsoleClass): Implemented.
        (consoleWndProc): Implemented.
        (DebuggerClient::onSize): Implemented.
        (DebuggerClient::createWebViewWithRequest): Implemented, now creates a
        new window.
        * Drosera/win/DebuggerClient.h: Added needed method and members for
        creating and maintaining a new window.
        * Drosera/win/Drosera.cpp: Fixed some minor bugs, and moved a couple of
        lines of code to more appropriate places.
        (Drosera::handleCommand):
        (Drosera::initUI):
        (Drosera::onSize):
        (Drosera::attach):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28091 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/Drosera/win/DebuggerClient.cpp
WebKitTools/Drosera/win/DebuggerClient.h
WebKitTools/Drosera/win/Drosera.cpp

index 026545af0bf3d4c1028d5789c026fd454f0f302a..6b032c86dc121bf81987582b8a34e58dca995471 100644 (file)
@@ -1,3 +1,25 @@
+2007-11-27  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Adam.
+
+        - Drosera now displays the console window, although it cannot currently
+        process JavaScript.
+
+        * Drosera/win/DebuggerClient.cpp: Shows the console window.
+        (registerConsoleClass): Implemented.
+        (consoleWndProc): Implemented.
+        (DebuggerClient::onSize): Implemented.
+        (DebuggerClient::createWebViewWithRequest): Implemented, now creates a
+        new window.
+        * Drosera/win/DebuggerClient.h: Added needed method and members for 
+        creating and maintaining a new window.
+        * Drosera/win/Drosera.cpp: Fixed some minor bugs, and moved a couple of
+        lines of code to more appropriate places.
+        (Drosera::handleCommand):
+        (Drosera::initUI):
+        (Drosera::onSize):
+        (Drosera::attach):
+
 2007-11-27  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Dave Hyatt.
index 09d260e65f6fa64408a6236451a3012e0c650310..f900eb20c868bd3f5462a053df6ac6c5e6bc48e3 100644 (file)
 #include "DebuggerClient.h"
 
 #include "DebuggerDocument.h"
+#include "Drosera.h"
 #include "ServerConnection.h"
 
 #include <WebKit/IWebView.h>
+#include <WebKit/IWebViewPrivate.h>
+#include <WebKit/WebKit.h>
 #include <JavaScriptCore/JSContextRef.h>
 
+static LPCTSTR kConsoleTitle = _T("Console");
+static LPCTSTR kConsoleClassName = _T("DroseraConsoleWindowClass");
+
+static LRESULT CALLBACK consoleWndProc(HWND, UINT, WPARAM, LPARAM);
+
+ATOM registerConsoleClass(HINSTANCE hInstance)
+{
+    static bool haveRegisteredWindowClass = false;
+
+    if (haveRegisteredWindowClass) {
+        haveRegisteredWindowClass = true;
+        return true;
+    }
+
+    WNDCLASSEX wcex;
+
+    wcex.cbSize = sizeof(WNDCLASSEX);
+
+    wcex.style         = 0;
+    wcex.lpfnWndProc   = consoleWndProc;
+    wcex.cbClsExtra    = 0;
+    wcex.cbWndExtra    = sizeof(DebuggerClient*);
+    wcex.hInstance     = hInstance;
+    wcex.hIcon         = 0;
+    wcex.hCursor       = LoadCursor(0, IDC_ARROW);
+    wcex.hbrBackground = 0;
+    wcex.lpszMenuName  = 0;
+    wcex.lpszClassName = kConsoleClassName;
+    wcex.hIconSm       = 0;
+
+    return RegisterClassEx(&wcex);
+}
+
+static LRESULT CALLBACK consoleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0);
+    DebuggerClient* client = reinterpret_cast<DebuggerClient*>(longPtr);
+
+    switch (message) {
+        case WM_SIZE:
+            if (!client)
+                return 0;
+            return client->onSize(wParam, lParam);
+        case WM_PAINT: {
+            PAINTSTRUCT ps;
+            BeginPaint(hWnd, &ps);
+            EndPaint(hWnd, &ps);
+            break;
+        }
+        default:
+            return DefWindowProc(hWnd, message, wParam, lParam);
+    }
+
+    return 0;
+}
+
+LRESULT DebuggerClient::onSize(WPARAM, LPARAM)
+{
+    if (!m_webViewPrivate)
+        return 0;
+
+    RECT clientRect = {0};
+    if (!GetClientRect(m_consoleWindow, &clientRect))
+        return 0;
+
+    HWND viewWindow;
+    if (SUCCEEDED(m_webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))))
+        SetWindowPos(viewWindow, 0, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, SWP_NOZORDER);
+
+    return 0;
+}
+
 DebuggerClient::DebuggerClient()
     : m_webViewLoaded(false)
     , m_debuggerDocument(new DebuggerDocument(new ServerConnection()))
@@ -130,14 +205,85 @@ HRESULT STDMETHODCALLTYPE DebuggerClient::didReceiveTitle(
 
 HRESULT STDMETHODCALLTYPE DebuggerClient::createWebViewWithRequest( 
         /* [in] */ IWebView*,
-        /* [in] */ IWebURLRequest*,
-        /* [retval][out] */ IWebView**)
+        /* [in] */ IWebURLRequest* request,
+        /* [retval][out] */ IWebView** newWebView)
 {
-    // FIXME: Opens the console window, this might get replaced by some Windows Fu
+    HRESULT ret = S_OK;
+
+    if (!newWebView)
+        return E_POINTER;
+
+    *newWebView = 0;
+
+    HINSTANCE instance = Drosera::getInst();
+
+    registerConsoleClass(instance);
+
+    m_consoleWindow = CreateWindow(kConsoleClassName, kConsoleTitle, WS_OVERLAPPEDWINDOW,
+        CW_USEDEFAULT, 0, 500, 350, 0, 0, instance, 0);
+
+    if (!m_consoleWindow)
+        return HRESULT_FROM_WIN32(GetLastError());
+
+    SetLastError(0);
+    SetWindowLongPtr(m_consoleWindow, 0, reinterpret_cast<LONG_PTR>(this));
+    ret = HRESULT_FROM_WIN32(GetLastError());
+    if (FAILED(ret))
+        return ret;
+
+    COMPtr<IWebView> view;
+    ret = CoCreateInstance(CLSID_WebView, 0, CLSCTX_ALL, IID_IWebView, (void**)&view);
+    if (FAILED(ret))
+        return ret;
+
+    m_webViewPrivate.query(view);
+    if (!m_webViewPrivate)
+        return E_FAIL;
+
+    ret = view->setHostWindow(reinterpret_cast<OLE_HANDLE>(m_consoleWindow));
+    if (FAILED(ret))
+        return ret;
+
+    RECT clientRect = {0};
+    GetClientRect(m_consoleWindow, &clientRect);
+    ret = view->initWithFrame(clientRect, 0, 0);
+    if (FAILED(ret))
+        return ret;
+
+    ret = view->setUIDelegate(this);
+    if (FAILED(ret))
+        return ret;
+
+    ret = view->setFrameLoadDelegate(this);
+    if (FAILED(ret))
+        return ret;
+
+    if (request) {
+        BOOL requestIsEmpty = FALSE;
+        ret = request->isEmpty(&requestIsEmpty);
+        if (FAILED(ret))
+            return ret;
+
+        if (!requestIsEmpty) {
+            COMPtr<IWebFrame> mainFrame;
+            ret = view->mainFrame(&mainFrame);
+            if (FAILED(ret))
+                return ret;
+
+            ret = mainFrame->loadRequest(request);
+            if (FAILED(ret))
+                return ret;
+        }
+    }
+
+    ShowWindow(m_consoleWindow, SW_SHOW);
+    UpdateWindow(m_consoleWindow);
+
+    *newWebView = view.releaseRef();
+
     return S_OK;
 }
 
-
 // IWebUIDelegate ------------------------------
 HRESULT STDMETHODCALLTYPE DebuggerClient::runJavaScriptAlertPanelWithMessage(  // For debugging purposes
     /* [in] */ IWebView*,
index 3a6921b6aa1c150acc74fc7b629e65a8a8888731..08b67e79be2b8c5abb0ad77199cd41820bb1d082 100644 (file)
 #include "BaseDelegate.h"
 
 #include <string>
+#include <WebCore/COMPtr.h>
 #include <wtf/OwnPtr.h>
 
 class DebuggerDocument;
-struct IWebView;
-struct IWebFrame;
+interface IWebView;
+interface IWebFrame;
+interface IWebViewPrivate;
 
 typedef const struct OpaqueJSContext* JSContextRef;
 typedef struct OpaqueJSValue* JSObjectRef;
@@ -47,6 +49,8 @@ public:
     ~DebuggerClient();
     explicit DebuggerClient(const std::wstring& serverName);
 
+    LRESULT DebuggerClient::onSize(WPARAM, LPARAM);
+
     // IUnknown
     HRESULT STDMETHODCALLTYPE QueryInterface(
         /* [in] */ REFIID riid,
@@ -103,6 +107,9 @@ private:
     bool m_webViewLoaded;
     JSGlobalContextRef m_globalContext;
 
+    HWND m_consoleWindow;
+    COMPtr<IWebViewPrivate> m_webViewPrivate;
+
     OwnPtr<DebuggerDocument> m_debuggerDocument;
 };
 
index 5ae0d9027d42bdb9de74879536bd105729c75158..ee6204f4988273e16fc88504bcf05922848e7793 100644 (file)
@@ -187,6 +187,7 @@ LRESULT CALLBACK Drosera::handleCommand(HWND hWnd, UINT message, WPARAM wParam,
             break;
         case ID_DEBUG_SHOWCONSOLE:
             m_debuggerClient->showConsole();
+            break;
         case ID_HELP_ABOUT:
             DialogBox(Drosera::getInst(), MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, ::aboutWndProc);
             break;
@@ -263,7 +264,7 @@ HRESULT Drosera::initUI(HINSTANCE hInstance, int nCmdShow)
         return ret;
 
     m_webViewPrivate.query(m_webView.get());
-    if (!m_webView)
+    if (!m_webViewPrivate)
         return E_FAIL;
 
     ret = m_webView->setHostWindow(reinterpret_cast<OLE_HANDLE>(m_hWnd));
@@ -299,11 +300,10 @@ LRESULT Drosera::onSize(WPARAM, LPARAM)
     ::GetClientRect(m_hWnd, &clientRect);
 
     HWND viewWindow;
-    if (FAILED(m_webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))))
-        return 0;
+    if (SUCCEEDED(m_webViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))))
+        // FIXME should this be the height-command bars height?
+        ::SetWindowPos(viewWindow, 0, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, SWP_NOZORDER);
 
-    // FIXME should this be the height-command bars height?
-    ::SetWindowPos(viewWindow, 0, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, SWP_NOZORDER);
     return 0;
 }
 
@@ -322,9 +322,6 @@ HRESULT Drosera::attach()
         return ret;
 
     ret = m_webView->setUIDelegate(m_debuggerClient.get());
-
-    COMPtr<IWebFrame> mainFrame;
-    ret = m_webView->mainFrame(&mainFrame);
     if (FAILED(ret))
         return ret;
 
@@ -344,6 +341,11 @@ HRESULT Drosera::attach()
     if (FAILED(ret))
         return ret;
 
+    COMPtr<IWebFrame> mainFrame;
+    ret = m_webView->mainFrame(&mainFrame);
+    if (FAILED(ret))
+        return ret;
+
     ret = mainFrame->loadRequest(request.get());
     if (FAILED(ret))
         return ret;