Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebViewImpl.h
1 /*
2  * Copyright (C) 2010 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef WebViewImpl_h
32 #define WebViewImpl_h
33
34 #include "core/page/PagePopupDriver.h"
35 #include "platform/geometry/IntPoint.h"
36 #include "platform/geometry/IntRect.h"
37 #include "platform/graphics/GraphicsLayer.h"
38 #include "public/platform/WebGestureCurveTarget.h"
39 #include "public/platform/WebLayer.h"
40 #include "public/platform/WebPoint.h"
41 #include "public/platform/WebRect.h"
42 #include "public/platform/WebSize.h"
43 #include "public/platform/WebString.h"
44 #include "public/web/WebInputEvent.h"
45 #include "public/web/WebNavigationPolicy.h"
46 #include "public/web/WebView.h"
47 #include "web/BackForwardClientImpl.h"
48 #include "web/ChromeClientImpl.h"
49 #include "web/ContextMenuClientImpl.h"
50 #include "web/DragClientImpl.h"
51 #include "web/EditorClientImpl.h"
52 #include "web/InspectorClientImpl.h"
53 #include "web/MediaKeysClientImpl.h"
54 #include "web/PageOverlayList.h"
55 #include "web/PageScaleConstraintsSet.h"
56 #include "web/PageWidgetDelegate.h"
57 #include "web/SpellCheckerClientImpl.h"
58 #include "web/StorageClientImpl.h"
59 #include "wtf/OwnPtr.h"
60 #include "wtf/RefCounted.h"
61 #include "wtf/Vector.h"
62
63 namespace blink {
64
65 class DataObject;
66 class Frame;
67 class FullscreenController;
68 class LinkHighlight;
69 class PopupContainer;
70 class RenderLayerCompositor;
71 class UserGestureToken;
72 class WebActiveGestureAnimation;
73 class WebDevToolsAgentPrivate;
74 class WebLocalFrameImpl;
75 class WebImage;
76 class WebPagePopupImpl;
77 class WebPlugin;
78 class WebSettingsImpl;
79
80 class WebViewImpl FINAL : public WebView
81     , public RefCounted<WebViewImpl>
82     , public WebGestureCurveTarget
83     , public PagePopupDriver
84     , public PageWidgetEventHandler {
85 public:
86     static WebViewImpl* create(WebViewClient*);
87
88     // WebWidget methods:
89     virtual void close() OVERRIDE;
90     virtual WebSize size() OVERRIDE;
91     virtual void willStartLiveResize() OVERRIDE;
92     virtual void resize(const WebSize&) OVERRIDE;
93     virtual void resizePinchViewport(const WebSize&) OVERRIDE;
94     virtual void willEndLiveResize() OVERRIDE;
95     virtual void willEnterFullScreen() OVERRIDE;
96     virtual void didEnterFullScreen() OVERRIDE;
97     virtual void willExitFullScreen() OVERRIDE;
98     virtual void didExitFullScreen() OVERRIDE;
99
100     virtual void beginFrame(const WebBeginFrameArgs&) OVERRIDE;
101
102     virtual void layout() OVERRIDE;
103     virtual void paint(WebCanvas*, const WebRect&) OVERRIDE;
104 #if OS(ANDROID)
105     virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) OVERRIDE;
106 #endif
107     virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) OVERRIDE;
108     virtual bool isTrackingRepaints() const OVERRIDE;
109     virtual void themeChanged() OVERRIDE;
110     virtual bool handleInputEvent(const WebInputEvent&) OVERRIDE;
111     virtual void setCursorVisibilityState(bool isVisible) OVERRIDE;
112     virtual bool hasTouchEventHandlersAt(const WebPoint&) OVERRIDE;
113     virtual void applyScrollAndScale(const WebSize&, float) OVERRIDE;
114     virtual void mouseCaptureLost() OVERRIDE;
115     virtual void setFocus(bool enable) OVERRIDE;
116     virtual bool setComposition(
117         const WebString& text,
118         const WebVector<WebCompositionUnderline>& underlines,
119         int selectionStart,
120         int selectionEnd) OVERRIDE;
121     virtual bool confirmComposition() OVERRIDE;
122     virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) OVERRIDE;
123     virtual bool confirmComposition(const WebString& text) OVERRIDE;
124     virtual bool compositionRange(size_t* location, size_t* length) OVERRIDE;
125     virtual WebTextInputInfo textInputInfo() OVERRIDE;
126     virtual WebColor backgroundColor() const OVERRIDE;
127     virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const OVERRIDE;
128     virtual void didShowCandidateWindow() OVERRIDE;
129     virtual void didUpdateCandidateWindow() OVERRIDE;
130     virtual void didHideCandidateWindow() OVERRIDE;
131     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const OVERRIDE;
132     virtual bool isSelectionAnchorFirst() const OVERRIDE;
133     virtual bool caretOrSelectionRange(size_t* location, size_t* length) OVERRIDE;
134     virtual void setTextDirection(WebTextDirection) OVERRIDE;
135     virtual bool isAcceleratedCompositingActive() const OVERRIDE;
136     virtual void willCloseLayerTreeView() OVERRIDE;
137     virtual void didAcquirePointerLock() OVERRIDE;
138     virtual void didNotAcquirePointerLock() OVERRIDE;
139     virtual void didLosePointerLock() OVERRIDE;
140     virtual void didChangeWindowResizerRect() OVERRIDE;
141
142     // WebView methods:
143     virtual void setMainFrame(WebFrame*) OVERRIDE;
144     virtual void setAutofillClient(WebAutofillClient*) OVERRIDE;
145     virtual void setDevToolsAgentClient(WebDevToolsAgentClient*) OVERRIDE;
146     virtual void setPrerendererClient(WebPrerendererClient*) OVERRIDE;
147     virtual void setSpellCheckClient(WebSpellCheckClient*) OVERRIDE;
148     virtual WebSettings* settings() OVERRIDE;
149     virtual WebString pageEncoding() const OVERRIDE;
150     virtual void setPageEncoding(const WebString&) OVERRIDE;
151     virtual bool isTransparent() const OVERRIDE;
152     virtual void setIsTransparent(bool value) OVERRIDE;
153     virtual void setBaseBackgroundColor(WebColor) OVERRIDE;
154     virtual bool tabsToLinks() const OVERRIDE;
155     virtual void setTabsToLinks(bool value) OVERRIDE;
156     virtual bool tabKeyCyclesThroughElements() const OVERRIDE;
157     virtual void setTabKeyCyclesThroughElements(bool value) OVERRIDE;
158     virtual bool isActive() const OVERRIDE;
159     virtual void setIsActive(bool value) OVERRIDE;
160     virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) OVERRIDE;
161     virtual void setWindowFeatures(const WebWindowFeatures&) OVERRIDE;
162     virtual void setOpenedByDOM() OVERRIDE;
163     virtual WebFrame* mainFrame() OVERRIDE;
164     virtual WebFrame* findFrameByName(
165         const WebString& name, WebFrame* relativeToFrame) OVERRIDE;
166     virtual WebFrame* focusedFrame() OVERRIDE;
167     virtual void setFocusedFrame(WebFrame*) OVERRIDE;
168     virtual void setInitialFocus(bool reverse) OVERRIDE;
169     virtual void clearFocusedElement() OVERRIDE;
170     virtual void scrollFocusedNodeIntoRect(const WebRect&) OVERRIDE;
171     virtual void zoomToFindInPageRect(const WebRect&) OVERRIDE;
172     virtual void advanceFocus(bool reverse) OVERRIDE;
173     virtual double zoomLevel() OVERRIDE;
174     virtual double setZoomLevel(double) OVERRIDE;
175     virtual void zoomLimitsChanged(double minimumZoomLevel, double maximumZoomLevel) OVERRIDE;
176     virtual float textZoomFactor() OVERRIDE;
177     virtual float setTextZoomFactor(float) OVERRIDE;
178     virtual void setInitialPageScaleOverride(float) OVERRIDE;
179     virtual bool zoomToMultipleTargetsRect(const WebRect&) OVERRIDE;
180     virtual float pageScaleFactor() const OVERRIDE;
181     virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale) OVERRIDE;
182     virtual void setMainFrameScrollOffset(const WebPoint&) OVERRIDE;
183     virtual void setPageScaleFactor(float) OVERRIDE;
184     virtual void setPinchViewportOffset(const WebFloatPoint&) OVERRIDE;
185     virtual WebFloatPoint pinchViewportOffset() const OVERRIDE;
186     virtual float minimumPageScaleFactor() const OVERRIDE;
187     virtual float maximumPageScaleFactor() const OVERRIDE;
188     virtual void resetScrollAndScaleState() OVERRIDE;
189     virtual void setIgnoreViewportTagScaleLimits(bool) OVERRIDE;
190     virtual WebSize contentsPreferredMinimumSize() OVERRIDE;
191
192     virtual float deviceScaleFactor() const OVERRIDE;
193     virtual void setDeviceScaleFactor(float) OVERRIDE;
194
195     virtual void setFixedLayoutSize(const WebSize&) OVERRIDE;
196
197     virtual void enableAutoResizeMode(
198         const WebSize& minSize,
199         const WebSize& maxSize) OVERRIDE;
200     virtual void disableAutoResizeMode() OVERRIDE;
201     virtual void performMediaPlayerAction(
202         const WebMediaPlayerAction& action,
203         const WebPoint& location) OVERRIDE;
204     virtual void performPluginAction(
205         const WebPluginAction&,
206         const WebPoint&) OVERRIDE;
207     virtual WebHitTestResult hitTestResultAt(const WebPoint&) OVERRIDE;
208     virtual void copyImageAt(const WebPoint&) OVERRIDE;
209     virtual void saveImageAt(const WebPoint&) OVERRIDE;
210     virtual void dragSourceEndedAt(
211         const WebPoint& clientPoint,
212         const WebPoint& screenPoint,
213         WebDragOperation) OVERRIDE;
214     virtual void dragSourceSystemDragEnded() OVERRIDE;
215     virtual WebDragOperation dragTargetDragEnter(
216         const WebDragData&,
217         const WebPoint& clientPoint,
218         const WebPoint& screenPoint,
219         WebDragOperationsMask operationsAllowed,
220         int keyModifiers) OVERRIDE;
221     virtual WebDragOperation dragTargetDragOver(
222         const WebPoint& clientPoint,
223         const WebPoint& screenPoint,
224         WebDragOperationsMask operationsAllowed,
225         int keyModifiers) OVERRIDE;
226     virtual void dragTargetDragLeave() OVERRIDE;
227     virtual void dragTargetDrop(
228         const WebPoint& clientPoint,
229         const WebPoint& screenPoint,
230         int keyModifiers) OVERRIDE;
231     virtual void spellingMarkers(WebVector<uint32_t>* markers) OVERRIDE;
232     virtual unsigned long createUniqueIdentifierForRequest() OVERRIDE;
233     virtual void inspectElementAt(const WebPoint&) OVERRIDE;
234     virtual void setCompositorDeviceScaleFactorOverride(float) OVERRIDE;
235     virtual void setRootLayerTransform(const WebSize& offset, float scale) OVERRIDE;
236     virtual WebDevToolsAgent* devToolsAgent() OVERRIDE;
237     virtual WebAXObject accessibilityObject() OVERRIDE;
238     virtual void setSelectionColors(unsigned activeBackgroundColor,
239                                     unsigned activeForegroundColor,
240                                     unsigned inactiveBackgroundColor,
241                                     unsigned inactiveForegroundColor) OVERRIDE;
242     virtual void performCustomContextMenuAction(unsigned action) OVERRIDE;
243     virtual void showContextMenu() OVERRIDE;
244     virtual void extractSmartClipData(WebRect, WebString&, WebString&, WebRect&) OVERRIDE;
245     virtual void hidePopups() OVERRIDE;
246     virtual void addPageOverlay(WebPageOverlay*, int /* zOrder */) OVERRIDE;
247     virtual void removePageOverlay(WebPageOverlay*) OVERRIDE;
248     virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) OVERRIDE;
249     virtual bool endActiveFlingAnimation() OVERRIDE;
250     virtual void setShowPaintRects(bool) OVERRIDE;
251     void setShowDebugBorders(bool);
252     virtual void setShowFPSCounter(bool) OVERRIDE;
253     virtual void setContinuousPaintingEnabled(bool) OVERRIDE;
254     virtual void setShowScrollBottleneckRects(bool) OVERRIDE;
255     virtual void getSelectionRootBounds(WebRect& bounds) const OVERRIDE;
256     virtual void acceptLanguagesChanged() OVERRIDE;
257
258     // WebViewImpl
259
260     HitTestResult coreHitTestResultAt(const WebPoint&);
261     void suppressInvalidations(bool enable);
262     void invalidateRect(const IntRect&);
263
264     void setIgnoreInputEvents(bool newValue);
265     void setBackgroundColorOverride(WebColor);
266     void setZoomFactorOverride(float);
267     WebDevToolsAgentPrivate* devToolsAgentPrivate() { return m_devToolsAgent.get(); }
268
269     Color baseBackgroundColor() const { return m_baseBackgroundColor; }
270
271     PageOverlayList* pageOverlays() const { return m_pageOverlays.get(); }
272
273     void setOverlayLayer(GraphicsLayer*);
274
275     const WebPoint& lastMouseDownPoint() const
276     {
277         return m_lastMouseDownPoint;
278     }
279
280     Frame* focusedCoreFrame() const;
281
282     // Returns the currently focused Element or null if no element has focus.
283     Element* focusedElement() const;
284
285     static WebViewImpl* fromPage(Page*);
286
287     WebViewClient* client()
288     {
289         return m_client;
290     }
291
292     WebAutofillClient* autofillClient()
293     {
294         return m_autofillClient;
295     }
296
297     WebSpellCheckClient* spellCheckClient()
298     {
299         return m_spellCheckClient;
300     }
301
302     // Returns the page object associated with this view. This may be null when
303     // the page is shutting down, but will be valid at all other times.
304     Page* page() const
305     {
306         return m_page.get();
307     }
308
309     // Returns the main frame associated with this view. This may be null when
310     // the page is shutting down, but will be valid at all other times.
311     WebLocalFrameImpl* mainFrameImpl();
312
313     // FIXME: Temporary method to accommodate out-of-process frame ancestors;
314     // will be removed when there can be multiple WebWidgets for a single page.
315     WebLocalFrameImpl* localFrameRootTemporary() const;
316
317     // Event related methods:
318     void mouseContextMenu(const WebMouseEvent&);
319     void mouseDoubleClick(const WebMouseEvent&);
320
321     bool detectContentOnTouch(const WebPoint&);
322     bool startPageScaleAnimation(const IntPoint& targetPosition, bool useAnchor, float newScale, double durationInSeconds);
323
324     void hasTouchEventHandlers(bool);
325
326     // WebGestureCurveTarget implementation for fling.
327     virtual bool scrollBy(const WebFloatSize& delta, const WebFloatSize& velocity) OVERRIDE;
328
329     // Handles context menu events orignated via the the keyboard. These
330     // include the VK_APPS virtual key and the Shift+F10 combine. Code is
331     // based on the Webkit function bool WebView::handleContextMenuEvent(WPARAM
332     // wParam, LPARAM lParam) in webkit\webkit\win\WebView.cpp. The only
333     // significant change in this function is the code to convert from a
334     // Keyboard event to the Right Mouse button down event.
335     bool sendContextMenuEvent(const WebKeyboardEvent&);
336
337     void showContextMenuAtPoint(float x, float y, PassRefPtr<ContextMenuProvider>);
338
339     // Notifies the WebView that a load has been committed. isNewNavigation
340     // will be true if a new session history item should be created for that
341     // load. isNavigationWithinPage will be true if the navigation does
342     // not take the user away from the current page.
343     void didCommitLoad(bool isNewNavigation, bool isNavigationWithinPage);
344
345     // Indicates two things:
346     //   1) This view may have a new layout now.
347     //   2) Calling layout() is a no-op.
348     // After calling WebWidget::layout(), expect to get this notification
349     // unless the view did not need a layout.
350     void layoutUpdated(WebLocalFrameImpl*);
351
352     void willInsertBody(WebLocalFrameImpl*);
353     void didRemoveAllPendingStylesheet(WebLocalFrameImpl*);
354     void didChangeContentsSize();
355     void deviceOrPageScaleFactorChanged();
356
357     // Returns true if popup menus should be rendered by the browser, false if
358     // they should be rendered by WebKit (which is the default).
359     static bool useExternalPopupMenus();
360
361     bool contextMenuAllowed() const
362     {
363         return m_contextMenuAllowed;
364     }
365
366     bool shouldAutoResize() const
367     {
368         return m_shouldAutoResize;
369     }
370
371     IntSize minAutoSize() const
372     {
373         return m_minAutoSize;
374     }
375
376     IntSize maxAutoSize() const
377     {
378         return m_maxAutoSize;
379     }
380
381     void updateMainFrameLayoutSize();
382     void updatePageDefinedViewportConstraints(const ViewportDescription&);
383
384     // Start a system drag and drop operation.
385     void startDragging(
386         LocalFrame*,
387         const WebDragData& dragData,
388         WebDragOperationsMask mask,
389         const WebImage& dragImage,
390         const WebPoint& dragImageOffset);
391
392     // Notification that a popup was opened/closed.
393     void popupOpened(PopupContainer*);
394     void popupClosed(PopupContainer*);
395     // PagePopupDriver functions.
396     virtual PagePopup* openPagePopup(PagePopupClient*, const IntRect& originBoundsInRootView) OVERRIDE;
397     virtual void closePagePopup(PagePopup*) OVERRIDE;
398
399     // Returns the input event we're currently processing. This is used in some
400     // cases where the WebCore DOM event doesn't have the information we need.
401     static const WebInputEvent* currentInputEvent()
402     {
403         return m_currentInputEvent;
404     }
405
406     GraphicsLayer* rootGraphicsLayer();
407     void setRootGraphicsLayer(GraphicsLayer*);
408     void scheduleCompositingLayerSync();
409     void scrollRootLayer();
410     GraphicsLayerFactory* graphicsLayerFactory() const;
411     RenderLayerCompositor* compositor() const;
412     void registerForAnimations(WebLayer*);
413     void scheduleAnimation();
414
415     virtual void setVisibilityState(WebPageVisibilityState, bool) OVERRIDE;
416
417     PopupContainer* selectPopup() const { return m_selectPopup.get(); }
418     bool hasOpenedPopup() const { return m_selectPopup || m_pagePopup; }
419
420     // Returns true if the event leads to scrolling.
421     static bool mapKeyCodeForScroll(
422         int keyCode,
423         ScrollDirection*,
424         ScrollGranularity*);
425
426     // Called by a full frame plugin inside this view to inform it that its
427     // zoom level has been updated.  The plugin should only call this function
428     // if the zoom change was triggered by the browser, it's only needed in case
429     // a plugin can update its own zoom, say because of its own UI.
430     void fullFramePluginZoomLevelChanged(double zoomLevel);
431
432     void computeScaleAndScrollForBlockRect(const WebPoint& hitPoint, const WebRect& blockRect, float padding, float defaultScaleWhenAlreadyLegible, float& scale, WebPoint& scroll);
433     Node* bestTapNode(const PlatformGestureEvent& tapEvent);
434     void enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent);
435     void enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >&);
436     void computeScaleAndScrollForFocusedNode(Node* focusedNode, float& scale, IntPoint& scroll, bool& needAnimation);
437
438     void animateDoubleTapZoom(const IntPoint&);
439
440     void enableFakePageScaleAnimationForTesting(bool);
441     bool fakeDoubleTapAnimationPendingForTesting() const { return m_doubleTapZoomPending; }
442     IntPoint fakePageScaleAnimationTargetPositionForTesting() const { return m_fakePageScaleAnimationTargetPosition; }
443     float fakePageScaleAnimationPageScaleForTesting() const { return m_fakePageScaleAnimationPageScaleFactor; }
444     bool fakePageScaleAnimationUseAnchorForTesting() const { return m_fakePageScaleAnimationUseAnchor; }
445
446     void enterFullScreenForElement(Element*);
447     void exitFullScreenForElement(Element*);
448
449     void clearCompositedSelectionBounds();
450
451     // Exposed for the purpose of overriding device metrics.
452     void sendResizeEventAndRepaint();
453
454     // Exposed for testing purposes.
455     bool hasHorizontalScrollbar();
456     bool hasVerticalScrollbar();
457
458     // Pointer Lock calls allow a page to capture all mouse events and
459     // disable the system cursor.
460     bool requestPointerLock();
461     void requestPointerUnlock();
462     bool isPointerLocked();
463
464     // Heuristic-based function for determining if we should disable workarounds
465     // for viewing websites that are not optimized for mobile devices.
466     bool shouldDisableDesktopWorkarounds();
467
468     // Exposed for tests.
469     unsigned numLinkHighlights() { return m_linkHighlights.size(); }
470     LinkHighlight* linkHighlight(int i) { return m_linkHighlights[i].get(); }
471
472     WebSettingsImpl* settingsImpl();
473
474     // Returns the bounding box of the block type node touched by the WebRect.
475     WebRect computeBlockBounds(const WebRect&, bool ignoreClipping);
476
477     IntPoint clampOffsetAtScale(const IntPoint& offset, float scale);
478
479     // Exposed for tests.
480     WebVector<WebCompositionUnderline> compositionUnderlines() const;
481
482     WebLayerTreeView* layerTreeView() const { return m_layerTreeView; }
483
484     bool pinchVirtualViewportEnabled() const;
485
486     bool matchesHeuristicsForGpuRasterizationForTesting() const { return m_matchesHeuristicsForGpuRasterization; }
487
488 private:
489     // TODO(bokan): Remains for legacy pinch. Remove once it's gone. Made private to
490     // prevent external usage
491     virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) OVERRIDE;
492
493     float legibleScale() const;
494     void refreshPageScaleFactorAfterLayout();
495     void resumeTreeViewCommits();
496     void setUserAgentPageScaleConstraints(PageScaleConstraints newConstraints);
497     float clampPageScaleFactorToLimits(float) const;
498     IntSize contentsSize() const;
499
500     void resetSavedScrollAndScaleState();
501
502     void updateMainFrameScrollPosition(const IntPoint& scrollPosition, bool programmaticScroll);
503
504     void performResize();
505
506     friend class WebView;  // So WebView::Create can call our constructor
507     friend class WTF::RefCounted<WebViewImpl>;
508     friend void setCurrentInputEventForTest(const WebInputEvent*);
509
510     enum DragAction {
511       DragEnter,
512       DragOver
513     };
514
515     explicit WebViewImpl(WebViewClient*);
516     virtual ~WebViewImpl();
517
518     WebTextInputType textInputType();
519     int textInputFlags();
520
521     WebString inputModeOfFocusedElement();
522
523     // Returns true if the event was actually processed.
524     bool keyEventDefault(const WebKeyboardEvent&);
525
526     bool confirmComposition(const WebString& text, ConfirmCompositionBehavior);
527
528     // Returns true if the view was scrolled.
529     bool scrollViewWithKeyboard(int keyCode, int modifiers);
530
531     void hideSelectPopup();
532
533     // Converts |pos| from window coordinates to contents coordinates and gets
534     // the HitTestResult for it.
535     HitTestResult hitTestResultForWindowPos(const IntPoint&);
536
537     // Consolidate some common code between starting a drag over a target and
538     // updating a drag over a target. If we're starting a drag, |isEntering|
539     // should be true.
540     WebDragOperation dragTargetDragEnterOrOver(const WebPoint& clientPoint,
541                                                const WebPoint& screenPoint,
542                                                DragAction,
543                                                int keyModifiers);
544
545     void configureAutoResizeMode();
546
547     void initializeLayerTreeView();
548
549     void setIsAcceleratedCompositingActive(bool);
550     void doComposite();
551     void reallocateRenderer();
552     void updateLayerTreeViewport();
553     void updateLayerTreeBackgroundColor();
554     void updateRootLayerTransform();
555     void updateLayerTreeDeviceScaleFactor();
556
557     // Helper function: Widens the width of |source| by the specified margins
558     // while keeping it smaller than page width.
559     WebRect widenRectWithinPageBounds(const WebRect& source, int targetMargin, int minimumMargin);
560
561     void pointerLockMouseEvent(const WebInputEvent&);
562
563     // PageWidgetEventHandler functions
564     virtual void handleMouseLeave(LocalFrame&, const WebMouseEvent&) OVERRIDE;
565     virtual void handleMouseDown(LocalFrame&, const WebMouseEvent&) OVERRIDE;
566     virtual void handleMouseUp(LocalFrame&, const WebMouseEvent&) OVERRIDE;
567     virtual bool handleMouseWheel(LocalFrame&, const WebMouseWheelEvent&) OVERRIDE;
568     virtual bool handleGestureEvent(const WebGestureEvent&) OVERRIDE;
569     virtual bool handleKeyEvent(const WebKeyboardEvent&) OVERRIDE;
570     virtual bool handleCharEvent(const WebKeyboardEvent&) OVERRIDE;
571
572     InputMethodContext* inputMethodContext();
573     WebPlugin* focusedPluginIfInputMethodSupported(LocalFrame*);
574
575     WebViewClient* m_client; // Can be 0 (e.g. unittests, shared workers, etc.)
576     WebAutofillClient* m_autofillClient;
577     WebSpellCheckClient* m_spellCheckClient;
578
579     ChromeClientImpl m_chromeClientImpl;
580     ContextMenuClientImpl m_contextMenuClientImpl;
581     DragClientImpl m_dragClientImpl;
582     EditorClientImpl m_editorClientImpl;
583     InspectorClientImpl m_inspectorClientImpl;
584     BackForwardClientImpl m_backForwardClientImpl;
585     SpellCheckerClientImpl m_spellCheckerClientImpl;
586     StorageClientImpl m_storageClientImpl;
587
588     WebSize m_size;
589     bool m_fixedLayoutSizeLock;
590     // If true, automatically resize the render view around its content.
591     bool m_shouldAutoResize;
592     // The lower bound on the size when auto-resizing.
593     IntSize m_minAutoSize;
594     // The upper bound on the size when auto-resizing.
595     IntSize m_maxAutoSize;
596
597     OwnPtrWillBePersistent<Page> m_page;
598
599     // An object that can be used to manipulate m_page->settings() without linking
600     // against WebCore. This is lazily allocated the first time GetWebSettings()
601     // is called.
602     OwnPtr<WebSettingsImpl> m_webSettings;
603
604     // A copy of the web drop data object we received from the browser.
605     RefPtrWillBePersistent<DataObject> m_currentDragData;
606
607     // The point relative to the client area where the mouse was last pressed
608     // down. This is used by the drag client to determine what was under the
609     // mouse when the drag was initiated. We need to track this here in
610     // WebViewImpl since DragClient::startDrag does not pass the position the
611     // mouse was at when the drag was initiated, only the current point, which
612     // can be misleading as it is usually not over the element the user actually
613     // dragged by the time a drag is initiated.
614     WebPoint m_lastMouseDownPoint;
615
616     // Keeps track of the current zoom level. 0 means no zoom, positive numbers
617     // mean zoom in, negative numbers mean zoom out.
618     double m_zoomLevel;
619
620     double m_minimumZoomLevel;
621
622     double m_maximumZoomLevel;
623
624     PageScaleConstraintsSet m_pageScaleConstraintsSet;
625
626     // The scale moved to by the latest double tap zoom, if any.
627     float m_doubleTapZoomPageScaleFactor;
628     // Have we sent a double-tap zoom and not yet heard back the scale?
629     bool m_doubleTapZoomPending;
630
631     // Used for testing purposes.
632     bool m_enableFakePageScaleAnimationForTesting;
633     IntPoint m_fakePageScaleAnimationTargetPosition;
634     float m_fakePageScaleAnimationPageScaleFactor;
635     bool m_fakePageScaleAnimationUseAnchor;
636
637     bool m_contextMenuAllowed;
638
639     bool m_doingDragAndDrop;
640
641     bool m_ignoreInputEvents;
642
643     float m_compositorDeviceScaleFactorOverride;
644     WebSize m_rootLayerOffset;
645     float m_rootLayerScale;
646
647     // Webkit expects keyPress events to be suppressed if the associated keyDown
648     // event was handled. Safari implements this behavior by peeking out the
649     // associated WM_CHAR event if the keydown was handled. We emulate
650     // this behavior by setting this flag if the keyDown was handled.
651     bool m_suppressNextKeypressEvent;
652
653     // Represents whether or not this object should process incoming IME events.
654     bool m_imeAcceptEvents;
655
656     // The available drag operations (copy, move link...) allowed by the source.
657     WebDragOperation m_operationsAllowed;
658
659     // The current drag operation as negotiated by the source and destination.
660     // When not equal to DragOperationNone, the drag data can be dropped onto the
661     // current drop target in this WebView (the drop target can accept the drop).
662     WebDragOperation m_dragOperation;
663
664     // The popup associated with a select element.
665     RefPtr<PopupContainer> m_selectPopup;
666
667     // The popup associated with an input element.
668     RefPtr<WebPagePopupImpl> m_pagePopup;
669
670     OwnPtr<WebDevToolsAgentPrivate> m_devToolsAgent;
671     OwnPtr<PageOverlayList> m_pageOverlays;
672
673     // Whether the webview is rendering transparently.
674     bool m_isTransparent;
675
676     // Whether the user can press tab to focus links.
677     bool m_tabsToLinks;
678
679     // If set, the (plugin) node which has mouse capture.
680     RefPtrWillBePersistent<Node> m_mouseCaptureNode;
681     RefPtr<UserGestureToken> m_mouseCaptureGestureToken;
682
683     IntRect m_rootLayerScrollDamage;
684     WebLayerTreeView* m_layerTreeView;
685     WebLayer* m_rootLayer;
686     GraphicsLayer* m_rootGraphicsLayer;
687     GraphicsLayer* m_rootTransformLayer;
688     OwnPtr<GraphicsLayerFactory> m_graphicsLayerFactory;
689     bool m_isAcceleratedCompositingActive;
690     bool m_layerTreeViewCommitsDeferred;
691     bool m_layerTreeViewClosed;
692     bool m_matchesHeuristicsForGpuRasterization;
693     // If true, the graphics context is being restored.
694     bool m_recreatingGraphicsContext;
695     static const WebInputEvent* m_currentInputEvent;
696
697     MediaKeysClientImpl m_mediaKeysClientImpl;
698     OwnPtr<WebActiveGestureAnimation> m_gestureAnimation;
699     WebPoint m_positionOnFlingStart;
700     WebPoint m_globalPositionOnFlingStart;
701     int m_flingModifier;
702     bool m_flingSourceDevice;
703     Vector<OwnPtr<LinkHighlight> > m_linkHighlights;
704     OwnPtr<FullscreenController> m_fullscreenController;
705
706     bool m_showFPSCounter;
707     bool m_showPaintRects;
708     bool m_showDebugBorders;
709     bool m_continuousPaintingEnabled;
710     bool m_showScrollBottleneckRects;
711     WebColor m_baseBackgroundColor;
712     WebColor m_backgroundColorOverride;
713     float m_zoomFactorOverride;
714
715     bool m_userGestureObserved;
716 };
717
718 // We have no ways to check if the specified WebView is an instance of
719 // WebViewImpl because WebViewImpl is the only implementation of WebView.
720 DEFINE_TYPE_CASTS(WebViewImpl, WebView, webView, true, true);
721
722 } // namespace blink
723
724 #endif