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