summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/WebProcess/WebPage/mac
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-05-24 11:24:40 +0100
committerBen Murdoch <benm@google.com>2011-06-02 09:53:15 +0100
commit81bc750723a18f21cd17d1b173cd2a4dda9cea6e (patch)
tree7a9e5ed86ff429fd347a25153107221543909b19 /Source/WebKit2/WebProcess/WebPage/mac
parent94088a6d336c1dd80a1e734af51e96abcbb689a7 (diff)
downloadexternal_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.zip
external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.gz
external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.bz2
Merge WebKit at r80534: Intial merge by Git
Change-Id: Ia7a83357124c9e1cdb1debf55d9661ec0bd09a61
Diffstat (limited to 'Source/WebKit2/WebProcess/WebPage/mac')
-rw-r--r--Source/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm187
-rw-r--r--Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h6
-rw-r--r--Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm29
-rw-r--r--Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm128
4 files changed, 145 insertions, 205 deletions
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm
deleted file mode 100644
index 25a1dfd..0000000
--- a/Source/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (C) 2010 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 "config.h"
-#import "LayerBackedDrawingArea.h"
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#import "DrawingAreaProxyMessageKinds.h"
-#import "WebKitSystemInterface.h"
-#import "WebPage.h"
-#import "WebProcess.h"
-#import <WebCore/Frame.h>
-#import <WebCore/FrameView.h>
-#import <WebCore/GraphicsLayer.h>
-#import <WebCore/Page.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-void LayerBackedDrawingArea::platformInit()
-{
- setUpUpdateLayoutRunLoopObserver();
-
- [m_hostingLayer->platformLayer() setGeometryFlipped:YES];
-#if HAVE(HOSTED_CORE_ANIMATION)
- attachCompositingContext();
-#endif
-
- scheduleCompositingLayerSync();
-}
-
-void LayerBackedDrawingArea::platformClear()
-{
- if (!m_attached)
- return;
-
- if (m_updateLayoutRunLoopObserver) {
- CFRunLoopObserverInvalidate(m_updateLayoutRunLoopObserver.get());
- m_updateLayoutRunLoopObserver = 0;
- }
-
-#if HAVE(HOSTED_CORE_ANIMATION)
- WKCARemoteLayerClientInvalidate(m_remoteLayerRef.get());
- m_remoteLayerRef = nullptr;
-#endif
-
- m_attached = false;
-}
-
-void LayerBackedDrawingArea::attachCompositingContext()
-{
- if (m_attached)
- return;
-
- m_attached = true;
-
-#if HAVE(HOSTED_CORE_ANIMATION)
- mach_port_t serverPort = WebProcess::shared().compositingRenderServerPort();
- m_remoteLayerRef = WKCARemoteLayerClientMakeWithServerPort(serverPort);
- WKCARemoteLayerClientSetLayer(m_remoteLayerRef.get(), m_hostingLayer->platformLayer());
-
- uint32_t contextID = WKCARemoteLayerClientGetClientId(m_remoteLayerRef.get());
- WebProcess::shared().connection()->deprecatedSendSync(DrawingAreaProxyLegacyMessage::AttachCompositingContext, m_webPage->pageID(), CoreIPC::In(contextID), CoreIPC::Out());
-#endif
-}
-
-void LayerBackedDrawingArea::detachCompositingContext()
-{
- m_backingLayer->removeAllChildren();
-
- scheduleCompositingLayerSync();
-}
-
-void LayerBackedDrawingArea::setRootCompositingLayer(WebCore::GraphicsLayer* layer)
-{
- m_backingLayer->removeAllChildren();
- if (layer)
- m_backingLayer->addChild(layer);
-
- scheduleCompositingLayerSync();
-}
-
-void LayerBackedDrawingArea::scheduleCompositingLayerSync()
-{
-// if (m_syncTimer.isActive())
-// return;
-//
-// m_syncTimer.startOneShot(0);
-
- scheduleUpdateLayoutRunLoopObserver();
-}
-
-void LayerBackedDrawingArea::syncCompositingLayers()
-{
- m_hostingLayer->syncCompositingStateForThisLayerOnly();
- m_backingLayer->syncCompositingStateForThisLayerOnly();
-
- bool didSync = m_webPage->corePage()->mainFrame()->view()->syncCompositingStateIncludingSubframes();
- if (!didSync) {
-
- }
-}
-
-void LayerBackedDrawingArea::setUpUpdateLayoutRunLoopObserver()
-{
- if (m_updateLayoutRunLoopObserver)
- return;
-
- // Run before Core Animations commit observer, which has order 2000000.
- const CFIndex runLoopOrder = 2000000 - 1;
- CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
- m_updateLayoutRunLoopObserver.adoptCF(CFRunLoopObserverCreate(0,
- kCFRunLoopBeforeWaiting | kCFRunLoopExit, true /* repeats */,
- runLoopOrder, updateLayoutRunLoopObserverCallback, &context));
-}
-
-void LayerBackedDrawingArea::scheduleUpdateLayoutRunLoopObserver()
-{
- CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
- CFRunLoopWakeUp(currentRunLoop);
-
- if (CFRunLoopContainsObserver(currentRunLoop, m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes))
- return;
-
- CFRunLoopAddObserver(currentRunLoop, m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes);
-}
-
-void LayerBackedDrawingArea::removeUpdateLayoutRunLoopObserver()
-{
- // FIXME: cache the run loop ref?
- CFRunLoopRemoveObserver(CFRunLoopGetCurrent(), m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes);
-}
-
-void LayerBackedDrawingArea::updateLayoutRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* info)
-{
- // Keep the drawing area alive while running the callback, since that does layout,
- // which might replace this drawing area with one of another type.
- RefPtr<LayerBackedDrawingArea> drawingArea = reinterpret_cast<LayerBackedDrawingArea*>(info);
- drawingArea->updateLayoutRunLoopObserverFired();
-}
-
-void LayerBackedDrawingArea::updateLayoutRunLoopObserverFired()
-{
- // Laying out the page can cause the drawing area to change so we keep an extra reference.
- RefPtr<LayerBackedDrawingArea> protect(this);
-
- m_webPage->layoutIfNeeded();
-
- if (m_webPage->drawingArea() != this)
- return;
-
- if (m_attached)
- syncCompositingLayers();
-}
-
-void LayerBackedDrawingArea::onPageClose()
-{
- platformClear();
-}
-
-} // namespace WebKit
-
-#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h
index 016f0d6..d05e43e 100644
--- a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h
+++ b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h
@@ -47,12 +47,14 @@ private:
// LayerTreeHost.
virtual const LayerTreeContext& layerTreeContext();
virtual void scheduleLayerFlush();
+ virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool);
virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
virtual void invalidate();
virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
virtual void sizeDidChange(const WebCore::IntSize& newSize);
+ virtual void forceRepaint();
virtual void didInstallPageOverlay();
virtual void didUninstallPageOverlay();
@@ -78,6 +80,10 @@ private:
// Whether the layer tree host is valid or not.
bool m_isValid;
+ // Whether we should let the drawing area know the next time we've flushed
+ // layer tree changes.
+ bool m_notifyAfterScheduledLayerFlush;
+
// The root layer.
OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm
index 9734aec..494f5e6 100644
--- a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm
+++ b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm
@@ -26,6 +26,7 @@
#import "config.h"
#import "LayerTreeHostMac.h"
+#import "DrawingAreaImpl.h"
#import "WebPage.h"
#import "WebProcess.h"
#import <QuartzCore/CATransaction.h>
@@ -51,6 +52,7 @@ PassRefPtr<LayerTreeHostMac> LayerTreeHostMac::create(WebPage* webPage)
LayerTreeHostMac::LayerTreeHostMac(WebPage* webPage)
: LayerTreeHost(webPage)
, m_isValid(true)
+ , m_notifyAfterScheduledLayerFlush(false)
{
mach_port_t serverPort = WebProcess::shared().compositingRenderServerPort();
m_remoteLayerClient = WKCARemoteLayerClientMakeWithServerPort(serverPort);
@@ -72,6 +74,8 @@ LayerTreeHostMac::LayerTreeHostMac(WebPage* webPage)
m_nonCompositedContentLayer->setDrawsContent(true);
m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground());
m_nonCompositedContentLayer->setSize(webPage->size());
+ if (m_webPage->corePage()->settings()->acceleratedDrawingEnabled())
+ m_nonCompositedContentLayer->setAcceleratesDrawing(true);
m_rootLayer->addChild(m_nonCompositedContentLayer.get());
@@ -116,14 +120,18 @@ void LayerTreeHostMac::scheduleLayerFlush()
CFRunLoopAddObserver(currentRunLoop, m_flushPendingLayerChangesRunLoopObserver.get(), kCFRunLoopCommonModes);
}
-void LayerTreeHostMac::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
+void LayerTreeHostMac::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
{
- ASSERT(graphicsLayer);
+ m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush;
+}
+void LayerTreeHostMac::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
+{
m_nonCompositedContentLayer->removeAllChildren();
// Add the accelerated layer tree hierarchy.
- m_nonCompositedContentLayer->addChild(graphicsLayer);
+ if (graphicsLayer)
+ m_nonCompositedContentLayer->addChild(graphicsLayer);
}
void LayerTreeHostMac::invalidate()
@@ -170,6 +178,15 @@ void LayerTreeHostMac::sizeDidChange(const IntSize& newSize)
[CATransaction synchronize];
}
+void LayerTreeHostMac::forceRepaint()
+{
+ scheduleLayerFlush();
+ flushPendingLayerChanges();
+
+ [CATransaction flush];
+ [CATransaction synchronize];
+}
+
void LayerTreeHostMac::didInstallPageOverlay()
{
createPageOverlayLayer();
@@ -242,6 +259,12 @@ void LayerTreeHostMac::flushPendingLayerChangesRunLoopObserverCallback()
ASSERT(m_flushPendingLayerChangesRunLoopObserver);
CFRunLoopObserverInvalidate(m_flushPendingLayerChangesRunLoopObserver.get());
m_flushPendingLayerChangesRunLoopObserver = 0;
+
+ if (m_notifyAfterScheduledLayerFlush) {
+ // Let the drawing area know that we've done a flush of the layer changes.
+ static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
+ m_notifyAfterScheduledLayerFlush = false;
+ }
}
bool LayerTreeHostMac::flushPendingLayerChanges()
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
index 71bbf78..4cae5aa 100644
--- a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
+++ b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
@@ -42,6 +42,7 @@
#import <WebCore/KeyboardEvent.h>
#import <WebCore/Page.h>
#import <WebCore/PlatformKeyboardEvent.h>
+#import <WebCore/ResourceHandle.h>
#import <WebCore/ScrollView.h>
#import <WebCore/TextIterator.h>
#import <WebCore/WindowsKeyboardCodes.h>
@@ -163,29 +164,29 @@ void WebPage::getMarkedRange(uint64_t& location, uint64_t& length)
getLocationAndLengthFromRange(frame->editor()->compositionRange().get(), location, length);
}
-static Range *characterRangeAtPoint(Frame* frame, const IntPoint point)
+static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& point)
{
VisiblePosition position = frame->visiblePositionForPoint(point);
if (position.isNull())
- return NULL;
+ return 0;
VisiblePosition previous = position.previous();
if (previous.isNotNull()) {
- Range *previousCharacterRange = makeRange(previous, position).get();
- NSRect rect = frame->editor()->firstRectForRange(previousCharacterRange);
- if (NSPointInRect(point, rect))
- return previousCharacterRange;
+ RefPtr<Range> previousCharacterRange = makeRange(previous, position);
+ IntRect rect = frame->editor()->firstRectForRange(previousCharacterRange.get());
+ if (rect.contains(point))
+ return previousCharacterRange.release();
}
VisiblePosition next = position.next();
if (next.isNotNull()) {
- Range *nextCharacterRange = makeRange(position, next).get();
- NSRect rect = frame->editor()->firstRectForRange(nextCharacterRange);
- if (NSPointInRect(point, rect))
- return nextCharacterRange;
+ RefPtr<Range> nextCharacterRange = makeRange(position, next);
+ IntRect rect = frame->editor()->firstRectForRange(nextCharacterRange.get());
+ if (rect.contains(point))
+ return nextCharacterRange.release();
}
- return NULL;
+ return 0;
}
void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index)
@@ -198,12 +199,12 @@ void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index)
HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, false);
frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame();
- Range *range = characterRangeAtPoint(frame, result.point());
+ RefPtr<Range> range = characterRangeAtPoint(frame, result.point());
if (!range)
return;
uint64_t length;
- getLocationAndLengthFromRange(range, index, length);
+ getLocationAndLengthFromRange(range.get(), index, length);
}
static PassRefPtr<Range> convertToRange(Frame* frame, NSRange nsrange)
@@ -241,6 +242,84 @@ void WebPage::firstRectForCharacterRange(uint64_t location, uint64_t length, Web
resultRect = frame->view()->contentsToWindow(rect);
}
+void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
+{
+ Frame* frame = m_page->mainFrame();
+ if (!frame)
+ return;
+
+ // Find the frame the point is over.
+ IntPoint point = roundedIntPoint(floatPoint);
+
+ HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, false);
+ frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame();
+
+ // Figure out if there are any characters under the point.
+ RefPtr<Range> characterRange = characterRangeAtPoint(frame, frame->view()->windowToContents(point));
+ if (!characterRange)
+ return;
+
+ // Grab the currently selected text.
+ RefPtr<Range> selectedRange = m_page->focusController()->focusedOrMainFrame()->selection()->selection().toNormalizedRange();
+
+ // Use the selected text if the point was anywhere in it. Assertain this by seeing if either character range
+ // the mouse is over is contained by the selection range.
+ if (characterRange && selectedRange) {
+ ExceptionCode ec = 0;
+ selectedRange->compareBoundaryPoints(Range::START_TO_START, characterRange.get(), ec);
+ if (!ec) {
+ if (selectedRange->isPointInRange(characterRange->startContainer(), characterRange->startOffset(), ec)) {
+ if (!ec)
+ characterRange = selectedRange;
+ }
+ }
+ }
+
+ if (!characterRange)
+ return;
+
+ // Ensure we have whole words.
+ VisibleSelection selection(characterRange.get());
+ selection.expandUsingGranularity(WordGranularity);
+
+ RefPtr<Range> finalRange = selection.toNormalizedRange();
+ if (!finalRange)
+ return;
+
+ performDictionaryLookupForRange(DictionaryPopupInfo::HotKey, frame, finalRange.get());
+}
+
+void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range)
+{
+ String rangeText = range->text();
+ if (rangeText.stripWhiteSpace().isEmpty())
+ return;
+
+ RenderObject* renderer = range->startContainer()->renderer();
+ RenderStyle* style = renderer->style();
+ NSFont *font = style->font().primaryFont()->getNSFont();
+ if (!font)
+ return;
+
+ 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());
+ dictionaryPopupInfo.fontInfo.fontAttributeDictionary = fontDescriptorAttributes;
+
+ send(Messages::WebPageProxy::DidPerformDictionaryLookup(rangeText, dictionaryPopupInfo));
+}
+
static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
{
page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
@@ -349,6 +428,13 @@ void WebPage::registerUIProcessAccessibilityTokens(const CoreIPC::DataReference&
#endif
}
+void WebPage::writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes, bool& result)
+{
+ Frame* frame = m_page->focusController()->focusedOrMainFrame();
+ frame->editor()->writeSelectionToPasteboard(pasteboardName, pasteboardTypes);
+ result = true;
+}
+
AccessibilityWebPageObject* WebPage::accessibilityRemoteObject()
{
return m_mockAccessibilityElement.get();
@@ -358,7 +444,13 @@ bool WebPage::platformHasLocalDataForURL(const WebCore::KURL& url)
{
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:(NSString*)userAgent() forHTTPHeaderField:@"User-Agent"];
- NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
+ NSCachedURLResponse *cachedResponse;
+#if USE(CFURLSTORAGESESSIONS)
+ if (CFURLStorageSessionRef storageSession = ResourceHandle::privateBrowsingStorageSession())
+ cachedResponse = WKCachedResponseForRequest(storageSession, request);
+ else
+#endif
+ cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
[request release];
return cachedResponse;
@@ -368,7 +460,13 @@ String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url)
{
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:(NSString*)userAgent() forHTTPHeaderField:@"User-Agent"];
- NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
+ NSCachedURLResponse *cachedResponse;
+#if USE(CFURLSTORAGESESSIONS)
+ if (CFURLStorageSessionRef storageSession = ResourceHandle::privateBrowsingStorageSession())
+ cachedResponse = WKCachedResponseForRequest(storageSession, request);
+ else
+#endif
+ cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
[request release];
return [[cachedResponse response] MIMEType];