1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef WebView_h 27 #define WebView_h 28 29 #include "APIObject.h" 30 #include "PageClient.h" 31 #include "WKView.h" 32 #include "WebPageProxy.h" 33 #include "WebUndoClient.h" 34 #include <ShlObj.h> 35 #include <WebCore/COMPtr.h> 36 #include <WebCore/DragActions.h> 37 #include <WebCore/DragData.h> 38 #include <WebCore/WindowMessageListener.h> 39 #include <wtf/Forward.h> 40 #include <wtf/PassRefPtr.h> 41 #include <wtf/RefPtr.h> 42 43 #if ENABLE(FULLSCREEN_API) 44 #include <WebCore/FullScreenControllerClient.h> 45 #endif 46 47 namespace WebCore { 48 class FullScreenController; 49 } 50 51 interface IDropTargetHelper; 52 53 namespace WebKit { 54 55 class DrawingAreaProxy; 56 57 class WebView 58 : public APIObject 59 , public PageClient 60 , WebCore::WindowMessageListener 61 , public IDropTarget 62 #if ENABLE(FULLSCREEN_API) 63 , WebCore::FullScreenControllerClient 64 #endif 65 { 66 public: create(RECT rect,WebContext * context,WebPageGroup * pageGroup,HWND parentWindow)67 static PassRefPtr<WebView> create(RECT rect, WebContext* context, WebPageGroup* pageGroup, HWND parentWindow) 68 { 69 RefPtr<WebView> webView = adoptRef(new WebView(rect, context, pageGroup, parentWindow)); 70 webView->initialize(); 71 return webView; 72 } 73 ~WebView(); 74 window()75 HWND window() const { return m_window; } 76 void setParentWindow(HWND); 77 void windowAncestryDidChange(); 78 void setIsInWindow(bool); 79 void setIsVisible(bool); 80 void setOverrideCursor(HCURSOR); 81 void setInitialFocus(bool forward); 82 void setScrollOffsetOnNextResize(const WebCore::IntSize&); 83 void setFindIndicatorCallback(WKViewFindIndicatorCallback, void*); 84 WKViewFindIndicatorCallback getFindIndicatorCallback(void**); 85 void initialize(); 86 87 void initializeUndoClient(const WKViewUndoClient*); 88 void reapplyEditCommand(WebEditCommandProxy*); 89 void unapplyEditCommand(WebEditCommandProxy*); 90 91 // IUnknown 92 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); 93 virtual ULONG STDMETHODCALLTYPE AddRef(void); 94 virtual ULONG STDMETHODCALLTYPE Release(void); 95 96 // IDropTarget 97 virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 98 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 99 virtual HRESULT STDMETHODCALLTYPE DragLeave(); 100 virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); 101 page()102 WebPageProxy* page() const { return m_page.get(); } 103 104 #if ENABLE(FULLSCREEN_API) 105 WebCore::FullScreenController* fullScreenController(); 106 #endif 107 108 private: 109 WebView(RECT, WebContext*, WebPageGroup*, HWND parentWindow); 110 type()111 virtual Type type() const { return TypeView; } 112 113 static bool registerWebViewWindowClass(); 114 static LRESULT CALLBACK WebViewWndProc(HWND, UINT, WPARAM, LPARAM); 115 LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 116 117 LRESULT onMouseEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 118 LRESULT onWheelEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 119 LRESULT onHorizontalScroll(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 120 LRESULT onVerticalScroll(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 121 LRESULT onGestureNotify(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 122 LRESULT onGesture(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 123 LRESULT onKeyEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 124 LRESULT onPaintEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 125 LRESULT onPrintClientEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 126 LRESULT onSizeEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 127 LRESULT onWindowPositionChangedEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 128 LRESULT onSetFocusEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 129 LRESULT onKillFocusEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 130 LRESULT onTimerEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 131 LRESULT onShowWindowEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 132 LRESULT onSetCursor(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled); 133 134 void paint(HDC, const WebCore::IntRect& dirtyRect); setWasActivatedByMouseEvent(bool flag)135 void setWasActivatedByMouseEvent(bool flag) { m_wasActivatedByMouseEvent = flag; } 136 bool onIMEStartComposition(); 137 bool onIMEComposition(LPARAM); 138 bool onIMEEndComposition(); 139 LRESULT onIMERequest(WPARAM, LPARAM); 140 bool onIMESelect(WPARAM, LPARAM); 141 bool onIMESetContext(WPARAM, LPARAM); 142 void resetIME(); 143 void setInputMethodState(bool); 144 HIMC getIMMContext(); 145 void prepareCandidateWindow(HIMC); 146 LRESULT onIMERequestCharPosition(IMECHARPOSITION*); 147 LRESULT onIMERequestReconvertString(RECONVERTSTRING*); 148 149 void updateActiveState(); 150 void updateActiveStateSoon(); 151 152 void initializeToolTipWindow(); 153 154 void startTrackingMouseLeave(); 155 void stopTrackingMouseLeave(); 156 157 bool shouldInitializeTrackPointHack(); 158 159 void close(); 160 161 HCURSOR cursorToShow() const; 162 void updateNativeCursor(); 163 164 void updateChildWindowGeometries(); 165 166 // PageClient 167 virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy(); 168 virtual void setViewNeedsDisplay(const WebCore::IntRect&); 169 virtual void displayView(); 170 virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); 171 virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects); userSpaceScaleFactor()172 virtual float userSpaceScaleFactor() const { return 1; } 173 174 virtual WebCore::IntSize viewSize(); 175 virtual bool isViewWindowActive(); 176 virtual bool isViewFocused(); 177 virtual bool isViewVisible(); 178 virtual bool isViewInWindow(); 179 virtual void processDidCrash(); 180 virtual void didRelaunchProcess(); 181 virtual void pageClosed(); 182 virtual void toolTipChanged(const WTF::String&, const WTF::String&); 183 virtual void setCursor(const WebCore::Cursor&); 184 virtual void setViewportArguments(const WebCore::ViewportArguments&); 185 virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo); 186 virtual void clearAllEditCommands(); 187 virtual bool canUndoRedo(WebPageProxy::UndoOrRedo); 188 virtual void executeUndoRedo(WebPageProxy::UndoOrRedo); 189 virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&); 190 virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&); 191 virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&); 192 virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled); 193 virtual void compositionSelectionChanged(bool); 194 virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*); 195 virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*); 196 virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut); 197 198 #if USE(ACCELERATED_COMPOSITING) 199 virtual void enterAcceleratedCompositingMode(const LayerTreeContext&); 200 virtual void exitAcceleratedCompositingMode(); 201 #endif 202 203 void didCommitLoadForMainFrame(bool useCustomRepresentation); 204 void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&); 205 virtual double customRepresentationZoomFactor(); 206 virtual void setCustomRepresentationZoomFactor(double); 207 WebCore::DragOperation keyStateToDragOperation(DWORD grfKeyState) const; 208 virtual void didChangeScrollbarsForMainFrame() const; 209 210 virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount); 211 virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount); 212 213 virtual HWND nativeWindow(); 214 virtual void scheduleChildWindowGeometryUpdate(HWND, const WebCore::IntRect& rectInParentClientCoordinates, const WebCore::IntRect& clipRectInChildClientCoordinates); 215 setGestureReachedScrollingLimit(bool limitReached)216 virtual void setGestureReachedScrollingLimit(bool limitReached) { m_gestureReachedScrollingLimit = limitReached; } 217 218 // WebCore::WindowMessageListener 219 virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM); 220 221 #if ENABLE(FULLSCREEN_API) 222 virtual HWND fullScreenClientWindow() const; 223 virtual HWND fullScreenClientParentWindow() const; 224 virtual void fullScreenClientSetParentWindow(HWND); 225 virtual void fullScreenClientWillEnterFullScreen(); 226 virtual void fullScreenClientDidEnterFullScreen(); 227 virtual void fullScreenClientWillExitFullScreen(); 228 virtual void fullScreenClientDidExitFullScreen(); 229 #endif 230 231 HWND m_window; 232 HWND m_topLevelParentWindow; 233 HWND m_toolTipWindow; 234 235 WebCore::IntSize m_nextResizeScrollOffset; 236 237 HCURSOR m_lastCursorSet; 238 HCURSOR m_webCoreCursor; 239 HCURSOR m_overrideCursor; 240 241 bool m_isInWindow; 242 bool m_isVisible; 243 bool m_wasActivatedByMouseEvent; 244 bool m_trackingMouseLeave; 245 bool m_isBeingDestroyed; 246 247 RefPtr<WebPageProxy> m_page; 248 249 unsigned m_inIMEComposition; 250 251 WebUndoClient m_undoClient; 252 253 WKViewFindIndicatorCallback m_findIndicatorCallback; 254 void* m_findIndicatorCallbackContext; 255 256 COMPtr<IDataObject> m_dragData; 257 COMPtr<IDropTargetHelper> m_dropTargetHelper; 258 // FIXME: This variable is part of a workaround. The drop effect (pdwEffect) passed to Drop is incorrect. 259 // We set this variable in DragEnter and DragOver so that it can be used in Drop to set the correct drop effect. 260 // Thus, on return from DoDragDrop we have the correct pdwEffect for the drag-and-drop operation. 261 // (see https://bugs.webkit.org/show_bug.cgi?id=29264) 262 DWORD m_lastDropEffect; 263 264 int m_lastPanX; 265 int m_lastPanY; 266 267 int m_overPanY; 268 269 bool m_gestureReachedScrollingLimit; 270 271 struct ChildWindowGeometry { 272 WebCore::IntRect rectInParentClientCoordinates; 273 WebCore::IntRect clipRectInChildClientCoordinates; 274 }; 275 276 HashMap<HWND, ChildWindowGeometry> m_childWindowGeometriesToUpdate; 277 278 #if ENABLE(FULLSCREEN_API) 279 OwnPtr<WebCore::FullScreenController> m_fullScreenController; 280 #endif 281 }; 282 283 } // namespace WebKit 284 285 #endif // WebView_h 286