2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
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"
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"
69 class GraphicsLayerFactory;
75 class PagePopupClient;
76 class PlatformKeyboardEvent;
77 class PopupMenuClient;
78 class RenderLayerCompositor;
82 class AutocompletePopupMenuClient;
83 class ContextFeaturesClientImpl;
84 class ContextMenuClientImpl;
85 class GeolocationClientProxy;
87 class MIDIClientProxy;
89 class PrerendererClientImpl;
90 class SpeechInputClientImpl;
91 class SpeechRecognitionClientProxy;
92 class UserMediaClientImpl;
93 class ValidationMessageClientImpl;
95 class WebActiveGestureAnimation;
96 class WebDevToolsAgentClient;
97 class WebDevToolsAgentPrivate;
99 class WebGestureEvent;
101 class WebKeyboardEvent;
102 class WebLayerTreeView;
104 class WebMouseWheelEvent;
105 class WebPagePopupImpl;
107 class WebPrerendererClient;
108 class WebSettingsImpl;
110 class WorkerGlobalScopeProxyProviderImpl;
111 class FullscreenController;
113 class WebViewImpl FINAL : public WebView
114 , public RefCounted<WebViewImpl>
115 , public WebGestureCurveTarget
116 , public WebCore::PagePopupDriver
117 , public PageWidgetEventHandler {
119 static WebViewImpl* create(WebViewClient*);
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,
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;
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;
223 virtual float deviceScaleFactor() const OVERRIDE;
224 virtual void setDeviceScaleFactor(float) OVERRIDE;
226 virtual void setFixedLayoutSize(const WebSize&) OVERRIDE;
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(
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;
297 void suppressInvalidations(bool enable);
298 void invalidateRect(const WebCore::IntRect&);
300 void setIgnoreInputEvents(bool newValue);
301 void setBackgroundColorOverride(WebColor);
302 void setZoomFactorOverride(float);
303 WebDevToolsAgentPrivate* devToolsAgentPrivate() { return m_devToolsAgent.get(); }
305 WebCore::Color baseBackgroundColor() const { return m_baseBackgroundColor; }
307 PageOverlayList* pageOverlays() const { return m_pageOverlays.get(); }
309 void setOverlayLayer(WebCore::GraphicsLayer*);
311 const WebPoint& lastMouseDownPoint() const
313 return m_lastMouseDownPoint;
316 WebCore::LocalFrame* focusedWebCoreFrame() const;
318 // Returns the currently focused Element or null if no element has focus.
319 WebCore::Element* focusedElement() const;
321 static WebViewImpl* fromPage(WebCore::Page*);
323 WebViewClient* client()
328 WebAutofillClient* autofillClient()
330 return m_autofillClient;
333 WebSpellCheckClient* spellCheckClient()
335 return m_spellCheckClient;
338 WebPasswordGeneratorClient* passwordGeneratorClient() const
340 return m_passwordGeneratorClient;
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
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();
354 // Event related methods:
355 void mouseContextMenu(const WebMouseEvent&);
356 void mouseDoubleClick(const WebMouseEvent&);
358 bool detectContentOnTouch(const WebPoint&);
359 bool startPageScaleAnimation(const WebCore::IntPoint& targetPosition, bool useAnchor, float newScale, double durationInSeconds);
361 void numberOfWheelEventHandlersChanged(unsigned);
362 void hasTouchEventHandlers(bool);
364 // WebGestureCurveTarget implementation for fling.
365 virtual void scrollBy(const WebFloatSize&) OVERRIDE;
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&);
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);
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*);
388 void willInsertBody(WebFrameImpl*);
389 void didChangeContentsSize();
390 void deviceOrPageScaleFactorChanged();
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();
396 bool contextMenuAllowed() const
398 return m_contextMenuAllowed;
401 bool shouldAutoResize() const
403 return m_shouldAutoResize;
406 WebCore::IntSize minAutoSize() const
408 return m_minAutoSize;
411 WebCore::IntSize maxAutoSize() const
413 return m_maxAutoSize;
416 void updateMainFrameLayoutSize();
417 void updatePageDefinedViewportConstraints(const WebCore::ViewportDescription&);
419 // Start a system drag and drop operation.
421 WebCore::LocalFrame*,
422 const WebDragData& dragData,
423 WebDragOperationsMask mask,
424 const WebImage& dragImage,
425 const WebPoint& dragImageOffset);
427 // Returns the provider of desktop notifications.
428 NotificationPresenterImpl* notificationPresenterImpl();
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);
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;
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()
445 return m_currentInputEvent;
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();
458 virtual void setVisibilityState(WebPageVisibilityState, bool) OVERRIDE;
460 PopupContainer* selectPopup() const { return m_selectPopup.get(); }
461 bool hasOpenedPopup() const { return m_selectPopup || m_pagePopup; }
463 // Returns true if the event leads to scrolling.
464 static bool mapKeyCodeForScroll(int keyCode,
465 WebCore::ScrollDirection* scrollDirection,
466 WebCore::ScrollGranularity* scrollGranularity);
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);
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);
480 void animateDoubleTapZoom(const WebCore::IntPoint&);
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; }
488 void enterFullScreenForElement(WebCore::Element*);
489 void exitFullScreenForElement(WebCore::Element*);
491 // Exposed for the purpose of overriding device metrics.
492 void sendResizeEventAndRepaint();
494 // Exposed for testing purposes.
495 bool hasHorizontalScrollbar();
496 bool hasVerticalScrollbar();
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();
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();
508 // Exposed for tests.
509 unsigned numLinkHighlights() { return m_linkHighlights.size(); }
510 LinkHighlight* linkHighlight(int i) { return m_linkHighlights[i].get(); }
512 WebSettingsImpl* settingsImpl();
514 // Returns the bounding box of the block type node touched by the WebRect.
515 WebRect computeBlockBounds(const WebRect&, bool ignoreClipping);
517 WebCore::IntPoint clampOffsetAtScale(const WebCore::IntPoint& offset, float scale);
519 // Exposed for tests.
520 WebVector<WebCompositionUnderline> compositionUnderlines() const;
522 WebLayerTreeView* layerTreeView() const { return m_layerTreeView; }
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;
532 void resetSavedScrollAndScaleState();
534 void updateMainFrameScrollPosition(const WebCore::IntPoint& scrollPosition, bool programmaticScroll);
536 friend class WebView; // So WebView::Create can call our constructor
537 friend class WTF::RefCounted<WebViewImpl>;
538 friend void setCurrentInputEventForTest(const WebInputEvent*);
545 explicit WebViewImpl(WebViewClient*);
546 virtual ~WebViewImpl();
548 WebTextInputType textInputType();
550 WebString inputModeOfFocusedElement();
552 // Returns true if the event was actually processed.
553 bool keyEventDefault(const WebKeyboardEvent&);
555 bool confirmComposition(const WebString& text, ConfirmCompositionBehavior);
557 // Returns true if the view was scrolled.
558 bool scrollViewWithKeyboard(int keyCode, int modifiers);
560 void hideSelectPopup();
562 // Converts |pos| from window coordinates to contents coordinates and gets
563 // the HitTestResult for it.
564 WebCore::HitTestResult hitTestResultForWindowPos(const WebCore::IntPoint&);
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|
569 WebDragOperation dragTargetDragEnterOrOver(const WebPoint& clientPoint,
570 const WebPoint& screenPoint,
574 void configureAutoResizeMode();
576 void setIsAcceleratedCompositingActive(bool);
578 void doPixelReadbackToCanvas(WebCanvas*, const WebCore::IntRect&);
579 void reallocateRenderer();
580 void updateLayerTreeViewport();
581 void updateLayerTreeBackgroundColor();
582 void updateRootLayerTransform();
583 void updateLayerTreeDeviceScaleFactor();
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);
589 void pointerLockMouseEvent(const WebInputEvent&);
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;
600 WebCore::InputMethodContext* inputMethodContext();
601 WebPlugin* focusedPluginIfInputMethodSupported(WebCore::LocalFrame*);
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;
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;
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;
626 OwnPtr<WebCore::Page> m_page;
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()
631 OwnPtr<WebSettingsImpl> m_webSettings;
633 // A copy of the web drop data object we received from the browser.
634 RefPtrWillBePersistent<WebCore::DataObject> m_currentDragData;
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;
645 // Keeps track of the current zoom level. 0 means no zoom, positive numbers
646 // mean zoom in, negative numbers mean zoom out.
649 double m_minimumZoomLevel;
651 double m_maximumZoomLevel;
653 PageScaleConstraintsSet m_pageScaleConstraintsSet;
655 // Saved page scale state.
656 float m_savedPageScaleFactor; // 0 means that no page scale factor is saved.
657 WebCore::IntSize m_savedScrollOffset;
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;
664 // Used for testing purposes.
665 bool m_enableFakePageScaleAnimationForTesting;
666 WebCore::IntPoint m_fakePageScaleAnimationTargetPosition;
667 float m_fakePageScaleAnimationPageScaleFactor;
668 bool m_fakePageScaleAnimationUseAnchor;
670 bool m_contextMenuAllowed;
672 bool m_doingDragAndDrop;
674 bool m_ignoreInputEvents;
676 float m_compositorDeviceScaleFactorOverride;
677 WebSize m_rootLayerOffset;
678 float m_rootLayerScale;
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;
686 // Represents whether or not this object should process incoming IME events.
687 bool m_imeAcceptEvents;
689 // The available drag operations (copy, move link...) allowed by the source.
690 WebDragOperation m_operationsAllowed;
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;
697 // Context-based feature switches.
698 OwnPtr<ContextFeaturesClientImpl> m_featureSwitchClient;
700 // The popup associated with a select element.
701 RefPtr<PopupContainer> m_selectPopup;
703 // The popup associated with an input element.
704 RefPtr<WebPagePopupImpl> m_pagePopup;
706 OwnPtr<WebDevToolsAgentPrivate> m_devToolsAgent;
707 OwnPtr<PageOverlayList> m_pageOverlays;
709 // Whether the webview is rendering transparently.
710 bool m_isTransparent;
712 // Whether the user can press tab to focus links.
715 // Inspector settings.
716 WebString m_inspectorSettings;
718 typedef HashMap<WTF::String, WTF::String> SettingsMap;
719 OwnPtr<SettingsMap> m_inspectorSettingsMap;
721 // The provider of desktop notifications;
722 NotificationPresenterImpl m_notificationPresenter;
724 // If set, the (plugin) node which has mouse capture.
725 RefPtr<WebCore::Node> m_mouseCaptureNode;
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;
740 #if ENABLE(INPUT_SPEECH)
741 OwnPtr<SpeechInputClientImpl> m_speechInputClient;
743 OwnPtr<SpeechRecognitionClientProxy> m_speechRecognitionClient;
745 OwnPtr<GeolocationClientProxy> m_geolocationClientProxy;
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;
755 bool m_flingSourceDevice;
756 Vector<OwnPtr<LinkHighlight> > m_linkHighlights;
757 OwnPtr<ValidationMessageClientImpl> m_validationMessage;
758 OwnPtr<FullscreenController> m_fullscreenController;
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;
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);