diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
commit | 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch) | |
tree | 988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/WebKit2/WebProcess/WebPage/WebPage.cpp | |
parent | dd91e772430dc294e3bf478c119ef8d43c0a3358 (diff) | |
download | qtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz |
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/WebKit2/WebProcess/WebPage/WebPage.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/WebPage/WebPage.cpp | 392 |
1 files changed, 230 insertions, 162 deletions
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index 9f8b417a5..717f67371 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -42,6 +42,7 @@ #include "PrintInfo.h" #include "SessionState.h" #include "ShareableBitmap.h" +#include "WebAlternativeTextClient.h" #include "WebBackForwardList.h" #include "WebBackForwardListItem.h" #include "WebBackForwardListProxy.h" @@ -97,11 +98,9 @@ #include <WebCore/PlatformKeyboardEvent.h> #include <WebCore/PluginDocument.h> #include <WebCore/PrintContext.h> -#include <WebCore/RenderArena.h> #include <WebCore/RenderLayer.h> #include <WebCore/RenderTreeAsText.h> #include <WebCore/RenderView.h> -#include <WebCore/ReplaceSelectionCommand.h> #include <WebCore/ResourceRequest.h> #include <WebCore/RunLoop.h> #include <WebCore/SchemeRegistry.h> @@ -129,6 +128,10 @@ #endif #if PLATFORM(QT) +#if ENABLE(DEVICE_ORIENTATION) +#include "DeviceMotionClientQt.h" +#include "DeviceOrientationClientQt.h" +#endif #include "HitTestResult.h" #include <QMimeData> #endif @@ -188,6 +191,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) #if PLATFORM(MAC) , m_windowIsVisible(false) , m_isSmartInsertDeleteEnabled(parameters.isSmartInsertDeleteEnabled) + , m_layerHostingMode(LayerHostingModeDefault) , m_keyboardEventBeingInterpreted(0) #elif PLATFORM(WIN) , m_nativeWindow(parameters.nativeWindow) @@ -196,9 +200,11 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) #endif , m_setCanStartMediaTimer(WebProcess::shared().runLoop(), this, &WebPage::setCanStartMediaTimerFired) , m_findController(this) +#if ENABLE(TOUCH_EVENTS) #if PLATFORM(QT) , m_tapHighlightController(this) #endif +#endif #if ENABLE(GEOLOCATION) , m_geolocationPermissionRequestManager(this) #endif @@ -211,7 +217,9 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) , m_canShortCircuitHorizontalWheelEvents(false) , m_numWheelEventHandlers(0) , m_cachedPageCount(0) +#if ENABLE(CONTEXT_MENUS) , m_isShowingContextMenu(false) +#endif , m_willGoToBackForwardItemCallbackEnabled(true) #if PLATFORM(WIN) , m_gestureReachedScrollingLimit(false) @@ -224,20 +232,29 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) Page::PageClients pageClients; pageClients.chromeClient = new WebChromeClient(this); +#if ENABLE(CONTEXT_MENUS) pageClients.contextMenuClient = new WebContextMenuClient(this); +#endif pageClients.editorClient = new WebEditorClient(this); pageClients.dragClient = new WebDragClient(this); pageClients.backForwardClient = WebBackForwardListProxy::create(this); -#if ENABLE(CLIENT_BASED_GEOLOCATION) - pageClients.geolocationClient = new WebGeolocationClient(this); -#endif #if ENABLE(INSPECTOR) pageClients.inspectorClient = new WebInspectorClient(this); #endif +#if USE(AUTOCORRECTION_PANEL) + pageClients.alternativeTextClient = new WebAlternativeTextClient(this); +#endif m_page = adoptPtr(new Page(pageClients)); -#if ENABLE(NOTIFICATIONS) +#if ENABLE(GEOLOCATION) + WebCore::provideGeolocationTo(m_page.get(), new WebGeolocationClient(this)); +#endif +#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(QT) + WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientQt); + WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientQt); +#endif +#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) WebCore::provideNotification(m_page.get(), new WebNotificationClient(this)); #endif @@ -253,6 +270,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData); m_page->setGroupName(m_pageGroup->identifier()); + m_page->setDeviceScaleFactor(parameters.deviceScaleFactor); platformInitialize(); @@ -320,10 +338,12 @@ CoreIPC::Connection* WebPage::connection() const return WebProcess::shared().connection(); } +#if ENABLE(CONTEXT_MENUS) void WebPage::initializeInjectedBundleContextMenuClient(WKBundlePageContextMenuClient* client) { m_contextMenuClient.initialize(client); } +#endif void WebPage::initializeInjectedBundleEditorClient(WKBundlePageEditorClient* client) { @@ -439,7 +459,7 @@ EditorState WebPage::editorState() const } if (selectionRoot) - result.editorRect = frame->view()->contentsToWindow(selectionRoot->getRect()); + result.editorRect = frame->view()->contentsToWindow(selectionRoot->getPixelSnappedRect()); RefPtr<Range> range; if (result.hasComposition && (range = frame->editor()->compositionRange())) { @@ -482,16 +502,7 @@ uint64_t WebPage::renderTreeSize() const { if (!m_page) return 0; - - Frame* mainFrame = m_page->mainFrame(); - if (!mainFrame) - return 0; - - uint64_t size = 0; - for (Frame* coreFrame = mainFrame; coreFrame; coreFrame = coreFrame->tree()->traverseNext()) - size += coreFrame->document()->renderArena()->totalRenderArenaSize(); - - return size; + return m_page->renderTreeSize().treeSize; } void WebPage::setPaintedObjectsCounterThreshold(uint64_t threshold) @@ -682,6 +693,12 @@ void WebPage::loadPlainTextString(const String& string) loadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL()); } +void WebPage::loadWebArchiveData(const CoreIPC::DataReference& webArchiveData) +{ + RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(webArchiveData.data()), webArchiveData.size() * sizeof(uint8_t)); + loadData(sharedBuffer, "application/x-webarchive", "utf-16", blankURL(), KURL()); +} + void WebPage::linkClicked(const String& url, const WebMouseEvent& event) { Frame* frame = m_page->mainFrame(); @@ -802,9 +819,7 @@ void WebPage::setFixedVisibleContentRect(const IntRect& rect) { ASSERT(m_useFixedLayout); - Frame* frame = m_page->mainFrame(); - - frame->view()->setFixedVisibleContentRect(rect); + m_page->mainFrame()->view()->setFixedVisibleContentRect(rect); } void WebPage::setResizesToContentsUsingLayoutSize(const IntSize& targetLayoutSize) @@ -824,6 +839,9 @@ void WebPage::setResizesToContentsUsingLayoutSize(const IntSize& targetLayoutSiz // Always reset even when empty. view->setFixedLayoutSize(targetLayoutSize); + m_page->settings()->setAcceleratedCompositingForFixedPositionEnabled(true); + m_page->settings()->setFixedElementsLayoutRelativeToFrame(true); + // Schedule a layout to use the new target size. if (!view->layoutPending()) { view->setNeedsLayout(); @@ -840,31 +858,45 @@ void WebPage::resizeToContentsIfNeeded() if (!view->useFixedLayout()) return; - IntSize contentSize = view->contentsSize(); - if (contentSize == m_viewSize) + IntSize newSize = view->contentsSize().expandedTo(view->fixedLayoutSize()); + + if (newSize == m_viewSize) return; - m_viewSize = contentSize; - view->resize(m_viewSize); + m_viewSize = newSize; + view->resize(newSize); view->setNeedsLayout(); } -void WebPage::setViewportSize(const IntSize& size) +void WebPage::sendViewportAttributesChanged() { ASSERT(m_useFixedLayout); - if (m_viewportSize == size) + // Viewport properties have no impact on zero sized fixed viewports. + if (m_viewportSize.isEmpty()) return; - m_viewportSize = size; - // Recalculate the recommended layout size, when the available size (device pixel) changes. Settings* settings = m_page->settings(); - int minimumLayoutFallbackWidth = std::max(settings->layoutFallbackWidth(), size.width()); + int minimumLayoutFallbackWidth = std::max(settings->layoutFallbackWidth(), m_viewportSize.width()); + + ViewportAttributes attr = computeViewportAttributes(m_page->viewportArguments(), minimumLayoutFallbackWidth, settings->deviceWidth(), settings->deviceHeight(), static_cast<int>(160 * settings->devicePixelRatio()), m_viewportSize); + + setResizesToContentsUsingLayoutSize(IntSize(static_cast<int>(attr.layoutSize.width()), static_cast<int>(attr.layoutSize.height()))); + send(Messages::WebPageProxy::DidChangeViewportProperties(attr)); +} + +void WebPage::setViewportSize(const IntSize& size) +{ + ASSERT(m_useFixedLayout); + + if (m_viewportSize == size) + return; + + m_viewportSize = size; - IntSize targetLayoutSize = computeViewportAttributes(m_page->viewportArguments(), minimumLayoutFallbackWidth, settings->deviceWidth(), settings->deviceHeight(), settings->deviceDPI(), size).layoutSize; - setResizesToContentsUsingLayoutSize(targetLayoutSize); + sendViewportAttributesChanged(); } #endif @@ -1157,9 +1189,6 @@ PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect, void WebPage::pageDidScroll() { - // Hide the find indicator. - m_findController.hideFindIndicator(); - m_uiClient.pageDidScroll(this); send(Messages::WebPageProxy::PageDidScroll()); @@ -1172,12 +1201,14 @@ void WebPage::pageDidRequestScroll(const IntPoint& point) } #endif +#if ENABLE(CONTEXT_MENUS) WebContextMenu* WebPage::contextMenu() { if (!m_contextMenu) m_contextMenu = WebContextMenu::create(this); return m_contextMenu.get(); } +#endif // Events @@ -1208,6 +1239,7 @@ private: const WebEvent* m_previousCurrentEvent; }; +#if ENABLE(CONTEXT_MENUS) static bool isContextClick(const PlatformMouseEvent& event) { if (event.button() == WebCore::RightButton) @@ -1237,6 +1269,7 @@ static bool handleContextMenuEvent(const PlatformMouseEvent& platformMouseEvent, return handled; } +#endif static bool handleMouseEvent(const WebMouseEvent& mouseEvent, WebPage* page, bool onlyUpdateScrollbars) { @@ -1248,12 +1281,16 @@ static bool handleMouseEvent(const WebMouseEvent& mouseEvent, WebPage* page, boo switch (platformMouseEvent.type()) { case PlatformEvent::MousePressed: { +#if ENABLE(CONTEXT_MENUS) if (isContextClick(platformMouseEvent)) page->corePage()->contextMenuController()->clearContextMenu(); - +#endif + bool handled = frame->eventHandler()->handleMousePressEvent(platformMouseEvent); +#if ENABLE(CONTEXT_MENUS) if (isContextClick(platformMouseEvent)) handled = handleContextMenuEvent(platformMouseEvent, page); +#endif return handled; } @@ -1271,11 +1308,13 @@ static bool handleMouseEvent(const WebMouseEvent& mouseEvent, WebPage* page, boo void WebPage::mouseEvent(const WebMouseEvent& mouseEvent) { +#if ENABLE(CONTEXT_MENUS) // Don't try to handle any pending mouse events if a context menu is showing. if (m_isShowingContextMenu) { send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), false)); return; } +#endif bool handled = false; @@ -1443,23 +1482,42 @@ void WebPage::restoreSessionAndNavigateToCurrentItem(const SessionState& session #if ENABLE(TOUCH_EVENTS) #if PLATFORM(QT) -void WebPage::highlightPotentialActivation(const IntPoint& point) +void WebPage::highlightPotentialActivation(const IntPoint& point, const IntSize& area) { - Node* activationNode = 0; - Frame* mainframe = m_page->mainFrame(); + if (point == IntPoint::zero()) { + // An empty point deactivates the highlighting. + tapHighlightController().hideHighlight(); + } else { + Frame* mainframe = m_page->mainFrame(); + Node* activationNode = 0; + Node* adjustedNode = 0; + IntPoint adjustedPoint; - if (point != IntPoint::zero()) { +#if ENABLE(TOUCH_ADJUSTMENT) + if (!mainframe->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adjustedPoint, adjustedNode)) + return; + +#else HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true); - activationNode = result.innerNode(); + adjustedNode = result.innerNode(); +#endif + // Find the node to highlight. This is not the same as the node responding the tap gesture, because many + // pages has a global click handler and we do not want to highlight the body. + // Instead find the enclosing link or focusable element, or the last enclosing inline element. + for (Node* node = adjustedNode; node; node = node->parentOrHostNode()) { + if (node->isMouseFocusable() || node->isLink()) { + activationNode = node; + break; + } + if (node->renderer() && node->renderer()->isInline()) + activationNode = node; + else if (activationNode) + break; + } - if (!activationNode->isFocusable()) - activationNode = activationNode->enclosingLinkEventParentOrSelf(); + if (activationNode) + tapHighlightController().highlight(activationNode); } - - if (activationNode) - tapHighlightController().highlight(activationNode); - else - tapHighlightController().hideHighlight(); } #endif @@ -1857,6 +1915,7 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setLoadsSiteIconsIgnoringImageLoadingSetting(store.getBoolValueForKey(WebPreferencesKey::loadsSiteIconsIgnoringImageLoadingPreferenceKey())); settings->setPluginsEnabled(store.getBoolValueForKey(WebPreferencesKey::pluginsEnabledKey())); settings->setJavaEnabled(store.getBoolValueForKey(WebPreferencesKey::javaEnabledKey())); + settings->setJavaEnabledForLocalFiles(store.getBoolValueForKey(WebPreferencesKey::javaEnabledForLocalFilesKey())); settings->setOfflineWebApplicationCacheEnabled(store.getBoolValueForKey(WebPreferencesKey::offlineWebApplicationCacheEnabledKey())); settings->setLocalStorageEnabled(store.getBoolValueForKey(WebPreferencesKey::localStorageEnabledKey())); settings->setXSSAuditorEnabled(store.getBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey())); @@ -1888,7 +1947,7 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setDefaultFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFontSizeKey())); settings->setDefaultFixedFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFixedFontSizeKey())); settings->setLayoutFallbackWidth(store.getUInt32ValueForKey(WebPreferencesKey::layoutFallbackWidthKey())); - settings->setDeviceDPI(store.getUInt32ValueForKey(WebPreferencesKey::deviceDPIKey())); + settings->setDevicePixelRatio(store.getDoubleValueForKey(WebPreferencesKey::devicePixelRatioKey())); settings->setDeviceWidth(store.getUInt32ValueForKey(WebPreferencesKey::deviceWidthKey())); settings->setDeviceHeight(store.getUInt32ValueForKey(WebPreferencesKey::deviceHeightKey())); settings->setEditableLinkBehavior(static_cast<WebCore::EditableLinkBehavior>(store.getUInt32ValueForKey(WebPreferencesKey::editableLinkBehaviorKey()))); @@ -1901,11 +1960,13 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setShowRepaintCounter(store.getBoolValueForKey(WebPreferencesKey::compositingRepaintCountersVisibleKey())); settings->setCSSCustomFilterEnabled(store.getBoolValueForKey(WebPreferencesKey::cssCustomFilterEnabledKey())); settings->setCSSRegionsEnabled(store.getBoolValueForKey(WebPreferencesKey::cssRegionsEnabledKey())); + settings->setRegionBasedColumnsEnabled(store.getBoolValueForKey(WebPreferencesKey::regionBasedColumnsEnabledKey())); settings->setWebGLEnabled(store.getBoolValueForKey(WebPreferencesKey::webGLEnabledKey())); settings->setMediaPlaybackRequiresUserGesture(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackRequiresUserGestureKey())); settings->setMediaPlaybackAllowsInline(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackAllowsInlineKey())); settings->setMockScrollbarsEnabled(store.getBoolValueForKey(WebPreferencesKey::mockScrollbarsEnabledKey())); settings->setHyperlinkAuditingEnabled(store.getBoolValueForKey(WebPreferencesKey::hyperlinkAuditingEnabledKey())); + settings->setRequestAnimationFrameEnabled(store.getBoolValueForKey(WebPreferencesKey::requestAnimationFrameEnabledKey())); // <rdar://problem/10697417>: It is necessary to force compositing when accelerate drawing // is enabled on Mac so that scrollbars are always in their own layers. @@ -1938,9 +1999,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setWebAudioEnabled(store.getBoolValueForKey(WebPreferencesKey::webAudioEnabledKey())); #endif - settings->setApplicationChromeMode(store.getBoolValueForKey(WebPreferencesKey::applicationChromeModeKey())); + settings->setApplicationChromeMode(store.getBoolValueForKey(WebPreferencesKey::applicationChromeModeKey())); settings->setSuppressesIncrementalRendering(store.getBoolValueForKey(WebPreferencesKey::suppressesIncrementalRenderingKey())); settings->setBackspaceKeyNavigationEnabled(store.getBoolValueForKey(WebPreferencesKey::backspaceKeyNavigationEnabledKey())); + settings->setWantsBalancedSetDefersLoadingBehavior(store.getBoolValueForKey(WebPreferencesKey::wantsBalancedSetDefersLoadingBehaviorKey())); settings->setCaretBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::caretBrowsingEnabledKey())); #if ENABLE(VIDEO_TRACK) @@ -1949,11 +2011,16 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setShouldDisplayTextDescriptions(store.getBoolValueForKey(WebPreferencesKey::shouldDisplayTextDescriptionsKey())); #endif -#if ENABLE(NOTIFICATIONS) +#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) settings->setNotificationsEnabled(store.getBoolValueForKey(WebPreferencesKey::notificationsEnabledKey())); #endif + settings->setShouldRespectImageOrientation(store.getBoolValueForKey(WebPreferencesKey::shouldRespectImageOrientationKey())); + platformPreferencesDidChange(store); + + if (m_drawingArea) + m_drawingArea->updatePreferences(); } #if ENABLE(INSPECTOR) @@ -2093,7 +2160,7 @@ void WebPage::performDragControllerAction(uint64_t action, WebCore::DragData dra } #else -void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const String& dragStorageName, uint32_t flags, const SandboxExtension::Handle& sandboxExtensionHandle) +void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const String& dragStorageName, uint32_t flags, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsHandleArray) { if (!m_page) { send(Messages::WebPageProxy::DidPerformDragControllerAction(WebCore::DragSession())); @@ -2118,6 +2185,8 @@ void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint cli ASSERT(!m_pendingDropSandboxExtension); m_pendingDropSandboxExtension = SandboxExtension::create(sandboxExtensionHandle); + for (size_t i = 0; i < sandboxExtensionsHandleArray.size(); i++) + m_pendingDropExtensionsForFileUpload.append(SandboxExtension::create(sandboxExtensionsHandleArray[i])); m_page->dragController()->performDrag(&dragData); @@ -2127,7 +2196,10 @@ void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint cli m_pendingDropSandboxExtension->invalidate(); m_pendingDropSandboxExtension = nullptr; } + for (size_t i = 0; i < m_pendingDropExtensionsForFileUpload.size(); i++) + m_pendingDropExtensionsForFileUpload[i]->invalidate(); + m_pendingDropExtensionsForFileUpload.clear(); break; } @@ -2156,6 +2228,13 @@ void WebPage::willPerformLoadDragDestinationAction() m_sandboxExtensionTracker.willPerformLoadDragDestinationAction(m_pendingDropSandboxExtension.release()); } +void WebPage::mayPerformUploadDragDestinationAction() +{ + for (size_t i = 0; i < m_pendingDropExtensionsForFileUpload.size(); i++) + m_pendingDropExtensionsForFileUpload[i]->consumePermanently(); + m_pendingDropExtensionsForFileUpload.clear(); +} + WebUndoStep* WebPage::webUndoStep(uint64_t stepID) { return m_undoStepMap.get(stepID).get(); @@ -2330,6 +2409,7 @@ void WebPage::failedToShowPopupMenu() } #endif +#if ENABLE(CONTEXT_MENUS) void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& item) { if (!m_contextMenu) @@ -2338,6 +2418,7 @@ void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& i m_contextMenu->itemSelected(item); m_contextMenu = 0; } +#endif void WebPage::replaceSelectionWithText(Frame* frame, const String& text) { @@ -2423,17 +2504,21 @@ void WebPage::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInSc for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it) (*it)->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates); } - #endif bool WebPage::windowIsFocused() const { + return m_page->focusController()->isActive(); +} + +bool WebPage::windowAndWebPageAreFocused() const +{ #if PLATFORM(MAC) if (!m_windowIsVisible) return false; #endif return m_page->focusController()->isFocused() && m_page->focusController()->isActive(); -} +} void WebPage::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) { @@ -2482,8 +2567,27 @@ InjectedBundleBackForwardList* WebPage::backForwardList() } #if PLATFORM(QT) -void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point) +#if ENABLE(TOUCH_ADJUSTMENT) +void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point, const WebCore::IntSize& area) { + Node* node = 0; + IntRect zoomableArea; + bool foundAreaForTouchPoint = m_mainFrame->coreFrame()->eventHandler()->bestZoomableAreaForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), zoomableArea, node); + ASSERT(node); + + if (!foundAreaForTouchPoint) + return; + + if (node->document() && node->document()->view()) + zoomableArea = node->document()->view()->contentsToWindow(zoomableArea); + + send(Messages::WebPageProxy::DidFindZoomableArea(point, zoomableArea)); +} + +#else +void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point, const WebCore::IntSize& area) +{ + UNUSED_PARAM(area); Frame* mainframe = m_mainFrame->coreFrame(); HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true); @@ -2519,6 +2623,7 @@ void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point) send(Messages::WebPageProxy::DidFindZoomableArea(point, zoomableArea)); } #endif +#endif WebPage::SandboxExtensionTracker::~SandboxExtensionTracker() { @@ -2614,8 +2719,13 @@ void WebPage::SandboxExtensionTracker::didCommitProvisionalLoad(WebFrame* frame) { if (!frame->isMainFrame()) return; - - ASSERT(!m_pendingProvisionalSandboxExtension); + + // Generally, there should be no pending extension at this stage, but we can have one if UI process + // has an out of date idea of WebProcess state, and initiates a load or reload without stopping an existing one. + if (m_pendingProvisionalSandboxExtension) { + m_pendingProvisionalSandboxExtension->invalidate(); + m_pendingProvisionalSandboxExtension = nullptr; + } // The provisional load has been committed. Invalidate the currently committed sandbox // extension and make the provisional sandbox extension the committed sandbox extension. @@ -2630,6 +2740,13 @@ void WebPage::SandboxExtensionTracker::didFailProvisionalLoad(WebFrame* frame) if (!frame->isMainFrame()) return; + // Generally, there should be no pending extension at this stage, but we can have one if UI process + // has an out of date idea of WebProcess state, and initiates a load or reload without stopping an existing one. + if (m_pendingProvisionalSandboxExtension) { + m_pendingProvisionalSandboxExtension->invalidate(); + m_pendingProvisionalSandboxExtension = nullptr; + } + if (!m_provisionalSandboxExtension) return; @@ -2680,8 +2797,8 @@ void WebPage::stopSpeaking() #endif -#if USE(CG) -static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame) +#if PLATFORM(MAC) +RetainPtr<PDFDocument> WebPage::pdfDocumentForPrintingFrame(Frame* coreFrame) { Document* document = coreFrame->document(); if (!document) @@ -2696,7 +2813,7 @@ static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame) return pluginView->pdfDocumentForPrinting(); } -#endif // USE(CG) +#endif // PLATFORM(MAC) void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo) { @@ -2708,10 +2825,10 @@ void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo) if (!coreFrame) return; -#if USE(CG) +#if PLATFORM(MAC) if (pdfDocumentForPrintingFrame(coreFrame)) return; -#endif // USE(CG) +#endif // PLATFORM(MAC) if (!m_printContext) m_printContext = adoptPtr(new PrintContext(coreFrame)); @@ -2748,21 +2865,10 @@ void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printIn resultPageRects = m_printContext->pageRects(); resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight)) * printInfo.pageSetupScaleFactor; } -#if USE(CG) - else { - WebFrame* frame = WebProcess::shared().webFrame(frameID); - Frame* coreFrame = frame ? frame->coreFrame() : 0; - RetainPtr<CGPDFDocumentRef> pdfDocument = coreFrame ? pdfDocumentForPrintingFrame(coreFrame) : 0; - if (pdfDocument && CGPDFDocumentAllowsPrinting(pdfDocument.get())) { - CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get()); - IntRect pageRect(0, 0, ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight)); - for (CFIndex i = 1; i <= pageCount; ++i) { - resultPageRects.append(pageRect); - pageRect.move(0, pageRect.height()); - } - } - } -#endif // USE(CG) +#if PLATFORM(MAC) + else + computePagesForPrintingPDFDocument(frameID, printInfo, resultPageRects); +#endif // PLATFORM(MAC) // If we're asked to print, we should actually print at least a blank page. if (resultPageRects.isEmpty()) @@ -2771,48 +2877,6 @@ void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printIn send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID)); } -#if USE(CG) -static inline CGFloat roundCGFloat(CGFloat f) -{ - if (sizeof(CGFloat) == sizeof(float)) - return roundf(static_cast<float>(f)); - return static_cast<CGFloat>(round(f)); -} - -static void drawPDFPage(CGPDFDocumentRef pdfDocument, CFIndex pageIndex, CGContextRef context, CGFloat pageSetupScaleFactor, CGSize paperSize) -{ - CGContextSaveGState(context); - - CGContextScaleCTM(context, pageSetupScaleFactor, pageSetupScaleFactor); - - CGPDFPageRef page = CGPDFDocumentGetPage(pdfDocument, pageIndex + 1); - CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox); - if (CGRectIsEmpty(cropBox)) - cropBox = CGRectIntersection(cropBox, CGPDFPageGetBoxRect(page, kCGPDFMediaBox)); - else - cropBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); - - bool shouldRotate = (paperSize.width < paperSize.height) != (cropBox.size.width < cropBox.size.height); - if (shouldRotate) - swap(cropBox.size.width, cropBox.size.height); - - // Center. - CGFloat widthDifference = paperSize.width / pageSetupScaleFactor - cropBox.size.width; - CGFloat heightDifference = paperSize.height / pageSetupScaleFactor - cropBox.size.height; - if (widthDifference || heightDifference) - CGContextTranslateCTM(context, roundCGFloat(widthDifference / 2), roundCGFloat(heightDifference / 2)); - - if (shouldRotate) { - CGContextRotateCTM(context, static_cast<CGFloat>(piOverTwoDouble)); - CGContextTranslateCTM(context, 0, -cropBox.size.width); - } - - CGContextDrawPDFPage(context, page); - - CGContextRestoreGState(context); -} -#endif // USE(CG) - #if PLATFORM(MAC) || PLATFORM(WIN) void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const WebCore::IntRect& rect, uint64_t callbackID) { @@ -2822,12 +2886,11 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0)); if (coreFrame) { -#if !USE(CG) - UNUSED_PARAM(printInfo); - - ASSERT(coreFrame->document()->printing()); -#else +#if PLATFORM(MAC) ASSERT(coreFrame->document()->printing() || pdfDocumentForPrintingFrame(coreFrame)); +#else + ASSERT(coreFrame->document()->printing()); +#endif // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data. RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get())); @@ -2837,22 +2900,13 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); CGPDFContextBeginPage(context.get(), pageInfo.get()); - if (RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) { - CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get()); - IntSize paperSize(ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight)); - IntRect pageRect(IntPoint(), paperSize); - for (CFIndex i = 0; i < pageCount; ++i) { - if (pageRect.intersects(rect)) { - CGContextSaveGState(context.get()); - - CGContextTranslateCTM(context.get(), pageRect.x() - rect.x(), pageRect.y() - rect.y()); - drawPDFPage(pdfDocument.get(), i, context.get(), printInfo.pageSetupScaleFactor, paperSize); - - CGContextRestoreGState(context.get()); - } - pageRect.move(0, pageRect.height()); - } - } else { +#if PLATFORM(MAC) + if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) { + ASSERT(!m_printContext); + drawRectToPDFFromPDFDocument(context.get(), pdfDocument.get(), printInfo, rect); + } else +#endif + { GraphicsContext ctx(context.get()); ctx.scale(FloatSize(1, -1)); ctx.translate(0, -rect.height()); @@ -2861,7 +2915,6 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const CGPDFContextEndPage(context.get()); CGPDFContextClose(context.get()); -#endif } send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID)); @@ -2876,44 +2929,49 @@ void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo& printInfo, uint3 if (coreFrame) { -#if !USE(CG) - ASSERT(coreFrame->document()->printing()); -#else +#if PLATFORM(MAC) ASSERT(coreFrame->document()->printing() || pdfDocumentForPrintingFrame(coreFrame)); - - RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame); +#else + ASSERT(coreFrame->document()->printing()); +#endif // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data. RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get())); - CGRect mediaBox = m_printContext && m_printContext->pageCount() ? m_printContext->pageRect(0) : CGRectMake(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight); + CGRect mediaBox = (m_printContext && m_printContext->pageCount()) ? m_printContext->pageRect(0) : CGRectMake(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight); RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0)); - size_t pageCount = m_printContext ? m_printContext->pageCount() : CGPDFDocumentGetNumberOfPages(pdfDocument.get()); - for (uint32_t page = first; page < first + count; ++page) { - if (page >= pageCount) - break; - RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); - CGPDFContextBeginPage(context.get(), pageInfo.get()); +#if PLATFORM(MAC) + if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) { + ASSERT(!m_printContext); + drawPagesToPDFFromPDFDocument(context.get(), pdfDocument.get(), printInfo, first, count); + } else +#endif + { + size_t pageCount = m_printContext->pageCount(); + for (uint32_t page = first; page < first + count; ++page) { + if (page >= pageCount) + break; + + RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); + CGPDFContextBeginPage(context.get(), pageInfo.get()); - if (pdfDocument) - drawPDFPage(pdfDocument.get(), page, context.get(), printInfo.pageSetupScaleFactor, CGSizeMake(printInfo.availablePaperWidth, printInfo.availablePaperHeight)); - else { GraphicsContext ctx(context.get()); ctx.scale(FloatSize(1, -1)); ctx.translate(0, -m_printContext->pageRect(page).height()); m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width()); - } - CGPDFContextEndPage(context.get()); + CGPDFContextEndPage(context.get()); + } } CGPDFContextClose(context.get()); -#endif } send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID)); } + #elif PLATFORM(GTK) + void WebPage::drawPagesForPrinting(uint64_t frameID, const PrintInfo& printInfo, uint64_t callbackID) { beginPrinting(frameID, printInfo); @@ -2957,12 +3015,12 @@ bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request) } #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) -void WebPage::handleCorrectionPanelResult(const String& result) +void WebPage::handleAlternativeTextUIResult(const String& result) { Frame* frame = m_page->focusController()->focusedOrMainFrame(); if (!frame) return; - frame->editor()->handleCorrectionPanelResult(result); + frame->editor()->handleAlternativeTextUIResult(result); } #endif @@ -2987,7 +3045,7 @@ String WebPage::viewportConfigurationAsText(int deviceDPI, int deviceWidth, int ViewportAttributes attrs = WebCore::computeViewportAttributes(arguments, /* default layout width for non-mobile pages */ 980, deviceWidth, deviceHeight, deviceDPI, IntSize(availableWidth, availableHeight)); WebCore::restrictMinimumScaleFactorToViewportSize(attrs, IntSize(availableWidth, availableHeight)); WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(attrs); - return String::format("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n", attrs.layoutSize.width(), attrs.layoutSize.height(), attrs.initialScale, attrs.minimumScale, attrs.maximumScale, attrs.userScalable); + return String::format("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n", static_cast<int>(attrs.layoutSize.width()), static_cast<int>(attrs.layoutSize.height()), attrs.initialScale, attrs.minimumScale, attrs.maximumScale, attrs.userScalable); } void WebPage::setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length) @@ -3053,7 +3111,8 @@ static bool pageContainsAnyHorizontalScrollbars(Frame* mainFrame) for (HashSet<ScrollableArea*>::const_iterator it = scrollableAreas->begin(), end = scrollableAreas->end(); it != end; ++it) { ScrollableArea* scrollableArea = *it; - ASSERT(scrollableArea->isOnActivePage()); + if (!scrollableArea->isOnActivePage()) + continue; if (hasEnabledHorizontalScrollbar(scrollableArea)) return true; @@ -3093,4 +3152,13 @@ FrameView* WebPage::mainFrameView() const return 0; } +#if ENABLE(PAGE_VISIBILITY_API) +void WebPage::setVisibilityState(int visibilityState, bool isInitialState) +{ + if (!m_page) + return; + m_page->setVisibilityState(static_cast<WebCore::PageVisibilityState>(visibilityState), isInitialState); +} +#endif + } // namespace WebKit |