#include "config.h"
#include "WebViewImpl.h"
#include "AXObjectCache.h"
#include "ActivePlatformGestureAnimation.h"
#include "AutofillPopupMenuClient.h"
#include "BackForwardListChromium.h"
#include "BatteryClientImpl.h"
#include "CSSValueKeywords.h"
#include "Chrome.h"
#include "Color.h"
#include "ColorSpace.h"
#include "CompositionUnderlineVectorBuilder.h"
#include "ContextMenu.h"
#include "ContextMenuController.h"
#include "ContextMenuItem.h"
#include "Cursor.h"
#include "DOMUtilitiesPrivate.h"
#include "DeviceOrientationClientProxy.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "DragController.h"
#include "DragData.h"
#include "DragScrollTimer.h"
#include "DragSession.h"
#include "Editor.h"
#include "EventHandler.h"
#include "Extensions3D.h"
#include "FocusController.h"
#include "FontDescription.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameSelection.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "GeolocationClientProxy.h"
#include "GeolocationController.h"
#include "GraphicsContext.h"
#include "GraphicsContext3D.h"
#include "GraphicsContext3DPrivate.h"
#include "HTMLInputElement.h"
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "HTMLTextAreaElement.h"
#include "HitTestResult.h"
#include "Image.h"
#include "ImageBuffer.h"
#include "InspectorController.h"
#include "InspectorInstrumentation.h"
#include "KeyboardCodes.h"
#include "KeyboardEvent.h"
#include "LayerChromium.h"
#include "LayerPainterChromium.h"
#include "MIMETypeRegistry.h"
#include "NodeRenderStyle.h"
#include "NonCompositedContentHost.h"
#include "Page.h"
#include "PageGroup.h"
#include "PageGroupLoadDeferrer.h"
#include "PagePopupClient.h"
#include "PageWidgetDelegate.h"
#include "Pasteboard.h"
#include "PlatformContextSkia.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformMouseEvent.h"
#include "PlatformThemeChromiumLinux.h"
#include "PlatformWheelEvent.h"
#include "PointerLock.h"
#include "PointerLockController.h"
#include "PopupContainer.h"
#include "PopupMenuClient.h"
#include "ProgressTracker.h"
#include "RenderLayerCompositor.h"
#include "RenderView.h"
#include "RenderWidget.h"
#include "ResourceHandle.h"
#include "SchemeRegistry.h"
#include "SecurityOrigin.h"
#include "SecurityPolicy.h"
#include "Settings.h"
#include "SharedGraphicsContext3D.h"
#include "SpeechInputClientImpl.h"
#include "SpeechRecognitionClientProxy.h"
#include "StyleResolver.h"
#include "TextFieldDecoratorImpl.h"
#include "TextIterator.h"
#include "Timer.h"
#include "TouchpadFlingPlatformGestureCurve.h"
#include "TraceEvent.h"
#include "UserGestureIndicator.h"
#include "WebAccessibilityObject.h"
#include "WebActiveWheelFlingParameters.h"
#include "WebAutofillClient.h"
#include "WebCompositorImpl.h"
#include "WebDevToolsAgentImpl.h"
#include "WebDevToolsAgentPrivate.h"
#include "WebFrameImpl.h"
#include "WebInputElement.h"
#include "WebInputEvent.h"
#include "WebInputEventConversion.h"
#include "WebKit.h"
#include "WebMediaPlayerAction.h"
#include "WebNode.h"
#include "WebPagePopupImpl.h"
#include "WebPlugin.h"
#include "WebPluginAction.h"
#include "WebPluginContainerImpl.h"
#include "WebPopupMenuImpl.h"
#include "WebRange.h"
#include "WebRuntimeFeatures.h"
#include "WebSettingsImpl.h"
#include "WebViewClient.h"
#include "WheelEvent.h"
#include "cc/CCProxy.h"
#include "painting/GraphicsContextBuilder.h"
#include "platform/WebDragData.h"
#include "platform/WebImage.h"
#include "platform/WebKitPlatformSupport.h"
#include "platform/WebString.h"
#include "platform/WebVector.h"
#include <public/Platform.h>
#include <public/WebFloatPoint.h>
#include <public/WebGraphicsContext3D.h>
#include <public/WebLayer.h>
#include <public/WebLayerTreeView.h>
#include <public/WebPoint.h>
#include <public/WebRect.h>
#include <wtf/CurrentTime.h>
#include <wtf/MainThread.h>
#include <wtf/RefPtr.h>
#include <wtf/Uint8ClampedArray.h>
#if ENABLE(GESTURE_EVENTS)
#include "PlatformGestureEvent.h"
#endif
#if USE(CG)
#include <CoreGraphics/CGBitmapContext.h>
#include <CoreGraphics/CGContext.h>
#endif
#if OS(WINDOWS)
#include "RenderThemeChromiumWin.h"
#else
#if OS(UNIX) && !OS(DARWIN)
#include "RenderThemeChromiumLinux.h"
#endif
#include "RenderTheme.h"
#endif
#undef pow
#include <cmath> // for std::pow
using namespace WebCore;
using namespace std;
static const int touchPointPadding = 32;
static const float minScaleDifference = 0.01f;
static const float doubleTapZoomContentDefaultMargin = 5;
static const float doubleTapZoomContentMinimumMargin = 2;
namespace WebKit {
const double WebView::textSizeMultiplierRatio = 1.2;
const double WebView::minTextSizeMultiplier = 0.5;
const double WebView::maxTextSizeMultiplier = 3.0;
const float WebView::minPageScaleFactor = 0.25;
const float WebView::maxPageScaleFactor = 4.0;
const char* pageGroupName = "default";
static Vector<PageGroupLoadDeferrer*>& pageGroupLoadDeferrerStack()
{
DEFINE_STATIC_LOCAL(Vector<PageGroupLoadDeferrer*>, deferrerStack, ());
return deferrerStack;
}
#define COMPILE_ASSERT_MATCHING_ENUM(coreName) \
COMPILE_ASSERT(int(coreName) == int(Web##coreName), dummy##coreName)
COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery);
static const PopupContainerSettings autofillPopupSettings = {
false, false, true, false };
static bool shouldUseExternalPopupMenus = false;
WebView* WebView::create(WebViewClient* client)
{
WebRuntimeFeatures::enableDeviceMotion(false);
return adoptRef(new WebViewImpl(client)).leakRef();
}
void WebView::setUseExternalPopupMenus(bool useExternalPopupMenus)
{
shouldUseExternalPopupMenus = useExternalPopupMenus;
}
void WebView::updateVisitedLinkState(unsigned long long linkHash)
{
Page::visitedStateChanged(PageGroup::pageGroup(pageGroupName), linkHash);
}
void WebView::resetVisitedLinkState()
{
Page::allVisitedStateChanged(PageGroup::pageGroup(pageGroupName));
}
void WebView::willEnterModalLoop()
{
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
ASSERT(pageGroup);
if (pageGroup->pages().isEmpty())
pageGroupLoadDeferrerStack().append(static_cast<PageGroupLoadDeferrer*>(0));
else {
pageGroupLoadDeferrerStack().append(new PageGroupLoadDeferrer(*pageGroup->pages().begin(), true));
}
}
void WebView::didExitModalLoop()
{
ASSERT(pageGroupLoadDeferrerStack().size());
delete pageGroupLoadDeferrerStack().last();
pageGroupLoadDeferrerStack().removeLast();
}
void WebViewImpl::initializeMainFrame(WebFrameClient* frameClient)
{
RefPtr<WebFrameImpl> frame = WebFrameImpl::create(frameClient);
frame->initializeAsMainFrame(this);
SecurityPolicy::setLocalLoadPolicy(SecurityPolicy::AllowLocalLoadsForLocalOnly);
}
void WebViewImpl::setAutofillClient(WebAutofillClient* autofillClient)
{
m_autofillClient = autofillClient;
}
void WebViewImpl::setDevToolsAgentClient(WebDevToolsAgentClient* devToolsClient)
{
if (devToolsClient)
m_devToolsAgent = adoptPtr(new WebDevToolsAgentImpl(this, devToolsClient));
else
m_devToolsAgent.clear();
}
void WebViewImpl::setPermissionClient(WebPermissionClient* permissionClient)
{
m_permissionClient = permissionClient;
}
void WebViewImpl::setSpellCheckClient(WebSpellCheckClient* spellCheckClient)
{
m_spellCheckClient = spellCheckClient;
}
void WebViewImpl::addTextFieldDecoratorClient(WebTextFieldDecoratorClient* client)
{
ASSERT(client);
const unsigned maximumNumberOfDecorators = 8;
if (m_textFieldDecorators.size() >= maximumNumberOfDecorators)
CRASH();
m_textFieldDecorators.append(TextFieldDecoratorImpl::create(client));
}
WebViewImpl::WebViewImpl(WebViewClient* client)
: m_client(client)
, m_autofillClient(0)
, m_permissionClient(0)
, m_spellCheckClient(0)
, m_chromeClientImpl(this)
, m_contextMenuClientImpl(this)
, m_dragClientImpl(this)
, m_editorClientImpl(this)
, m_inspectorClientImpl(this)
, m_shouldAutoResize(false)
, m_observedNewNavigation(false)
#ifndef NDEBUG
, m_newNavigationLoader(0)
#endif
, m_zoomLevel(0)
, m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
, m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
, m_pageDefinedMinimumPageScaleFactor(-1)
, m_pageDefinedMaximumPageScaleFactor(-1)
, m_minimumPageScaleFactor(minPageScaleFactor)
, m_maximumPageScaleFactor(maxPageScaleFactor)
, m_pageScaleFactorIsSet(false)
, m_contextMenuAllowed(false)
, m_doingDragAndDrop(false)
, m_ignoreInputEvents(false)
, m_suppressNextKeypressEvent(false)
, m_initialNavigationPolicy(WebNavigationPolicyIgnore)
, m_imeAcceptEvents(true)
, m_operationsAllowed(WebDragOperationNone)
, m_dragOperation(WebDragOperationNone)
, m_autofillPopupShowing(false)
, m_autofillPopup(0)
, m_isTransparent(false)
, m_tabsToLinks(false)
, m_dragScrollTimer(adoptPtr(new DragScrollTimer))
, m_isCancelingFullScreen(false)
#if USE(ACCELERATED_COMPOSITING)
, m_rootGraphicsLayer(0)
, m_isAcceleratedCompositingActive(false)
, m_compositorCreationFailed(false)
, m_recreatingGraphicsContext(false)
, m_compositorSurfaceReady(false)
#endif
#if ENABLE(INPUT_SPEECH)
, m_speechInputClient(SpeechInputClientImpl::create(client))
#endif
#if ENABLE(SCRIPTED_SPEECH)
, m_speechRecognitionClient(SpeechRecognitionClientProxy::create(client ? client->speechRecognizer() : 0))
#endif
, m_deviceOrientationClientProxy(adoptPtr(new DeviceOrientationClientProxy(client ? client->deviceOrientationClient() : 0)))
, m_geolocationClientProxy(adoptPtr(new GeolocationClientProxy(client ? client->geolocationClient() : 0)))
#if ENABLE(BATTERY_STATUS)
, m_batteryClient(adoptPtr(new BatteryClientImpl(client ? client->batteryStatusClient() : 0)))
#endif
, m_emulatedTextZoomFactor(1)
#if ENABLE(MEDIA_STREAM)
, m_userMediaClientImpl(this)
#endif
, m_flingModifier(0)
{
WTF::initializeThreading();
WTF::initializeMainThread();
Page::PageClients pageClients;
pageClients.chromeClient = &m_chromeClientImpl;
pageClients.contextMenuClient = &m_contextMenuClientImpl;
pageClients.editorClient = &m_editorClientImpl;
pageClients.dragClient = &m_dragClientImpl;
pageClients.inspectorClient = &m_inspectorClientImpl;
pageClients.backForwardClient = BackForwardListChromium::create(this);
m_page = adoptPtr(new Page(pageClients));
#if ENABLE(MEDIA_STREAM)
provideUserMediaTo(m_page.get(), &m_userMediaClientImpl);
#endif
#if ENABLE(INPUT_SPEECH)
provideSpeechInputTo(m_page.get(), m_speechInputClient.get());
#endif
#if ENABLE(SCRIPTED_SPEECH)
provideSpeechRecognitionTo(m_page.get(), m_speechRecognitionClient.get());
#endif
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
provideNotification(m_page.get(), notificationPresenterImpl());
#endif
provideDeviceOrientationTo(m_page.get(), m_deviceOrientationClientProxy.get());
provideGeolocationTo(m_page.get(), m_geolocationClientProxy.get());
m_geolocationClientProxy->setController(GeolocationController::from(m_page.get()));
#if ENABLE(BATTERY_STATUS)
provideBatteryTo(m_page.get(), m_batteryClient.get());
#endif
m_page->setGroupName(pageGroupName);
#if ENABLE(PAGE_VISIBILITY_API)
if (m_client)
setVisibilityState(m_client->visibilityState(), true);
#endif
m_inspectorSettingsMap = adoptPtr(new SettingsMap);
}
WebViewImpl::~WebViewImpl()
{
ASSERT(!m_page);
}
RenderTheme* WebViewImpl::theme() const
{
return m_page ? m_page->theme() : RenderTheme::defaultTheme().get();
}
WebFrameImpl* WebViewImpl::mainFrameImpl()
{
return m_page ? WebFrameImpl::fromFrame(m_page->mainFrame()) : 0;
}
bool WebViewImpl::tabKeyCyclesThroughElements() const
{
ASSERT(m_page);
return m_page->tabKeyCyclesThroughElements();
}
void WebViewImpl::setTabKeyCyclesThroughElements(bool value)
{
if (m_page)
m_page->setTabKeyCyclesThroughElements(value);
}
void WebViewImpl::handleMouseLeave(Frame& mainFrame, const WebMouseEvent& event)
{
m_client->setMouseOverURL(WebURL());
PageWidgetEventHandler::handleMouseLeave(mainFrame, event);
}
void WebViewImpl::handleMouseDown(Frame& mainFrame, const WebMouseEvent& event)
{
RefPtr<WebCore::PopupContainer> selectPopup;
if (event.button == WebMouseEvent::ButtonLeft) {
selectPopup = m_selectPopup;
hideSelectPopup();
ASSERT(!m_selectPopup);
}
m_lastMouseDownPoint = WebPoint(event.x, event.y);
if (event.button == WebMouseEvent::ButtonLeft) {
IntPoint point(event.x, event.y);
point = m_page->mainFrame()->view()->windowToContents(point);
HitTestResult result(m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, false));
Node* hitNode = result.innerNonSharedNode();
if (hitNode && hitNode->renderer() && hitNode->renderer()->isEmbeddedObject())
m_mouseCaptureNode = hitNode;
}
PageWidgetEventHandler::handleMouseDown(mainFrame, event);
if (m_selectPopup && m_selectPopup == selectPopup) {
hideSelectPopup();
}
#if OS(DARWIN)
if (event.button == WebMouseEvent::ButtonRight
|| (event.button == WebMouseEvent::ButtonLeft
&& event.modifiers & WebMouseEvent::ControlKey))
mouseContextMenu(event);
#elif OS(UNIX) || OS(ANDROID)
if (event.button == WebMouseEvent::ButtonRight)
mouseContextMenu(event);
#endif
}
void WebViewImpl::mouseContextMenu(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
m_page->contextMenuController()->clearContextMenu();
PlatformMouseEventBuilder pme(mainFrameImpl()->frameView(), event);
HitTestResult result = hitTestResultForWindowPos(pme.position());
Frame* targetFrame;
if (result.innerNonSharedNode())
targetFrame = result.innerNonSharedNode()->document()->frame();
else
targetFrame = m_page->focusController()->focusedOrMainFrame();
#if OS(WINDOWS)
targetFrame->view()->setCursor(pointerCursor());
#endif
m_contextMenuAllowed = true;
targetFrame->eventHandler()->sendContextMenuEvent(pme);
m_contextMenuAllowed = false;
}
void WebViewImpl::handleMouseUp(Frame& mainFrame, const WebMouseEvent& event)
{
#if OS(UNIX) && !OS(DARWIN)
if (event.button == WebMouseEvent::ButtonMiddle) {
Frame* focused = focusedWebCoreFrame();
FrameView* view = m_page->mainFrame()->view();
IntPoint clickPoint(m_lastMouseDownPoint.x, m_lastMouseDownPoint.y);
IntPoint contentPoint = view->windowToContents(clickPoint);
HitTestResult hitTestResult = focused->eventHandler()->hitTestResultAtPoint(contentPoint, false, false, ShouldHitTestScrollbars);
if (!hitTestResult.scrollbar() && !hitTestResult.isLiveLink() && focused && !view->scrollbarAtPoint(clickPoint)) {
Editor* editor = focused->editor();
Pasteboard* pasteboard = Pasteboard::generalPasteboard();
bool oldSelectionMode = pasteboard->isSelectionMode();
pasteboard->setSelectionMode(true);
editor->command(AtomicString("Paste")).execute();
pasteboard->setSelectionMode(oldSelectionMode);
}
}
#endif
PageWidgetEventHandler::handleMouseUp(mainFrame, event);
#if OS(WINDOWS)
if (event.button == WebMouseEvent::ButtonRight)
mouseContextMenu(event);
#endif
}
void WebViewImpl::scrollBy(const WebCore::IntPoint& delta)
{
WebMouseWheelEvent syntheticWheel;
const float tickDivisor = WebCore::WheelEvent::tickMultiplier;
syntheticWheel.deltaX = delta.x();
syntheticWheel.deltaY = delta.y();
syntheticWheel.wheelTicksX = delta.x() / tickDivisor;
syntheticWheel.wheelTicksY = delta.y() / tickDivisor;
syntheticWheel.hasPreciseScrollingDeltas = true;
syntheticWheel.x = m_lastWheelPosition.x;
syntheticWheel.y = m_lastWheelPosition.y;
syntheticWheel.globalX = m_lastWheelGlobalPosition.x;
syntheticWheel.globalY = m_lastWheelGlobalPosition.y;
syntheticWheel.modifiers = m_flingModifier;
if (m_page && m_page->mainFrame() && m_page->mainFrame()->view())
handleMouseWheel(*m_page->mainFrame(), syntheticWheel);
}
#if ENABLE(GESTURE_EVENTS)
bool WebViewImpl::handleGestureEvent(const WebGestureEvent& event)
{
switch (event.type) {
case WebInputEvent::GestureFlingStart: {
m_lastWheelPosition = WebPoint(event.x, event.y);
m_lastWheelGlobalPosition = WebPoint(event.globalX, event.globalY);
m_flingModifier = event.modifiers;
m_gestureAnimation = ActivePlatformGestureAnimation::create(TouchpadFlingPlatformGestureCurve::create(FloatPoint(event.deltaX, event.deltaY)), this);
scheduleAnimation();
return true;
}
case WebInputEvent::GestureFlingCancel:
if (m_gestureAnimation) {
m_gestureAnimation.clear();
return true;
}
return false;
case WebInputEvent::GestureTap: {
PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
RefPtr<WebCore::PopupContainer> selectPopup;
selectPopup = m_selectPopup;
hideSelectPopup();
ASSERT(!m_selectPopup);
bool gestureHandled = mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent);
if (m_selectPopup && m_selectPopup == selectPopup) {
hideSelectPopup();
}
return gestureHandled;
}
case WebInputEvent::GestureScrollBegin:
case WebInputEvent::GestureScrollEnd:
case WebInputEvent::GestureScrollUpdate:
case WebInputEvent::GestureTapDown:
case WebInputEvent::GestureDoubleTap:
case WebInputEvent::GestureLongPress:
case WebInputEvent::GesturePinchBegin:
case WebInputEvent::GesturePinchEnd:
case WebInputEvent::GesturePinchUpdate: {
PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
return mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent);
}
default:
ASSERT_NOT_REACHED();
}
return false;
}
void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters& parameters)
{
TRACE_EVENT0("webkit", "WebViewImpl::transferActiveWheelFlingAnimation");
ASSERT(!m_gestureAnimation);
m_lastWheelPosition = parameters.point;
m_lastWheelGlobalPosition = parameters.globalPoint;
m_flingModifier = parameters.modifiers;
OwnPtr<PlatformGestureCurve> curve = TouchpadFlingPlatformGestureCurve::create(parameters.delta, IntPoint(parameters.cumulativeScroll));
m_gestureAnimation = ActivePlatformGestureAnimation::create(curve.release(), this, parameters.startTime);
scheduleAnimation();
}
void WebViewImpl::startPageScaleAnimation(const IntPoint& scroll, bool useAnchor, float newScale, double durationSec)
{
if (!m_layerTreeView.isNull())
m_layerTreeView.startPageScaleAnimation(scroll, useAnchor, newScale, durationSec);
}
#endif
bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event)
{
ASSERT((event.type == WebInputEvent::RawKeyDown)
|| (event.type == WebInputEvent::KeyDown)
|| (event.type == WebInputEvent::KeyUp));
if (m_gestureAnimation)
m_gestureAnimation.clear();
m_suppressNextKeypressEvent = false;
if (m_selectPopup)
return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
#if ENABLE(PAGE_POPUP)
if (m_pagePopup) {
m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
if (WebInputEvent::RawKeyDown == event.type)
m_suppressNextKeypressEvent = true;
return true;
}
#endif
if (autocompleteHandleKeyEvent(event))
return true;
RefPtr<Frame> frame = focusedWebCoreFrame();
if (!frame)
return false;
EventHandler* handler = frame->eventHandler();
if (!handler)
return keyEventDefault(event);
#if !OS(DARWIN)
const WebInputEvent::Type contextMenuTriggeringEventType =
#if OS(WINDOWS)
WebInputEvent::KeyUp;
#elif OS(UNIX)
WebInputEvent::RawKeyDown;
#endif
bool isUnmodifiedMenuKey = !(event.modifiers & WebInputEvent::InputModifiers) && event.windowsKeyCode == VKEY_APPS;
bool isShiftF10 = event.modifiers == WebInputEvent::ShiftKey && event.windowsKeyCode == VKEY_F10;
if ((isUnmodifiedMenuKey || isShiftF10) && event.type == contextMenuTriggeringEventType) {
sendContextMenuEvent(event);
return true;
}
#endif // !OS(DARWIN)
PlatformKeyboardEventBuilder evt(event);
if (handler->keyEvent(evt)) {
if (WebInputEvent::RawKeyDown == event.type) {
Node* node = focusedWebCoreNode();
if (!node || !node->renderer() || !node->renderer()->isEmbeddedObject())
m_suppressNextKeypressEvent = true;
}
return true;
}
return keyEventDefault(event);
}
bool WebViewImpl::autocompleteHandleKeyEvent(const WebKeyboardEvent& event)
{
if (!m_autofillPopupShowing
|| event.windowsKeyCode == VKEY_HOME
|| event.windowsKeyCode == VKEY_END)
return false;
if (event.windowsKeyCode == VKEY_DELETE
&& m_autofillPopup->selectedIndex() != -1) {
Node* node = focusedWebCoreNode();
if (!node || (node->nodeType() != Node::ELEMENT_NODE)) {
ASSERT_NOT_REACHED();
return false;
}
Element* element = static_cast<Element*>(node);
if (!element->hasLocalName(HTMLNames::inputTag)) {
ASSERT_NOT_REACHED();
return false;
}
int selectedIndex = m_autofillPopup->selectedIndex();
if (!m_autofillPopupClient->canRemoveSuggestionAtIndex(selectedIndex))
return false;
WebString name = WebInputElement(static_cast<HTMLInputElement*>(element)).nameForAutofill();
WebString value = m_autofillPopupClient->itemText(selectedIndex);
m_autofillClient->removeAutocompleteSuggestion(name, value);
m_autofillPopupClient->removeSuggestionAtIndex(selectedIndex);
refreshAutofillPopup();
return false;
}
if (!m_autofillPopup->isInterestedInEventForKey(event.windowsKeyCode))
return false;
if (m_autofillPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event))) {
if (WebInputEvent::RawKeyDown == event.type)
m_suppressNextKeypressEvent = true;
return true;
}
return false;
}
bool WebViewImpl::handleCharEvent(const WebKeyboardEvent& event)
{
ASSERT(event.type == WebInputEvent::Char);
bool suppress = m_suppressNextKeypressEvent;
m_suppressNextKeypressEvent = false;
if (m_selectPopup)
return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
#if ENABLE(PAGE_POPUP)
if (m_pagePopup)
return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
#endif
Frame* frame = focusedWebCoreFrame();
if (!frame)
return suppress;
EventHandler* handler = frame->eventHandler();
if (!handler)
return suppress || keyEventDefault(event);
PlatformKeyboardEventBuilder evt(event);
if (!evt.isCharacterKey())
return true;
if (handler->handleAccessKey(evt))
return true;
if (evt.isSystemKey())
return false;
if (!suppress && !handler->keyEvent(evt))
return keyEventDefault(event);
return true;
}
#if ENABLE(GESTURE_EVENTS)
WebRect WebViewImpl::computeBlockBounds(const WebRect& rect, AutoZoomType zoomType)
{
if (!mainFrameImpl())
return WebRect();
IntPoint point = mainFrameImpl()->frameView()->windowToContents(IntPoint(rect.x, rect.y));
HitTestResult result = mainFrameImpl()->frame()->eventHandler()->hitTestResultAtPoint(point,
false, zoomType == FindInPage, DontHitTestScrollbars, HitTestRequest::Active | HitTestRequest::ReadOnly,
IntSize(rect.width, rect.height));
Node* node = result.innerNonSharedNode();
if (!node)
return WebRect();
while (node && (!node->renderer() || node->renderer()->isInline()))
node = node->parentNode();
if (node) {
IntRect rect = node->Node::getPixelSnappedRect();
Frame* frame = node->document()->frame();
return frame->view()->contentsToWindow(rect);
}
return WebRect();
}
WebRect WebViewImpl::widenRectWithinPageBounds(const WebRect& source, int targetMargin, int minimumMargin)
{
WebSize maxSize;
if (mainFrame())
maxSize = mainFrame()->contentsSize();
IntSize scrollOffset;
if (mainFrame())
scrollOffset = mainFrame()->scrollOffset();
int leftMargin = targetMargin;
int rightMargin = targetMargin;
const int absoluteSourceX = source.x + scrollOffset.width();
if (leftMargin > absoluteSourceX) {
leftMargin = absoluteSourceX;
rightMargin = max(leftMargin, minimumMargin);
}
const int maximumRightMargin = maxSize.width - (source.width + absoluteSourceX);
if (rightMargin > maximumRightMargin) {
rightMargin = maximumRightMargin;
leftMargin = min(leftMargin, max(rightMargin, minimumMargin));
}
const int newWidth = source.width + leftMargin + rightMargin;
const int newX = source.x - leftMargin;
ASSERT(newWidth >= 0);
ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width);
return WebRect(newX, source.y, newWidth, source.height);
}
void WebViewImpl::computeScaleAndScrollForHitRect(const WebRect& hitRect, AutoZoomType zoomType, float& scale, WebPoint& scroll)
{
scale = pageScaleFactor();
scroll.x = scroll.y = 0;
WebRect targetRect = hitRect;
if (targetRect.isEmpty())
targetRect.width = targetRect.height = touchPointPadding;
WebRect rect = computeBlockBounds(targetRect, zoomType);
const float overviewScale = m_minimumPageScaleFactor;
bool scaleUnchanged = true;
if (!rect.isEmpty()) {
const float maxScale = deviceScaleFactor();
const float defaultMargin = doubleTapZoomContentDefaultMargin * deviceScaleFactor();
const float minimumMargin = doubleTapZoomContentMinimumMargin * deviceScaleFactor();
rect = widenRectWithinPageBounds(rect,
static_cast<int>(defaultMargin * rect.width / m_size.width),
static_cast<int>(minimumMargin * rect.width / m_size.width));
scale *= static_cast<float>(m_size.width) / rect.width;
scale = min(scale, maxScale);
scale = clampPageScaleFactorToLimits(scale);
scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference;
}
if (zoomType == DoubleTap) {
if (rect.isEmpty() || scaleUnchanged) {
if (overviewScale)
scale = overviewScale;
return;
}
} else if (rect.isEmpty()) {
return;
}
float screenHeight = m_size.height / scale * pageScaleFactor();
float screenWidth = m_size.width / scale * pageScaleFactor();
if (rect.height < screenHeight) {
rect.y -= 0.5 * (screenHeight - rect.height);
} else {
rect.y = max<float>(rect.y, hitRect.y + touchPointPadding - screenHeight);
}
if (rect.width < screenWidth)
rect.x -= 0.5 * (screenWidth - rect.width);
else
rect.x = max<float>(rect.x, hitRect.x + touchPointPadding - screenWidth);
scroll.x = rect.x;
scroll.y = rect.y;
}
#endif
void WebViewImpl::numberOfWheelEventHandlersChanged(unsigned numberOfWheelHandlers)
{
if (m_client)
m_client->numberOfWheelEventHandlersChanged(numberOfWheelHandlers);
}
void WebViewImpl::numberOfTouchEventHandlersChanged(unsigned numberOfTouchHandlers)
{
if (m_client)
m_client->numberOfTouchEventHandlersChanged(numberOfTouchHandlers);
}
#if !OS(DARWIN)
bool WebViewImpl::sendContextMenuEvent(const WebKeyboardEvent& event)
{
page()->contextMenuController()->clearContextMenu();
m_contextMenuAllowed = true;
Frame* focusedFrame = page()->focusController()->focusedOrMainFrame();
bool handled = focusedFrame->eventHandler()->sendContextMenuEventForKey();
m_contextMenuAllowed = false;
return handled;
}
#endif
bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event)
{
Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
switch (event.type) {
case WebInputEvent::Char:
if (event.windowsKeyCode == VKEY_SPACE) {
int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR : VKEY_NEXT);
return scrollViewWithKeyboard(keyCode, event.modifiers);
}
break;
case WebInputEvent::RawKeyDown:
if (event.modifiers == WebInputEvent::ControlKey) {
switch (event.windowsKeyCode) {
#if !OS(DARWIN)
case 'A':
focusedFrame()->executeCommand(WebString::fromUTF8("SelectAll"));
return true;
case VKEY_INSERT:
case 'C':
focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
return true;
#endif
case VKEY_HOME:
case VKEY_END:
break;
default:
return false;
}
}
if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey))
return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers);
break;
default:
break;
}
return false;
}
bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers)
{
ScrollDirection scrollDirection;
ScrollGranularity scrollGranularity;
#if OS(DARWIN)
if (modifiers & WebMouseEvent::ControlKey) {
if (keyCode == VKEY_UP)
keyCode = VKEY_PRIOR;
else if (keyCode == VKEY_DOWN)
keyCode = VKEY_NEXT;
}
#endif
if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity))
return false;
return propagateScroll(scrollDirection, scrollGranularity);
}
bool WebViewImpl::mapKeyCodeForScroll(int keyCode,
WebCore::ScrollDirection* scrollDirection,
WebCore::ScrollGranularity* scrollGranularity)
{
switch (keyCode) {
case VKEY_LEFT:
*scrollDirection = ScrollLeft;
*scrollGranularity = ScrollByLine;
break;
case VKEY_RIGHT:
*scrollDirection = ScrollRight;
*scrollGranularity = ScrollByLine;
break;
case VKEY_UP:
*scrollDirection = ScrollUp;
*scrollGranularity = ScrollByLine;
break;
case VKEY_DOWN:
*scrollDirection = ScrollDown;
*scrollGranularity = ScrollByLine;
break;
case VKEY_HOME:
*scrollDirection = ScrollUp;
*scrollGranularity = ScrollByDocument;
break;
case VKEY_END:
*scrollDirection = ScrollDown;
*scrollGranularity = ScrollByDocument;
break;
case VKEY_PRIOR: *scrollDirection = ScrollUp;
*scrollGranularity = ScrollByPage;
break;
case VKEY_NEXT: *scrollDirection = ScrollDown;
*scrollGranularity = ScrollByPage;
break;
default:
return false;
}
return true;
}
void WebViewImpl::hideSelectPopup()
{
if (m_selectPopup)
m_selectPopup->hidePopup();
}
bool WebViewImpl::propagateScroll(ScrollDirection scrollDirection,
ScrollGranularity scrollGranularity)
{
Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
bool scrollHandled = frame->eventHandler()->scrollOverflow(scrollDirection, scrollGranularity);
Frame* currentFrame = frame;
while (!scrollHandled && currentFrame) {
scrollHandled = currentFrame->view()->scroll(scrollDirection, scrollGranularity);
currentFrame = currentFrame->tree()->parent();
}
return scrollHandled;
}
void WebViewImpl::popupOpened(WebCore::PopupContainer* popupContainer)
{
if (popupContainer->popupType() == WebCore::PopupContainer::Select) {
ASSERT(!m_selectPopup);
m_selectPopup = popupContainer;
}
}
void WebViewImpl::popupClosed(WebCore::PopupContainer* popupContainer)
{
if (popupContainer->popupType() == WebCore::PopupContainer::Select) {
ASSERT(m_selectPopup);
m_selectPopup = 0;
}
}
#if ENABLE(PAGE_POPUP)
PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView)
{
ASSERT(client);
if (hasOpenedPopup())
hidePopups();
ASSERT(!m_pagePopup);
WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage);
ASSERT(popupWidget);
m_pagePopup = static_cast<WebPagePopupImpl*>(popupWidget);
if (!m_pagePopup->init(this, client, originBoundsInRootView)) {
m_pagePopup->closePopup();
m_pagePopup = 0;
}
if (Frame* frame = focusedWebCoreFrame())
frame->selection()->setCaretVisible(false);
return m_pagePopup.get();
}
void WebViewImpl::closePagePopup(PagePopup* popup)
{
ASSERT(popup);
WebPagePopupImpl* popupImpl = static_cast<WebPagePopupImpl*>(popup);
ASSERT(m_pagePopup.get() == popupImpl);
if (m_pagePopup.get() != popupImpl)
return;
m_pagePopup->closePopup();
m_pagePopup = 0;
if (Frame* frame = focusedWebCoreFrame())
frame->selection()->pageActivationChanged();
}
#endif
void WebViewImpl::hideAutofillPopup()
{
if (m_autofillPopupShowing) {
m_autofillPopup->hidePopup();
m_autofillPopupShowing = false;
}
}
Frame* WebViewImpl::focusedWebCoreFrame() const
{
return m_page ? m_page->focusController()->focusedOrMainFrame() : 0;
}
WebViewImpl* WebViewImpl::fromPage(Page* page)
{
if (!page)
return 0;
ChromeClientImpl* chromeClient = static_cast<ChromeClientImpl*>(page->chrome()->client());
return static_cast<WebViewImpl*>(chromeClient->webView());
}
void WebViewImpl::close()
{
RefPtr<WebFrameImpl> mainFrameImpl;
if (m_page) {
if (m_page->mainFrame()) {
mainFrameImpl = WebFrameImpl::fromFrame(m_page->mainFrame());
m_page->mainFrame()->loader()->frameDetached();
}
m_page.clear();
}
if (m_devToolsAgent)
m_devToolsAgent.clear();
m_client = 0;
deref(); }
void WebViewImpl::willStartLiveResize()
{
if (mainFrameImpl() && mainFrameImpl()->frameView())
mainFrameImpl()->frameView()->willStartLiveResize();
Frame* frame = mainFrameImpl()->frame();
WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromFrame(frame);
if (pluginContainer)
pluginContainer->willStartLiveResize();
}
void WebViewImpl::resize(const WebSize& newSize)
{
if (m_shouldAutoResize || m_size == newSize)
return;
m_size = newSize;
WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
if (agentPrivate && agentPrivate->metricsOverridden())
agentPrivate->webViewResized();
else {
WebFrameImpl* webFrame = mainFrameImpl();
if (webFrame->frameView())
webFrame->frameView()->resize(newSize.width, newSize.height);
}
sendResizeEventAndRepaint();
}
void WebViewImpl::willEndLiveResize()
{
if (mainFrameImpl() && mainFrameImpl()->frameView())
mainFrameImpl()->frameView()->willEndLiveResize();
Frame* frame = mainFrameImpl()->frame();
WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromFrame(frame);
if (pluginContainer)
pluginContainer->willEndLiveResize();
}
void WebViewImpl::willEnterFullScreen()
{
#if ENABLE(FULLSCREEN_API)
if (!m_provisionalFullScreenElement)
return;
Document* doc = m_provisionalFullScreenElement->document();
if (doc->frame()) {
doc->webkitWillEnterFullScreenForElement(m_provisionalFullScreenElement.get());
m_fullScreenFrame = doc->frame();
}
m_provisionalFullScreenElement.clear();
#endif
}
void WebViewImpl::didEnterFullScreen()
{
#if ENABLE(FULLSCREEN_API)
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
if (doc->webkitIsFullScreen())
doc->webkitDidEnterFullScreenForElement(0);
}
#endif
}
void WebViewImpl::willExitFullScreen()
{
#if ENABLE(FULLSCREEN_API)
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
if (doc->webkitIsFullScreen()) {
m_isCancelingFullScreen = true;
doc->webkitCancelFullScreen();
m_isCancelingFullScreen = false;
doc->webkitWillExitFullScreenForElement(0);
}
}
#endif
}
void WebViewImpl::didExitFullScreen()
{
#if ENABLE(FULLSCREEN_API)
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
if (doc->webkitIsFullScreen())
doc->webkitDidExitFullScreenForElement(0);
}
m_fullScreenFrame.clear();
#endif
}
void WebViewImpl::instrumentBeginFrame()
{
InspectorInstrumentation::didBeginFrame(m_page.get());
}
void WebViewImpl::instrumentCancelFrame()
{
InspectorInstrumentation::didCancelFrame(m_page.get());
}
#if ENABLE(BATTERY_STATUS)
void WebViewImpl::updateBatteryStatus(const WebBatteryStatus& status)
{
m_batteryClient->updateBatteryStatus(status);
}
#endif
void WebViewImpl::setCompositorSurfaceReady()
{
m_compositorSurfaceReady = true;
if (!m_layerTreeView.isNull())
m_layerTreeView.setSurfaceReady();
}
void WebViewImpl::animate(double)
{
#if ENABLE(REQUEST_ANIMATION_FRAME)
double monotonicFrameBeginTime = monotonicallyIncreasingTime();
#if USE(ACCELERATED_COMPOSITING)
if (isAcceleratedCompositingActive())
m_layerTreeView.updateAnimations(monotonicFrameBeginTime);
else
#endif
updateAnimations(monotonicFrameBeginTime);
#endif
}
void WebViewImpl::willBeginFrame()
{
instrumentBeginFrame();
m_client->willBeginCompositorFrame();
}
void WebViewImpl::updateAnimations(double monotonicFrameBeginTime)
{
#if ENABLE(REQUEST_ANIMATION_FRAME)
TRACE_EVENT("WebViewImpl::updateAnimations", this, 0);
WebFrameImpl* webframe = mainFrameImpl();
if (!webframe)
return;
FrameView* view = webframe->frameView();
if (!view)
return;
if (m_gestureAnimation) {
if (m_gestureAnimation->animate(monotonicFrameBeginTime))
scheduleAnimation();
else
m_gestureAnimation.clear();
}
PageWidgetDelegate::animate(m_page.get(), monotonicFrameBeginTime);
#endif
}
void WebViewImpl::layout()
{
TRACE_EVENT("WebViewImpl::layout", this, 0);
PageWidgetDelegate::layout(m_page.get());
}
#if USE(ACCELERATED_COMPOSITING)
void WebViewImpl::doPixelReadbackToCanvas(WebCanvas* canvas, const IntRect& rect)
{
ASSERT(!m_layerTreeView.isNull());
#if USE(SKIA)
PlatformContextSkia context(canvas);
GraphicsContext gc(reinterpret_cast<PlatformGraphicsContext*>(&context));
int bitmapHeight = canvas->getDevice()->accessBitmap(false).height();
#elif USE(CG)
GraphicsContext gc(canvas);
int bitmapHeight = CGBitmapContextGetHeight(reinterpret_cast<CGContextRef>(canvas));
#else
notImplemented();
#endif
IntRect invertRect(rect.x(), bitmapHeight - rect.maxY(), rect.width(), rect.height());
OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(rect.size()));
RefPtr<Uint8ClampedArray> pixelArray(Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4));
if (imageBuffer && pixelArray) {
m_layerTreeView.compositeAndReadback(pixelArray->data(), invertRect);
imageBuffer->putByteArray(Premultiplied, pixelArray.get(), rect.size(), IntRect(IntPoint(), rect.size()), IntPoint());
gc.save();
gc.translate(IntSize(0, bitmapHeight));
gc.scale(FloatSize(1.0f, -1.0f));
gc.drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, invertRect.location());
gc.restore();
}
}
#endif
void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect)
{
if (isAcceleratedCompositingActive()) {
#if USE(ACCELERATED_COMPOSITING)
if (canvas) {
IntRect resizeRect(rect);
resizeRect.intersect(IntRect(IntPoint(0, 0), m_layerTreeView.viewportSize()));
doPixelReadbackToCanvas(canvas, resizeRect);
}
#endif
} else {
double paintStart = currentTime();
PageWidgetDelegate::paint(m_page.get(), pageOverlays(), canvas, rect);
double paintEnd = currentTime();
double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStart);
WebKit::Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
WebKit::Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
}
}
void WebViewImpl::themeChanged()
{
if (!page())
return;
FrameView* view = page()->mainFrame()->view();
WebRect damagedRect(0, 0, m_size.width, m_size.height);
view->invalidateRect(damagedRect);
}
void WebViewImpl::composite(bool)
{
#if USE(ACCELERATED_COMPOSITING)
if (CCProxy::hasImplThread())
m_layerTreeView.setNeedsRedraw();
else {
ASSERT(isAcceleratedCompositingActive());
if (!page())
return;
if (m_pageOverlays)
m_pageOverlays->update();
m_layerTreeView.composite();
}
#endif
}
void WebViewImpl::setNeedsRedraw()
{
#if USE(ACCELERATED_COMPOSITING)
if (!m_layerTreeView.isNull() && isAcceleratedCompositingActive())
m_layerTreeView.setNeedsRedraw();
#endif
}
bool WebViewImpl::isInputThrottled() const
{
#if USE(ACCELERATED_COMPOSITING)
if (!m_layerTreeView.isNull() && isAcceleratedCompositingActive())
return m_layerTreeView.commitRequested();
#endif
return false;
}
void WebViewImpl::loseCompositorContext(int numTimes)
{
#if USE(ACCELERATED_COMPOSITING)
if (!m_layerTreeView.isNull())
m_layerTreeView.loseCompositorContext(numTimes);
#endif
}
void WebViewImpl::enterFullScreenForElement(WebCore::Element* element)
{
if (m_provisionalFullScreenElement) {
m_provisionalFullScreenElement = element;
return;
}
if (m_fullScreenFrame) {
m_provisionalFullScreenElement = element;
willEnterFullScreen();
didEnterFullScreen();
return;
}
#if USE(NATIVE_FULLSCREEN_VIDEO)
if (element && element->isMediaElement()) {
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(element);
if (mediaElement->player() && mediaElement->player()->enterFullscreen())
m_provisionalFullScreenElement = element;
return;
}
#endif
if (m_client && m_client->enterFullScreen())
m_provisionalFullScreenElement = element;
}
void WebViewImpl::exitFullScreenForElement(WebCore::Element* element)
{
if (m_isCancelingFullScreen)
return;
#if USE(NATIVE_FULLSCREEN_VIDEO)
if (element && element->isMediaElement()) {
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(element);
if (mediaElement->player())
mediaElement->player()->exitFullscreen();
return;
}
#endif
if (m_client)
m_client->exitFullScreen();
}
bool WebViewImpl::hasHorizontalScrollbar()
{
return mainFrameImpl()->frameView()->horizontalScrollbar();
}
bool WebViewImpl::hasVerticalScrollbar()
{
return mainFrameImpl()->frameView()->verticalScrollbar();
}
const WebInputEvent* WebViewImpl::m_currentInputEvent = 0;
bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent)
{
UserGestureIndicator gestureIndicator(WebInputEvent::isUserGestureEventType(inputEvent.type) ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
if (m_doingDragAndDrop)
return true;
if (m_ignoreInputEvents)
return true;
m_currentInputEvent = &inputEvent;
#if ENABLE(POINTER_LOCK)
if (isPointerLocked() && WebInputEvent::isMouseEventType(inputEvent.type)) {
pointerLockMouseEvent(inputEvent);
return true;
}
#endif
if (m_mouseCaptureNode && WebInputEvent::isMouseEventType(inputEvent.type)) {
RefPtr<Node> node = m_mouseCaptureNode;
if (inputEvent.type == WebInputEvent::MouseUp)
mouseCaptureLost();
AtomicString eventType;
switch (inputEvent.type) {
case WebInputEvent::MouseMove:
eventType = eventNames().mousemoveEvent;
break;
case WebInputEvent::MouseLeave:
eventType = eventNames().mouseoutEvent;
break;
case WebInputEvent::MouseDown:
eventType = eventNames().mousedownEvent;
break;
case WebInputEvent::MouseUp:
eventType = eventNames().mouseupEvent;
break;
default:
ASSERT_NOT_REACHED();
}
node->dispatchMouseEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), *static_cast<const WebMouseEvent*>(&inputEvent)),
eventType, static_cast<const WebMouseEvent*>(&inputEvent)->clickCount);
m_currentInputEvent = 0;
return true;
}
bool handled = PageWidgetDelegate::handleInputEvent(m_page.get(), *this, inputEvent);
m_currentInputEvent = 0;
return handled;
}
void WebViewImpl::mouseCaptureLost()
{
m_mouseCaptureNode = 0;
}
void WebViewImpl::setFocus(bool enable)
{
m_page->focusController()->setFocused(enable);
if (enable) {
m_page->focusController()->setActive(true);
RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
if (focusedFrame) {
Node* focusedNode = focusedFrame->document()->focusedNode();
if (focusedNode && focusedNode->isElementNode()
&& focusedFrame->selection()->selection().isNone()) {
Element* element = static_cast<Element*>(focusedNode);
if (element->isTextFormControl())
element->updateFocusAppearance(true);
else if (focusedNode->isContentEditable()) {
Position position(focusedNode, 0,
Position::PositionIsOffsetInAnchor);
focusedFrame->selection()->setSelection(
VisibleSelection(position, SEL_DEFAULT_AFFINITY));
}
}
}
m_imeAcceptEvents = true;
} else {
hidePopups();
if (!m_page)
return;
Frame* frame = m_page->mainFrame();
if (!frame)
return;
RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
if (focusedFrame) {
Editor* editor = focusedFrame->editor();
if (editor && editor->hasComposition())
editor->confirmComposition();
m_imeAcceptEvents = false;
}
}
}
bool WebViewImpl::setComposition(
const WebString& text,
const WebVector<WebCompositionUnderline>& underlines,
int selectionStart,
int selectionEnd)
{
Frame* focused = focusedWebCoreFrame();
if (!focused || !m_imeAcceptEvents)
return false;
Editor* editor = focused->editor();
if (!editor)
return false;
if (!editor->canEdit() && !editor->hasComposition())
return false;
PassRefPtr<Range> range = editor->compositionRange();
if (range) {
Node* node = range->startContainer();
if (!node || !node->isContentEditable())
return false;
}
if (text.isEmpty() || m_suppressNextKeypressEvent) {
String emptyString;
Vector<CompositionUnderline> emptyUnderlines;
editor->setComposition(emptyString, emptyUnderlines, 0, 0);
return text.isEmpty();
}
editor->setComposition(String(text),
CompositionUnderlineVectorBuilder(underlines),
selectionStart, selectionEnd);
return editor->hasComposition();
}
bool WebViewImpl::confirmComposition()
{
return confirmComposition(WebString());
}
bool WebViewImpl::confirmComposition(const WebString& text)
{
Frame* focused = focusedWebCoreFrame();
if (!focused || !m_imeAcceptEvents)
return false;
Editor* editor = focused->editor();
if (!editor || (!editor->hasComposition() && !text.length()))
return false;
PassRefPtr<Range> range = editor->compositionRange();
if (range) {
Node* node = range->startContainer();
if (!node || !node->isContentEditable())
return false;
}
if (editor->hasComposition()) {
if (text.length())
editor->confirmComposition(String(text));
else
editor->confirmComposition();
} else
editor->insertText(String(text), 0);
return true;
}
bool WebViewImpl::compositionRange(size_t* location, size_t* length)
{
Frame* focused = focusedWebCoreFrame();
if (!focused || !focused->selection() || !m_imeAcceptEvents)
return false;
Editor* editor = focused->editor();
if (!editor || !editor->hasComposition())
return false;
RefPtr<Range> range = editor->compositionRange();
if (!range)
return false;
if (TextIterator::getLocationAndLengthFromRange(focused->selection()->rootEditableElementOrDocumentElement(), range.get(), *location, *length))
return true;
return false;
}
WebTextInputType WebViewImpl::textInputType()
{
Node* node = focusedWebCoreNode();
if (!node)
return WebTextInputTypeNone;
if (node->nodeType() == Node::ELEMENT_NODE) {
Element* element = static_cast<Element*>(node);
if (element->hasLocalName(HTMLNames::inputTag)) {
HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
if (input->readOnly() || input->disabled())
return WebTextInputTypeNone;
if (input->isPasswordField())
return WebTextInputTypePassword;
if (input->isSearchField())
return WebTextInputTypeSearch;
if (input->isEmailField())
return WebTextInputTypeEmail;
if (input->isNumberField())
return WebTextInputTypeNumber;
if (input->isTelephoneField())
return WebTextInputTypeTelephone;
if (input->isURLField())
return WebTextInputTypeURL;
if (input->isTextField())
return WebTextInputTypeText;
return WebTextInputTypeNone;
}
if (element->hasLocalName(HTMLNames::textareaTag)) {
HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(element);
if (textarea->readOnly() || textarea->disabled())
return WebTextInputTypeNone;
return WebTextInputTypeText;
}
}
if (node->shouldUseInputMethod())
return WebTextInputTypeText;
return WebTextInputTypeNone;
}
bool WebViewImpl::selectionBounds(WebRect& start, WebRect& end) const
{
const Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
FrameSelection* selection = frame->selection();
if (!selection)
return false;
if (selection->isCaret()) {
start = end = frame->view()->contentsToWindow(selection->absoluteCaretBounds());
return true;
}
RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange();
if (!selectedRange)
return false;
RefPtr<Range> range(Range::create(selectedRange->startContainer()->document(),
selectedRange->startContainer(),
selectedRange->startOffset(),
selectedRange->startContainer(),
selectedRange->startOffset()));
start = frame->editor()->firstRectForRange(range.get());
range = Range::create(selectedRange->endContainer()->document(),
selectedRange->endContainer(),
selectedRange->endOffset(),
selectedRange->endContainer(),
selectedRange->endOffset());
end = frame->editor()->firstRectForRange(range.get());
start = frame->view()->contentsToWindow(start);
end = frame->view()->contentsToWindow(end);
if (!frame->selection()->selection().isBaseFirst())
std::swap(start, end);
return true;
}
bool WebViewImpl::caretOrSelectionRange(size_t* location, size_t* length)
{
const Frame* focused = focusedWebCoreFrame();
if (!focused)
return false;
FrameSelection* selection = focused->selection();
if (!selection)
return false;
RefPtr<Range> range = selection->selection().firstRange();
if (!range)
return false;
if (TextIterator::getLocationAndLengthFromRange(selection->rootEditableElementOrDocumentElement(), range.get(), *location, *length))
return true;
return false;
}
void WebViewImpl::setTextDirection(WebTextDirection direction)
{
const Frame* focused = focusedWebCoreFrame();
if (!focused)
return;
Editor* editor = focused->editor();
if (!editor || !editor->canEdit())
return;
switch (direction) {
case WebTextDirectionDefault:
editor->setBaseWritingDirection(NaturalWritingDirection);
break;
case WebTextDirectionLeftToRight:
editor->setBaseWritingDirection(LeftToRightWritingDirection);
break;
case WebTextDirectionRightToLeft:
editor->setBaseWritingDirection(RightToLeftWritingDirection);
break;
default:
notImplemented();
break;
}
}
bool WebViewImpl::isAcceleratedCompositingActive() const
{
#if USE(ACCELERATED_COMPOSITING)
return m_isAcceleratedCompositingActive;
#else
return false;
#endif
}
void WebViewImpl::didAcquirePointerLock()
{
#if ENABLE(POINTER_LOCK)
if (page())
page()->pointerLockController()->didAcquirePointerLock();
#endif
}
void WebViewImpl::didNotAcquirePointerLock()
{
#if ENABLE(POINTER_LOCK)
if (page())
page()->pointerLockController()->didNotAcquirePointerLock();
#endif
}
void WebViewImpl::didLosePointerLock()
{
#if ENABLE(POINTER_LOCK)
if (page())
page()->pointerLockController()->didLosePointerLock();
#endif
}
void WebViewImpl::didChangeWindowResizerRect()
{
if (mainFrameImpl()->frameView())
mainFrameImpl()->frameView()->windowResizerRectChanged();
}
WebSettings* WebViewImpl::settings()
{
if (!m_webSettings)
m_webSettings = adoptPtr(new WebSettingsImpl(m_page->settings()));
ASSERT(m_webSettings);
return m_webSettings.get();
}
WebString WebViewImpl::pageEncoding() const
{
if (!m_page)
return WebString();
if (!m_page->mainFrame()->document()->loader())
return WebString();
return m_page->mainFrame()->document()->encoding();
}
void WebViewImpl::setPageEncoding(const WebString& encodingName)
{
if (!m_page)
return;
String newEncodingName;
if (!encodingName.isEmpty())
newEncodingName = encodingName;
m_page->mainFrame()->loader()->reloadWithOverrideEncoding(newEncodingName);
}
bool WebViewImpl::dispatchBeforeUnloadEvent()
{
Frame* frame = m_page->mainFrame();
if (!frame)
return true;
return frame->loader()->shouldClose();
}
void WebViewImpl::dispatchUnloadEvent()
{
m_page->mainFrame()->loader()->closeURL();
}
WebFrame* WebViewImpl::mainFrame()
{
return mainFrameImpl();
}
WebFrame* WebViewImpl::findFrameByName(
const WebString& name, WebFrame* relativeToFrame)
{
if (!relativeToFrame)
relativeToFrame = mainFrame();
Frame* frame = static_cast<WebFrameImpl*>(relativeToFrame)->frame();
frame = frame->tree()->find(name);
return WebFrameImpl::fromFrame(frame);
}
WebFrame* WebViewImpl::focusedFrame()
{
return WebFrameImpl::fromFrame(focusedWebCoreFrame());
}
void WebViewImpl::setFocusedFrame(WebFrame* frame)
{
if (!frame) {
Frame* frame = focusedWebCoreFrame();
if (frame)
frame->selection()->setFocused(false);
return;
}
WebFrameImpl* frameImpl = static_cast<WebFrameImpl*>(frame);
Frame* webcoreFrame = frameImpl->frame();
webcoreFrame->page()->focusController()->setFocusedFrame(webcoreFrame);
}
void WebViewImpl::setInitialFocus(bool reverse)
{
if (!m_page)
return;
WebKeyboardEvent keyboardEvent;
keyboardEvent.type = WebInputEvent::RawKeyDown;
if (reverse)
keyboardEvent.modifiers = WebInputEvent::ShiftKey;
keyboardEvent.windowsKeyCode = 0x09;
PlatformKeyboardEventBuilder platformEvent(keyboardEvent);
RefPtr<KeyboardEvent> webkitEvent = KeyboardEvent::create(platformEvent, 0);
Frame* frame = page()->focusController()->focusedOrMainFrame();
if (Document* document = frame->document())
document->setFocusedNode(0);
page()->focusController()->setInitialFocus(
reverse ? FocusDirectionBackward : FocusDirectionForward,
webkitEvent.get());
}
void WebViewImpl::clearFocusedNode()
{
RefPtr<Frame> frame = focusedWebCoreFrame();
if (!frame)
return;
RefPtr<Document> document = frame->document();
if (!document)
return;
RefPtr<Node> oldFocusedNode = document->focusedNode();
document->setFocusedNode(0);
if (!oldFocusedNode)
return;
if (oldFocusedNode->isContentEditable()
|| (oldFocusedNode->isElementNode()
&& static_cast<Element*>(oldFocusedNode.get())->isTextFormControl())) {
frame->selection()->clear();
}
}
void WebViewImpl::scrollFocusedNodeIntoView()
{
Node* focusedNode = focusedWebCoreNode();
if (focusedNode && focusedNode->isElementNode()) {
Element* elementNode = static_cast<Element*>(focusedNode);
elementNode->scrollIntoViewIfNeeded(true);
}
}
void WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rect)
{
Frame* frame = page()->mainFrame();
Node* focusedNode = focusedWebCoreNode();
if (!frame || !frame->view() || !focusedNode || !focusedNode->isElementNode())
return;
Element* elementNode = static_cast<Element*>(focusedNode);
frame->view()->scrollElementToRect(elementNode, IntRect(rect.x, rect.y, rect.width, rect.height));
}
double WebViewImpl::zoomLevel()
{
return m_zoomLevel;
}
double WebViewImpl::setZoomLevel(bool textOnly, double zoomLevel)
{
if (zoomLevel < m_minimumZoomLevel)
m_zoomLevel = m_minimumZoomLevel;
else if (zoomLevel > m_maximumZoomLevel)
m_zoomLevel = m_maximumZoomLevel;
else
m_zoomLevel = zoomLevel;
Frame* frame = mainFrameImpl()->frame();
WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromFrame(frame);
if (pluginContainer)
pluginContainer->plugin()->setZoomLevel(m_zoomLevel, textOnly);
else {
float zoomFactor = static_cast<float>(zoomLevelToZoomFactor(m_zoomLevel));
if (textOnly)
frame->setPageAndTextZoomFactors(1, zoomFactor * m_emulatedTextZoomFactor);
else
frame->setPageAndTextZoomFactors(zoomFactor, m_emulatedTextZoomFactor);
}
return m_zoomLevel;
}
void WebViewImpl::zoomLimitsChanged(double minimumZoomLevel,
double maximumZoomLevel)
{
m_minimumZoomLevel = minimumZoomLevel;
m_maximumZoomLevel = maximumZoomLevel;
m_client->zoomLimitsChanged(m_minimumZoomLevel, m_maximumZoomLevel);
}
void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel)
{
if (zoomLevel == m_zoomLevel)
return;
m_zoomLevel = max(min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel);
m_client->zoomLevelChanged();
}
double WebView::zoomLevelToZoomFactor(double zoomLevel)
{
return pow(textSizeMultiplierRatio, zoomLevel);
}
double WebView::zoomFactorToZoomLevel(double factor)
{
return log(factor) / log(textSizeMultiplierRatio);
}
float WebViewImpl::pageScaleFactor() const
{
if (!page())
return 1;
return page()->pageScaleFactor();
}
bool WebViewImpl::isPageScaleFactorSet() const
{
return m_pageScaleFactorIsSet;
}
float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor)
{
return min(max(scaleFactor, m_minimumPageScaleFactor), m_maximumPageScaleFactor);
}
WebPoint WebViewImpl::clampOffsetAtScale(const WebPoint& offset, float scale)
{
WebSize contentSize = mainFrame()->contentsSize();
float deltaScale = scale / pageScaleFactor();
int docWidthAtNewScale = contentSize.width * deltaScale;
int docHeightAtNewScale = contentSize.height * deltaScale;
int viewWidth = m_size.width;
int viewHeight = m_size.height;
IntPoint clampedOffset = offset;
clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
clampedOffset.clampNegativeToZero();
return clampedOffset;
}
void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
{
scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
IntPoint scrollOffsetAtNewScale(mainFrame()->scrollOffset().width, mainFrame()->scrollOffset().height);
float deltaScale = scaleFactor / pageScaleFactor();
scrollOffsetAtNewScale.scale(deltaScale, deltaScale);
WebPoint clampedOffsetAtNewScale = clampOffsetAtScale(scrollOffsetAtNewScale, scaleFactor);
setPageScaleFactor(scaleFactor, clampedOffsetAtNewScale);
}
void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin)
{
if (!page())
return;
if (!scaleFactor)
scaleFactor = 1;
scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
WebPoint clampedOrigin = clampOffsetAtScale(origin, scaleFactor);
page()->setPageScaleFactor(scaleFactor, clampedOrigin);
m_pageScaleFactorIsSet = true;
}
float WebViewImpl::deviceScaleFactor() const
{
if (!page())
return 1;
return page()->deviceScaleFactor();
}
void WebViewImpl::setDeviceScaleFactor(float scaleFactor)
{
if (!page())
return;
page()->setDeviceScaleFactor(scaleFactor);
}
bool WebViewImpl::isFixedLayoutModeEnabled() const
{
if (!page())
return false;
Frame* frame = page()->mainFrame();
if (!frame || !frame->view())
return false;
return frame->view()->useFixedLayout();
}
void WebViewImpl::enableFixedLayoutMode(bool enable)
{
if (!page())
return;
Frame* frame = page()->mainFrame();
if (!frame || !frame->view())
return;
frame->view()->setUseFixedLayout(enable);
#if USE(ACCELERATED_COMPOSITING)
if (m_nonCompositedContentHost) {
m_nonCompositedContentHost->topLevelRootLayer()->deviceOrPageScaleFactorChanged();
updateLayerTreeViewport();
}
#endif
}
void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& maxSize)
{
m_shouldAutoResize = true;
m_minAutoSize = minSize;
m_maxAutoSize = maxSize;
configureAutoResizeMode();
}
void WebViewImpl::disableAutoResizeMode()
{
m_shouldAutoResize = false;
configureAutoResizeMode();
}
void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScale)
{
m_pageDefinedMinimumPageScaleFactor = minPageScale;
m_pageDefinedMaximumPageScaleFactor = maxPageScale;
computePageScaleFactorLimits();
}
bool WebViewImpl::computePageScaleFactorLimits()
{
if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageScaleFactor == -1)
return false;
if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()->view())
return false;
m_minimumPageScaleFactor = min(max(m_pageDefinedMinimumPageScaleFactor, minPageScaleFactor), maxPageScaleFactor) * deviceScaleFactor();
m_maximumPageScaleFactor = max(min(m_pageDefinedMaximumPageScaleFactor, maxPageScaleFactor), minPageScaleFactor) * deviceScaleFactor();
int viewWidthNotIncludingScrollbars = page()->mainFrame()->view()->visibleContentRect(false).width();
int contentsWidth = mainFrame()->contentsSize().width;
if (viewWidthNotIncludingScrollbars && contentsWidth) {
int unscaledContentWidth = contentsWidth / pageScaleFactor();
m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / unscaledContentWidth);
m_maximumPageScaleFactor = max(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
}
ASSERT(m_minimumPageScaleFactor <= m_maximumPageScaleFactor);
float clampedScale = clampPageScaleFactorToLimits(pageScaleFactor());
#if USE(ACCELERATED_COMPOSITING)
if (!m_layerTreeView.isNull())
m_layerTreeView.setPageScaleFactorAndLimits(clampedScale, m_minimumPageScaleFactor, m_maximumPageScaleFactor);
#endif
if (clampedScale != pageScaleFactor()) {
setPageScaleFactorPreservingScrollOffset(clampedScale);
return true;
}
return false;
}
float WebViewImpl::minimumPageScaleFactor() const
{
return m_minimumPageScaleFactor;
}
float WebViewImpl::maximumPageScaleFactor() const
{
return m_maximumPageScaleFactor;
}
WebSize WebViewImpl::fixedLayoutSize() const
{
if (!page())
return WebSize();
Frame* frame = page()->mainFrame();
if (!frame || !frame->view())
return WebSize();
return frame->view()->fixedLayoutSize();
}
void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize)
{
if (!page())
return;
Frame* frame = page()->mainFrame();
if (!frame || !frame->view())
return;
frame->view()->setFixedLayoutSize(layoutSize);
}
void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action,
const WebPoint& location)
{
HitTestResult result = hitTestResultForWindowPos(location);
RefPtr<Node> node = result.innerNonSharedNode();
if (!node->hasTagName(HTMLNames::videoTag) && !node->hasTagName(HTMLNames::audioTag))
return;
RefPtr<HTMLMediaElement> mediaElement =
static_pointer_cast<HTMLMediaElement>(node);
switch (action.type) {
case WebMediaPlayerAction::Play:
if (action.enable)
mediaElement->play();
else
mediaElement->pause();
break;
case WebMediaPlayerAction::Mute:
mediaElement->setMuted(action.enable);
break;
case WebMediaPlayerAction::Loop:
mediaElement->setLoop(action.enable);
break;
case WebMediaPlayerAction::Controls:
mediaElement->setControls(action.enable);
break;
default:
ASSERT_NOT_REACHED();
}
}
void WebViewImpl::performPluginAction(const WebPluginAction& action,
const WebPoint& location)
{
HitTestResult result = hitTestResultForWindowPos(location);
RefPtr<Node> node = result.innerNonSharedNode();
if (!node->hasTagName(HTMLNames::objectTag) && !node->hasTagName(HTMLNames::embedTag))
return;
RenderObject* object = node->renderer();
if (object && object->isWidget()) {
Widget* widget = toRenderWidget(object)->widget();
if (widget && widget->isPluginContainer()) {
WebPluginContainerImpl* plugin = static_cast<WebPluginContainerImpl*>(widget);
switch (action.type) {
case WebPluginAction::Rotate90Clockwise:
plugin->plugin()->rotateView(WebPlugin::RotationType90Clockwise);
break;
case WebPluginAction::Rotate90Counterclockwise:
plugin->plugin()->rotateView(WebPlugin::RotationType90Counterclockwise);
break;
default:
ASSERT_NOT_REACHED();
}
}
}
}
void WebViewImpl::copyImageAt(const WebPoint& point)
{
if (!m_page)
return;
HitTestResult result = hitTestResultForWindowPos(point);
if (result.absoluteImageURL().isEmpty()) {
return;
}
m_page->mainFrame()->editor()->copyImage(result);
}
void WebViewImpl::dragSourceEndedAt(
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperation operation)
{
PlatformMouseEvent pme(clientPoint,
screenPoint,
LeftButton, PlatformEvent::MouseMoved, 0, false, false, false,
false, 0);
m_page->mainFrame()->eventHandler()->dragSourceEndedAt(pme,
static_cast<DragOperation>(operation));
m_dragScrollTimer->stop();
}
void WebViewImpl::dragSourceMovedTo(
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperation operation)
{
m_dragScrollTimer->triggerScroll(mainFrameImpl()->frameView(), clientPoint);
}
void WebViewImpl::dragSourceSystemDragEnded()
{
if (m_doingDragAndDrop) {
m_page->dragController()->dragEnded();
m_doingDragAndDrop = false;
}
}
WebDragOperation WebViewImpl::dragTargetDragEnter(
const WebDragData& webDragData,
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperationsMask operationsAllowed)
{
ASSERT(!m_currentDragData);
m_currentDragData = webDragData;
m_operationsAllowed = operationsAllowed;
return dragTargetDragEnterOrOver(clientPoint, screenPoint, DragEnter);
}
WebDragOperation WebViewImpl::dragTargetDragOver(
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperationsMask operationsAllowed)
{
m_operationsAllowed = operationsAllowed;
return dragTargetDragEnterOrOver(clientPoint, screenPoint, DragOver);
}
void WebViewImpl::dragTargetDragLeave()
{
ASSERT(m_currentDragData);
DragData dragData(
m_currentDragData.get(),
IntPoint(),
IntPoint(),
static_cast<DragOperation>(m_operationsAllowed));
m_page->dragController()->dragExited(&dragData);
m_dragOperation = WebDragOperationNone;
m_currentDragData = 0;
}
void WebViewImpl::dragTargetDrop(const WebPoint& clientPoint,
const WebPoint& screenPoint)
{
ASSERT(m_currentDragData);
if (m_dragOperation == WebDragOperationNone) { dragTargetDragLeave();
return;
}
DragData dragData(
m_currentDragData.get(),
clientPoint,
screenPoint,
static_cast<DragOperation>(m_operationsAllowed));
m_page->dragController()->performDrag(&dragData);
m_dragOperation = WebDragOperationNone;
m_currentDragData = 0;
m_dragScrollTimer->stop();
}
WebDragOperation WebViewImpl::dragTargetDragEnterOrOver(const WebPoint& clientPoint, const WebPoint& screenPoint, DragAction dragAction)
{
ASSERT(m_currentDragData);
DragData dragData(
m_currentDragData.get(),
clientPoint,
screenPoint,
static_cast<DragOperation>(m_operationsAllowed));
DragSession dragSession;
if (dragAction == DragEnter)
dragSession = m_page->dragController()->dragEntered(&dragData);
else
dragSession = m_page->dragController()->dragUpdated(&dragData);
DragOperation dropEffect = dragSession.operation;
if (!(dropEffect & dragData.draggingSourceOperationMask()))
dropEffect = DragOperationNone;
m_dragOperation = static_cast<WebDragOperation>(dropEffect);
if (dragAction == DragOver)
m_dragScrollTimer->triggerScroll(mainFrameImpl()->frameView(), clientPoint);
else
m_dragScrollTimer->stop();
return m_dragOperation;
}
void WebViewImpl::sendResizeEventAndRepaint()
{
if (mainFrameImpl()->frameView()) {
mainFrameImpl()->frame()->eventHandler()->sendResizeEvent();
}
if (m_client) {
if (isAcceleratedCompositingActive()) {
#if USE(ACCELERATED_COMPOSITING)
updateLayerTreeViewport();
#endif
} else {
WebRect damagedRect(0, 0, m_size.width, m_size.height);
m_client->didInvalidateRect(damagedRect);
}
}
}
void WebViewImpl::configureAutoResizeMode()
{
if (!mainFrameImpl() || !mainFrameImpl()->frame() || !mainFrameImpl()->frame()->view())
return;
mainFrameImpl()->frame()->view()->enableAutoSizeMode(m_shouldAutoResize, m_minAutoSize, m_maxAutoSize);
}
unsigned long WebViewImpl::createUniqueIdentifierForRequest()
{
if (m_page)
return m_page->progress()->createUniqueIdentifier();
return 0;
}
void WebViewImpl::inspectElementAt(const WebPoint& point)
{
if (!m_page)
return;
if (point.x == -1 || point.y == -1)
m_page->inspectorController()->inspect(0);
else {
HitTestResult result = hitTestResultForWindowPos(point);
if (!result.innerNonSharedNode())
return;
m_page->inspectorController()->inspect(result.innerNonSharedNode());
}
}
WebString WebViewImpl::inspectorSettings() const
{
return m_inspectorSettings;
}
void WebViewImpl::setInspectorSettings(const WebString& settings)
{
m_inspectorSettings = settings;
}
bool WebViewImpl::inspectorSetting(const WebString& key, WebString* value) const
{
if (!m_inspectorSettingsMap->contains(key))
return false;
*value = m_inspectorSettingsMap->get(key);
return true;
}
void WebViewImpl::setInspectorSetting(const WebString& key,
const WebString& value)
{
m_inspectorSettingsMap->set(key, value);
client()->didUpdateInspectorSetting(key, value);
}
WebDevToolsAgent* WebViewImpl::devToolsAgent()
{
return m_devToolsAgent.get();
}
WebAccessibilityObject WebViewImpl::accessibilityObject()
{
if (!mainFrameImpl())
return WebAccessibilityObject();
Document* document = mainFrameImpl()->frame()->document();
return WebAccessibilityObject(
document->axObjectCache()->getOrCreate(document->renderer()));
}
void WebViewImpl::applyAutofillSuggestions(
const WebNode& node,
const WebVector<WebString>& names,
const WebVector<WebString>& labels,
const WebVector<WebString>& icons,
const WebVector<int>& itemIDs,
int separatorIndex)
{
ASSERT(names.size() == labels.size());
ASSERT(names.size() == itemIDs.size());
if (names.isEmpty()) {
hideAutofillPopup();
return;
}
RefPtr<Node> focusedNode = focusedWebCoreNode();
if (!focusedNode || focusedNode != PassRefPtr<Node>(node)) {
hideAutofillPopup();
return;
}
HTMLInputElement* inputElem = focusedNode->toInputElement();
ASSERT(inputElem);
if (!m_autofillPopupClient)
m_autofillPopupClient = adoptPtr(new AutofillPopupMenuClient);
m_autofillPopupClient->initialize(
inputElem, names, labels, icons, itemIDs, separatorIndex);
if (!m_autofillPopup) {
PopupContainerSettings popupSettings = autofillPopupSettings;
popupSettings.defaultDeviceScaleFactor =
m_page->settings()->defaultDeviceScaleFactor();
if (!popupSettings.defaultDeviceScaleFactor)
popupSettings.defaultDeviceScaleFactor = 1;
m_autofillPopup = PopupContainer::create(m_autofillPopupClient.get(),
PopupContainer::Suggestion,
popupSettings);
}
if (m_autofillPopupShowing) {
refreshAutofillPopup();
} else {
m_autofillPopupShowing = true;
m_autofillPopup->showInRect(focusedNode->getPixelSnappedRect(), focusedNode->ownerDocument()->view(), 0);
}
}
void WebViewImpl::hidePopups()
{
hideSelectPopup();
hideAutofillPopup();
#if ENABLE(PAGE_POPUP)
if (m_pagePopup)
closePagePopup(m_pagePopup.get());
#endif
}
void WebViewImpl::performCustomContextMenuAction(unsigned action)
{
if (!m_page)
return;
ContextMenu* menu = m_page->contextMenuController()->contextMenu();
if (!menu)
return;
ContextMenuItem* item = menu->itemWithAction(static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + action));
if (item)
m_page->contextMenuController()->contextMenuItemSelected(item);
m_page->contextMenuController()->clearContextMenu();
}
void WebViewImpl::setIsTransparent(bool isTransparent)
{
Frame* frame = m_page->mainFrame();
while (frame) {
frame->view()->setTransparent(isTransparent);
frame = frame->tree()->traverseNext();
}
m_isTransparent = isTransparent;
}
bool WebViewImpl::isTransparent() const
{
return m_isTransparent;
}
void WebViewImpl::setIsActive(bool active)
{
if (page() && page()->focusController())
page()->focusController()->setActive(active);
}
bool WebViewImpl::isActive() const
{
return (page() && page()->focusController()) ? page()->focusController()->isActive() : false;
}
void WebViewImpl::setDomainRelaxationForbidden(bool forbidden, const WebString& scheme)
{
SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String(scheme));
}
void WebViewImpl::setScrollbarColors(unsigned inactiveColor,
unsigned activeColor,
unsigned trackColor) {
#if OS(UNIX) && !OS(DARWIN) && !OS(ANDROID)
PlatformThemeChromiumLinux::setScrollbarColors(inactiveColor, activeColor, trackColor);
#endif
}
void WebViewImpl::setSelectionColors(unsigned activeBackgroundColor,
unsigned activeForegroundColor,
unsigned inactiveBackgroundColor,
unsigned inactiveForegroundColor) {
#if OS(UNIX) && !OS(DARWIN) && !OS(ANDROID)
RenderThemeChromiumLinux::setSelectionColors(activeBackgroundColor,
activeForegroundColor,
inactiveBackgroundColor,
inactiveForegroundColor);
theme()->platformColorsDidChange();
#endif
}
void WebView::addUserScript(const WebString& sourceCode,
const WebVector<WebString>& patternsIn,
WebView::UserScriptInjectAt injectAt,
WebView::UserContentInjectIn injectIn)
{
OwnPtr<Vector<String> > patterns = adoptPtr(new Vector<String>);
for (size_t i = 0; i < patternsIn.size(); ++i)
patterns->append(patternsIn[i]);
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
pageGroup->addUserScriptToWorld(world.get(), sourceCode, WebURL(), patterns.release(), nullptr,
static_cast<UserScriptInjectionTime>(injectAt),
static_cast<UserContentInjectedFrames>(injectIn));
}
void WebView::addUserStyleSheet(const WebString& sourceCode,
const WebVector<WebString>& patternsIn,
WebView::UserContentInjectIn injectIn,
WebView::UserStyleInjectionTime injectionTime)
{
OwnPtr<Vector<String> > patterns = adoptPtr(new Vector<String>);
for (size_t i = 0; i < patternsIn.size(); ++i)
patterns->append(patternsIn[i]);
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns.release(), nullptr,
static_cast<UserContentInjectedFrames>(injectIn),
UserStyleAuthorLevel,
static_cast<WebCore::UserStyleInjectionTime>(injectionTime));
}
void WebView::removeAllUserContent()
{
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
pageGroup->removeAllUserContent();
}
void WebViewImpl::didCommitLoad(bool* isNewNavigation, bool isNavigationWithinPage)
{
if (isNewNavigation)
*isNewNavigation = m_observedNewNavigation;
#ifndef NDEBUG
ASSERT(!m_observedNewNavigation
|| m_page->mainFrame()->loader()->documentLoader() == m_newNavigationLoader);
m_newNavigationLoader = 0;
#endif
m_observedNewNavigation = false;
if (!isNavigationWithinPage)
m_pageScaleFactorIsSet = false;
m_gestureAnimation.clear();
}
void WebViewImpl::layoutUpdated(WebFrameImpl* webframe)
{
if (!m_client || webframe != mainFrameImpl())
return;
if (m_shouldAutoResize && mainFrameImpl()->frame() && mainFrameImpl()->frame()->view()) {
WebSize frameSize = mainFrameImpl()->frame()->view()->frameRect().size();
if (frameSize != m_size) {
m_size = frameSize;
m_client->didAutoResize(m_size);
sendResizeEventAndRepaint();
}
}
m_client->didUpdateLayout();
}
void WebViewImpl::didChangeContentsSize()
{
bool didClampScale = computePageScaleFactorLimits();
if (!didClampScale)
return;
if (!mainFrameImpl())
return;
FrameView* view = mainFrameImpl()->frameView();
if (view && view->needsLayout())
view->layout();
}
bool WebViewImpl::useExternalPopupMenus()
{
return shouldUseExternalPopupMenus;
}
void WebViewImpl::setEmulatedTextZoomFactor(float textZoomFactor)
{
m_emulatedTextZoomFactor = textZoomFactor;
Frame* frame = mainFrameImpl()->frame();
if (frame)
frame->setPageAndTextZoomFactors(frame->pageZoomFactor(), m_emulatedTextZoomFactor);
}
bool WebViewImpl::navigationPolicyFromMouseEvent(unsigned short button,
bool ctrl, bool shift,
bool alt, bool meta,
WebNavigationPolicy* policy)
{
#if OS(DARWIN)
const bool newTabModifier = (button == 1) || meta;
#else
const bool newTabModifier = (button == 1) || ctrl;
#endif
if (!newTabModifier && !shift && !alt)
return false;
ASSERT(policy);
if (newTabModifier) {
if (shift)
*policy = WebNavigationPolicyNewForegroundTab;
else
*policy = WebNavigationPolicyNewBackgroundTab;
} else {
if (shift)
*policy = WebNavigationPolicyNewWindow;
else
*policy = WebNavigationPolicyDownload;
}
return true;
}
void WebViewImpl::startDragging(const WebDragData& dragData,
WebDragOperationsMask mask,
const WebImage& dragImage,
const WebPoint& dragImageOffset)
{
if (!m_client)
return;
ASSERT(!m_doingDragAndDrop);
m_doingDragAndDrop = true;
m_client->startDragging(dragData, mask, dragImage, dragImageOffset);
}
void WebViewImpl::observeNewNavigation()
{
m_observedNewNavigation = true;
#ifndef NDEBUG
m_newNavigationLoader = m_page->mainFrame()->loader()->documentLoader();
#endif
}
void WebViewImpl::setIgnoreInputEvents(bool newValue)
{
ASSERT(m_ignoreInputEvents != newValue);
m_ignoreInputEvents = newValue;
}
void WebViewImpl::addPageOverlay(WebPageOverlay* overlay, int zOrder)
{
if (!m_pageOverlays)
m_pageOverlays = PageOverlayList::create(this);
m_pageOverlays->add(overlay, zOrder);
}
void WebViewImpl::removePageOverlay(WebPageOverlay* overlay)
{
if (m_pageOverlays && m_pageOverlays->remove(overlay) && m_pageOverlays->empty())
m_pageOverlays = nullptr;
}
void WebViewImpl::setOverlayLayer(WebCore::GraphicsLayer* layer)
{
if (m_rootGraphicsLayer) {
if (layer->parent() != m_rootGraphicsLayer)
m_rootGraphicsLayer->addChild(layer);
}
}
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
NotificationPresenterImpl* WebViewImpl::notificationPresenterImpl()
{
if (!m_notificationPresenter.isInitialized() && m_client)
m_notificationPresenter.initialize(m_client->notificationPresenter());
return &m_notificationPresenter;
}
#endif
void WebViewImpl::refreshAutofillPopup()
{
ASSERT(m_autofillPopupShowing);
if (!m_autofillPopupClient->listSize()) {
hideAutofillPopup();
return;
}
WebRect newWidgetRect = m_autofillPopup->refresh(focusedWebCoreNode()->getPixelSnappedRect());
WebPopupMenuImpl* popupMenu = static_cast<WebPopupMenuImpl*>(m_autofillPopup->client());
if (popupMenu && popupMenu->client()->windowRect() != newWidgetRect)
popupMenu->client()->setWindowRect(newWidgetRect);
}
Node* WebViewImpl::focusedWebCoreNode()
{
Frame* frame = m_page->focusController()->focusedFrame();
if (!frame)
return 0;
Document* document = frame->document();
if (!document)
return 0;
return document->focusedNode();
}
HitTestResult WebViewImpl::hitTestResultForWindowPos(const IntPoint& pos)
{
IntPoint docPoint(m_page->mainFrame()->view()->windowToContents(pos));
return m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(docPoint, false);
}
void WebViewImpl::setTabsToLinks(bool enable)
{
m_tabsToLinks = enable;
}
bool WebViewImpl::tabsToLinks() const
{
return m_tabsToLinks;
}
#if USE(ACCELERATED_COMPOSITING)
bool WebViewImpl::allowsAcceleratedCompositing()
{
return !m_compositorCreationFailed;
}
bool WebViewImpl::pageHasRTLStyle() const
{
if (!page())
return false;
Document* document = page()->mainFrame()->document();
if (!document)
return false;
RenderView* renderView = document->renderView();
if (!renderView)
return false;
RenderStyle* style = renderView->style();
if (!style)
return false;
return (style->direction() == RTL);
}
void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* layer)
{
m_rootGraphicsLayer = layer;
setIsAcceleratedCompositingActive(layer);
if (m_nonCompositedContentHost) {
GraphicsLayer* scrollLayer = 0;
if (layer) {
Document* document = page()->mainFrame()->document();
RenderView* renderView = document->renderView();
RenderLayerCompositor* compositor = renderView->compositor();
scrollLayer = compositor->scrollLayer();
}
m_nonCompositedContentHost->setScrollLayer(scrollLayer);
}
if (layer)
m_rootLayer = WebLayer(layer->platformLayer());
if (!m_layerTreeView.isNull())
m_layerTreeView.setRootLayer(layer ? &m_rootLayer : 0);
IntRect damagedRect(0, 0, m_size.width, m_size.height);
if (!m_isAcceleratedCompositingActive)
m_client->didInvalidateRect(damagedRect);
}
void WebViewImpl::scheduleCompositingLayerSync()
{
m_layerTreeView.setNeedsRedraw();
}
void WebViewImpl::scrollRootLayerRect(const IntSize&, const IntRect&)
{
updateLayerTreeViewport();
}
void WebViewImpl::invalidateRootLayerRect(const IntRect& rect)
{
ASSERT(!m_layerTreeView.isNull());
if (!page())
return;
FrameView* view = page()->mainFrame()->view();
IntRect dirtyRect = view->windowToContents(rect);
updateLayerTreeViewport();
m_nonCompositedContentHost->invalidateRect(dirtyRect);
}
NonCompositedContentHost* WebViewImpl::nonCompositedContentHost()
{
return m_nonCompositedContentHost.get();
}
void WebViewImpl::setBackgroundColor(const WebCore::Color& color)
{
WebCore::Color documentBackgroundColor = color.isValid() ? color : WebCore::Color::white;
WebColor webDocumentBackgroundColor = documentBackgroundColor.rgb();
m_nonCompositedContentHost->setBackgroundColor(documentBackgroundColor);
m_layerTreeView.setBackgroundColor(webDocumentBackgroundColor);
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
void WebViewImpl::scheduleAnimation()
{
if (isAcceleratedCompositingActive()) {
if (CCProxy::hasImplThread()) {
ASSERT(!m_layerTreeView.isNull());
m_layerTreeView.setNeedsAnimate();
} else
m_client->scheduleAnimation();
} else
m_client->scheduleAnimation();
}
#endif
class WebViewImplContentPainter : public LayerPainterChromium {
WTF_MAKE_NONCOPYABLE(WebViewImplContentPainter);
public:
static PassOwnPtr<WebViewImplContentPainter*> create(WebViewImpl* webViewImpl)
{
return adoptPtr(new WebViewImplContentPainter(webViewImpl));
}
virtual void paint(GraphicsContext& context, const IntRect& contentRect)
{
double paintStart = currentTime();
Page* page = m_webViewImpl->page();
if (!page)
return;
FrameView* view = page->mainFrame()->view();
view->paintContents(&context, contentRect);
double paintEnd = currentTime();
double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelRootPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelRootPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
m_webViewImpl->setBackgroundColor(view->documentBackgroundColor());
}
private:
explicit WebViewImplContentPainter(WebViewImpl* webViewImpl)
: m_webViewImpl(webViewImpl)
{
}
WebViewImpl* m_webViewImpl;
};
void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
{
WebKit::Platform::current()->histogramEnumeration("GPU.setIsAcceleratedCompositingActive", active * 2 + m_isAcceleratedCompositingActive, 4);
if (m_isAcceleratedCompositingActive == active)
return;
if (!active) {
m_isAcceleratedCompositingActive = false;
if (!m_layerTreeView.isNull())
m_layerTreeView.finishAllRendering();
m_client->didDeactivateCompositor();
} else if (!m_layerTreeView.isNull()) {
m_isAcceleratedCompositingActive = true;
updateLayerTreeViewport();
m_client->didActivateCompositor(m_layerTreeView.compositorIdentifier());
} else {
TRACE_EVENT("WebViewImpl::setIsAcceleratedCompositingActive(true)", this, 0);
WebLayerTreeView::Settings layerTreeViewSettings;
layerTreeViewSettings.acceleratePainting = page()->settings()->acceleratedDrawingEnabled();
layerTreeViewSettings.showFPSCounter = settings()->showFPSCounter();
layerTreeViewSettings.showPlatformLayerTree = settings()->showPlatformLayerTree();
layerTreeViewSettings.perTilePainting = page()->settings()->perTileDrawingEnabled();
layerTreeViewSettings.partialSwapEnabled = page()->settings()->partialSwapEnabled();
layerTreeViewSettings.threadedAnimationEnabled = page()->settings()->threadedAnimationEnabled();
m_nonCompositedContentHost = NonCompositedContentHost::create(WebViewImplContentPainter::create(this));
m_nonCompositedContentHost->setShowDebugBorders(page()->settings()->showDebugBorders());
m_layerTreeView.initialize(this, m_rootLayer, layerTreeViewSettings);
if (!m_layerTreeView.isNull()) {
m_layerTreeView.setPageScaleFactorAndLimits(pageScaleFactor(), m_minimumPageScaleFactor, m_maximumPageScaleFactor);
if (m_compositorSurfaceReady)
m_layerTreeView.setSurfaceReady();
updateLayerTreeViewport();
m_client->didActivateCompositor(m_layerTreeView.compositorIdentifier());
m_isAcceleratedCompositingActive = true;
m_compositorCreationFailed = false;
if (m_pageOverlays)
m_pageOverlays->update();
} else {
m_nonCompositedContentHost.clear();
m_isAcceleratedCompositingActive = false;
m_client->didDeactivateCompositor();
m_compositorCreationFailed = true;
}
}
if (page())
page()->mainFrame()->view()->setClipsRepaints(!m_isAcceleratedCompositingActive);
}
#endif
PassOwnPtr<WebKit::WebGraphicsContext3D> WebViewImpl::createCompositorGraphicsContext3D()
{
WebKit::WebGraphicsContext3D::Attributes attributes;
attributes.antialias = false;
attributes.shareResources = true;
OwnPtr<WebGraphicsContext3D> webContext = adoptPtr(client()->createGraphicsContext3D(attributes));
if (!webContext)
return nullptr;
return webContext.release();
}
WebKit::WebGraphicsContext3D* WebViewImpl::createContext3D()
{
OwnPtr<WebKit::WebGraphicsContext3D> webContext;
if (m_temporaryOnscreenGraphicsContext3D)
webContext = m_temporaryOnscreenGraphicsContext3D.release();
else webContext = createCompositorGraphicsContext3D();
return webContext.leakPtr();
}
void WebViewImpl::applyScrollAndScale(const WebSize& scrollDelta, float pageScaleDelta)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
if (pageScaleDelta == 1) {
TRACE_EVENT_INSTANT2("webkit", "WebViewImpl::applyScrollAndScale::scrollBy", "x", scrollDelta.width, "y", scrollDelta.height);
mainFrameImpl()->frameView()->scrollBy(scrollDelta);
} else {
WebSize scrollOffset = mainFrame()->scrollOffset();
scrollOffset.width += scrollDelta.width;
scrollOffset.height += scrollDelta.height;
WebPoint scaledScrollOffset(scrollOffset.width * pageScaleDelta,
scrollOffset.height * pageScaleDelta);
setPageScaleFactor(pageScaleFactor() * pageScaleDelta, scaledScrollOffset);
}
}
void WebViewImpl::didCommit()
{
if (m_client)
m_client->didBecomeReadyForAdditionalInput();
}
void WebViewImpl::didCommitAndDrawFrame()
{
if (m_client)
m_client->didCommitAndDrawCompositorFrame();
}
void WebViewImpl::didCompleteSwapBuffers()
{
if (m_client)
m_client->didCompleteSwapBuffers();
}
void WebViewImpl::didRebindGraphicsContext(bool success)
{
if (!success) {
ASSERT(m_isAcceleratedCompositingActive);
setIsAcceleratedCompositingActive(false);
m_compositorCreationFailed = true;
m_client->didInvalidateRect(IntRect(0, 0, m_size.width, m_size.height));
m_page->mainFrame()->document()->scheduleForcedStyleRecalc();
return;
}
if (m_pageOverlays)
m_pageOverlays->update();
}
void WebViewImpl::scheduleComposite()
{
ASSERT(!CCProxy::hasImplThread());
m_client->scheduleComposite();
}
void WebViewImpl::updateLayerTreeViewport()
{
if (!page() || !m_nonCompositedContentHost || m_layerTreeView.isNull())
return;
FrameView* view = page()->mainFrame()->view();
IntRect visibleRect = view->visibleContentRect(true );
IntPoint scroll(view->scrollX(), view->scrollY());
int layerAdjustX = 0;
if (pageHasRTLStyle()) {
layerAdjustX = -view->contentsSize().width() + view->visibleContentRect(false).width();
}
m_nonCompositedContentHost->setViewport(visibleRect.size(), view->contentsSize(), scroll, pageScaleFactor(), layerAdjustX);
m_layerTreeView.setViewportSize(size());
m_layerTreeView.setPageScaleFactorAndLimits(pageScaleFactor(), m_minimumPageScaleFactor, m_maximumPageScaleFactor);
}
WebGraphicsContext3D* WebViewImpl::graphicsContext3D()
{
#if USE(ACCELERATED_COMPOSITING)
if (m_page->settings()->acceleratedCompositingEnabled() && allowsAcceleratedCompositing()) {
if (!m_layerTreeView.isNull()) {
WebGraphicsContext3D* context = m_layerTreeView.context();
if (context && !context->isContextLost())
return context;
}
if (!m_temporaryOnscreenGraphicsContext3D)
m_temporaryOnscreenGraphicsContext3D = createCompositorGraphicsContext3D();
WebGraphicsContext3D* webContext = m_temporaryOnscreenGraphicsContext3D.get();
if (webContext && !webContext->isContextLost())
return webContext;
}
#endif
return 0;
}
WebGraphicsContext3D* WebViewImpl::sharedGraphicsContext3D()
{
if (!m_page->settings()->acceleratedCompositingEnabled() || !allowsAcceleratedCompositing())
return 0;
return GraphicsContext3DPrivate::extractWebGraphicsContext3D(SharedGraphicsContext3D::get().get());
}
void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
bool isInitialState) {
if (!page())
return;
#if ENABLE(PAGE_VISIBILITY_API)
ASSERT(visibilityState == WebPageVisibilityStateVisible
|| visibilityState == WebPageVisibilityStateHidden
|| visibilityState == WebPageVisibilityStatePrerender
|| visibilityState == WebPageVisibilityStatePreview);
m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int>(visibilityState)), isInitialState);
#endif
#if USE(ACCELERATED_COMPOSITING)
if (!m_layerTreeView.isNull()) {
bool visible = visibilityState == WebPageVisibilityStateVisible;
if (!visible && isAcceleratedCompositingActive())
m_nonCompositedContentHost->protectVisibleTileTextures();
m_layerTreeView.setVisible(visible);
}
#endif
}
#if ENABLE(POINTER_LOCK)
bool WebViewImpl::requestPointerLock()
{
return m_client && m_client->requestPointerLock();
}
void WebViewImpl::requestPointerUnlock()
{
if (m_client)
m_client->requestPointerUnlock();
}
bool WebViewImpl::isPointerLocked()
{
return m_client && m_client->isPointerLocked();
}
void WebViewImpl::pointerLockMouseEvent(const WebInputEvent& event)
{
AtomicString eventType;
switch (event.type) {
case WebInputEvent::MouseDown:
eventType = eventNames().mousedownEvent;
break;
case WebInputEvent::MouseUp:
eventType = eventNames().mouseupEvent;
break;
case WebInputEvent::MouseMove:
eventType = eventNames().mousemoveEvent;
break;
default:
ASSERT_NOT_REACHED();
}
const WebMouseEvent& mouseEvent = static_cast<const WebMouseEvent&>(event);
if (page())
page()->pointerLockController()->dispatchLockedMouseEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), mouseEvent),
eventType);
}
#endif
}