1 | /* |
2 | * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> |
3 | * 1999-2001 Lars Knoll <knoll@kde.org> |
4 | * 1999-2001 Antti Koivisto <koivisto@kde.org> |
5 | * 2000-2001 Simon Hausmann <hausmann@kde.org> |
6 | * 2000-2001 Dirk Mueller <mueller@kde.org> |
7 | * 2000 Stefan Schimanski <1Stein@gmx.de> |
8 | * Copyright (C) 2004-2016 Apple Inc. All rights reserved. |
9 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
10 | * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
11 | * |
12 | * This library is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU Library General Public |
14 | * License as published by the Free Software Foundation; either |
15 | * version 2 of the License, or (at your option) any later version. |
16 | * |
17 | * This library is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * Library General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU Library General Public License |
23 | * along with this library; see the file COPYING.LIB. If not, write to |
24 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | * Boston, MA 02110-1301, USA. |
26 | */ |
27 | |
28 | #ifndef Frame_h |
29 | #define Frame_h |
30 | |
31 | #include "AdjustViewSizeOrNot.h" |
32 | #include "FrameLoader.h" |
33 | #include "FrameTree.h" |
34 | #include "IntRect.h" |
35 | #include "NavigationScheduler.h" |
36 | #include "ScrollTypes.h" |
37 | #include "UserScriptTypes.h" |
38 | #include <memory> |
39 | #include <wtf/ThreadSafeRefCounted.h> |
40 | |
41 | #if PLATFORM(IOS) |
42 | #include "ViewportArguments.h" |
43 | #include "VisibleSelection.h" |
44 | #endif |
45 | |
46 | #if PLATFORM(WIN) |
47 | #include "FrameWin.h" |
48 | #endif |
49 | |
50 | #if PLATFORM(COCOA) |
51 | OBJC_CLASS NSArray; |
52 | #endif |
53 | |
54 | #if PLATFORM(IOS) |
55 | OBJC_CLASS DOMCSSStyleDeclaration; |
56 | OBJC_CLASS DOMNode; |
57 | OBJC_CLASS NSString; |
58 | #endif |
59 | |
60 | #if PLATFORM(WIN) |
61 | typedef struct HBITMAP__* HBITMAP; |
62 | #endif |
63 | |
64 | namespace JSC { namespace Yarr { |
65 | class RegularExpression; |
66 | } } |
67 | |
68 | namespace WebCore { |
69 | |
70 | class AnimationController; |
71 | class Color; |
72 | class Document; |
73 | class Editor; |
74 | class Element; |
75 | class EventHandler; |
76 | class FloatSize; |
77 | class FrameDestructionObserver; |
78 | class FrameSelection; |
79 | class FrameView; |
80 | class HTMLFrameOwnerElement; |
81 | class HTMLTableCellElement; |
82 | class HitTestResult; |
83 | class ImageBuffer; |
84 | class IntRect; |
85 | class MainFrame; |
86 | class Node; |
87 | class Range; |
88 | class RenderLayer; |
89 | class RenderView; |
90 | class RenderWidget; |
91 | class ScriptController; |
92 | class Settings; |
93 | class VisiblePosition; |
94 | class Widget; |
95 | |
96 | #if PLATFORM(IOS) |
97 | enum { |
98 | OverflowScrollNone = 0, |
99 | OverflowScrollLeft = 1 << 0, |
100 | OverflowScrollRight = 1 << 1, |
101 | OverflowScrollUp = 1 << 2, |
102 | OverflowScrollDown = 1 << 3 |
103 | }; |
104 | |
105 | enum OverflowScrollAction { DoNotPerformOverflowScroll, PerformOverflowScroll }; |
106 | typedef Node* (*NodeQualifier)(const HitTestResult&, Node* terminationNode, IntRect* nodeBounds); |
107 | #endif |
108 | |
109 | enum { |
110 | LayerTreeFlagsIncludeDebugInfo = 1 << 0, |
111 | LayerTreeFlagsIncludeVisibleRects = 1 << 1, |
112 | LayerTreeFlagsIncludeTileCaches = 1 << 2, |
113 | LayerTreeFlagsIncludeRepaintRects = 1 << 3, |
114 | LayerTreeFlagsIncludePaintingPhases = 1 << 4, |
115 | LayerTreeFlagsIncludeContentLayers = 1 << 5 |
116 | }; |
117 | typedef unsigned LayerTreeFlags; |
118 | |
119 | class Frame : public ThreadSafeRefCounted<Frame> { |
120 | public: |
121 | WEBCORE_EXPORT static Ref<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*); |
122 | |
123 | void init(); |
124 | #if PLATFORM(IOS) |
125 | // Creates <html><body style="..."></body></html> doing minimal amount of work. |
126 | WEBCORE_EXPORT void initWithSimpleHTMLDocument(const String& style, const URL&); |
127 | #endif |
128 | WEBCORE_EXPORT void setView(RefPtr<FrameView>&&); |
129 | WEBCORE_EXPORT void createView(const IntSize&, const Color&, bool, |
130 | const IntSize& fixedLayoutSize = IntSize(), const IntRect& fixedVisibleContentRect = IntRect(), |
131 | bool useFixedLayout = false, ScrollbarMode = ScrollbarAuto, bool horizontalLock = false, |
132 | ScrollbarMode = ScrollbarAuto, bool verticalLock = false); |
133 | |
134 | WEBCORE_EXPORT virtual ~Frame(); |
135 | |
136 | void addDestructionObserver(FrameDestructionObserver*); |
137 | void removeDestructionObserver(FrameDestructionObserver*); |
138 | |
139 | void willDetachPage(); |
140 | void detachFromPage(); |
141 | void disconnectOwnerElement(); |
142 | |
143 | MainFrame& mainFrame() const; |
144 | WEBCORE_EXPORT bool isMainFrame() const; |
145 | |
146 | Page* page() const; |
147 | HTMLFrameOwnerElement* ownerElement() const; |
148 | |
149 | Document* document() const; |
150 | FrameView* view() const; |
151 | |
152 | Editor& editor() const; |
153 | EventHandler& eventHandler() const; |
154 | EventHandler* eventHandlerPtr() const; |
155 | FrameLoader& loader() const; |
156 | NavigationScheduler& navigationScheduler() const; |
157 | FrameSelection& selection() const; |
158 | FrameTree& tree() const; |
159 | AnimationController& animation() const; |
160 | ScriptController& script(); |
161 | |
162 | WEBCORE_EXPORT RenderView* contentRenderer() const; // Root of the render tree for the document contained in this frame. |
163 | WEBCORE_EXPORT RenderWidget* ownerRenderer() const; // Renderer for the element that contains this frame. |
164 | |
165 | bool documentIsBeingReplaced() const { return m_documentIsBeingReplaced; } |
166 | |
167 | // ======== All public functions below this point are candidates to move out of Frame into another class. ======== |
168 | |
169 | void injectUserScripts(UserScriptInjectionTime); |
170 | |
171 | WEBCORE_EXPORT String layerTreeAsText(LayerTreeFlags = 0) const; |
172 | WEBCORE_EXPORT String trackedRepaintRectsAsText() const; |
173 | |
174 | WEBCORE_EXPORT static Frame* frameForWidget(const Widget*); |
175 | |
176 | Settings& settings() const { return *m_settings; } |
177 | |
178 | void setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot); |
179 | bool shouldUsePrintingLayout() const; |
180 | WEBCORE_EXPORT FloatSize (const FloatSize& originalSize, const FloatSize& expectedSize); |
181 | |
182 | void setDocument(RefPtr<Document>&&); |
183 | |
184 | WEBCORE_EXPORT void setPageZoomFactor(float); |
185 | float pageZoomFactor() const { return m_pageZoomFactor; } |
186 | WEBCORE_EXPORT void setTextZoomFactor(float); |
187 | float textZoomFactor() const { return m_textZoomFactor; } |
188 | WEBCORE_EXPORT void setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor); |
189 | |
190 | // Scale factor of this frame with respect to the container. |
191 | WEBCORE_EXPORT float frameScaleFactor() const; |
192 | |
193 | void deviceOrPageScaleFactorChanged(); |
194 | |
195 | #if ENABLE(DATA_DETECTION) |
196 | void setDataDetectionResults(NSArray *results) { m_dataDetectionResults = results; } |
197 | NSArray *dataDetectionResults() const { return m_dataDetectionResults.get(); } |
198 | #endif |
199 | |
200 | #if PLATFORM(IOS) |
201 | const ViewportArguments& viewportArguments() const; |
202 | WEBCORE_EXPORT void setViewportArguments(const ViewportArguments&); |
203 | |
204 | WEBCORE_EXPORT Node* deepestNodeAtLocation(const FloatPoint& viewportLocation); |
205 | WEBCORE_EXPORT Node* nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation); |
206 | WEBCORE_EXPORT Node* nodeRespondingToScrollWheelEvents(const FloatPoint& viewportLocation); |
207 | |
208 | int indexCountOfWordPrecedingSelection(NSString* word) const; |
209 | WEBCORE_EXPORT NSArray* wordsInCurrentParagraph() const; |
210 | WEBCORE_EXPORT CGRect renderRectForPoint(CGPoint, bool* isReplaced, float* fontSize) const; |
211 | |
212 | WEBCORE_EXPORT void setSelectionChangeCallbacksDisabled(bool = true); |
213 | bool selectionChangeCallbacksDisabled() const; |
214 | |
215 | enum ViewportOffsetChangeType { IncrementalScrollOffset, CompletedScrollOffset }; |
216 | WEBCORE_EXPORT void viewportOffsetChanged(ViewportOffsetChangeType); |
217 | bool containsTiledBackingLayers() const; |
218 | |
219 | WEBCORE_EXPORT void overflowScrollPositionChangedForNode(const IntPoint&, Node*, bool isUserScroll); |
220 | |
221 | WEBCORE_EXPORT void resetAllGeolocationPermission(); |
222 | #endif |
223 | |
224 | #if ENABLE(ORIENTATION_EVENTS) |
225 | // Orientation is the interface orientation in degrees. Some examples are: |
226 | // 0 is straight up; -90 is when the device is rotated 90 clockwise; |
227 | // 90 is when rotated counter clockwise. |
228 | WEBCORE_EXPORT void orientationChanged(); |
229 | int orientation() const; |
230 | #endif |
231 | |
232 | void clearTimers(); |
233 | static void clearTimers(FrameView*, Document*); |
234 | |
235 | WEBCORE_EXPORT String displayStringModifiedByEncoding(const String&) const; |
236 | |
237 | WEBCORE_EXPORT VisiblePosition visiblePositionForPoint(const IntPoint& framePoint) const; |
238 | Document* documentAtPoint(const IntPoint& windowPoint); |
239 | WEBCORE_EXPORT RefPtr<Range> rangeForPoint(const IntPoint& framePoint); |
240 | |
241 | WEBCORE_EXPORT String searchForLabelsAboveCell(const JSC::Yarr::RegularExpression&, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell); |
242 | String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove); |
243 | String matchLabelsAgainstElement(const Vector<String>& labels, Element*); |
244 | |
245 | #if PLATFORM(IOS) |
246 | // Scroll the selection in an overflow layer on iOS. |
247 | void scrollOverflowLayer(RenderLayer* , const IntRect& visibleRect, const IntRect& exposeRect); |
248 | |
249 | WEBCORE_EXPORT int preferredHeight() const; |
250 | WEBCORE_EXPORT int innerLineHeight(DOMNode*) const; |
251 | WEBCORE_EXPORT void updateLayout() const; |
252 | WEBCORE_EXPORT NSRect caretRect() const; |
253 | WEBCORE_EXPORT NSRect rectForScrollToVisible() const; |
254 | WEBCORE_EXPORT DOMCSSStyleDeclaration* styleAtSelectionStart() const; |
255 | WEBCORE_EXPORT unsigned formElementsCharacterCount() const; |
256 | |
257 | // This function is used by Legacy WebKit. |
258 | WEBCORE_EXPORT void setTimersPaused(bool); |
259 | |
260 | WEBCORE_EXPORT void dispatchPageHideEventBeforePause(); |
261 | WEBCORE_EXPORT void dispatchPageShowEventBeforeResume(); |
262 | WEBCORE_EXPORT void setRangedSelectionBaseToCurrentSelection(); |
263 | WEBCORE_EXPORT void setRangedSelectionBaseToCurrentSelectionStart(); |
264 | WEBCORE_EXPORT void setRangedSelectionBaseToCurrentSelectionEnd(); |
265 | WEBCORE_EXPORT void clearRangedSelectionInitialExtent(); |
266 | WEBCORE_EXPORT void setRangedSelectionInitialExtentToCurrentSelectionStart(); |
267 | WEBCORE_EXPORT void setRangedSelectionInitialExtentToCurrentSelectionEnd(); |
268 | WEBCORE_EXPORT VisibleSelection rangedSelectionBase() const; |
269 | WEBCORE_EXPORT VisibleSelection rangedSelectionInitialExtent() const; |
270 | WEBCORE_EXPORT void recursiveSetUpdateAppearanceEnabled(bool); |
271 | WEBCORE_EXPORT NSArray* interpretationsForCurrentRoot() const; |
272 | #endif |
273 | void suspendActiveDOMObjectsAndAnimations(); |
274 | void resumeActiveDOMObjectsAndAnimations(); |
275 | bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; } |
276 | |
277 | bool isURLAllowed(const URL&) const; |
278 | |
279 | // ======== |
280 | |
281 | protected: |
282 | Frame(Page&, HTMLFrameOwnerElement*, FrameLoaderClient&); |
283 | void setMainFrameWasDestroyed(); |
284 | |
285 | private: |
286 | void injectUserScriptsForWorld(DOMWrapperWorld&, const UserScriptVector&, UserScriptInjectionTime); |
287 | |
288 | HashSet<FrameDestructionObserver*> m_destructionObservers; |
289 | |
290 | MainFrame& m_mainFrame; |
291 | Page* m_page; |
292 | const RefPtr<Settings> m_settings; |
293 | mutable FrameTree m_treeNode; |
294 | mutable FrameLoader m_loader; |
295 | mutable NavigationScheduler m_navigationScheduler; |
296 | |
297 | HTMLFrameOwnerElement* m_ownerElement; |
298 | RefPtr<FrameView> m_view; |
299 | RefPtr<Document> m_doc; |
300 | |
301 | const std::unique_ptr<ScriptController> m_script; |
302 | const std::unique_ptr<Editor> m_editor; |
303 | const std::unique_ptr<FrameSelection> m_selection; |
304 | const std::unique_ptr<AnimationController> m_animationController; |
305 | |
306 | #if ENABLE(DATA_DETECTION) |
307 | RetainPtr<NSArray> m_dataDetectionResults; |
308 | #endif |
309 | #if PLATFORM(IOS) |
310 | void betterApproximateNode(const IntPoint& testPoint, NodeQualifier, Node*& best, Node* failedNode, IntPoint& bestPoint, IntRect& bestRect, const IntRect& testRect); |
311 | bool hitTestResultAtViewportLocation(const FloatPoint& viewportLocation, HitTestResult&, IntPoint& center); |
312 | Node* qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, NodeQualifier, bool shouldApproximate); |
313 | |
314 | void overflowAutoScrollTimerFired(); |
315 | void startOverflowAutoScroll(const IntPoint&); |
316 | int checkOverflowScroll(OverflowScrollAction); |
317 | |
318 | void setTimersPausedInternal(bool); |
319 | |
320 | Timer m_overflowAutoScrollTimer; |
321 | float m_overflowAutoScrollDelta; |
322 | IntPoint m_overflowAutoScrollPos; |
323 | ViewportArguments m_viewportArguments; |
324 | bool m_selectionChangeCallbacksDisabled; |
325 | VisibleSelection m_rangedSelectionBase; |
326 | VisibleSelection m_rangedSelectionInitialExtent; |
327 | #endif |
328 | |
329 | float m_pageZoomFactor; |
330 | float m_textZoomFactor; |
331 | |
332 | int m_activeDOMObjectsAndAnimationsSuspendedCount; |
333 | bool m_mainFrameWasDestroyed { false }; |
334 | bool m_documentIsBeingReplaced { false }; |
335 | |
336 | protected: |
337 | std::unique_ptr<EventHandler> m_eventHandler; |
338 | }; |
339 | |
340 | inline void Frame::init() |
341 | { |
342 | m_loader.init(); |
343 | } |
344 | |
345 | inline FrameLoader& Frame::loader() const |
346 | { |
347 | return m_loader; |
348 | } |
349 | |
350 | inline NavigationScheduler& Frame::navigationScheduler() const |
351 | { |
352 | return m_navigationScheduler; |
353 | } |
354 | |
355 | inline FrameView* Frame::view() const |
356 | { |
357 | return m_view.get(); |
358 | } |
359 | |
360 | inline ScriptController& Frame::script() |
361 | { |
362 | return *m_script; |
363 | } |
364 | |
365 | inline Document* Frame::document() const |
366 | { |
367 | return m_doc.get(); |
368 | } |
369 | |
370 | inline FrameSelection& Frame::selection() const |
371 | { |
372 | return *m_selection; |
373 | } |
374 | |
375 | inline Editor& Frame::editor() const |
376 | { |
377 | return *m_editor; |
378 | } |
379 | |
380 | inline AnimationController& Frame::animation() const |
381 | { |
382 | return *m_animationController; |
383 | } |
384 | |
385 | inline HTMLFrameOwnerElement* Frame::ownerElement() const |
386 | { |
387 | return m_ownerElement; |
388 | } |
389 | |
390 | inline FrameTree& Frame::tree() const |
391 | { |
392 | return m_treeNode; |
393 | } |
394 | |
395 | inline Page* Frame::page() const |
396 | { |
397 | return m_page; |
398 | } |
399 | |
400 | inline void Frame::detachFromPage() |
401 | { |
402 | m_page = nullptr; |
403 | } |
404 | |
405 | inline EventHandler& Frame::eventHandler() const |
406 | { |
407 | return *m_eventHandler; |
408 | } |
409 | |
410 | inline EventHandler* Frame::eventHandlerPtr() const |
411 | { |
412 | return m_eventHandler.get(); |
413 | } |
414 | |
415 | inline MainFrame& Frame::mainFrame() const |
416 | { |
417 | ASSERT_WITH_SECURITY_IMPLICATION(!m_mainFrameWasDestroyed); |
418 | return m_mainFrame; |
419 | } |
420 | |
421 | inline void Frame::setMainFrameWasDestroyed() |
422 | { |
423 | m_mainFrameWasDestroyed = false; |
424 | } |
425 | |
426 | } // namespace WebCore |
427 | |
428 | #endif // Frame_h |
429 | |