Changeset 84990 in webkit


Ignore:
Timestamp:
Apr 26, 2011 5:29:28 PM (13 years ago)
Author:
bfulgham@webkit.org
Message:

2011-04-26 Brent Fulgham <bfulgham@webkit.org>

Reviewed by Adam Roben.

Implement a transparent WebView under Windows. This feature
allows the user to create small web-based applications, similar
to the dashboard on Mac OS X.
https://bugs.webkit.org/show_bug.cgi?id=58300

  • Interfaces/IWebViewPrivate.idl: Add new set/get accessors to change the state of a WebView into a Layered Window, or back into a standard window.
  • Interfaces/WebKit.idl: touch to force clean build
  • WebView.cpp: (WebView::WebView): Set layered window state in constructor. (WebView::updateBackingStore): Cleanup old bitmap when finished. (WebView::performLayeredWindowUpdate): New method to do the work of calling ::UpdateLayeredWindow for the WebView with proper alpha blending. (WebView::paint): Small change to prevent accelerated compositing when using a layered window. DirectX is not compatible with ::UpdateLayeredWindow (at least currently). (WebView::WebViewWndProc): Adjust main window procedure to avoid painting a default background on a layered window (this is handled by Windows during compositing), and to deal with paint messages properly in the layered window case. (WebView::active): The layered window is not a child window, so the active state logic is slightly different. (WebView::setUsesLayeredWindow): New set method for layered stated. When called, it will convert a WebView into a Layered Window. (WebView::usesLayeredWindow): Accessor
  • WebView.h: (WebView::setUsesLayeredWindow): Declare new accessor (WebView::usesLayeredWindow): Declare new accessor

2011-04-26 Brent Fulgham <bfulgham@webkit.org>

Reviewed by Adam Roben.

Update WinLauncher with command-line arguments to allow the
transparency to be tested. Use --transparent to create a
transparent view. Use --desktop to have the view fill the
desktop area of the screen.
https://bugs.webkit.org/show_bug.cgi?id=58300

  • WinLauncher/WinLauncher.cpp: (usesLayeredWebView): New method to indicate that the program is running with layered windows (alpha-blended transparent windows). (shouldUseFullDesktop): New method to indicate that the program is running across the full desktop (less any task bars.) (resizeSubViews): Layered window mode doesn't have any winapi child windows, so this routine is exited early for that case. (subclassForLayeredWindow): Subclass the window so we can override its defaut message loop. (computeFullDesktopFrame): Convenience function to get the desktop region and update the frame dimensions appropriately. (_tWinMain): Updated to accept the new '--transparent' and '--desktop' arguments. (InitInstance): Modified to exit early for the transparent background case. WebKit will construct our primary window (with appropriate settings) so we don't need to create one ourselves. (WndProc): (TransparentWndProc): New message loop for transparent windows, since they need special handling to support dragging.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/win/ChangeLog

    r84578 r84990  
     12011-04-26  Brent Fulgham  <bfulgham@webkit.org>
     2
     3        Reviewed by Adam Roben.
     4
     5        Implement a transparent WebView under Windows.  This feature
     6        allows the user to create small web-based applications, similar
     7        to the dashboard on Mac OS X.
     8        https://bugs.webkit.org/show_bug.cgi?id=58300
     9
     10        * Interfaces/IWebViewPrivate.idl: Add new set/get accessors to
     11        change the state of a WebView into a Layered Window, or back
     12        into a standard window.
     13        * Interfaces/WebKit.idl: touch to force clean build
     14        * WebView.cpp:
     15        (WebView::WebView): Set layered window state in constructor.
     16        (WebView::updateBackingStore): Cleanup old bitmap when finished.
     17        (WebView::performLayeredWindowUpdate): New method to do the work
     18        of calling ::UpdateLayeredWindow for the WebView with proper
     19        alpha blending.
     20        (WebView::paint): Small change to prevent accelerated compositing
     21        when using a layered window.  DirectX is not compatible with
     22        ::UpdateLayeredWindow (at least currently).
     23        (WebView::WebViewWndProc): Adjust main window procedure to avoid
     24        painting a default background on a layered window (this is handled
     25        by Windows during compositing), and to deal with paint messages
     26        properly in the layered window case.
     27        (WebView::active): The layered window is not a child window,
     28        so the active state logic is slightly different.
     29        (WebView::setUsesLayeredWindow): New set method for layered stated.
     30        When called, it will convert a WebView into a Layered Window.
     31        (WebView::usesLayeredWindow): Accessor
     32        * WebView.h:
     33        (WebView::setUsesLayeredWindow): Declare new accessor
     34        (WebView::usesLayeredWindow): Declare new accessor
     35
    1362011-04-21  Ryosuke Niwa  <rniwa@webkit.org>
    237
  • trunk/Source/WebKit/win/Interfaces/IWebViewPrivate.idl

    r78620 r84990  
    154154    HRESULT transparent([out, retval] BOOL* transparent);
    155155
     156    HRESULT setUsesLayeredWindow([in] BOOL usesLayeredWindow);
     157    HRESULT usesLayeredWindow([out, retval] BOOL* usesLayeredWindow);
     158
    156159    HRESULT setAlwaysUsesComplexTextCodePath([in] BOOL complex);
    157160    HRESULT alwaysUsesComplexTextCodePath([out, retval] BOOL* complex);
  • trunk/Source/WebKit/win/Interfaces/WebKit.idl

    r83628 r84990  
    302302    }
    303303}
     304
  • trunk/Source/WebKit/win/WebView.cpp

    r84101 r84990  
    11/*
    22 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple, Inc.  All rights reserved.
     3 * Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
     4 * Copyright (C) 2011 Brent Fulgham. All rights reserved.
    35 *
    46 * Redistribution and use in source and binary forms, with or without
     
    359361    , m_nextDisplayIsSynchronous(false)
    360362    , m_lastSetCursor(0)
     363    , m_usesLayeredWindow(false)
    361364{
    362365    JSC::initializeThreading();
     
    950953    HDC windowDC = 0;
    951954    HDC bitmapDC = dc;
     955    HGDIOBJ oldBitmap = 0;
    952956    if (!dc) {
    953957        windowDC = ::GetDC(m_viewWindow);
    954958        bitmapDC = ::CreateCompatibleDC(windowDC);
    955         ::SelectObject(bitmapDC, m_backingStoreBitmap->handle());
     959        oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap->handle());
    956960    }
    957961
     
    983987
    984988    if (!dc) {
     989        ::SelectObject(bitmapDC, oldBitmap);
    985990        ::DeleteDC(bitmapDC);
    986991        ::ReleaseDC(m_viewWindow, windowDC);
     
    990995}
    991996
     997void WebView::performLayeredWindowUpdate()
     998{
     999    HDC hdcScreen = ::GetDC(m_viewWindow);
     1000    OwnPtr<HDC> hdcMem = adoptPtr(::CreateCompatibleDC(hdcScreen));
     1001    HBITMAP hbmOld = static_cast<HBITMAP>(::SelectObject(hdcMem.get(), m_backingStoreBitmap->handle()));
     1002
     1003    BITMAP bmpInfo;
     1004    ::GetObject(m_backingStoreBitmap->handle(), sizeof(bmpInfo), &bmpInfo);
     1005    SIZE windowSize = { bmpInfo.bmWidth, bmpInfo.bmHeight };
     1006
     1007    BLENDFUNCTION blendFunction;
     1008    blendFunction.BlendOp = AC_SRC_OVER;
     1009    blendFunction.BlendFlags = 0;
     1010    blendFunction.SourceConstantAlpha = 0xFF;
     1011    blendFunction.AlphaFormat = AC_SRC_ALPHA;
     1012
     1013    POINT layerPos = { 0, 0 };
     1014    ::UpdateLayeredWindow(m_viewWindow, hdcScreen, 0, &windowSize, hdcMem.get(), &layerPos, 0, &blendFunction, ULW_ALPHA);
     1015
     1016    ::SelectObject(hdcMem.get(), hbmOld);
     1017    ::ReleaseDC(0, hdcScreen);
     1018}
     1019
    9921020void WebView::paint(HDC dc, LPARAM options)
    9931021{
     
    9951023
    9961024#if USE(ACCELERATED_COMPOSITING)
    997     if (isAcceleratedCompositing()) {
     1025    if (isAcceleratedCompositing() && !usesLayeredWindow()) {
    9981026        m_layerTreeHost->flushPendingLayerChangesNow();
    9991027        // Flushing might have taken us out of compositing mode.
     
    20982126        case WM_PAINT: {
    20992127            webView->paint(0, 0);
     2128            if (webView->usesLayeredWindow())
     2129                webView->performLayeredWindowUpdate();
    21002130            break;
    21012131        }
     2132        case WM_ERASEBKGND:
     2133            if (webView->usesLayeredWindow()) {
     2134                // Don't perform a background erase for transparent views.
     2135                handled = true;
     2136                lResult = 1;
     2137            }
     2138            break;
    21022139        case WM_PRINTCLIENT:
    21032140            webView->paint((HDC)wParam, lParam);
     
    33153352{
    33163353    HWND activeWindow = GetActiveWindow();
     3354    if (usesLayeredWindow() && activeWindow == m_viewWindow)
     3355        return true;
     3356
    33173357    return (activeWindow && m_topLevelParent == findTopLevelParent(activeWindow));
    33183358}
     
    57895829}
    57905830
     5831static bool setWindowStyle(HWND window, int index, LONG_PTR newValue)
     5832{
     5833    // According to MSDN, if the last value of the flag we are setting was zero,
     5834    // then SetWindowLongPtr returns zero, even though the call succeeded. So,
     5835    // we have to clear the error state, then check the last error after
     5836    // setting the value to see if it actually was a failure.
     5837    ::SetLastError(0);
     5838    return ::SetWindowLongPtr(window, index, newValue) || !::GetLastError();
     5839}
     5840
     5841HRESULT WebView::setUsesLayeredWindow(BOOL usesLayeredWindow)
     5842{
     5843    if (m_usesLayeredWindow == !!usesLayeredWindow)
     5844        return S_OK;
     5845
     5846    if (!m_viewWindow)
     5847        return E_FAIL;
     5848
     5849    RECT rect;
     5850    ::GetWindowRect(m_viewWindow, &rect);
     5851
     5852    LONG_PTR origExStyle = ::GetWindowLongPtr(m_viewWindow, GWL_EXSTYLE);
     5853    LONG_PTR origStyle = ::GetWindowLongPtr(m_viewWindow, GWL_STYLE);
     5854
     5855    // The logic here has to account for the way SetParent works.
     5856    // According to MSDN, to go from a child window to a popup window,
     5857    // you must clear the child bit after setting the parent to 0.
     5858    // On the other hand, to go from a popup window to a child, you
     5859    // must clear the popup state before setting the parent.
     5860    if (usesLayeredWindow) {
     5861        LONG_PTR newExStyle = origExStyle | WS_EX_LAYERED;
     5862        LONG_PTR newStyle = (origStyle & ~(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN)) | WS_POPUP;
     5863
     5864        HWND origParent = ::SetParent(m_viewWindow, 0);
     5865
     5866        if (!setWindowStyle(m_viewWindow, GWL_STYLE, newStyle)) {
     5867            ::SetParent(m_viewWindow, origParent);
     5868            return E_FAIL;
     5869        }
     5870
     5871        if (!setWindowStyle(m_viewWindow, GWL_EXSTYLE, newExStyle)) {
     5872            setWindowStyle(m_viewWindow, GWL_STYLE, origStyle);
     5873            ::SetParent(m_viewWindow, origParent);
     5874            return E_FAIL;
     5875        }
     5876    } else {
     5877        LONG_PTR newExStyle = origExStyle & ~WS_EX_LAYERED;
     5878        LONG_PTR newStyle = (origStyle & ~WS_POPUP) | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
     5879
     5880        if (!setWindowStyle(m_viewWindow, GWL_EXSTYLE, newExStyle))
     5881            return E_FAIL;
     5882
     5883        if (!setWindowStyle(m_viewWindow, GWL_STYLE, newStyle)) {
     5884            setWindowStyle(m_viewWindow, GWL_EXSTYLE, origExStyle);
     5885            return E_FAIL;
     5886        }
     5887
     5888        ::SetParent(m_viewWindow, m_hostWindow ? m_hostWindow : HWND_MESSAGE);
     5889    }
     5890
     5891    // MSDN indicates that SetWindowLongPtr doesn't take effect for some settings until a
     5892    // SetWindowPos is called.
     5893    ::SetWindowPos(m_viewWindow, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
     5894        SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
     5895
     5896    m_usesLayeredWindow = usesLayeredWindow;
     5897    return S_OK;
     5898}
     5899
     5900HRESULT WebView::usesLayeredWindow(BOOL* usesLayeredWindow)
     5901{
     5902    if (!usesLayeredWindow)
     5903        return E_POINTER;
     5904
     5905    *usesLayeredWindow = this->usesLayeredWindow() ? TRUE : FALSE;
     5906    return S_OK;
     5907}
     5908
    57915909HRESULT STDMETHODCALLTYPE WebView::setCookieEnabled(BOOL enable)
    57925910{
  • trunk/Source/WebKit/win/WebView.h

    r84146 r84990  
    11/*
    2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
     4 * Copyright (C) 2011 Brent Fulgham. All rights reserved.
    35 *
    46 * Redistribution and use in source and binary forms, with or without
     
    124126        /* [in] */ BSTR frameName,
    125127        /* [in] */ BSTR groupName);
    126    
     128
    127129    virtual HRESULT STDMETHODCALLTYPE setUIDelegate(
    128130        /* [in] */ IWebUIDelegate *d);
     
    823825    virtual HRESULT STDMETHODCALLTYPE setMinimumTimerInterval(
    824826        /* [in] */ double);
     827
     828    virtual HRESULT STDMETHODCALLTYPE setUsesLayeredWindow(BOOL);
     829    virtual HRESULT STDMETHODCALLTYPE usesLayeredWindow(BOOL*);
    825830
    826831    // WebView
     
    860865
    861866    bool transparent() const { return m_transparent; }
     867    bool usesLayeredWindow() const { return m_usesLayeredWindow; }
    862868
    863869    bool onIMEStartComposition();
     
    947953    void paintIntoBackingStore(WebCore::FrameView*, HDC bitmapDC, const WebCore::IntRect& dirtyRect, WindowsToPaint);
    948954    void updateBackingStore(WebCore::FrameView*, HDC = 0, bool backingStoreCompletelyDirty = false, WindowsToPaint = PaintWebViewOnly);
     955
     956    void performLayeredWindowUpdate();
    949957
    950958    WebCore::DragOperation keyStateToDragOperation(DWORD grfKeyState) const;
     
    10781086
    10791087    bool m_nextDisplayIsSynchronous;
     1088    bool m_usesLayeredWindow;
    10801089
    10811090    HCURSOR m_lastSetCursor;
  • trunk/Tools/ChangeLog

    r84985 r84990  
     12011-04-26  Brent Fulgham  <bfulgham@webkit.org>
     2
     3        Reviewed by Adam Roben.
     4
     5        Update WinLauncher with command-line arguments to allow the
     6        transparency to be tested.  Use --transparent to create a
     7        transparent view.  Use --desktop to have the view fill the
     8        desktop area of the screen.
     9        https://bugs.webkit.org/show_bug.cgi?id=58300
     10
     11        * WinLauncher/WinLauncher.cpp:
     12        (usesLayeredWebView): New method to indicate that the
     13        program is running with layered windows (alpha-blended
     14        transparent windows).
     15        (shouldUseFullDesktop): New method to indicate that the
     16        program is running across the full desktop (less any
     17        task bars.)
     18        (resizeSubViews): Layered window mode doesn't have any
     19        winapi child windows, so this routine is exited early
     20        for that case.
     21        (subclassForLayeredWindow): Subclass the window so we can
     22        override its defaut message loop.
     23        (computeFullDesktopFrame): Convenience function to get the
     24        desktop region and update the frame dimensions appropriately.
     25        (_tWinMain): Updated to accept the new '--transparent' and
     26        '--desktop' arguments.
     27        (InitInstance): Modified to exit early for the transparent
     28        background case.  WebKit will construct our primary window (with
     29        appropriate settings) so we don't need to create one ourselves.
     30        (WndProc):
     31        (TransparentWndProc): New message loop for transparent windows,
     32        since they need special handling to support dragging.
     33
    1342011-04-26  Alexandre MAzari  <amazari@igalia.com>
    235
  • trunk/Tools/WinLauncher/WinLauncher.cpp

    r84154 r84990  
    11/*
    22 * Copyright (C) 2006, 2008 Apple Computer, Inc.  All rights reserved.
    3  * Copyright (C) 2009 Brent Fulgha.  All rights reserved.
     3 * Copyright (C) 2009, 2011 Brent Fulgham.  All rights reserved.
     4 * Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    2930#include <WebKit/WebKitCOMAPI.h>
    3031
     32#include <string>
     33
    3134#include <commctrl.h>
    3235#include <commdlg.h>
    3336#include <objbase.h>
     37#include <shellapi.h>
    3438#include <shlwapi.h>
    3539#include <wininet.h>
     
    4448HWND hMainWnd;
    4549HWND hURLBarWnd;
    46 long DefEditProc;
     50WNDPROC DefEditProc = 0;
     51WNDPROC DefWebKitProc = 0;
    4752IWebView* gWebView = 0;
     53IWebViewPrivate* gWebViewPrivate = 0;
    4854HWND gViewWindow = 0;
    4955WinLauncherWebHost* gWebHost = 0;
     
    5157TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
    5258TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
     59
     60// Support moving the transparent window
     61POINT s_windowPosition = { 100, 100 };
     62SIZE s_windowSize = { 800, 400 };
     63bool s_usesLayeredWebView = false;
     64bool s_fullDesktop = false;
    5365
    5466// Forward declarations of functions included in this code module:
     
    6072
    6173static void loadURL(BSTR urlBStr);
     74
     75static bool usesLayeredWebView()
     76{
     77    return s_usesLayeredWebView;
     78}
     79
     80static bool shouldUseFullDesktop()
     81{
     82    return s_fullDesktop;
     83}
    6284
    6385HRESULT WinLauncherWebHost::updateAddressBar(IWebView* webView)
     
    131153static void resizeSubViews()
    132154{
     155    if (usesLayeredWebView() || !gViewWindow)
     156        return;
     157
    133158    RECT rcClient;
    134159    GetClientRect(hMainWnd, &rcClient);
     
    137162}
    138163
     164static void subclassForLayeredWindow()
     165{
     166    hMainWnd = gViewWindow;
     167    DefWebKitProc = reinterpret_cast<WNDPROC>(::GetWindowLongPtr(hMainWnd, GWL_WNDPROC));
     168    ::SetWindowLongPtr(hMainWnd, GWL_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc));
     169}
     170
     171static void computeFullDesktopFrame()
     172{
     173    RECT desktop;
     174    if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, static_cast<void*>(&desktop), 0))
     175        return;
     176
     177    s_windowPosition.x = 0;
     178    s_windowPosition.y = 0;
     179    s_windowSize.cx = desktop.right - desktop.left;
     180    s_windowSize.cy = desktop.bottom - desktop.top;
     181}
     182
    139183int APIENTRY _tWinMain(HINSTANCE hInstance,
    140184                     HINSTANCE hPrevInstance,
     
    160204    InitCommonControlsEx(&InitCtrlEx);
    161205
     206    int argc = 0;
     207    WCHAR** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
     208    for (int i = 1; i < argc; ++i) {
     209        if (!wcsicmp(argv[i], L"--transparent"))
     210            s_usesLayeredWebView = true;
     211        else if (!wcsicmp(argv[i], L"--desktop"))
     212            s_fullDesktop = true;
     213    }
     214
    162215    // Initialize global strings
    163216    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
     
    165218    MyRegisterClass(hInstance);
    166219
     220    if (shouldUseFullDesktop())
     221        computeFullDesktopFrame();
     222
    167223    // Perform application initialization:
    168224    if (!InitInstance (hInstance, nCmdShow))
     
    172228    OleInitialize(NULL);
    173229
    174     hURLBarWnd = CreateWindow(L"EDIT", 0,
    175                         WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL,
    176                         0, 0, 0, 0,
    177                         hMainWnd,
    178                         0,
    179                         hInstance, 0);
    180 
    181     DefEditProc = GetWindowLong(hURLBarWnd, GWL_WNDPROC);
    182     SetWindowLong(hURLBarWnd, GWL_WNDPROC,(long)MyEditProc);
     230    if (usesLayeredWebView()) {
     231        hURLBarWnd = CreateWindow(L"EDIT", L"Type URL Here",
     232                    WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL,
     233                    s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT,
     234                    0,
     235                    0,
     236                    hInstance, 0);
     237    } else {
     238        hURLBarWnd = CreateWindow(L"EDIT", 0,
     239                    WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL,
     240                    0, 0, 0, 0,
     241                    hMainWnd,
     242                    0,
     243                    hInstance, 0);
     244    }
     245
     246    DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWL_WNDPROC));
     247    SetWindowLongPtr(hURLBarWnd, GWL_WNDPROC, reinterpret_cast<LONG_PTR>(MyEditProc));
    183248    SetFocus(hURLBarWnd);
    184249
    185     HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, (void**)&gWebView);
     250    RECT clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy };
     251
     252    IWebPreferences* tmpPreferences = 0;
     253    IWebPreferences* standardPreferences = 0;
     254    if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences))))
     255        goto exit;
     256
     257    if (FAILED(tmpPreferences->standardPreferences(&standardPreferences)))
     258        goto exit;
     259
     260    standardPreferences->setAcceleratedCompositingEnabled(TRUE);
     261
     262    HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView));
     263    if (FAILED(hr))
     264        goto exit;
     265
     266    hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate));
    186267    if (FAILED(hr))
    187268        goto exit;
     
    199280        goto exit;
    200281
    201     hr = gWebView->setHostWindow((OLE_HANDLE) hMainWnd);
    202     if (FAILED(hr))
    203         goto exit;
    204 
    205     RECT clientRect;
    206     GetClientRect(hMainWnd, &clientRect);
     282    hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd));
     283    if (FAILED(hr))
     284        goto exit;
     285
    207286    hr = gWebView->initWithFrame(clientRect, 0, 0);
    208287    if (FAILED(hr))
     
    214293        goto exit;
    215294
    216     static BSTR defaultHTML = SysAllocString(TEXT("<p style=\"background-color: #00FF00\">Testing</p><img src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>"));
     295    static BSTR defaultHTML = SysAllocString(TEXT("<p style=\"background-color: #00FF00\">Testing</p><img src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>"));
    217296    frame->loadHTMLString(defaultHTML, 0);
    218297    frame->Release();
    219298
    220     IWebViewPrivate* viewExt;
    221     hr = gWebView->QueryInterface(IID_IWebViewPrivate, (void**)&viewExt);
    222     if (FAILED(hr))
    223         goto exit;
    224 
    225     hr = viewExt->viewWindow((OLE_HANDLE*) &gViewWindow);
    226     viewExt->Release();
     299    hr = gWebViewPrivate->setTransparent(usesLayeredWebView());
     300    if (FAILED(hr))
     301        goto exit;
     302
     303    hr = gWebViewPrivate->setUsesLayeredWindow(usesLayeredWebView());
     304    if (FAILED(hr))
     305        goto exit;
     306
     307    hr = gWebViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&gViewWindow));
    227308    if (FAILED(hr) || !gViewWindow)
    228309        goto exit;
     310
     311    if (usesLayeredWebView())
     312        subclassForLayeredWindow();
    229313
    230314    resizeSubViews();
     
    245329exit:
    246330    gPrintDelegate->Release();
     331    if (gWebViewPrivate)
     332        gWebViewPrivate->Release();
    247333    gWebView->Release();
     334    if (standardPreferences)
     335        standardPreferences->Release();
     336    tmpPreferences->Release();
     337
    248338    shutDownWebKit();
    249339#ifdef _CRTDBG_MAP_ALLOC
     
    280370BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    281371{
    282    hInst = hInstance; // Store instance handle in our global variable
    283 
    284    hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
    285       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    286 
    287    if (!hMainWnd)
    288       return FALSE;
    289 
    290    ShowWindow(hMainWnd, nCmdShow);
    291    UpdateWindow(hMainWnd);
    292 
    293    return TRUE;
     372    hInst = hInstance; // Store instance handle in our global variable
     373
     374    if (usesLayeredWebView())
     375        return TRUE;
     376
     377    hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
     378                   CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
     379
     380    if (!hMainWnd)
     381        return FALSE;
     382
     383    ShowWindow(hMainWnd, nCmdShow);
     384    UpdateWindow(hMainWnd);
     385
     386    return TRUE;
    294387}
    295388
     
    374467}
    375468
     469static const int dragBarHeight = 30;
     470
    376471LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    377472{
    378     int wmId, wmEvent;
     473    WNDPROC parentProc = usesLayeredWebView() ? DefWebKitProc : DefWindowProc;
    379474
    380475    switch (message) {
    381     case WM_COMMAND:
    382         wmId    = LOWORD(wParam);
    383         wmEvent = HIWORD(wParam);
     476    case WM_NCHITTEST:
     477        if (usesLayeredWebView()) {
     478            RECT window;
     479            ::GetWindowRect(hWnd, &window);
     480            // For testing our transparent window, we need a region to use as a handle for
     481            // dragging. The right way to do this would be to query the web view to see what's
     482            // under the mouse. However, for testing purposes we just use an arbitrary
     483            // 30 pixel band at the top of the view as an arbitrary gripping location.
     484            //
     485            // When we are within this bad, return HT_CAPTION to tell Windows we want to
     486            // treat this region as if it were the title bar on a normal window.
     487            int y = HIWORD(lParam);
     488
     489            if ((y > window.top) && (y < window.top + dragBarHeight))
     490                return HTCAPTION;
     491
     492            return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     493        }
     494        break;
     495    case WM_COMMAND: {
     496        int wmId = LOWORD(wParam);
     497        int wmEvent = HIWORD(wParam);
    384498        // Parse the menu selections:
    385499        switch (wmId) {
    386             case IDM_ABOUT:
    387                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
    388                 break;
    389             case IDM_EXIT:
    390                 DestroyWindow(hWnd);
    391                 break;
    392             case IDM_PRINT:
    393                 PrintView(hWnd, message, wParam, lParam);
    394                 break;
    395             default:
    396                 return DefWindowProc(hWnd, message, wParam, lParam);
     500        case IDM_ABOUT:
     501            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
     502            break;
     503        case IDM_EXIT:
     504            DestroyWindow(hWnd);
     505            break;
     506        case IDM_PRINT:
     507            PrintView(hWnd, message, wParam, lParam);
     508            break;
     509        default:
     510            return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     511        }
    397512        }
    398513        break;
     
    401516        break;
    402517    case WM_SIZE:
    403         if (!gWebView)
    404             break;
     518        if (!gWebView || usesLayeredWebView())
     519           return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     520
    405521        resizeSubViews();
    406         break; 
     522        break;
    407523    default:
    408         return DefWindowProc(hWnd, message, wParam, lParam);
    409     }
     524        return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     525        break;
     526    }
     527
    410528    return 0;
    411529}
    412 
    413530
    414531#define MAX_URL_LENGTH  1024
Note: See TracChangeset for help on using the changeset viewer.