diff options
author | Steve Block <steveblock@google.com> | 2011-06-08 08:26:01 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-08 08:26:01 -0700 |
commit | 3742ac093d35d923c81693096ab6671e9b147700 (patch) | |
tree | c2add9100f789dad45ef1ec5328bddde02c47a4c /Source/WebKit2/WebProcess/WebPage/mac | |
parent | 901401d90459bc22580842455d4588b9a697514d (diff) | |
parent | e5926f4a0d6adc9ad4a75824129f117181953560 (diff) | |
download | external_webkit-3742ac093d35d923c81693096ab6671e9b147700.zip external_webkit-3742ac093d35d923c81693096ab6671e9b147700.tar.gz external_webkit-3742ac093d35d923c81693096ab6671e9b147700.tar.bz2 |
Merge changes I55c6d71a,Ifb3277d4,Ia1b847a2,I7ba9cf3f,Ida2b2a8a,I1280ec90,I72f818d5,I2e3b588b,I9a4e6289,Ia724c78b,Icd8612c8,Ie31b15d7,Ie125edae,I77941a88,I89dae78b,I3516e5ca,I1a4c17b5,I2c4ecc1a,I9c8e6537,Ifac13115,Ie1f80e09,Ia541ed77,I60ce9d78
* changes:
Merge WebKit at r82507: Update ThirdPartyProject.prop
Merge WebKit at r82507: Cherry-pick change r88166 to add INSPECTOR guards to ScriptProfiler
Merge WebKit at r82507: Work around a V8 bug
Merge WebKit at r82507: JNIType renamed to JavaType
Merge WebKit at r82507: IconDatabaseClient interface expanded
Merge WebKit at r82507: Don't use new loss-free code path in HTMLCanvasElement::toDataURL()
Merge WebKit at r82507: IcondDatabaseBase::iconForPageURL() renamed
Merge WebKit at r82507: IconDatabaseBase::Open() signature changed
Merge WebKit at r82507: Node::isContentEditable() renamed
Merge WebKit at r82507: Use icon database through IconDatabaseBase
Merge WebKit at r82507: toInputElement() is now a member of Node
Merge WebKit at r82507: FrameLoaderClient::objectContentType() signature changed
Merge WebKit at r82507: StringImpl::computeHash() removed
Merge WebKit at r82507: Stub out FontPlatformData::setOrientation()
Merge WebKit at r82507: Path::strokeBoundingRect() is now const
Merge WebKit at r82507: Add missing UnusedParam.h include in ApplicationCacheGroup.cpp
Merge WebKit at r82507: Continue to use Android's version of FontPlatformData.h
Merge WebKit at r82507: Update signature of FontCustomPlatformData::fontPlatformData()
Merge WebKit at r82507: Fix conflicts due to JNI refactoring
Merge WebKit at r82507: Fix conflicts due to new StorageTracker
Merge WebKit at r82507: Fix conflicts
Merge WebKit at r82507: Fix makefiles
Merge WebKit at r82507: Initial merge by git
Diffstat (limited to 'Source/WebKit2/WebProcess/WebPage/mac')
4 files changed, 126 insertions, 455 deletions
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/AccessibilityWebPageObject.mm b/Source/WebKit2/WebProcess/WebPage/mac/AccessibilityWebPageObject.mm index c88ab7e..1d036fa 100644 --- a/Source/WebKit2/WebProcess/WebPage/mac/AccessibilityWebPageObject.mm +++ b/Source/WebKit2/WebProcess/WebPage/mac/AccessibilityWebPageObject.mm @@ -175,10 +175,12 @@ using namespace WebKit; point.y -= remotePosition.y; point.x -= remotePosition.x; - WebCore::FrameView* fv = m_page->mainFrame()->coreFrame()->view(); - if (fv) { - point.y += fv->scrollPosition().y(); - point.x += fv->scrollPosition().x(); + if (m_page && m_page->mainFrame() && m_page->mainFrame()->coreFrame()) { + WebCore::FrameView* fv = m_page->mainFrame()->coreFrame()->view(); + if (fv) { + point.y += fv->scrollPosition().y(); + point.x += fv->scrollPosition().x(); + } } return [[self accessibilityRootObjectWrapper] accessibilityHitTest:point]; @@ -186,7 +188,7 @@ using namespace WebKit; - (id)accessibilityFocusedUIElement { - return NSAccessibilityUnignoredDescendant(self); + return [[self accessibilityRootObjectWrapper] accessibilityFocusedUIElement]; } diff --git a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h deleted file mode 100644 index d05e43e..0000000 --- a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -#ifndef LayerTreeHostMac_h -#define LayerTreeHostMac_h - -#include "LayerTreeContext.h" -#include "LayerTreeHost.h" -#include <WebCore/GraphicsLayerClient.h> -#include <wtf/OwnPtr.h> -#include <wtf/RetainPtr.h> - -typedef struct __WKCARemoteLayerClientRef* WKCARemoteLayerClientRef; - -namespace WebKit { - -class LayerTreeHostMac : public LayerTreeHost, WebCore::GraphicsLayerClient { -public: - static PassRefPtr<LayerTreeHostMac> create(WebPage*); - ~LayerTreeHostMac(); - -private: - explicit LayerTreeHostMac(WebPage*); - - // 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(); - virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&); - - // GraphicsLayerClient - virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time); - virtual void notifySyncRequired(const WebCore::GraphicsLayer*); - virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect); - virtual bool showDebugBorders() const; - virtual bool showRepaintCounter() const; - - static void flushPendingLayerChangesRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void*); - void flushPendingLayerChangesRunLoopObserverCallback(); - bool flushPendingLayerChanges(); - - void createPageOverlayLayer(); - void destroyPageOverlayLayer(); - - // The context for this layer tree. - LayerTreeContext m_layerTreeContext; - - // 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; - - // The layer which contains all non-composited content. - OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer; - - // The page overlay layer. Will be null if there's no page overlay. - OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer; - - RetainPtr<WKCARemoteLayerClientRef> m_remoteLayerClient; - RetainPtr<CFRunLoopObserverRef> m_flushPendingLayerChangesRunLoopObserver; -}; - -} // namespace WebKit - -#endif // LayerTreeHostMac_h diff --git a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm deleted file mode 100644 index 494f5e6..0000000 --- a/Source/WebKit2/WebProcess/WebPage/mac/LayerTreeHostMac.mm +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (C) 2011 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 "LayerTreeHostMac.h" - -#import "DrawingAreaImpl.h" -#import "WebPage.h" -#import "WebProcess.h" -#import <QuartzCore/CATransaction.h> -#import <WebCore/Frame.h> -#import <WebCore/FrameView.h> -#import <WebCore/Page.h> -#import <WebCore/Settings.h> -#import <WebKitSystemInterface.h> - -@interface CATransaction (Details) -+ (void)synchronize; -@end - -using namespace WebCore; - -namespace WebKit { - -PassRefPtr<LayerTreeHostMac> LayerTreeHostMac::create(WebPage* webPage) -{ - return adoptRef(new LayerTreeHostMac(webPage)); -} - -LayerTreeHostMac::LayerTreeHostMac(WebPage* webPage) - : LayerTreeHost(webPage) - , m_isValid(true) - , m_notifyAfterScheduledLayerFlush(false) -{ - mach_port_t serverPort = WebProcess::shared().compositingRenderServerPort(); - m_remoteLayerClient = WKCARemoteLayerClientMakeWithServerPort(serverPort); - - // Create a root layer. - m_rootLayer = GraphicsLayer::create(this); -#ifndef NDEBUG - m_rootLayer->setName("LayerTreeHost root layer"); -#endif - m_rootLayer->setDrawsContent(false); - m_rootLayer->setSize(webPage->size()); - - [m_rootLayer->platformLayer() setGeometryFlipped:YES]; - - m_nonCompositedContentLayer = GraphicsLayer::create(this); -#ifndef NDEBUG - m_nonCompositedContentLayer->setName("LayerTreeHost non-composited content"); -#endif - 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()); - - WKCARemoteLayerClientSetLayer(m_remoteLayerClient.get(), m_rootLayer->platformLayer()); - - if (m_webPage->hasPageOverlay()) - createPageOverlayLayer(); - - scheduleLayerFlush(); - - m_layerTreeContext.contextID = WKCARemoteLayerClientGetClientId(m_remoteLayerClient.get()); -} - -LayerTreeHostMac::~LayerTreeHostMac() -{ - ASSERT(!m_isValid); - ASSERT(!m_flushPendingLayerChangesRunLoopObserver); - ASSERT(!m_remoteLayerClient); - ASSERT(!m_rootLayer); -} - -const LayerTreeContext& LayerTreeHostMac::layerTreeContext() -{ - return m_layerTreeContext; -} - -void LayerTreeHostMac::scheduleLayerFlush() -{ - CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent(); - - // Make sure we wake up the loop or the observer could be delayed until some other source fires. - CFRunLoopWakeUp(currentRunLoop); - - if (m_flushPendingLayerChangesRunLoopObserver) - return; - - // Run before the Core Animation commit observer, which has order 2000000. - const CFIndex runLoopOrder = 2000000 - 1; - CFRunLoopObserverContext context = { 0, this, 0, 0, 0 }; - m_flushPendingLayerChangesRunLoopObserver.adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, runLoopOrder, flushPendingLayerChangesRunLoopObserverCallback, &context)); - - CFRunLoopAddObserver(currentRunLoop, m_flushPendingLayerChangesRunLoopObserver.get(), kCFRunLoopCommonModes); -} - -void LayerTreeHostMac::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush) -{ - m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush; -} - -void LayerTreeHostMac::setRootCompositingLayer(GraphicsLayer* graphicsLayer) -{ - m_nonCompositedContentLayer->removeAllChildren(); - - // Add the accelerated layer tree hierarchy. - if (graphicsLayer) - m_nonCompositedContentLayer->addChild(graphicsLayer); -} - -void LayerTreeHostMac::invalidate() -{ - ASSERT(m_isValid); - - if (m_flushPendingLayerChangesRunLoopObserver) { - CFRunLoopObserverInvalidate(m_flushPendingLayerChangesRunLoopObserver.get()); - m_flushPendingLayerChangesRunLoopObserver = nullptr; - } - - WKCARemoteLayerClientInvalidate(m_remoteLayerClient.get()); - m_remoteLayerClient = nullptr; - m_rootLayer = nullptr; - m_isValid = false; -} - -void LayerTreeHostMac::setNonCompositedContentsNeedDisplay(const IntRect& rect) -{ - m_nonCompositedContentLayer->setNeedsDisplayInRect(rect); - if (m_pageOverlayLayer) - m_pageOverlayLayer->setNeedsDisplayInRect(rect); - - scheduleLayerFlush(); -} - -void LayerTreeHostMac::scrollNonCompositedContents(const IntRect& scrollRect, const IntSize& scrollOffset) -{ - setNonCompositedContentsNeedDisplay(scrollRect); -} - -void LayerTreeHostMac::sizeDidChange(const IntSize& newSize) -{ - m_rootLayer->setSize(newSize); - m_nonCompositedContentLayer->setSize(newSize); - - if (m_pageOverlayLayer) - m_pageOverlayLayer->setSize(newSize); - - scheduleLayerFlush(); - flushPendingLayerChanges(); - - [CATransaction flush]; - [CATransaction synchronize]; -} - -void LayerTreeHostMac::forceRepaint() -{ - scheduleLayerFlush(); - flushPendingLayerChanges(); - - [CATransaction flush]; - [CATransaction synchronize]; -} - -void LayerTreeHostMac::didInstallPageOverlay() -{ - createPageOverlayLayer(); - scheduleLayerFlush(); -} - -void LayerTreeHostMac::didUninstallPageOverlay() -{ - destroyPageOverlayLayer(); - scheduleLayerFlush(); -} - -void LayerTreeHostMac::setPageOverlayNeedsDisplay(const IntRect& rect) -{ - ASSERT(m_pageOverlayLayer); - m_pageOverlayLayer->setNeedsDisplayInRect(rect); - scheduleLayerFlush(); -} - -void LayerTreeHostMac::notifyAnimationStarted(const WebCore::GraphicsLayer*, double time) -{ -} - -void LayerTreeHostMac::notifySyncRequired(const WebCore::GraphicsLayer*) -{ -} - -void LayerTreeHostMac::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& clipRect) -{ - if (graphicsLayer == m_nonCompositedContentLayer) { - m_webPage->drawRect(graphicsContext, clipRect); - return; - } - - if (graphicsLayer == m_pageOverlayLayer) { - m_webPage->drawPageOverlay(graphicsContext, clipRect); - return; - } -} - -bool LayerTreeHostMac::showDebugBorders() const -{ - return m_webPage->corePage()->settings()->showDebugBorders(); -} - -bool LayerTreeHostMac::showRepaintCounter() const -{ - return m_webPage->corePage()->settings()->showRepaintCounter(); -} - -void LayerTreeHostMac::flushPendingLayerChangesRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context) -{ - static_cast<LayerTreeHostMac*>(context)->flushPendingLayerChangesRunLoopObserverCallback(); -} - -void LayerTreeHostMac::flushPendingLayerChangesRunLoopObserverCallback() -{ - { - RefPtr<LayerTreeHostMac> protect(this); - m_webPage->layoutIfNeeded(); - - if (!m_isValid) - return; - } - - if (!flushPendingLayerChanges()) - return; - - // We successfully flushed the pending layer changes, remove the run loop observer. - 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() -{ - m_rootLayer->syncCompositingStateForThisLayerOnly(); - m_nonCompositedContentLayer->syncCompositingStateForThisLayerOnly(); - if (m_pageOverlayLayer) - m_pageOverlayLayer->syncCompositingStateForThisLayerOnly(); - - return m_webPage->corePage()->mainFrame()->view()->syncCompositingStateIncludingSubframes(); -} - -void LayerTreeHostMac::createPageOverlayLayer() -{ - ASSERT(!m_pageOverlayLayer); - - m_pageOverlayLayer = GraphicsLayer::create(this); -#ifndef NDEBUG - m_pageOverlayLayer->setName("LayerTreeHost page overlay content"); -#endif - - m_pageOverlayLayer->setDrawsContent(true); - m_pageOverlayLayer->setSize(m_webPage->size()); - - m_rootLayer->addChild(m_pageOverlayLayer.get()); -} - -void LayerTreeHostMac::destroyPageOverlayLayer() -{ - ASSERT(m_pageOverlayLayer); - m_pageOverlayLayer->removeFromParent(); - m_pageOverlayLayer = nullptr; -} - -} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm index 4cae5aa..8d81889 100644 --- a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm +++ b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,6 +46,7 @@ #import <WebCore/ScrollView.h> #import <WebCore/TextIterator.h> #import <WebCore/WindowsKeyboardCodes.h> +#import <WebCore/visible_units.h> #import <WebKitSystemInterface.h> using namespace WebCore; @@ -76,8 +77,6 @@ void WebPage::platformPreferencesDidChange(const WebPreferencesStore&) { } -// FIXME: need to add support for input methods - bool WebPage::interceptEditingKeyboardEvent(KeyboardEvent* evt, bool shouldSaveCommand) { Node* node = evt->target()->toNode(); @@ -164,12 +163,12 @@ void WebPage::getMarkedRange(uint64_t& location, uint64_t& length) getLocationAndLengthFromRange(frame->editor()->compositionRange().get(), location, length); } -static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& point) + +static PassRefPtr<Range> characterRangeAtPositionForPoint(Frame* frame, const VisiblePosition& position, const IntPoint& point) { - VisiblePosition position = frame->visiblePositionForPoint(point); if (position.isNull()) return 0; - + VisiblePosition previous = position.previous(); if (previous.isNotNull()) { RefPtr<Range> previousCharacterRange = makeRange(previous, position); @@ -188,7 +187,12 @@ static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& poi return 0; } - + +static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& point) +{ + return characterRangeAtPositionForPoint(frame, frame->visiblePositionForPoint(point), point); +} + void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index) { index = NSNotFound; @@ -242,6 +246,32 @@ void WebPage::firstRectForCharacterRange(uint64_t location, uint64_t length, Web resultRect = frame->view()->contentsToWindow(rect); } +static bool isPositionInRange(const VisiblePosition& position, Range* range) +{ + RefPtr<Range> positionRange = makeRange(position, position); + + ExceptionCode ec = 0; + range->compareBoundaryPoints(Range::START_TO_START, positionRange.get(), ec); + if (ec) + return false; + + if (!range->isPointInRange(positionRange->startContainer(), positionRange->startOffset(), ec)) + return false; + if (ec) + return false; + + return true; +} + +static bool shouldUseSelection(const VisiblePosition& position, const VisibleSelection& selection) +{ + RefPtr<Range> selectedRange = selection.toNormalizedRange(); + if (!selectedRange) + return false; + + return isPositionInRange(position, selectedRange.get()); +} + void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint) { Frame* frame = m_page->mainFrame(); @@ -250,46 +280,78 @@ void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint) // 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) + IntPoint translatedPoint = frame->view()->windowToContents(point); + VisiblePosition position = frame->visiblePositionForPoint(translatedPoint); + + // Don't do anything if there is no character at the point. + if (!characterRangeAtPositionForPoint(frame, position, translatedPoint)) 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; - } - } + VisibleSelection selection = m_page->focusController()->focusedOrMainFrame()->selection()->selection(); + if (shouldUseSelection(position, selection)) { + performDictionaryLookupForSelection(DictionaryPopupInfo::HotKey, frame, selection); + return; } - if (!characterRange) - return; + NSDictionary *options = nil; + +#if !defined(BUILDING_ON_SNOW_LEOPARD) + // As context, we are going to use the surrounding paragraph of text. + VisiblePosition paragraphStart = startOfParagraph(position); + VisiblePosition paragraphEnd = endOfParagraph(position); + + NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(paragraphStart, position).get()), 0); - // Ensure we have whole words. - VisibleSelection selection(characterRange.get()); - selection.expandUsingGranularity(WordGranularity); + RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd); + String fullPlainTextString = plainText(fullCharacterRange.get()); - RefPtr<Range> finalRange = selection.toNormalizedRange(); + NSRange extractedRange = WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, &options); + + RefPtr<Range> finalRange = TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length); + if (!finalRange) + return; +#else + RefPtr<Range> finalRange = makeRange(startOfWord(position), endOfWord(position)); if (!finalRange) return; +#endif + + performDictionaryLookupForRange(DictionaryPopupInfo::HotKey, frame, finalRange.get(), options); +} + +void WebPage::performDictionaryLookupForSelection(DictionaryPopupInfo::Type type, Frame* frame, const VisibleSelection& selection) +{ + RefPtr<Range> selectedRange = selection.toNormalizedRange(); + if (!selectedRange) + return; - performDictionaryLookupForRange(DictionaryPopupInfo::HotKey, frame, finalRange.get()); + NSDictionary *options = nil; + +#if !defined(BUILDING_ON_SNOW_LEOPARD) + VisiblePosition selectionStart = selection.visibleStart(); + VisiblePosition selectionEnd = selection.visibleEnd(); + + // As context, we are going to use the surrounding paragraphs of text. + VisiblePosition paragraphStart = startOfParagraph(selectionStart); + VisiblePosition paragraphEnd = endOfParagraph(selectionEnd); + + int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get()); + int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get()); + NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart); + + String fullPlainTextString = plainText(makeRange(paragraphStart, paragraphEnd).get()); + + // Since we already have the range we want, we just need to grab the returned options. + WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, &options); +#endif + + performDictionaryLookupForRange(type, frame, selectedRange.get(), options); } -void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range) +void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range, NSDictionary *options) { String rangeText = range->text(); if (rangeText.stripWhiteSpace().isEmpty()) @@ -316,20 +378,11 @@ void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Fr dictionaryPopupInfo.type = type; dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y()); dictionaryPopupInfo.fontInfo.fontAttributeDictionary = fontDescriptorAttributes; + dictionaryPopupInfo.options = (CFDictionaryRef)options; send(Messages::WebPageProxy::DidPerformDictionaryLookup(rangeText, dictionaryPopupInfo)); } -static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity) -{ - page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity); -} - -static inline void logicalScroll(Page* page, ScrollLogicalDirection direction, ScrollGranularity granularity) -{ - page->focusController()->focusedOrMainFrame()->eventHandler()->logicalScrollRecursively(direction, granularity); -} - bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent) { if (keyboardEvent.type() != WebEvent::KeyDown) @@ -390,7 +443,7 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard if (keyboardEvent.metaKey()) m_page->goBack(); else { - if (keyboardEvent.altKey() | keyboardEvent.controlKey()) + if (keyboardEvent.altKey() || keyboardEvent.controlKey()) scroll(m_page.get(), ScrollLeft, ScrollByPage); else scroll(m_page.get(), ScrollLeft, ScrollByLine); @@ -435,6 +488,13 @@ void WebPage::writeSelectionToPasteboard(const String& pasteboardName, const Vec result = true; } +void WebPage::readSelectionFromPasteboard(const String& pasteboardName, bool& result) +{ + Frame* frame = m_page->focusController()->focusedOrMainFrame(); + frame->editor()->readSelectionFromPasteboard(pasteboardName); + result = true; +} + AccessibilityWebPageObject* WebPage::accessibilityRemoteObject() { return m_mockAccessibilityElement.get(); @@ -472,13 +532,26 @@ String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url) return [[cachedResponse response] MIMEType]; } -bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request) +bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest& request) { if ([NSURLConnection canHandleRequest:request.nsURLRequest()]) - return YES; + return true; // FIXME: Return true if this scheme is any one WebKit2 knows how to handle. return request.url().protocolIs("applewebdata"); } +void WebPage::setDragSource(NSObject *dragSource) +{ + m_dragSource = dragSource; +} + +void WebPage::platformDragEnded() +{ + // The drag source we care about here is NSFilePromiseDragSource, which doesn't look at + // the arguments. It's OK to just pass arbitrary constant values, so we just pass all zeroes. + [m_dragSource.get() draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationNone]; + m_dragSource = nullptr; +} + } // namespace WebKit |