2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include "APIObject.h"
30 #include "PageClient.h"
32 #include "WebPageProxy.h"
34 #include <WebCore/COMPtr.h>
35 #include <WebCore/DragActions.h>
36 #include <WebCore/DragData.h>
37 #include <WebCore/WindowMessageListener.h>
38 #include <wtf/Forward.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefPtr.h>
42 interface IDropTargetHelper;
46 class DrawingAreaProxy;
48 class WebView : public APIObject, public PageClient, WebCore::WindowMessageListener, public IDropTarget {
50 static PassRefPtr<WebView> create(RECT rect, WebContext* context, WebPageGroup* pageGroup, HWND parentWindow)
52 RefPtr<WebView> webView = adoptRef(new WebView(rect, context, pageGroup, parentWindow));
53 webView->initialize();
58 HWND window() const { return m_window; }
59 void setParentWindow(HWND);
60 void windowAncestryDidChange();
61 void setIsInWindow(bool);
62 void setOverrideCursor(HCURSOR);
63 void setInitialFocus(bool forward);
64 void setFindIndicatorCallback(WKViewFindIndicatorCallback, void*);
65 WKViewFindIndicatorCallback getFindIndicatorCallback(void**);
69 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
70 virtual ULONG STDMETHODCALLTYPE AddRef(void);
71 virtual ULONG STDMETHODCALLTYPE Release(void);
74 virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
75 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
76 virtual HRESULT STDMETHODCALLTYPE DragLeave();
77 virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
79 WebPageProxy* page() const { return m_page.get(); }
82 WebView(RECT, WebContext*, WebPageGroup*, HWND parentWindow);
84 virtual Type type() const { return TypeView; }
86 static bool registerWebViewWindowClass();
87 static LRESULT CALLBACK WebViewWndProc(HWND, UINT, WPARAM, LPARAM);
88 LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
90 LRESULT onMouseEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
91 LRESULT onWheelEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
92 LRESULT onKeyEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
93 LRESULT onPaintEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
94 LRESULT onPrintClientEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
95 LRESULT onSizeEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
96 LRESULT onWindowPositionChangedEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
97 LRESULT onSetFocusEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
98 LRESULT onKillFocusEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
99 LRESULT onTimerEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
100 LRESULT onShowWindowEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
101 LRESULT onSetCursor(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
103 void paint(HDC, const WebCore::IntRect& dirtyRect);
104 void setWasActivatedByMouseEvent(bool flag) { m_wasActivatedByMouseEvent = flag; }
105 bool onIMEStartComposition();
106 bool onIMEComposition(LPARAM);
107 bool onIMEEndComposition();
108 LRESULT onIMERequest(WPARAM, LPARAM);
109 bool onIMESelect(WPARAM, LPARAM);
110 bool onIMESetContext(WPARAM, LPARAM);
112 void setInputMethodState(bool);
113 HIMC getIMMContext();
114 void prepareCandidateWindow(HIMC);
115 LRESULT onIMERequestCharPosition(IMECHARPOSITION*);
116 LRESULT onIMERequestReconvertString(RECONVERTSTRING*);
118 void updateActiveState();
119 void updateActiveStateSoon();
121 void initializeToolTipWindow();
123 void startTrackingMouseLeave();
124 void stopTrackingMouseLeave();
128 HCURSOR cursorToShow() const;
129 void updateNativeCursor();
132 virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
133 virtual void setViewNeedsDisplay(const WebCore::IntRect&);
134 virtual void displayView();
135 virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
136 virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
138 virtual WebCore::IntSize viewSize();
139 virtual bool isViewWindowActive();
140 virtual bool isViewFocused();
141 virtual bool isViewVisible();
142 virtual bool isViewInWindow();
143 virtual void processDidCrash();
144 virtual void didRelaunchProcess();
145 virtual void pageClosed();
146 virtual void takeFocus(bool direction);
147 virtual void setFocus(bool focused) { }
148 virtual void toolTipChanged(const WTF::String&, const WTF::String&);
149 virtual void setCursor(const WebCore::Cursor&);
150 virtual void setViewportArguments(const WebCore::ViewportArguments&);
151 virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
152 virtual void clearAllEditCommands();
153 virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
154 virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
155 virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&);
156 virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled);
157 virtual void compositionSelectionChanged(bool);
158 virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*);
159 virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
160 virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
162 #if USE(ACCELERATED_COMPOSITING)
163 virtual void enterAcceleratedCompositingMode(const LayerTreeContext&);
164 virtual void exitAcceleratedCompositingMode();
167 void didCommitLoadForMainFrame(bool useCustomRepresentation);
168 void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&);
169 virtual double customRepresentationZoomFactor();
170 virtual void setCustomRepresentationZoomFactor(double);
171 WebCore::DragOperation keyStateToDragOperation(DWORD grfKeyState) const;
172 virtual void didChangeScrollbarsForMainFrame() const;
174 virtual HWND nativeWindow();
176 // WebCore::WindowMessageListener
177 virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM);
180 HWND m_topLevelParentWindow;
181 HWND m_toolTipWindow;
183 HCURSOR m_lastCursorSet;
184 HCURSOR m_webCoreCursor;
185 HCURSOR m_overrideCursor;
189 bool m_wasActivatedByMouseEvent;
190 bool m_trackingMouseLeave;
191 bool m_isBeingDestroyed;
193 RefPtr<WebPageProxy> m_page;
195 unsigned m_inIMEComposition;
197 WKViewFindIndicatorCallback m_findIndicatorCallback;
198 void* m_findIndicatorCallbackContext;
200 COMPtr<IDataObject> m_dragData;
201 COMPtr<IDropTargetHelper> m_dropTargetHelper;
202 // FIXME: This variable is part of a workaround. The drop effect (pdwEffect) passed to Drop is incorrect.
203 // We set this variable in DragEnter and DragOver so that it can be used in Drop to set the correct drop effect.
204 // Thus, on return from DoDragDrop we have the correct pdwEffect for the drag-and-drop operation.
205 // (see https://bugs.webkit.org/show_bug.cgi?id=29264)
206 DWORD m_lastDropEffect;
209 } // namespace WebKit