Upstream version 9.37.197.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 WebCore {
64 class DataObject;
65 class Frame;
66 class RenderLayerCompositor;
67 class UserGestureToken;
68 }
69
70 namespace blink {
71 class LinkHighlight;
72 class PopupContainer;
73 class WebActiveGestureAnimation;
74 class WebDevToolsAgentPrivate;
75 class WebLocalFrameImpl;
76 class WebImage;
77 class WebPagePopupImpl;
78 class WebPlugin;
79 class WebSettingsImpl;
80 class FullscreenController;
81
82 class WebViewImpl FINAL : public WebView
83     , public RefCounted<WebViewImpl>
84     , public WebGestureCurveTarget
85     , public WebCore::PagePopupDriver
86     , public PageWidgetEventHandler {
87 public:
88     static WebViewImpl* create(WebViewClient*);
89
90     // WebWidget methods:
91     virtual void close() OVERRIDE;
92     virtual WebSize size() OVERRIDE;
93     virtual void willStartLiveResize() OVERRIDE;
94     virtual void resize(const WebSize&) OVERRIDE;
95     virtual void resizePinchViewport(const WebSize&) OVERRIDE;
96     virtual void willEndLiveResize() OVERRIDE;
97     virtual void willEnterFullScreen() OVERRIDE;
98     virtual void didEnterFullScreen() OVERRIDE;
99     virtual void willExitFullScreen() OVERRIDE;
100     virtual void didExitFullScreen() OVERRIDE;
101     virtual void animate(double) OVERRIDE;
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 WebString inspectorSettings() const OVERRIDE;
235     virtual void setInspectorSettings(const WebString&) OVERRIDE;
236     virtual bool inspectorSetting(const WebString& key, WebString* value) const OVERRIDE;
237     virtual void setInspectorSetting(const WebString& key, const WebString& value) OVERRIDE;
238     virtual void setCompositorDeviceScaleFactorOverride(float) OVERRIDE;
239     virtual void setRootLayerTransform(const WebSize& offset, float scale) OVERRIDE;
240     virtual WebDevToolsAgent* devToolsAgent() OVERRIDE;
241     virtual WebAXObject accessibilityObject() OVERRIDE;
242     virtual void setSelectionColors(unsigned activeBackgroundColor,
243                                     unsigned activeForegroundColor,
244                                     unsigned inactiveBackgroundColor,
245                                     unsigned inactiveForegroundColor) OVERRIDE;
246     virtual void performCustomContextMenuAction(unsigned action) OVERRIDE;
247     virtual void showContextMenu() OVERRIDE;
248     // FIXME: This should be removed when the chromium side patch lands
249     // http://codereview.chromium.org/260623004
250     virtual WebString getSmartClipData(WebRect) OVERRIDE;
251     virtual void getSmartClipData(WebRect, WebString&, WebRect&) OVERRIDE;
252     virtual void extractSmartClipData(WebRect, WebString&, WebString&, WebRect&) OVERRIDE;
253     virtual void hidePopups() OVERRIDE;
254     virtual void addPageOverlay(WebPageOverlay*, int /* zOrder */) OVERRIDE;
255     virtual void removePageOverlay(WebPageOverlay*) OVERRIDE;
256     virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) OVERRIDE;
257     virtual bool endActiveFlingAnimation() OVERRIDE;
258     virtual void setShowPaintRects(bool) OVERRIDE;
259     void setShowDebugBorders(bool);
260     virtual void setShowFPSCounter(bool) OVERRIDE;
261     virtual void setContinuousPaintingEnabled(bool) OVERRIDE;
262     virtual void setShowScrollBottleneckRects(bool) OVERRIDE;
263     virtual void getSelectionRootBounds(WebRect& bounds) const OVERRIDE;
264     virtual void acceptLanguagesChanged() OVERRIDE;
265
266     // WebViewImpl
267
268     void suppressInvalidations(bool enable);
269     void invalidateRect(const WebCore::IntRect&);
270
271     void setIgnoreInputEvents(bool newValue);
272     void setBackgroundColorOverride(WebColor);
273     void setZoomFactorOverride(float);
274     WebDevToolsAgentPrivate* devToolsAgentPrivate() { return m_devToolsAgent.get(); }
275
276     WebCore::Color baseBackgroundColor() const { return m_baseBackgroundColor; }
277
278     PageOverlayList* pageOverlays() const { return m_pageOverlays.get(); }
279
280     void setOverlayLayer(WebCore::GraphicsLayer*);
281
282     const WebPoint& lastMouseDownPoint() const
283     {
284         return m_lastMouseDownPoint;
285     }
286
287     WebCore::Frame* focusedWebCoreFrame() const;
288
289     // Returns the currently focused Element or null if no element has focus.
290     WebCore::Element* focusedElement() const;
291
292     static WebViewImpl* fromPage(WebCore::Page*);
293
294     WebViewClient* client()
295     {
296         return m_client;
297     }
298
299     WebAutofillClient* autofillClient()
300     {
301         return m_autofillClient;
302     }
303
304     WebSpellCheckClient* spellCheckClient()
305     {
306         return m_spellCheckClient;
307     }
308
309     // Returns the page object associated with this view. This may be null when
310     // the page is shutting down, but will be valid at all other times.
311     WebCore::Page* page() const
312     {
313         return m_page.get();
314     }
315
316     // Returns the main frame associated with this view. This may be null when
317     // the page is shutting down, but will be valid at all other times.
318     WebLocalFrameImpl* mainFrameImpl();
319
320     // Event related methods:
321     void mouseContextMenu(const WebMouseEvent&);
322     void mouseDoubleClick(const WebMouseEvent&);
323
324     bool detectContentOnTouch(const WebPoint&);
325     bool startPageScaleAnimation(const WebCore::IntPoint& targetPosition, bool useAnchor, float newScale, double durationInSeconds);
326
327     void hasTouchEventHandlers(bool);
328
329     // WebGestureCurveTarget implementation for fling.
330     virtual bool scrollBy(const WebFloatSize& delta, const WebFloatSize& velocity) OVERRIDE;
331
332     // Handles context menu events orignated via the the keyboard. These
333     // include the VK_APPS virtual key and the Shift+F10 combine. Code is
334     // based on the Webkit function bool WebView::handleContextMenuEvent(WPARAM
335     // wParam, LPARAM lParam) in webkit\webkit\win\WebView.cpp. The only
336     // significant change in this function is the code to convert from a
337     // Keyboard event to the Right Mouse button down event.
338     bool sendContextMenuEvent(const WebKeyboardEvent&);
339
340     // Notifies the WebView that a load has been committed. isNewNavigation
341     // will be true if a new session history item should be created for that
342     // load. isNavigationWithinPage will be true if the navigation does
343     // not take the user away from the current page.
344     void didCommitLoad(bool isNewNavigation, bool isNavigationWithinPage);
345
346     // Indicates two things:
347     //   1) This view may have a new layout now.
348     //   2) Calling layout() is a no-op.
349     // After calling WebWidget::layout(), expect to get this notification
350     // unless the view did not need a layout.
351     void layoutUpdated(WebLocalFrameImpl*);
352
353     void willInsertBody(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     WebCore::IntSize minAutoSize() const
372     {
373         return m_minAutoSize;
374     }
375
376     WebCore::IntSize maxAutoSize() const
377     {
378         return m_maxAutoSize;
379     }
380
381     void updateMainFrameLayoutSize();
382     void updatePageDefinedViewportConstraints(const WebCore::ViewportDescription&);
383
384     // Start a system drag and drop operation.
385     void startDragging(
386         WebCore::LocalFrame*,
387         const WebDragData& dragData,
388         WebDragOperationsMask mask,
389         const WebImage& dragImage,
390         const WebPoint& dragImageOffset);
391
392     // Tries to scroll the currently focused element and bubbles up through the
393     // DOM and frame hierarchies. Returns true if something was scrolled.
394     bool bubblingScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity);
395
396     // Notification that a popup was opened/closed.
397     void popupOpened(PopupContainer*);
398     void popupClosed(PopupContainer*);
399     // PagePopupDriver functions.
400     virtual WebCore::PagePopup* openPagePopup(WebCore::PagePopupClient*, const WebCore::IntRect& originBoundsInRootView) OVERRIDE;
401     virtual void closePagePopup(WebCore::PagePopup*) OVERRIDE;
402
403     // Returns the input event we're currently processing. This is used in some
404     // cases where the WebCore DOM event doesn't have the information we need.
405     static const WebInputEvent* currentInputEvent()
406     {
407         return m_currentInputEvent;
408     }
409
410     WebCore::GraphicsLayer* rootGraphicsLayer();
411     void setRootGraphicsLayer(WebCore::GraphicsLayer*);
412     void scheduleCompositingLayerSync();
413     void scrollRootLayer();
414     WebCore::GraphicsLayerFactory* graphicsLayerFactory() const;
415     WebCore::RenderLayerCompositor* compositor() const;
416     void registerForAnimations(WebLayer*);
417     void scheduleAnimation();
418
419     virtual void setVisibilityState(WebPageVisibilityState, bool) OVERRIDE;
420
421     PopupContainer* selectPopup() const { return m_selectPopup.get(); }
422     bool hasOpenedPopup() const { return m_selectPopup || m_pagePopup; }
423
424     // Returns true if the event leads to scrolling.
425     static bool mapKeyCodeForScroll(int keyCode,
426                                    WebCore::ScrollDirection* scrollDirection,
427                                    WebCore::ScrollGranularity* scrollGranularity);
428
429     // Called by a full frame plugin inside this view to inform it that its
430     // zoom level has been updated.  The plugin should only call this function
431     // if the zoom change was triggered by the browser, it's only needed in case
432     // a plugin can update its own zoom, say because of its own UI.
433     void fullFramePluginZoomLevelChanged(double zoomLevel);
434
435     void computeScaleAndScrollForBlockRect(const WebPoint& hitPoint, const WebRect& blockRect, float padding, float defaultScaleWhenAlreadyLegible, float& scale, WebPoint& scroll);
436     WebCore::Node* bestTapNode(const WebCore::PlatformGestureEvent& tapEvent);
437     void enableTapHighlightAtPoint(const WebCore::PlatformGestureEvent& tapEvent);
438     void enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<WebCore::Node> >&);
439     void computeScaleAndScrollForFocusedNode(WebCore::Node* focusedNode, float& scale, WebCore::IntPoint& scroll, bool& needAnimation);
440
441     void animateDoubleTapZoom(const WebCore::IntPoint&);
442
443     void enableFakePageScaleAnimationForTesting(bool);
444     bool fakeDoubleTapAnimationPendingForTesting() const { return m_doubleTapZoomPending; }
445     WebCore::IntPoint fakePageScaleAnimationTargetPositionForTesting() const { return m_fakePageScaleAnimationTargetPosition; }
446     float fakePageScaleAnimationPageScaleForTesting() const { return m_fakePageScaleAnimationPageScaleFactor; }
447     bool fakePageScaleAnimationUseAnchorForTesting() const { return m_fakePageScaleAnimationUseAnchor; }
448
449     void enterFullScreenForElement(WebCore::Element*);
450     void exitFullScreenForElement(WebCore::Element*);
451
452     // Exposed for the purpose of overriding device metrics.
453     void sendResizeEventAndRepaint();
454
455     // Exposed for testing purposes.
456     bool hasHorizontalScrollbar();
457     bool hasVerticalScrollbar();
458
459     // Pointer Lock calls allow a page to capture all mouse events and
460     // disable the system cursor.
461     bool requestPointerLock();
462     void requestPointerUnlock();
463     bool isPointerLocked();
464
465     // Heuristic-based function for determining if we should disable workarounds
466     // for viewing websites that are not optimized for mobile devices.
467     bool shouldDisableDesktopWorkarounds();
468
469     // Exposed for tests.
470     unsigned numLinkHighlights() { return m_linkHighlights.size(); }
471     LinkHighlight* linkHighlight(int i) { return m_linkHighlights[i].get(); }
472
473     WebSettingsImpl* settingsImpl();
474
475     // Returns the bounding box of the block type node touched by the WebRect.
476     WebRect computeBlockBounds(const WebRect&, bool ignoreClipping);
477
478     WebCore::IntPoint clampOffsetAtScale(const WebCore::IntPoint& offset, float scale);
479
480     // Exposed for tests.
481     WebVector<WebCompositionUnderline> compositionUnderlines() const;
482
483     WebLayerTreeView* layerTreeView() const { return m_layerTreeView; }
484
485     bool pinchVirtualViewportEnabled() const;
486
487     bool matchesHeuristicsForGpuRasterizationForTesting() const { return m_matchesHeuristicsForGpuRasterization; }
488
489 private:
490     // TODO(bokan): Remains for legacy pinch. Remove once it's gone. Made private to
491     // prevent external usage
492     virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) OVERRIDE;
493
494     float legibleScale() const;
495     void refreshPageScaleFactorAfterLayout();
496     void resumeTreeViewCommits();
497     void setUserAgentPageScaleConstraints(WebCore::PageScaleConstraints newConstraints);
498     float clampPageScaleFactorToLimits(float) const;
499     WebCore::IntSize contentsSize() const;
500
501     void resetSavedScrollAndScaleState();
502
503     void updateMainFrameScrollPosition(const WebCore::IntPoint& scrollPosition, bool programmaticScroll);
504
505     friend class WebView;  // So WebView::Create can call our constructor
506     friend class WTF::RefCounted<WebViewImpl>;
507     friend void setCurrentInputEventForTest(const WebInputEvent*);
508
509     enum DragAction {
510       DragEnter,
511       DragOver
512     };
513
514     explicit WebViewImpl(WebViewClient*);
515     virtual ~WebViewImpl();
516
517     WebTextInputType textInputType();
518
519     WebString inputModeOfFocusedElement();
520
521     // Returns true if the event was actually processed.
522     bool keyEventDefault(const WebKeyboardEvent&);
523
524     bool confirmComposition(const WebString& text, ConfirmCompositionBehavior);
525
526     // Returns true if the view was scrolled.
527     bool scrollViewWithKeyboard(int keyCode, int modifiers);
528
529     void hideSelectPopup();
530
531     // Converts |pos| from window coordinates to contents coordinates and gets
532     // the HitTestResult for it.
533     WebCore::HitTestResult hitTestResultForWindowPos(const WebCore::IntPoint&);
534
535     // Consolidate some common code between starting a drag over a target and
536     // updating a drag over a target. If we're starting a drag, |isEntering|
537     // should be true.
538     WebDragOperation dragTargetDragEnterOrOver(const WebPoint& clientPoint,
539                                                const WebPoint& screenPoint,
540                                                DragAction,
541                                                int keyModifiers);
542
543     void configureAutoResizeMode();
544
545     void setIsAcceleratedCompositingActive(bool);
546     void doComposite();
547     void reallocateRenderer();
548     void updateLayerTreeViewport();
549     void updateLayerTreeBackgroundColor();
550     void updateRootLayerTransform();
551     void updateLayerTreeDeviceScaleFactor();
552
553     // Helper function: Widens the width of |source| by the specified margins
554     // while keeping it smaller than page width.
555     WebRect widenRectWithinPageBounds(const WebRect& source, int targetMargin, int minimumMargin);
556
557     void pointerLockMouseEvent(const WebInputEvent&);
558
559     // PageWidgetEventHandler functions
560     virtual void handleMouseLeave(WebCore::LocalFrame&, const WebMouseEvent&) OVERRIDE;
561     virtual void handleMouseDown(WebCore::LocalFrame&, const WebMouseEvent&) OVERRIDE;
562     virtual void handleMouseUp(WebCore::LocalFrame&, const WebMouseEvent&) OVERRIDE;
563     virtual bool handleMouseWheel(WebCore::LocalFrame&, const WebMouseWheelEvent&) OVERRIDE;
564     virtual bool handleGestureEvent(const WebGestureEvent&) OVERRIDE;
565     virtual bool handleKeyEvent(const WebKeyboardEvent&) OVERRIDE;
566     virtual bool handleCharEvent(const WebKeyboardEvent&) OVERRIDE;
567
568     WebCore::InputMethodContext* inputMethodContext();
569     WebPlugin* focusedPluginIfInputMethodSupported(WebCore::LocalFrame*);
570
571     WebViewClient* m_client; // Can be 0 (e.g. unittests, shared workers, etc.)
572     WebAutofillClient* m_autofillClient;
573     WebSpellCheckClient* m_spellCheckClient;
574
575     ChromeClientImpl m_chromeClientImpl;
576     ContextMenuClientImpl m_contextMenuClientImpl;
577     DragClientImpl m_dragClientImpl;
578     EditorClientImpl m_editorClientImpl;
579     InspectorClientImpl m_inspectorClientImpl;
580     BackForwardClientImpl m_backForwardClientImpl;
581     SpellCheckerClientImpl m_spellCheckerClientImpl;
582     StorageClientImpl m_storageClientImpl;
583
584     WebSize m_size;
585     bool m_fixedLayoutSizeLock;
586     // If true, automatically resize the render view around its content.
587     bool m_shouldAutoResize;
588     // The lower bound on the size when auto-resizing.
589     WebCore::IntSize m_minAutoSize;
590     // The upper bound on the size when auto-resizing.
591     WebCore::IntSize m_maxAutoSize;
592
593     OwnPtrWillBePersistent<WebCore::Page> m_page;
594
595     // An object that can be used to manipulate m_page->settings() without linking
596     // against WebCore. This is lazily allocated the first time GetWebSettings()
597     // is called.
598     OwnPtr<WebSettingsImpl> m_webSettings;
599
600     // A copy of the web drop data object we received from the browser.
601     RefPtrWillBePersistent<WebCore::DataObject> m_currentDragData;
602
603     // The point relative to the client area where the mouse was last pressed
604     // down. This is used by the drag client to determine what was under the
605     // mouse when the drag was initiated. We need to track this here in
606     // WebViewImpl since DragClient::startDrag does not pass the position the
607     // mouse was at when the drag was initiated, only the current point, which
608     // can be misleading as it is usually not over the element the user actually
609     // dragged by the time a drag is initiated.
610     WebPoint m_lastMouseDownPoint;
611
612     // Keeps track of the current zoom level. 0 means no zoom, positive numbers
613     // mean zoom in, negative numbers mean zoom out.
614     double m_zoomLevel;
615
616     double m_minimumZoomLevel;
617
618     double m_maximumZoomLevel;
619
620     PageScaleConstraintsSet m_pageScaleConstraintsSet;
621
622     // The scale moved to by the latest double tap zoom, if any.
623     float m_doubleTapZoomPageScaleFactor;
624     // Have we sent a double-tap zoom and not yet heard back the scale?
625     bool m_doubleTapZoomPending;
626
627     // Used for testing purposes.
628     bool m_enableFakePageScaleAnimationForTesting;
629     WebCore::IntPoint m_fakePageScaleAnimationTargetPosition;
630     float m_fakePageScaleAnimationPageScaleFactor;
631     bool m_fakePageScaleAnimationUseAnchor;
632
633     bool m_contextMenuAllowed;
634
635     bool m_doingDragAndDrop;
636
637     bool m_ignoreInputEvents;
638
639     float m_compositorDeviceScaleFactorOverride;
640     WebSize m_rootLayerOffset;
641     float m_rootLayerScale;
642
643     // Webkit expects keyPress events to be suppressed if the associated keyDown
644     // event was handled. Safari implements this behavior by peeking out the
645     // associated WM_CHAR event if the keydown was handled. We emulate
646     // this behavior by setting this flag if the keyDown was handled.
647     bool m_suppressNextKeypressEvent;
648
649     // Represents whether or not this object should process incoming IME events.
650     bool m_imeAcceptEvents;
651
652     // The available drag operations (copy, move link...) allowed by the source.
653     WebDragOperation m_operationsAllowed;
654
655     // The current drag operation as negotiated by the source and destination.
656     // When not equal to DragOperationNone, the drag data can be dropped onto the
657     // current drop target in this WebView (the drop target can accept the drop).
658     WebDragOperation m_dragOperation;
659
660     // The popup associated with a select element.
661     RefPtr<PopupContainer> m_selectPopup;
662
663     // The popup associated with an input element.
664     RefPtr<WebPagePopupImpl> m_pagePopup;
665
666     OwnPtr<WebDevToolsAgentPrivate> m_devToolsAgent;
667     OwnPtr<PageOverlayList> m_pageOverlays;
668
669     // Whether the webview is rendering transparently.
670     bool m_isTransparent;
671
672     // Whether the user can press tab to focus links.
673     bool m_tabsToLinks;
674
675     // Inspector settings.
676     WebString m_inspectorSettings;
677
678     typedef HashMap<WTF::String, WTF::String> SettingsMap;
679     OwnPtr<SettingsMap> m_inspectorSettingsMap;
680
681     // If set, the (plugin) node which has mouse capture.
682     RefPtrWillBePersistent<WebCore::Node> m_mouseCaptureNode;
683     RefPtr<WebCore::UserGestureToken> m_mouseCaptureGestureToken;
684
685     WebCore::IntRect m_rootLayerScrollDamage;
686     WebLayerTreeView* m_layerTreeView;
687     WebLayer* m_rootLayer;
688     WebCore::GraphicsLayer* m_rootGraphicsLayer;
689     WebCore::GraphicsLayer* m_rootTransformLayer;
690     OwnPtr<WebCore::GraphicsLayerFactory> m_graphicsLayerFactory;
691     bool m_isAcceleratedCompositingActive;
692     bool m_layerTreeViewCommitsDeferred;
693     bool m_matchesHeuristicsForGpuRasterization;
694     // If true, the graphics context is being restored.
695     bool m_recreatingGraphicsContext;
696     static const WebInputEvent* m_currentInputEvent;
697
698     MediaKeysClientImpl m_mediaKeysClientImpl;
699     OwnPtr<WebActiveGestureAnimation> m_gestureAnimation;
700     WebPoint m_positionOnFlingStart;
701     WebPoint m_globalPositionOnFlingStart;
702     int m_flingModifier;
703     bool m_flingSourceDevice;
704     Vector<OwnPtr<LinkHighlight> > m_linkHighlights;
705     OwnPtr<FullscreenController> m_fullscreenController;
706
707     bool m_showFPSCounter;
708     bool m_showPaintRects;
709     bool m_showDebugBorders;
710     bool m_continuousPaintingEnabled;
711     bool m_showScrollBottleneckRects;
712     WebColor m_baseBackgroundColor;
713     WebColor m_backgroundColorOverride;
714     float m_zoomFactorOverride;
715
716     bool m_userGestureObserved;
717 };
718
719 // We have no ways to check if the specified WebView is an instance of
720 // WebViewImpl because WebViewImpl is the only implementation of WebView.
721 DEFINE_TYPE_CASTS(WebViewImpl, WebView, webView, true, true);
722
723 } // namespace blink
724
725 #endif