From 2daae5fd11344eaa88a0d92b0f6d65f8d2255c00 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 2 Jun 2011 12:07:03 +0100 Subject: Merge WebKit at r84325: Initial merge by git. Change-Id: Ic1a909300ecc0a13ddc6b4e784371d2ac6e3d59b --- Source/WebKit2/UIProcess/mac/CorrectionPanel.h | 6 +- Source/WebKit2/UIProcess/mac/CorrectionPanel.mm | 28 ++++---- Source/WebKit2/UIProcess/mac/TextCheckerMac.mm | 60 ++++++++++++++-- Source/WebKit2/UIProcess/mac/WebContextMac.mm | 7 +- .../UIProcess/mac/WebFullScreenManagerProxyMac.mm | 12 ++-- .../WebKit2/UIProcess/mac/WebInspectorProxyMac.mm | 5 +- Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm | 83 +++++++++++++++++++--- .../WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm | 60 +++++++++++++--- 8 files changed, 208 insertions(+), 53 deletions(-) (limited to 'Source/WebKit2/UIProcess/mac') diff --git a/Source/WebKit2/UIProcess/mac/CorrectionPanel.h b/Source/WebKit2/UIProcess/mac/CorrectionPanel.h index d4bc353..85a98ef 100644 --- a/Source/WebKit2/UIProcess/mac/CorrectionPanel.h +++ b/Source/WebKit2/UIProcess/mac/CorrectionPanel.h @@ -27,8 +27,8 @@ #define CorrectionPanel_h #if !defined(BUILDING_ON_SNOW_LEOPARD) -#import -#import +#import +#import #import @class WKView; @@ -47,7 +47,7 @@ public: private: bool isShowing() const { return m_view; } void dismissInternal(WebCore::ReasonForDismissingCorrectionPanel, bool dismissingExternally); - void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionBubbleType); + void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType); bool m_wasDismissedExternally; WebCore::ReasonForDismissingCorrectionPanel m_reasonForDismissing; diff --git a/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm b/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm index ab6818f..0fc520b 100644 --- a/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm +++ b/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm @@ -33,18 +33,18 @@ using namespace WebCore; -static inline NSCorrectionBubbleType correctionBubbleType(CorrectionPanelInfo::PanelType panelType) +static inline NSCorrectionIndicatorType correctionIndicatorType(CorrectionPanelInfo::PanelType panelType) { switch (panelType) { case CorrectionPanelInfo::PanelTypeCorrection: - return NSCorrectionBubbleTypeCorrection; + return NSCorrectionIndicatorTypeDefault; case CorrectionPanelInfo::PanelTypeReversion: - return NSCorrectionBubbleTypeReversion; + return NSCorrectionIndicatorTypeReversion; case CorrectionPanelInfo::PanelTypeSpellingSuggestions: - return NSCorrectionBubbleTypeGuesses; + return NSCorrectionIndicatorTypeGuesses; } ASSERT_NOT_REACHED(); - return NSCorrectionBubbleTypeCorrection; + return NSCorrectionIndicatorTypeDefault; } namespace WebKit { @@ -71,7 +71,7 @@ void CorrectionPanel::show(WKView* view, CorrectionPanelInfo::PanelType type, co NSString* replacedStringAsNSString = replacedString; NSString* replacementStringAsNSString = replacementString; m_view = view; - NSCorrectionBubbleType bubbleType = correctionBubbleType(type); + NSCorrectionIndicatorType indicatorType = correctionIndicatorType(type); NSMutableArray* alternativeStrings = 0; if (!alternativeReplacementStrings.isEmpty()) { @@ -82,8 +82,8 @@ void CorrectionPanel::show(WKView* view, CorrectionPanelInfo::PanelType type, co } NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; - [spellChecker showCorrectionBubbleOfType:bubbleType primaryString:replacementStringAsNSString alternativeStrings:alternativeStrings forStringInRect:boundingBoxOfReplacedString view:m_view.get() completionHandler:^(NSString* acceptedString) { - handleAcceptedReplacement(acceptedString, replacedStringAsNSString, replacementStringAsNSString, bubbleType); + [spellChecker showCorrectionIndicatorOfType:indicatorType primaryString:replacementStringAsNSString alternativeStrings:alternativeStrings forStringInRect:boundingBoxOfReplacedString view:m_view.get() completionHandler:^(NSString* acceptedString) { + handleAcceptedReplacement(acceptedString, replacedStringAsNSString, replacementStringAsNSString, indicatorType); }]; } @@ -113,7 +113,7 @@ void CorrectionPanel::dismissInternal(ReasonForDismissingCorrectionPanel reason, m_reasonForDismissing = reason; m_resultForSynchronousDismissal.clear(); - [[NSSpellChecker sharedSpellChecker] dismissCorrectionBubbleForView:m_view.get()]; + [[NSSpellChecker sharedSpellChecker] dismissCorrectionIndicatorForView:m_view.get()]; m_view.clear(); } @@ -122,13 +122,13 @@ void CorrectionPanel::recordAutocorrectionResponse(WKView* view, NSCorrectionRes [[NSSpellChecker sharedSpellChecker] recordResponse:response toCorrection:replacementString forWord:replacedString language:nil inSpellDocumentWithTag:[view spellCheckerDocumentTag]]; } -void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionBubbleType correctionBubbleType) +void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType correctionIndicatorType) { NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; NSInteger documentTag = [m_view.get() spellCheckerDocumentTag]; - switch (correctionBubbleType) { - case NSCorrectionBubbleTypeCorrection: + switch (correctionIndicatorType) { + case NSCorrectionIndicatorTypeDefault: if (acceptedReplacement) [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; else { @@ -138,11 +138,11 @@ void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, N [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; } break; - case NSCorrectionBubbleTypeReversion: + case NSCorrectionIndicatorTypeReversion: if (acceptedReplacement) [spellChecker recordResponse:NSCorrectionResponseReverted toCorrection:replaced forWord:acceptedReplacement language:nil inSpellDocumentWithTag:documentTag]; break; - case NSCorrectionBubbleTypeGuesses: + case NSCorrectionIndicatorTypeGuesses: if (acceptedReplacement) [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag]; break; diff --git a/Source/WebKit2/UIProcess/mac/TextCheckerMac.mm b/Source/WebKit2/UIProcess/mac/TextCheckerMac.mm index cef3a55..29493f9 100644 --- a/Source/WebKit2/UIProcess/mac/TextCheckerMac.mm +++ b/Source/WebKit2/UIProcess/mac/TextCheckerMac.mm @@ -27,10 +27,13 @@ #import "TextChecker.h" #import "TextCheckerState.h" +#import #import #ifndef BUILDING_ON_SNOW_LEOPARD -#import +@interface NSSpellChecker (WebNSSpellCheckerDetails) +- (NSString *)languageForWordRange:(NSRange)range inString:(NSString *)string orthography:(NSOrthography *)orthography; +@end #endif static NSString* const WebAutomaticSpellingCorrectionEnabled = @"WebAutomaticSpellingCorrectionEnabled"; @@ -195,7 +198,22 @@ void TextChecker::setSmartInsertDeleteEnabled(bool flag) [[NSUserDefaults standardUserDefaults] setBool:flag forKey:WebSmartInsertDeleteEnabled]; } -int64_t TextChecker::uniqueSpellDocumentTag() +bool TextChecker::substitutionsPanelIsShowing() +{ + return [[[NSSpellChecker sharedSpellChecker] substitutionsPanel] isVisible]; +} + +void TextChecker::toggleSubstitutionsPanelIsShowing() +{ + NSPanel *substitutionsPanel = [[NSSpellChecker sharedSpellChecker] substitutionsPanel]; + if ([substitutionsPanel isVisible]) { + [substitutionsPanel orderOut:nil]; + return; + } + [substitutionsPanel orderFront:nil]; +} + +int64_t TextChecker::uniqueSpellDocumentTag(WebPageProxy*) { return [NSSpellChecker uniqueSpellDocumentTag]; } @@ -205,6 +223,8 @@ void TextChecker::closeSpellDocumentWithTag(int64_t tag) [[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:tag]; } +#if USE(UNIFIED_TEXT_CHECKING) + Vector TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes) { Vector results; @@ -292,12 +312,40 @@ Vector TextChecker::checkTextOfParagraph(int64_t spellDocume return results; } -void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWord) +#endif + +void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&) +{ + // Mac uses checkTextOfParagraph instead. + notImplemented(); +} + +void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector&, int32_t&, int32_t&) +{ + // Mac uses checkTextOfParagraph instead. + notImplemented(); +} + +bool TextChecker::spellingUIIsShowing() +{ + return [[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible]; +} + +void TextChecker::toggleSpellingUIIsShowing() +{ + NSPanel *spellingPanel = [[NSSpellChecker sharedSpellChecker] spellingPanel]; + if ([spellingPanel isVisible]) + [spellingPanel orderOut:nil]; + else + [spellingPanel orderFront:nil]; +} + +void TextChecker::updateSpellingUIWithMisspelledWord(int64_t, const String& misspelledWord) { [[NSSpellChecker sharedSpellChecker] updateSpellingPanelWithMisspelledWord:misspelledWord]; } -void TextChecker::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail) +void TextChecker::updateSpellingUIWithGrammarString(int64_t, const String& badGrammarPhrase, const GrammarDetail& grammarDetail) { RetainPtr corrections(AdoptNS, [[NSMutableArray alloc] init]); for (size_t i = 0; i < grammarDetail.guesses.size(); ++i) { @@ -307,7 +355,7 @@ void TextChecker::updateSpellingUIWithGrammarString(const String& badGrammarPhra NSRange grammarRange = NSMakeRange(grammarDetail.location, grammarDetail.length); NSString *grammarUserDescription = grammarDetail.userDescription; - RetainPtr grammarDetailDict(AdoptNS, [[NSDictionary alloc] initWithObjectsAndKeys:[NSValue valueWithRange:grammarRange], NSGrammarRange, grammarUserDescription, NSGrammarUserDescription, corrections.get(), NSGrammarCorrections, nil]); + RetainPtr grammarDetailDict(AdoptNS, [[NSDictionary alloc] initWithObjectsAndKeys:[NSValue valueWithRange:grammarRange], NSGrammarRange, grammarUserDescription, NSGrammarUserDescription, corrections.get(), NSGrammarCorrections, nil]); [[NSSpellChecker sharedSpellChecker] updateSpellingPanelWithGrammarString:badGrammarPhrase detail:grammarDetailDict.get()]; } @@ -331,7 +379,7 @@ void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word guesses.append(guess); } -void TextChecker::learnWord(const String& word) +void TextChecker::learnWord(int64_t, const String& word) { [[NSSpellChecker sharedSpellChecker] learnWord:word]; } diff --git a/Source/WebKit2/UIProcess/mac/WebContextMac.mm b/Source/WebKit2/UIProcess/mac/WebContextMac.mm index f7c186d..e770d5b 100644 --- a/Source/WebKit2/UIProcess/mac/WebContextMac.mm +++ b/Source/WebKit2/UIProcess/mac/WebContextMac.mm @@ -84,12 +84,11 @@ void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& para NSURLCache *urlCache = [NSURLCache sharedURLCache]; parameters.parentProcessName = [[NSProcessInfo processInfo] processName]; - parameters.nsURLCachePath = fileSystemRepresentation([(NSString *)cachePath.get() stringByStandardizingPath]); + parameters.nsURLCachePath = [(NSString *)cachePath.get() stringByStandardizingPath]; parameters.nsURLCacheMemoryCapacity = [urlCache memoryCapacity]; parameters.nsURLCacheDiskCapacity = [urlCache diskCapacity]; - ASSERT(strlen(parameters.nsURLCachePath.data())); - ASSERT(parameters.nsURLCachePath.data()[strlen(parameters.nsURLCachePath.data()) - 1] != '/'); // Necessary for NSURLCache to find the cache file. + ASSERT(!parameters.nsURLCachePath.isEmpty()); #if USE(ACCELERATED_COMPOSITING) && HAVE(HOSTED_CORE_ANIMATION) mach_port_t renderServerPort = WKInitializeRenderServer(); @@ -98,7 +97,7 @@ void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& para #endif // FIXME: This should really be configurable; we shouldn't just blindly allow read access to the UI process bundle. - parameters.uiProcessBundleResourcePath = fileSystemRepresentation([[NSBundle mainBundle] resourcePath]); + parameters.uiProcessBundleResourcePath = [[NSBundle mainBundle] resourcePath]; #if USE(CFURLSTORAGESESSIONS) parameters.uiProcessBundleIdentifier = String([[NSBundle mainBundle] bundleIdentifier]); diff --git a/Source/WebKit2/UIProcess/mac/WebFullScreenManagerProxyMac.mm b/Source/WebKit2/UIProcess/mac/WebFullScreenManagerProxyMac.mm index d533573..33238b0 100644 --- a/Source/WebKit2/UIProcess/mac/WebFullScreenManagerProxyMac.mm +++ b/Source/WebKit2/UIProcess/mac/WebFullScreenManagerProxyMac.mm @@ -23,11 +23,13 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" -#include "WebFullScreenManagerProxy.h" -#include "LayerTreeContext.h" -#include "WKFullScreenWindowController.h" -#include "WKViewInternal.h" +#import "config.h" +#import "WebFullScreenManagerProxy.h" + +#import "LayerTreeContext.h" +#import "WKFullScreenWindowController.h" +#import "WKViewInternal.h" +#import #if ENABLE(FULLSCREEN_API) diff --git a/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm b/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm index 9657764..e406166 100644 --- a/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm +++ b/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm @@ -31,6 +31,7 @@ #import "WKAPICast.h" #import "WKView.h" #import "WebPageProxy.h" +#import "WebProcessProxy.h" #import #import #import @@ -80,7 +81,7 @@ WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() ASSERT(m_page); ASSERT(!m_inspectorView); - m_inspectorView.adoptNS([[WKView alloc] initWithFrame:NSZeroRect contextRef:toAPI(page()->context()) pageGroupRef:toAPI(inspectorPageGroup())]); + m_inspectorView.adoptNS([[WKView alloc] initWithFrame:NSZeroRect contextRef:toAPI(page()->process()->context()) pageGroupRef:toAPI(inspectorPageGroup())]); ASSERT(m_inspectorView); [m_inspectorView.get() setDrawsBackground:NO]; @@ -135,7 +136,7 @@ void WebInspectorProxy::platformClose() void WebInspectorProxy::platformInspectedURLChanged(const String& urlString) { - NSString *title = [NSString stringWithFormat:UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)urlString]; + NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)urlString]; [m_inspectorWindow.get() setTitle:title]; } diff --git a/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm b/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm index 90df81e..9dacae5 100644 --- a/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm +++ b/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm @@ -26,10 +26,13 @@ #import "config.h" #import "WebPageProxy.h" +#import "AttributedString.h" #import "DataReference.h" #import "DictionaryPopupInfo.h" +#import "EditorState.h" #import "NativeWebKeyboardEvent.h" #import "PageClient.h" +#import "PageClientImpl.h" #import "TextChecker.h" #import "WebPageMessages.h" #import "WebProcessProxy.h" @@ -105,8 +108,7 @@ void WebPageProxy::getIsSpeaking(bool& isSpeaking) void WebPageProxy::speak(const String& string) { - NSString *convertedString = string; - [NSApp speakString:convertedString]; + [NSApp speakString:nsStringFromWebCoreString(string)]; } void WebPageProxy::stopSpeaking() @@ -114,6 +116,11 @@ void WebPageProxy::stopSpeaking() [NSApp stopSpeaking:nil]; } +void WebPageProxy::searchWithSpotlight(const String& string) +{ + [[NSWorkspace sharedWorkspace] showSearchResultsForQueryString:nsStringFromWebCoreString(string)]; +} + CGContextRef WebPageProxy::containingWindowGraphicsContext() { return m_pageClient->containingWindowGraphicsContext(); @@ -134,11 +141,38 @@ void WebPageProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreen process()->send(Messages::WebPage::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates, accessibilityViewCoordinates), m_pageID); } +void WebPageProxy::setComposition(const String& text, Vector underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd) +{ + process()->sendSync(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), Messages::WebPage::SetComposition::Reply(m_editorState), m_pageID); +} + +void WebPageProxy::confirmComposition() +{ + process()->sendSync(Messages::WebPage::ConfirmComposition(), Messages::WebPage::ConfirmComposition::Reply(m_editorState), m_pageID); +} + +bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd) +{ + bool handled; + process()->sendSync(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeEnd), Messages::WebPage::InsertText::Reply(handled, m_editorState), m_pageID); + return handled; +} + void WebPageProxy::getMarkedRange(uint64_t& location, uint64_t& length) { process()->sendSync(Messages::WebPage::GetMarkedRange(), Messages::WebPage::GetMarkedRange::Reply(location, length), m_pageID); } - + +void WebPageProxy::getSelectedRange(uint64_t& location, uint64_t& length) +{ + process()->sendSync(Messages::WebPage::GetSelectedRange(), Messages::WebPage::GetSelectedRange::Reply(location, length), m_pageID); +} + +void WebPageProxy::getAttributedSubstringFromRange(uint64_t location, uint64_t length, AttributedString& result) +{ + process()->sendSync(Messages::WebPage::GetAttributedSubstringFromRange(location, length), Messages::WebPage::GetAttributedSubstringFromRange::Reply(result), m_pageID); +} + uint64_t WebPageProxy::characterIndexForPoint(const IntPoint point) { uint64_t result; @@ -152,20 +186,27 @@ WebCore::IntRect WebPageProxy::firstRectForCharacterRange(uint64_t location, uin process()->sendSync(Messages::WebPage::FirstRectForCharacterRange(location, length), Messages::WebPage::FirstRectForCharacterRange::Reply(resultRect), m_pageID); return resultRect; } - + +bool WebPageProxy::executeKeypressCommands(const Vector& commands) +{ + bool result; + process()->sendSync(Messages::WebPage::ExecuteKeypressCommands(commands), Messages::WebPage::ExecuteKeypressCommands::Reply(result, m_editorState), m_pageID); + return result; +} + bool WebPageProxy::writeSelectionToPasteboard(const String& pasteboardName, const Vector& pasteboardTypes) { bool result; - const double MessageTimeout = 20; - process()->sendSync(Messages::WebPage::WriteSelectionToPasteboard(pasteboardName, pasteboardTypes), Messages::WebPage::WriteSelectionToPasteboard::Reply(result), m_pageID, MessageTimeout); + const double messageTimeout = 20; + process()->sendSync(Messages::WebPage::WriteSelectionToPasteboard(pasteboardName, pasteboardTypes), Messages::WebPage::WriteSelectionToPasteboard::Reply(result), m_pageID, messageTimeout); return result; } bool WebPageProxy::readSelectionFromPasteboard(const String& pasteboardName) { bool result; - const double MessageTimeout = 20; - process()->sendSync(Messages::WebPage::ReadSelectionFromPasteboard(pasteboardName), Messages::WebPage::ReadSelectionFromPasteboard::Reply(result), m_pageID, MessageTimeout); + const double messageTimeout = 20; + process()->sendSync(Messages::WebPage::ReadSelectionFromPasteboard(pasteboardName), Messages::WebPage::ReadSelectionFromPasteboard::Reply(result), m_pageID, messageTimeout); return result; } @@ -186,9 +227,10 @@ void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& process()->send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID); } -void WebPageProxy::interpretKeyEvent(uint32_t type, Vector& commandsList, uint32_t selectionStart, uint32_t selectionEnd, Vector& underlines) +void WebPageProxy::interpretQueuedKeyEvent(const EditorState& state, bool& handled, Vector& commands) { - m_pageClient->interceptKeyEvent(m_keyEventQueue.first(), commandsList, selectionStart, selectionEnd, underlines); + m_editorState = state; + handled = m_pageClient->interpretKeyEvent(m_keyEventQueue.first(), commands); } // Complex text input support for plug-ins. @@ -248,4 +290,25 @@ void WebPageProxy::setComplexTextInputEnabled(uint64_t pluginComplexTextInputIde m_pageClient->setComplexTextInputEnabled(pluginComplexTextInputIdentifier, complexTextInputEnabled); } +void WebPageProxy::executeSavedCommandBySelector(const String& selector, bool& handled) +{ + handled = m_pageClient->executeSavedCommandBySelector(selector); +} + +bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent& event) +{ + bool result = false; + const double messageTimeout = 3; + process()->sendSync(Messages::WebPage::ShouldDelayWindowOrderingEvent(event), Messages::WebPage::ShouldDelayWindowOrderingEvent::Reply(result), m_pageID, messageTimeout); + return result; +} + +bool WebPageProxy::acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent& event) +{ + bool result = false; + const double messageTimeout = 3; + process()->sendSync(Messages::WebPage::AcceptsFirstMouse(eventNumber, event), Messages::WebPage::AcceptsFirstMouse::Reply(result), m_pageID, messageTimeout); + return result; +} + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm b/Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm index 7ce8764..d13a2a7 100644 --- a/Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm +++ b/Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm @@ -26,6 +26,7 @@ #import "config.h" #import "WebPopupMenuProxyMac.h" +#import "NativeWebMouseEvent.h" #import "PageClientImpl.h" #import "PlatformPopupMenuData.h" #import "WKView.h" @@ -61,7 +62,7 @@ void WebPopupMenuProxyMac::populate(const Vector& items, NSFont *f int size = items.size(); for (int i = 0; i < size; i++) { - if (items[i].m_type == WebPopupItem::Seperator) + if (items[i].m_type == WebPopupItem::Separator) [[m_popup.get() menu] addItem:[NSMenuItem separatorItem]]; else { [m_popup.get() addItemWithTitle:@""]; @@ -108,11 +109,20 @@ void WebPopupMenuProxyMac::showPopupMenu(const IntRect& rect, TextDirection text // These values were borrowed from AppKit to match their placement of the menu. const int popOverHorizontalAdjust = -10; - NSRect titleFrame = [m_popup.get() titleRectForBounds:rect]; - if (titleFrame.size.width <= 0 || titleFrame.size.height <= 0) - titleFrame = rect; - float vertOffset = roundf((NSMaxY(rect) - NSMaxY(titleFrame)) + NSHeight(titleFrame)); - NSPoint location = NSMakePoint(NSMinX(rect) + popOverHorizontalAdjust, NSMaxY(rect) - vertOffset); + const int popUnderHorizontalAdjust = 6; + const int popUnderVerticalAdjust = 6; + + // Menus that pop-over directly obscure the node that generated the popup menu. + // Menus that pop-under are offset underneath it. + NSPoint location; + if (data.shouldPopOver) { + NSRect titleFrame = [m_popup.get() titleRectForBounds:rect]; + if (titleFrame.size.width <= 0 || titleFrame.size.height <= 0) + titleFrame = rect; + float vertOffset = roundf((NSMaxY(rect) - NSMaxY(titleFrame)) + NSHeight(titleFrame)); + location = NSMakePoint(NSMinX(rect) + popOverHorizontalAdjust, NSMaxY(rect) - vertOffset); + } else + location = NSMakePoint(NSMinX(rect) + popUnderHorizontalAdjust, NSMaxY(rect) + popUnderVerticalAdjust); RetainPtr dummyView(AdoptNS, [[NSView alloc] initWithFrame:rect]); [m_webView addSubview:dummyView.get()]; @@ -122,9 +132,41 @@ void WebPopupMenuProxyMac::showPopupMenu(const IntRect& rect, TextDirection text [m_popup.get() dismissPopUp]; [dummyView.get() removeFromSuperview]; - - if (m_client) - m_client->valueChangedForPopupMenu(this, [m_popup.get() indexOfSelectedItem]); + + if (!m_client) + return; + + m_client->valueChangedForPopupMenu(this, [m_popup.get() indexOfSelectedItem]); + + // This code is adopted from EventHandler::sendFakeEventsAfterWidgetTracking(). + if (!m_client->currentlyProcessedMouseDownEvent()) + return; + + NSEvent* initiatingNSEvent = m_client->currentlyProcessedMouseDownEvent()->nativeEvent(); + if ([initiatingNSEvent type] != NSLeftMouseDown) + return; + + NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSLeftMouseUp + location:[initiatingNSEvent locationInWindow] + modifierFlags:[initiatingNSEvent modifierFlags] + timestamp:[initiatingNSEvent timestamp] + windowNumber:[initiatingNSEvent windowNumber] + context:[initiatingNSEvent context] + eventNumber:[initiatingNSEvent eventNumber] + clickCount:[initiatingNSEvent clickCount] + pressure:[initiatingNSEvent pressure]]; + + [NSApp postEvent:fakeEvent atStart:YES]; + fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved + location:[[m_webView window] convertScreenToBase:[NSEvent mouseLocation]] + modifierFlags:[initiatingNSEvent modifierFlags] + timestamp:[initiatingNSEvent timestamp] + windowNumber:[initiatingNSEvent windowNumber] + context:[initiatingNSEvent context] + eventNumber:0 + clickCount:0 + pressure:0]; + [NSApp postEvent:fakeEvent atStart:YES]; } void WebPopupMenuProxyMac::hidePopupMenu() -- cgit v1.1