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