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