1/*
2 * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 * Copyright (C) 2012, Samsung Electronics. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "Cursor.h"
25#include "DisabledAdaptations.h"
26#include "FocusDirection.h"
27#include "HostWindow.h"
28#include <wtf/Forward.h>
29#include <wtf/RefPtr.h>
30
31#if PLATFORM(COCOA)
32OBJC_CLASS NSView;
33#endif
34
35namespace WebCore {
36
37class ChromeClient;
38class ColorChooser;
39class ColorChooserClient;
40class DataListSuggestionPicker;
41class DataListSuggestionsClient;
42class DateTimeChooser;
43class DateTimeChooserClient;
44class FileChooser;
45class FileIconLoader;
46class FloatRect;
47class FrameLoadRequest;
48class Element;
49class Frame;
50class Geolocation;
51class HitTestResult;
52class IntPoint;
53class IntRect;
54class NavigationAction;
55class Page;
56class PopupMenu;
57class PopupMenuClient;
58class PopupOpeningObserver;
59class SearchPopupMenu;
60
61struct DateTimeChooserParameters;
62struct ShareDataWithParsedURL;
63struct ViewportArguments;
64struct WindowFeatures;
65
66class Chrome : public HostWindow {
67public:
68 Chrome(Page&, ChromeClient&);
69 virtual ~Chrome();
70
71 ChromeClient& client() { return m_client; }
72
73 // HostWindow methods.
74 void invalidateRootView(const IntRect&) override;
75 void invalidateContentsAndRootView(const IntRect&) override;
76 void invalidateContentsForSlowScroll(const IntRect&) override;
77 void scroll(const IntSize&, const IntRect&, const IntRect&) override;
78 IntPoint screenToRootView(const IntPoint&) const override;
79 IntRect rootViewToScreen(const IntRect&) const override;
80 IntPoint accessibilityScreenToRootView(const IntPoint&) const override;
81 IntRect rootViewToAccessibilityScreen(const IntRect&) const override;
82 PlatformPageClient platformPageClient() const override;
83 void setCursor(const Cursor&) override;
84 void setCursorHiddenUntilMouseMoves(bool) override;
85
86 void scheduleAnimation() override { }
87
88 PlatformDisplayID displayID() const override;
89 void windowScreenDidChange(PlatformDisplayID) override;
90
91 FloatSize screenSize() const override;
92 FloatSize availableScreenSize() const override;
93 FloatSize overrideScreenSize() const override;
94
95 void scrollRectIntoView(const IntRect&) const;
96
97 void contentsSizeChanged(Frame&, const IntSize&) const;
98
99 WEBCORE_EXPORT void setWindowRect(const FloatRect&) const;
100 WEBCORE_EXPORT FloatRect windowRect() const;
101
102 FloatRect pageRect() const;
103
104 void focus() const;
105 void unfocus() const;
106
107 bool canTakeFocus(FocusDirection) const;
108 void takeFocus(FocusDirection) const;
109
110 void focusedElementChanged(Element*) const;
111 void focusedFrameChanged(Frame*) const;
112
113 WEBCORE_EXPORT Page* createWindow(Frame&, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) const;
114 WEBCORE_EXPORT void show() const;
115
116 bool canRunModal() const;
117 void runModal() const;
118
119 void setToolbarsVisible(bool) const;
120 bool toolbarsVisible() const;
121
122 void setStatusbarVisible(bool) const;
123 bool statusbarVisible() const;
124
125 void setScrollbarsVisible(bool) const;
126 bool scrollbarsVisible() const;
127
128 void setMenubarVisible(bool) const;
129 bool menubarVisible() const;
130
131 void setResizable(bool) const;
132
133 bool canRunBeforeUnloadConfirmPanel();
134 bool runBeforeUnloadConfirmPanel(const String& message, Frame&);
135
136 void closeWindowSoon();
137
138 void runJavaScriptAlert(Frame&, const String&);
139 bool runJavaScriptConfirm(Frame&, const String&);
140 bool runJavaScriptPrompt(Frame&, const String& message, const String& defaultValue, String& result);
141 WEBCORE_EXPORT void setStatusbarText(Frame&, const String&);
142
143 void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
144
145 void setToolTip(const HitTestResult&);
146
147 WEBCORE_EXPORT bool print(Frame&);
148
149 WEBCORE_EXPORT void enableSuddenTermination();
150 WEBCORE_EXPORT void disableSuddenTermination();
151
152#if ENABLE(INPUT_TYPE_COLOR)
153 std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient&, const Color& initialColor);
154#endif
155
156#if ENABLE(DATALIST_ELEMENT)
157 std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&);
158#endif
159
160 void runOpenPanel(Frame&, FileChooser&);
161 void showShareSheet(ShareDataWithParsedURL&, CompletionHandler<void(bool)>&&);
162 void loadIconForFiles(const Vector<String>&, FileIconLoader&);
163
164 void dispatchDisabledAdaptationsDidChange(const OptionSet<DisabledAdaptations>&) const;
165 void dispatchViewportPropertiesDidChange(const ViewportArguments&) const;
166
167 bool requiresFullscreenForVideoPlayback();
168
169#if PLATFORM(COCOA)
170 WEBCORE_EXPORT void focusNSView(NSView*);
171#endif
172
173 bool selectItemWritingDirectionIsNatural();
174 bool selectItemAlignmentFollowsMenuWritingDirection();
175 RefPtr<PopupMenu> createPopupMenu(PopupMenuClient&) const;
176 RefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient&) const;
177
178#if PLATFORM(IOS_FAMILY)
179 // FIXME: Can we come up with a better name for this setter?
180 void setDispatchViewportDataDidChangeSuppressed(bool dispatchViewportDataDidChangeSuppressed) { m_isDispatchViewportDataDidChangeSuppressed = dispatchViewportDataDidChangeSuppressed; }
181#endif
182
183 void didReceiveDocType(Frame&);
184
185 void registerPopupOpeningObserver(PopupOpeningObserver&);
186 void unregisterPopupOpeningObserver(PopupOpeningObserver&);
187
188private:
189 void notifyPopupOpeningObservers() const;
190
191 Page& m_page;
192 ChromeClient& m_client;
193 PlatformDisplayID m_displayID { 0 };
194 Vector<PopupOpeningObserver*> m_popupOpeningObservers;
195#if PLATFORM(IOS_FAMILY)
196 bool m_isDispatchViewportDataDidChangeSuppressed { false };
197#endif
198};
199
200} // namespace WebCore
201