| 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 PlatformWebView_h |
| 27 | #define PlatformWebView_h |
| 28 | |
| 29 | #if USE(CG) |
| 30 | #include <CoreGraphics/CGGeometry.h> |
| 31 | #endif |
| 32 | |
| 33 | #if PLATFORM(MAC) |
| 34 | #include <objc/objc.h> |
| 35 | #endif |
| 36 | |
| 37 | #if defined(__APPLE__) && !PLATFORM(GTK) |
| 38 | #ifdef __OBJC__ |
| 39 | @class WKView; |
| 40 | @class NSWindow; |
| 41 | #else |
| 42 | class WKView; |
| 43 | class NSWindow; |
| 44 | #endif |
| 45 | typedef WKView *PlatformWKView; |
| 46 | typedef NSWindow *PlatformWindow; |
| 47 | #elif PLATFORM(GTK) |
| 48 | typedef WKViewRef PlatformWKView; |
| 49 | typedef GtkWidget *PlatformWindow; |
| 50 | #elif PLATFORM(WPE) |
| 51 | namespace WPEToolingBackends { |
| 52 | class HeadlessViewBackend; |
| 53 | } |
| 54 | struct wpe_view_backend; |
| 55 | typedef WKViewRef PlatformWKView; |
| 56 | typedef WPEToolingBackends::HeadlessViewBackend *PlatformWindow; |
| 57 | #elif PLATFORM(WIN) |
| 58 | typedef WKViewRef PlatformWKView; |
| 59 | typedef HWND PlatformWindow; |
| 60 | #endif |
| 61 | typedef uint32_t WKEventModifiers; |
| 62 | |
| 63 | namespace TestWebKitAPI { |
| 64 | |
| 65 | class PlatformWebView { |
| 66 | public: |
| 67 | explicit PlatformWebView(WKPageConfigurationRef); |
| 68 | explicit PlatformWebView(WKContextRef, WKPageGroupRef = 0); |
| 69 | explicit PlatformWebView(WKPageRef relatedPage); |
| 70 | #if PLATFORM(MAC) |
| 71 | explicit PlatformWebView(WKContextRef, WKPageGroupRef, Class wkViewSubclass); |
| 72 | #endif |
| 73 | ~PlatformWebView(); |
| 74 | |
| 75 | WKPageRef page() const; |
| 76 | PlatformWKView platformView() const { return m_view; } |
| 77 | void resizeTo(unsigned width, unsigned height); |
| 78 | void focus(); |
| 79 | |
| 80 | void simulateSpacebarKeyPress(); |
| 81 | void simulateAltKeyPress(); |
| 82 | void simulateRightClick(unsigned x, unsigned y); |
| 83 | void simulateMouseMove(unsigned x, unsigned y, WKEventModifiers = 0); |
| 84 | #if PLATFORM(MAC) |
| 85 | void simulateButtonClick(WKEventMouseButton, unsigned x, unsigned y, WKEventModifiers); |
| 86 | #endif |
| 87 | |
| 88 | private: |
| 89 | #if PLATFORM(MAC) |
| 90 | void initialize(WKPageConfigurationRef, Class wkViewSubclass); |
| 91 | #elif PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(WIN) |
| 92 | void initialize(WKPageConfigurationRef); |
| 93 | #endif |
| 94 | #if PLATFORM(WIN) |
| 95 | static void registerWindowClass(); |
| 96 | static LRESULT CALLBACK wndProc(HWND, UINT message, WPARAM, LPARAM); |
| 97 | #endif |
| 98 | |
| 99 | PlatformWKView m_view; |
| 100 | PlatformWindow m_window; |
| 101 | }; |
| 102 | |
| 103 | } // namespace TestWebKitAPI |
| 104 | |
| 105 | #endif // PlatformWebView_h |
| 106 | |