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#pragma once
27
28#include "TestOptions.h"
29
30#if PLATFORM(COCOA) && !defined(BUILDING_GTK__)
31#include <WebKit/WKFoundation.h>
32#include <wtf/RetainPtr.h>
33OBJC_CLASS NSView;
34OBJC_CLASS UIView;
35OBJC_CLASS TestRunnerWKWebView;
36OBJC_CLASS WKWebViewConfiguration;
37OBJC_CLASS WebKitTestRunnerWindow;
38typedef struct CGImage *CGImageRef;
39
40typedef TestRunnerWKWebView *PlatformWKView;
41typedef WebKitTestRunnerWindow *PlatformWindow;
42typedef RetainPtr<CGImageRef> PlatformImage;
43#elif defined(BUILDING_GTK__)
44typedef struct _GtkWidget GtkWidget;
45typedef WKViewRef PlatformWKView;
46typedef GtkWidget* PlatformWindow;
47#elif PLATFORM(WPE)
48namespace WPEToolingBackends {
49class HeadlessViewBackend;
50}
51typedef WKViewRef PlatformWKView;
52typedef WPEToolingBackends::HeadlessViewBackend* PlatformWindow;
53#elif PLATFORM(WIN)
54#include <cairo.h>
55class TestRunnerWindow;
56typedef HWND PlatformWindow;
57typedef WKViewRef PlatformWKView;
58#endif
59
60#if USE(CAIRO)
61typedef cairo_surface_t* PlatformImage;
62#endif
63
64namespace WTR {
65
66class PlatformWebView {
67public:
68#if PLATFORM(COCOA)
69 PlatformWebView(WKWebViewConfiguration*, const TestOptions&);
70#else
71 PlatformWebView(WKPageConfigurationRef, const TestOptions&);
72#endif
73 ~PlatformWebView();
74
75 WKPageRef page();
76 PlatformWKView platformView() { return m_view; }
77 PlatformWindow platformWindow() { return m_window; }
78 static PlatformWindow keyWindow();
79
80 enum class WebViewSizingMode {
81 Default,
82 HeightRespectsStatusBar
83 };
84
85 void resizeTo(unsigned width, unsigned height, WebViewSizingMode = WebViewSizingMode::Default);
86 void focus();
87
88 WKRect windowFrame();
89 void setWindowFrame(WKRect, WebViewSizingMode = WebViewSizingMode::Default);
90
91 void didInitializeClients();
92
93 void addChromeInputField();
94 void removeChromeInputField();
95 void makeWebViewFirstResponder();
96 void setWindowIsKey(bool);
97 bool windowIsKey() const { return m_windowIsKey; }
98
99 bool drawsBackground() const;
100 void setDrawsBackground(bool);
101
102 void setEditable(bool);
103
104 void removeFromWindow();
105 void addToWindow();
106
107 bool viewSupportsOptions(const TestOptions& options) const { return !options.runSingly && m_options.hasSameInitializationOptions(options); }
108
109 PlatformImage windowSnapshotImage();
110 const TestOptions& options() const { return m_options; }
111
112 void changeWindowScaleIfNeeded(float newScale);
113 void setNavigationGesturesEnabled(bool);
114
115#if PLATFORM(GTK)
116 void dismissAllPopupMenus();
117#endif
118
119private:
120 void forceWindowFramesChanged();
121
122 PlatformWKView m_view;
123 PlatformWindow m_window;
124 bool m_windowIsKey;
125 const TestOptions m_options;
126#if PLATFORM(GTK)
127 GtkWidget* m_otherWindow { nullptr };
128#endif
129};
130
131} // namespace WTR
132