diff options
Diffstat (limited to 'Source/WebKit2/WebProcess')
20 files changed, 302 insertions, 62 deletions
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm index cbcc8492e..fbf731768 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm @@ -123,6 +123,12 @@ static WKWebProcessPlugInController *sharedInstance; return self; } +- (WKWebProcessPlugInBrowserContextController *)_browserContextControllerForBundlePageRef:(WKBundlePageRef)pageRef +{ + ASSERT(_bundlePageWrapperCache.contains(pageRef)); + return _bundlePageWrapperCache.get(pageRef).get(); +} + @end @implementation WKWebProcessPlugInController diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h index 58b3cc3f7..a125e339e 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h @@ -32,6 +32,8 @@ + (WKWebProcessPlugInController *)_shared; - (id)_initWithPrincipalClassInstance:(id<WKWebProcessPlugIn>)principalClassInstance bundleRef:(WKBundleRef)bundleRef; +- (WKWebProcessPlugInBrowserContextController *)_browserContextControllerForBundlePageRef:(WKBundlePageRef)pageRef; + @end #endif // defined(__LP64__) && defined(__clang__) diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h index c3fb18d30..aa783a372 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h @@ -33,6 +33,10 @@ #include "WebPageGroupProxy.h" #include "WebProcess.h" +#if PLATFORM(MAC) +#include "ObjCObjectGraphCoders.h" +#endif + namespace WebKit { // Adds @@ -71,6 +75,13 @@ public: encoder << pageGroup->pageGroupID(); break; } +#if PLATFORM(MAC) + case APIObject::TypeObjCObjectGraph: { + ObjCObjectGraph* objectGraph = static_cast<ObjCObjectGraph*>(m_root); + encoder << InjectedBundleObjCObjectGraphEncoder(objectGraph); + break; + } +#endif default: ASSERT_NOT_REACHED(); break; @@ -128,6 +139,16 @@ public: coder.m_root = WebProcess::shared().webPageGroup(pageGroupData); break; } +#if PLATFORM(MAC) + case APIObject::TypeObjCObjectGraph: { + RefPtr<ObjCObjectGraph> objectGraph; + InjectedBundleObjCObjectGraphDecoder objectGraphDecoder(objectGraph, &WebProcess::shared()); + if (!decoder->decode(objectGraphDecoder)) + return false; + coder.m_root = objectGraph.get(); + break; + } +#endif default: return false; } diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h index 559aadab5..2063ccee6 100644 --- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h +++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h @@ -239,7 +239,7 @@ private: bool supportsSnapshotting() const; // Convert the given point from plug-in coordinates to root view coordinates. - WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const; + virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const OVERRIDE; // Convert the given point from root view coordinates to plug-in coordinates. Returns false if the point can't be // converted (if the transformation matrix isn't invertible). diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h b/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h new file mode 100644 index 000000000..8656ff466 --- /dev/null +++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <PDFKit/PDFKit.h> + +@interface PDFAnnotationTextWidget (Details) +- (BOOL)isMultiline; +- (BOOL)isReadOnly; +@end diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h index a1233fabe..132c28774 100644 --- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h +++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h @@ -94,11 +94,16 @@ private: virtual void setScrollOffset(const WebCore::IntPoint&) OVERRIDE; virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&) OVERRIDE; virtual void invalidateScrollCornerRect(const WebCore::IntRect&) OVERRIDE; + virtual WebCore::IntPoint currentMousePosition() const { return m_lastMousePositionInPluginCoordinates; } NSEvent *nsEventForWebMouseEvent(const WebMouseEvent&); + WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const; + WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const; bool supportsForms(); + void updatePageAndDeviceScaleFactors(); + RetainPtr<CALayer> m_containerLayer; RetainPtr<CALayer> m_contentLayer; RetainPtr<CALayer> m_horizontalScrollbarLayer; @@ -110,8 +115,8 @@ private: RefPtr<WebCore::Element> m_annotationContainer; WebCore::AffineTransform m_rootViewToPluginTransform; - WebCore::IntPoint m_lastMousePoint; WebMouseEvent m_lastMouseEvent; + WebCore::IntPoint m_lastMousePositionInPluginCoordinates; RetainPtr<WKPDFLayerControllerDelegate> m_pdfLayerControllerDelegate; }; diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm index 716b24e15..f50fb8c0e 100644 --- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm +++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm @@ -30,6 +30,7 @@ #import "ArgumentCoders.h" #import "DataReference.h" +#import "PDFAnnotationTextWidgetDetails.h" #import "PDFKitImports.h" #import "PDFLayerControllerDetails.h" #import "PDFPluginAnnotation.h" @@ -303,7 +304,7 @@ void PDFPlugin::pdfDocumentDidLoad() [m_pdfLayerController.get() setFrameSize:size()]; m_pdfLayerController.get().document = document.get(); - [m_pdfLayerController.get() setDeviceScaleFactor:controller()->contentsScaleFactor()]; + updatePageAndDeviceScaleFactors(); if (handlesPageScaleFactor()) pluginView()->setPageScaleFactor([m_pdfLayerController.get() contentScaleFactor], IntPoint()); @@ -316,9 +317,18 @@ void PDFPlugin::pdfDocumentDidLoad() runScriptsInPDFDocument(); } -void PDFPlugin::contentsScaleFactorChanged(float contentsScaleFactor) +void PDFPlugin::updatePageAndDeviceScaleFactors() { - [m_pdfLayerController.get() setDeviceScaleFactor:contentsScaleFactor]; + double newScaleFactor = controller()->contentsScaleFactor(); + if (!handlesPageScaleFactor()) + newScaleFactor *= webFrame()->page()->pageScaleFactor(); + + [m_pdfLayerController.get() setDeviceScaleFactor:newScaleFactor]; +} + +void PDFPlugin::contentsScaleFactorChanged(float) +{ + updatePageAndDeviceScaleFactors(); } void PDFPlugin::calculateSizes() @@ -405,6 +415,16 @@ PlatformLayer* PDFPlugin::pluginLayer() return m_containerLayer.get(); } +IntPoint PDFPlugin::convertFromRootViewToPlugin(const IntPoint& point) const +{ + return m_rootViewToPluginTransform.mapPoint(point); +} + +IntPoint PDFPlugin::convertFromPluginToPDFView(const IntPoint& point) const +{ + return IntPoint(point.x(), size().height() - point.y()); +} + void PDFPlugin::geometryDidChange(const IntSize& pluginSize, const IntRect&, const AffineTransform& pluginToRootViewTransform) { if (size() == pluginSize && pluginView()->pageScaleFactor() == [m_pdfLayerController.get() contentScaleFactor]) @@ -422,10 +442,14 @@ void PDFPlugin::geometryDidChange(const IntSize& pluginSize, const IntRect&, con if (handlesPageScaleFactor()) { CGFloat magnification = pluginView()->pageScaleFactor() - [m_pdfLayerController.get() contentScaleFactor]; - // FIXME: Instead of m_lastMousePoint, we should use the zoom origin from PluginView::setPageScaleFactor. + // FIXME: Instead of m_lastMousePositionInPluginCoordinates, we should use the zoom origin from PluginView::setPageScaleFactor. if (magnification) - [m_pdfLayerController.get() magnifyWithMagnification:magnification atPoint:m_lastMousePoint immediately:NO]; - } + [m_pdfLayerController.get() magnifyWithMagnification:magnification atPoint:convertFromPluginToPDFView(m_lastMousePositionInPluginCoordinates) immediately:NO]; + } else { + // If we don't handle page scale ourselves, we need to respect our parent page's + // scale, which may have changed. + updatePageAndDeviceScaleFactors(); + } calculateSizes(); updateScrollbars(); @@ -493,13 +517,9 @@ static NSEventType eventTypeFromWebEvent(const WebEvent& event) NSEvent *PDFPlugin::nsEventForWebMouseEvent(const WebMouseEvent& event) { - IntPoint mousePosition = event.position(); + m_lastMousePositionInPluginCoordinates = convertFromRootViewToPlugin(event.position()); - IntPoint positionInPDFView(mousePosition); - positionInPDFView = m_rootViewToPluginTransform.mapPoint(positionInPDFView); - positionInPDFView.setY(size().height() - positionInPDFView.y()); - - m_lastMousePoint = positionInPDFView; + IntPoint positionInPDFViewCoordinates(convertFromPluginToPDFView(m_lastMousePositionInPluginCoordinates)); NSEventType eventType = eventTypeFromWebEvent(event); @@ -508,27 +528,59 @@ NSEvent *PDFPlugin::nsEventForWebMouseEvent(const WebMouseEvent& event) NSUInteger modifierFlags = modifierFlagsFromWebEvent(event); - return [NSEvent mouseEventWithType:eventType location:positionInPDFView modifierFlags:modifierFlags timestamp:0 windowNumber:0 context:nil eventNumber:0 clickCount:event.clickCount() pressure:0]; + return [NSEvent mouseEventWithType:eventType location:positionInPDFViewCoordinates modifierFlags:modifierFlags timestamp:0 windowNumber:0 context:nil eventNumber:0 clickCount:event.clickCount() pressure:0]; } bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event) { + PlatformMouseEvent platformEvent = platform(event); + IntPoint mousePosition = convertFromRootViewToPlugin(event.position()); + m_lastMouseEvent = event; - IntPoint mousePosition = event.position(); + RefPtr<Scrollbar> targetScrollbar; + RefPtr<Scrollbar> targetScrollbarForLastMousePosition; - // FIXME: Forward mouse events to the appropriate scrollbar. - if (IntRect(m_verticalScrollbarLayer.get().frame).contains(mousePosition) - || IntRect(m_horizontalScrollbarLayer.get().frame).contains(mousePosition) - || IntRect(m_scrollCornerLayer.get().frame).contains(mousePosition)) + if (m_verticalScrollbarLayer) { + IntRect verticalScrollbarFrame(m_verticalScrollbarLayer.get().frame); + if (verticalScrollbarFrame.contains(mousePosition)) + targetScrollbar = verticalScrollbar(); + if (verticalScrollbarFrame.contains(m_lastMousePositionInPluginCoordinates)) + targetScrollbarForLastMousePosition = verticalScrollbar(); + } + + if (m_horizontalScrollbarLayer) { + IntRect horizontalScrollbarFrame(m_horizontalScrollbarLayer.get().frame); + if (horizontalScrollbarFrame.contains(mousePosition)) + targetScrollbar = horizontalScrollbar(); + if (horizontalScrollbarFrame.contains(m_lastMousePositionInPluginCoordinates)) + targetScrollbarForLastMousePosition = horizontalScrollbar(); + } + + if (m_scrollCornerLayer && IntRect(m_scrollCornerLayer.get().frame).contains(mousePosition)) return false; + // Right-clicks and Control-clicks always call handleContextMenuEvent as well. + if (event.button() == WebMouseEvent::RightButton || (event.button() == WebMouseEvent::LeftButton && event.controlKey())) + return true; + NSEvent *nsEvent = nsEventForWebMouseEvent(event); switch (event.type()) { case WebEvent::MouseMove: mouseMovedInContentArea(); + if (targetScrollbar) { + if (!targetScrollbarForLastMousePosition) { + targetScrollbar->mouseEntered(); + return true; + } + return targetScrollbar->mouseMoved(platformEvent); + } + + if (!targetScrollbar && targetScrollbarForLastMousePosition) + targetScrollbarForLastMousePosition->mouseExited(); + switch (event.button()) { case WebMouseEvent::LeftButton: [m_pdfLayerController.get() mouseDragged:nsEvent]; @@ -543,6 +595,9 @@ bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event) case WebEvent::MouseDown: switch (event.button()) { case WebMouseEvent::LeftButton: + if (targetScrollbar) + return targetScrollbar->mouseDown(platformEvent); + [m_pdfLayerController.get() mouseDown:nsEvent]; return true; case WebMouseEvent::RightButton: @@ -555,6 +610,9 @@ bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event) case WebEvent::MouseUp: switch (event.button()) { case WebMouseEvent::LeftButton: + if (targetScrollbar) + return targetScrollbar->mouseUp(platformEvent); + [m_pdfLayerController.get() mouseUp:nsEvent]; return true; case WebMouseEvent::RightButton: @@ -574,7 +632,7 @@ bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event) NSMenu *nsMenu = [m_pdfLayerController.get() menuForEvent:nsEventForWebMouseEvent(event)]; FrameView* frameView = webFrame()->coreFrame()->view(); - IntPoint point = frameView->contentsToScreen(IntRect(event.position(), IntSize())).location(); + IntPoint point = frameView->contentsToScreen(IntRect(frameView->windowToContents(event.position()), IntSize())).location(); if (nsMenu) { WKPopupContextMenu(nsMenu, point); return true; @@ -672,6 +730,11 @@ void PDFPlugin::setActiveAnnotation(PDFAnnotation *annotation) m_activeAnnotation->commit(); if (annotation) { + if ([annotation isKindOfClass:pdfAnnotationTextWidgetClass()] && static_cast<PDFAnnotationTextWidget *>(annotation).isReadOnly) { + m_activeAnnotation = 0; + return; + } + m_activeAnnotation = PDFPluginAnnotation::create(annotation, m_pdfLayerController.get(), this); m_activeAnnotation->attach(m_annotationContainer.get()); } else diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm index b5df3732d..f69a5d598 100644 --- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm +++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm @@ -28,6 +28,7 @@ #import "config.h" #import "PDFPluginTextAnnotation.h" +#import "PDFAnnotationTextWidgetDetails.h" #import "PDFKitImports.h" #import "PDFLayerControllerDetails.h" #import <PDFKit/PDFKit.h> @@ -40,10 +41,6 @@ #import <WebCore/HTMLTextAreaElement.h> #import <WebCore/Page.h> -@interface PDFAnnotationTextWidget (Details) -- (BOOL)isMultiline; -@end - using namespace WebCore; namespace WebKit { diff --git a/Source/WebKit2/WebProcess/Plugins/Plugin.cpp b/Source/WebKit2/WebProcess/Plugins/Plugin.cpp index 12e0b3d31..f2c6af46c 100644 --- a/Source/WebKit2/WebProcess/Plugins/Plugin.cpp +++ b/Source/WebKit2/WebProcess/Plugins/Plugin.cpp @@ -27,6 +27,7 @@ #include "Plugin.h" #include "WebCoreArgumentCoders.h" +#include <WebCore/IntPoint.h> using namespace WebCore; @@ -105,4 +106,10 @@ void Plugin::updateControlTints(GraphicsContext*) { } +IntPoint Plugin::convertToRootView(const IntPoint&) const +{ + ASSERT_NOT_REACHED(); + return IntPoint(); +} + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/Plugins/Plugin.h b/Source/WebKit2/WebProcess/Plugins/Plugin.h index 54f8b3ad8..d50a1764b 100644 --- a/Source/WebKit2/WebProcess/Plugins/Plugin.h +++ b/Source/WebKit2/WebProcess/Plugins/Plugin.h @@ -50,6 +50,7 @@ namespace CoreIPC { namespace WebCore { class AffineTransform; class GraphicsContext; + class IntPoint; class IntRect; class IntSize; class Scrollbar; @@ -250,6 +251,8 @@ public: virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; } #endif + virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint& pointInLocalCoordinates) const; + protected: Plugin(); diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp b/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp index a18834a6c..f7ead5664 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp @@ -665,6 +665,11 @@ void PluginProxy::update(const IntRect& paintedRect) controller()->invalidate(paintedRect); } +IntPoint PluginProxy::convertToRootView(const IntPoint& point) const +{ + return m_pluginToRootViewTransform.mapPoint(point); +} + } // namespace WebKit #endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProxy.h b/Source/WebKit2/WebProcess/Plugins/PluginProxy.h index b1a893bdd..535c8c7fe 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProxy.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginProxy.h @@ -125,6 +125,8 @@ private: virtual WebCore::Scrollbar* horizontalScrollbar(); virtual WebCore::Scrollbar* verticalScrollbar(); + virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const OVERRIDE; + float contentsScaleFactor(); bool needsBackingStore() const; bool updateBackingStore(); diff --git a/Source/WebKit2/WebProcess/Plugins/PluginView.cpp b/Source/WebKit2/WebProcess/Plugins/PluginView.cpp index 44f575ad5..6c74f4633 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginView.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginView.cpp @@ -68,7 +68,8 @@ using namespace WebCore; namespace WebKit { -static const double pluginSnapshotTimerDelay = 1; +// This simulated mouse click delay in HTMLPlugInImageElement.cpp should generally be the same or shorter than this delay. +static const double pluginSnapshotTimerDelay = 1.1; class PluginView::URLRequest : public RefCounted<URLRequest> { public: @@ -554,13 +555,17 @@ void PluginView::didInitializePlugin() redeliverManualStream(); #if PLATFORM(MAC) - if (m_pluginElement->displayState() < HTMLPlugInElement::Playing) + if (m_pluginElement->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) m_pluginSnapshotTimer.restart(); - else if (m_plugin->pluginLayer()) { - if (frame()) { - frame()->view()->enterCompositingMode(); - m_pluginElement->setNeedsStyleRecalc(SyntheticStyleChange); + else { + if (m_plugin->pluginLayer()) { + if (frame()) { + frame()->view()->enterCompositingMode(); + m_pluginElement->setNeedsStyleRecalc(SyntheticStyleChange); + } } + if (m_pluginElement->displayState() < HTMLPlugInElement::Playing) + m_pluginElement->dispatchPendingMouseClick(); } setWindowIsVisible(m_webPage->windowIsVisible()); @@ -686,7 +691,7 @@ void PluginView::setFrameRect(const WebCore::IntRect& rect) void PluginView::paint(GraphicsContext* context, const IntRect& /*dirtyRect*/) { - if (!m_plugin || !m_isInitialized || m_pluginElement->displayState() < HTMLPlugInElement::Playing) + if (!m_plugin || !m_isInitialized || m_pluginElement->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) return; if (context->paintingDisabled()) { @@ -728,12 +733,62 @@ void PluginView::setParent(ScrollView* scrollView) initializePlugin(); } +PassOwnPtr<WebEvent> PluginView::createWebEvent(MouseEvent* event) const +{ + WebEvent::Type type = WebEvent::NoType; + unsigned clickCount = 1; + if (event->type() == eventNames().mousedownEvent) + type = WebEvent::MouseDown; + else if (event->type() == eventNames().mouseupEvent) + type = WebEvent::MouseUp; + else if (event->type() == eventNames().mouseoverEvent) { + type = WebEvent::MouseMove; + clickCount = 0; + } else if (event->type() == eventNames().clickEvent) + return nullptr; + else + ASSERT_NOT_REACHED(); + + WebMouseEvent::Button button = WebMouseEvent::NoButton; + switch (event->button()) { + case WebCore::LeftButton: + button = WebMouseEvent::LeftButton; + break; + case WebCore::MiddleButton: + button = WebMouseEvent::MiddleButton; + break; + case WebCore::RightButton: + button = WebMouseEvent::RightButton; + break; + default: + ASSERT_NOT_REACHED(); + break; + } + + unsigned modifiers = 0; + if (event->shiftKey()) + modifiers |= WebEvent::ShiftKey; + if (event->ctrlKey()) + modifiers |= WebEvent::ControlKey; + if (event->altKey()) + modifiers |= WebEvent::AltKey; + if (event->metaKey()) + modifiers |= WebEvent::MetaKey; + + return adoptPtr(new WebMouseEvent(type, button, m_plugin->convertToRootView(IntPoint(event->offsetX(), event->offsetY())), event->screenLocation(), 0, 0, 0, clickCount, static_cast<WebEvent::Modifiers>(modifiers), 0)); +} + void PluginView::handleEvent(Event* event) { if (!m_isInitialized || !m_plugin) return; const WebEvent* currentEvent = WebPage::currentEvent(); + OwnPtr<WebEvent> simulatedWebEvent; + if (event->isMouseEvent() && toMouseEvent(event)->isSimulated()) { + simulatedWebEvent = createWebEvent(toMouseEvent(event)); + currentEvent = simulatedWebEvent.get(); + } if (!currentEvent) return; @@ -776,16 +831,25 @@ void PluginView::handleEvent(Event* event) bool PluginView::handleEditingCommand(const String& commandName, const String& argument) { + if (!m_isInitialized || !m_plugin) + return false; + return m_plugin->handleEditingCommand(commandName, argument); } bool PluginView::isEditingCommandEnabled(const String& commandName) { + if (!m_isInitialized || !m_plugin) + return false; + return m_plugin->isEditingCommandEnabled(commandName); } bool PluginView::shouldAllowScripting() { + if (!m_isInitialized || !m_plugin) + return false; + return m_plugin->shouldAllowScripting(); } @@ -950,7 +1014,10 @@ void PluginView::performFrameLoadURLRequest(URLRequest* request) Frame* targetFrame = frame->loader()->findFrameForNavigation(request->target()); if (!targetFrame) { // We did not find a target frame. Ask our frame to load the page. This may or may not create a popup window. - frame->loader()->load(request->request(), request->target(), false); + FrameLoadRequest frameRequest(frame, request->request()); + frameRequest.setFrameName(request->target()); + frameRequest.setShouldCheckNewWindowPolicy(true); + frame->loader()->load(frameRequest); // FIXME: We don't know whether the window was successfully created here so we just assume that it worked. // It's better than not telling the plug-in anything. @@ -959,7 +1026,7 @@ void PluginView::performFrameLoadURLRequest(URLRequest* request) } // Now ask the frame to load the request. - targetFrame->loader()->load(request->request(), false); + targetFrame->loader()->load(FrameLoadRequest(targetFrame, request->request())); WebFrame* targetWebFrame = static_cast<WebFrameLoaderClient*>(targetFrame->loader()->client())->webFrame(); if (WebFrame::LoadListener* loadListener = targetWebFrame->loadListener()) { @@ -1079,7 +1146,7 @@ void PluginView::invalidateRect(const IntRect& dirtyRect) return; #endif - if (m_pluginElement->displayState() < HTMLPlugInElement::Playing) + if (m_pluginElement->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) return; RenderBoxModelObject* renderer = toRenderBoxModelObject(m_pluginElement->renderer()); @@ -1237,7 +1304,7 @@ bool PluginView::isAcceleratedCompositingEnabled() if (!settings) return false; - if (m_pluginElement->displayState() < HTMLPlugInElement::Playing) + if (m_pluginElement->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) return false; return settings->acceleratedCompositingEnabled(); } diff --git a/Source/WebKit2/WebProcess/Plugins/PluginView.h b/Source/WebKit2/WebProcess/Plugins/PluginView.h index 59f0f8403..cd9e35b95 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginView.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginView.h @@ -44,11 +44,14 @@ namespace WebCore { class Frame; class HTMLPlugInElement; +class MouseEvent; class RenderBoxModelObject; } namespace WebKit { +class WebEvent; + class PluginView : public WebCore::PluginViewBase, public PluginController, private WebCore::MediaCanStartListener, private WebFrame::LoadListener { public: static PassRefPtr<PluginView> create(PassRefPtr<WebCore::HTMLPlugInElement>, PassRefPtr<Plugin>, const Plugin::Parameters&); @@ -201,6 +204,8 @@ private: virtual void didFinishLoad(WebFrame*); virtual void didFailLoad(WebFrame*, bool wasCancelled); + PassOwnPtr<WebEvent> createWebEvent(WebCore::MouseEvent*) const; + RefPtr<WebCore::HTMLPlugInElement> m_pluginElement; RefPtr<Plugin> m_plugin; WebPage* m_webPage; diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp index c7808b2b2..349948e05 100644 --- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp @@ -107,7 +107,6 @@ void CoordinatedGraphicsLayer::didChangeGeometry() CoordinatedGraphicsLayer::CoordinatedGraphicsLayer(GraphicsLayerClient* client) : GraphicsLayer(client) - , m_maskTarget(0) , m_inUpdateMode(false) , m_shouldUpdateVisibleRect(true) , m_shouldSyncLayerState(true) @@ -269,6 +268,8 @@ void CoordinatedGraphicsLayer::setContentsVisible(bool b) if (contentsAreVisible() == b) return; GraphicsLayer::setContentsVisible(b); + if (maskLayer()) + maskLayer()->setContentsVisible(b); didChangeLayerState(); } @@ -390,8 +391,8 @@ void CoordinatedGraphicsLayer::setMaskLayer(GraphicsLayer* layer) return; layer->setSize(size()); + layer->setContentsVisible(contentsAreVisible()); CoordinatedGraphicsLayer* CoordinatedGraphicsLayer = toCoordinatedGraphicsLayer(layer); - CoordinatedGraphicsLayer->setMaskTarget(this); CoordinatedGraphicsLayer->didChangeLayerState(); didChangeLayerState(); @@ -653,8 +654,6 @@ void CoordinatedGraphicsLayer::adjustContentsScale() // No reason to save the previous backing store for non-visible areas. m_previousBackingStore->removeAllNonVisibleTiles(); - - createBackingStore(); } void CoordinatedGraphicsLayer::createBackingStore() diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h index a903e6519..1517ae56f 100644 --- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h @@ -165,7 +165,6 @@ public: private: bool fixedToViewport() const { return m_fixedToViewport; } - void setMaskTarget(GraphicsLayer* layer) { m_maskTarget = layer; } void didChangeLayerState(); void didChangeAnimations(); @@ -207,7 +206,6 @@ private: WebKit::WebLayerID m_id; WebKit::WebLayerInfo m_layerInfo; - GraphicsLayer* m_maskTarget; GraphicsLayerTransform m_layerTransform; TransformationMatrix m_cachedInverseTransform; bool m_inUpdateMode : 1; diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index c91c73ed1..83c0ae7fd 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -325,6 +325,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) #endif m_page->setCanStartMedia(false); + m_mayStartMediaWhenInWindow = parameters.mayStartMediaWhenInWindow; m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData); m_page->setGroupName(m_pageGroup->identifier()); @@ -824,7 +825,7 @@ void WebPage::loadURLRequest(const ResourceRequest& request, const SandboxExtens SendStopResponsivenessTimer stopper(this); m_sandboxExtensionTracker.beginLoad(m_mainFrame.get(), sandboxExtensionHandle); - m_mainFrame->coreFrame()->loader()->load(request, false); + m_mainFrame->coreFrame()->loader()->load(FrameLoadRequest(m_mainFrame->coreFrame(), request)); } void WebPage::loadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIMEType, const String& encodingName, const KURL& baseURL, const KURL& unreachableURL) @@ -833,7 +834,7 @@ void WebPage::loadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIME ResourceRequest request(baseURL); SubstituteData substituteData(sharedBuffer, MIMEType, encodingName, unreachableURL); - m_mainFrame->coreFrame()->loader()->load(request, substituteData, false); + m_mainFrame->coreFrame()->loader()->load(FrameLoadRequest(m_mainFrame->coreFrame(), request, substituteData)); } void WebPage::loadHTMLString(const String& htmlString, const String& baseURLString) @@ -873,8 +874,7 @@ void WebPage::linkClicked(const String& url, const WebMouseEvent& event) if (event.type() != WebEvent::NoType) coreEvent = MouseEvent::create(eventNames().clickEvent, frame->document()->defaultView(), platform(event), 0, 0); - frame->loader()->loadFrameRequest(FrameLoadRequest(frame->document()->securityOrigin(), ResourceRequest(url)), - false, false, coreEvent.get(), 0, MaybeSendReferrer); + frame->loader()->loadFrameRequest(FrameLoadRequest(frame, ResourceRequest(url)), false, false, coreEvent.get(), 0, MaybeSendReferrer); } void WebPage::stopLoadingFrame(uint64_t frameID) @@ -1893,7 +1893,9 @@ void WebPage::setIsInWindow(bool isInWindow) // Defer the call to Page::setCanStartMedia() since it ends up sending a syncrhonous messages to the UI process // in order to get plug-in connections, and the UI process will be waiting for the Web process to update the backing // store after moving the view into a window, until it times out and paints white. See <rdar://problem/9242771>. - m_setCanStartMediaTimer.startOneShot(0); + if (m_mayStartMediaWhenInWindow) + m_setCanStartMediaTimer.startOneShot(0); + m_page->didMoveOnscreen(); } } @@ -2238,6 +2240,7 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setCSSGridLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::cssGridLayoutEnabledKey())); settings->setRegionBasedColumnsEnabled(store.getBoolValueForKey(WebPreferencesKey::regionBasedColumnsEnabledKey())); settings->setWebGLEnabled(store.getBoolValueForKey(WebPreferencesKey::webGLEnabledKey())); + settings->setAccelerated2dCanvasEnabled(store.getBoolValueForKey(WebPreferencesKey::accelerated2dCanvasEnabledKey())); settings->setMediaPlaybackRequiresUserGesture(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackRequiresUserGestureKey())); settings->setMediaPlaybackAllowsInline(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackAllowsInlineKey())); settings->setMockScrollbarsEnabled(store.getBoolValueForKey(WebPreferencesKey::mockScrollbarsEnabledKey())); @@ -2293,6 +2296,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setPlugInSnapshottingEnabled(store.getBoolValueForKey(WebPreferencesKey::plugInSnapshottingEnabledKey())); settings->setUsesEncodingDetector(store.getBoolValueForKey(WebPreferencesKey::usesEncodingDetectorKey())); +#if ENABLE(TEXT_AUTOSIZING) + settings->setTextAutosizingEnabled(store.getBoolValueForKey(WebPreferencesKey::textAutosizingEnabledKey())); +#endif + platformPreferencesDidChange(store); if (m_drawingArea) @@ -3313,6 +3320,16 @@ void WebPage::setMediaVolume(float volume) m_page->setMediaVolume(volume); } +void WebPage::setMayStartMediaWhenInWindow(bool mayStartMedia) +{ + if (mayStartMedia == m_mayStartMediaWhenInWindow) + return; + + m_mayStartMediaWhenInWindow = mayStartMedia; + if (m_mayStartMediaWhenInWindow && m_page->isOnscreen()) + m_setCanStartMediaTimer.startOneShot(0); +} + void WebPage::runModal() { if (m_isClosed) diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h index 19af39c6e..00ea81c8c 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h @@ -525,6 +525,7 @@ public: #endif void setMediaVolume(float); + void setMayStartMediaWhenInWindow(bool); bool mainFrameHasCustomRepresentation() const; @@ -851,6 +852,7 @@ private: #endif WebCore::RunLoop::Timer<WebPage> m_setCanStartMediaTimer; + bool m_mayStartMediaWhenInWindow; HashMap<uint64_t, RefPtr<WebUndoStep> > m_undoStepMap; diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in index bbf6a686c..ad4292b4b 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in @@ -226,6 +226,7 @@ messages -> WebPage { # Media SetMediaVolume(float volume) + SetMayStartMediaWhenInWindow(bool mayStartMedia) SetMemoryCacheMessagesEnabled(bool memoryCacheMessagesEnabled) diff --git a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm index 5f09d751b..de49bd2fe 100644 --- a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm +++ b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm @@ -545,39 +545,48 @@ void WebPage::performDictionaryLookupForSelection(DictionaryPopupInfo::Type type void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range, NSDictionary *options) { - String rangeText = range->text(); - if (rangeText.stripWhiteSpace().isEmpty()) + if (range->text().stripWhiteSpace().isEmpty()) return; RenderObject* renderer = range->startContainer()->renderer(); RenderStyle* style = renderer->style(); - NSFont *font = style->font().primaryFont()->getNSFont(); - - // We won't be able to get an NSFont in the case that a Web Font is being used, so use - // the default system font at the same size instead. - if (!font) - font = [NSFont systemFontOfSize:style->font().primaryFont()->platformData().size()]; - - CFDictionaryRef fontDescriptorAttributes = (CFDictionaryRef)[[font fontDescriptor] fontAttributes]; - if (!fontDescriptorAttributes) - return; Vector<FloatQuad> quads; range->textQuads(quads); if (quads.isEmpty()) return; - + IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox()); DictionaryPopupInfo dictionaryPopupInfo; dictionaryPopupInfo.type = type; dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + (style->fontMetrics().ascent() * pageScaleFactor())); - dictionaryPopupInfo.fontInfo.fontAttributeDictionary = fontDescriptorAttributes; #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 dictionaryPopupInfo.options = (CFDictionaryRef)options; #endif - send(Messages::WebPageProxy::DidPerformDictionaryLookup(rangeText, dictionaryPopupInfo)); + NSAttributedString *nsAttributedString = [WebHTMLConverter editingAttributedStringFromRange:range]; + + RetainPtr<NSMutableAttributedString> scaledNSAttributedString(AdoptNS, [[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]); + + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + + [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) { + RetainPtr<NSMutableDictionary> scaledAttributes(AdoptNS, [attributes mutableCopy]); + + NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName]; + if (font) { + font = [fontManager convertFont:font toSize:[font pointSize] * pageScaleFactor()]; + [scaledAttributes setObject:font forKey:NSFontAttributeName]; + } + + [scaledNSAttributedString.get() addAttributes:scaledAttributes.get() range:range]; + }]; + + AttributedString attributedString; + attributedString.string = scaledNSAttributedString; + + send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo)); } bool WebPage::performNonEditingBehaviorForSelector(const String& selector) |
