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