diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
commit | 49233e234e5c787396cadb2cea33b31ae0cd65c1 (patch) | |
tree | 5410cb9a8fd53168bb60d62c54b654d86f03c38d /Source/WebKit2/UIProcess/API/mac | |
parent | b211c645d8ab690f713515dfdc84d80b11c27d2c (diff) | |
download | qtwebkit-49233e234e5c787396cadb2cea33b31ae0cd65c1.tar.gz |
Imported WebKit commit 3a8c29f35d00659d2ce7a0ccdfa8304f14e82327 (http://svn.webkit.org/repository/webkit/trunk@120813)
New snapshot with Windows build fixes
Diffstat (limited to 'Source/WebKit2/UIProcess/API/mac')
8 files changed, 177 insertions, 28 deletions
diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h index a9d7a9fa9..ac074e8cc 100644 --- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h +++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h @@ -33,8 +33,11 @@ @class WKEditorUndoTargetObjC; @class WKView; -namespace WebKit { +namespace WebCore { +class AlternativeTextUIController; +} +namespace WebKit { class FindIndicatorWindow; class PageClientImpl : public PageClient { @@ -56,6 +59,7 @@ private: virtual bool isViewVisible(); virtual bool isViewInWindow(); virtual LayerHostingMode viewLayerHostingMode() OVERRIDE; + virtual ColorSpaceData colorSpace() OVERRIDE; virtual void processDidCrash(); virtual void pageClosed(); @@ -129,11 +133,22 @@ private: virtual WKView* wkView() const { return m_wkView; } +#if USE(DICTATION_ALTERNATIVES) + virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&); + virtual void removeDictationAlternatives(uint64_t dictationContext); + virtual void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext); + virtual void dismissDictationAlternativeUI(); + virtual Vector<String> dictationAlternatives(uint64_t dictationContext); +#endif + WKView* m_wkView; RetainPtr<WKEditorUndoTargetObjC> m_undoTarget; -#if !defined(BUILDING_ON_SNOW_LEOPARD) +#if USE(AUTOCORRECTION_PANEL) CorrectionPanel m_correctionPanel; #endif +#if USE(DICTATION_ALTERNATIVES) + OwnPtr<WebCore::AlternativeTextUIController> m_alternativeTextUIController; +#endif }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm index 72ea3493e..8d0913e52 100644 --- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm +++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm @@ -26,6 +26,10 @@ #import "config.h" #import "PageClientImpl.h" +#if USE(DICTATION_ALTERNATIVES) +#import <AppKit/NSTextAlternatives.h> +#endif +#import "ColorSpaceData.h" #import "DataReference.h" #import "DictionaryPopupInfo.h" #import "FindIndicator.h" @@ -37,6 +41,7 @@ #import "WebContextMenuProxyMac.h" #import "WebEditCommandProxy.h" #import "WebPopupMenuProxyMac.h" +#import <WebCore/AlternativeTextUIController.h> #import <WebCore/BitmapImage.h> #import <WebCore/Cursor.h> #import <WebCore/FloatRect.h> @@ -122,6 +127,9 @@ PassOwnPtr<PageClientImpl> PageClientImpl::create(WKView* wkView) PageClientImpl::PageClientImpl(WKView* wkView) : m_wkView(wkView) , m_undoTarget(AdoptNS, [[WKEditorUndoTargetObjC alloc] init]) +#if USE(DICTATION_ALTERNATIVES) + , m_alternativeTextUIController(adoptPtr(new AlternativeTextUIController)) +#endif { } @@ -205,14 +213,22 @@ LayerHostingMode PageClientImpl::viewLayerHostingMode() #endif } +ColorSpaceData PageClientImpl::colorSpace() +{ + return [m_wkView _colorSpace]; +} + void PageClientImpl::processDidCrash() { [m_wkView _processDidCrash]; } - + void PageClientImpl::pageClosed() { [m_wkView _pageClosed]; +#if USE(DICTATION_ALTERNATIVES) + m_alternativeTextUIController->clear(); +#endif } void PageClientImpl::didRelaunchProcess() @@ -465,7 +481,7 @@ void PageClientImpl::dismissDictionaryLookupPanel() void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) { -#if !defined(BUILDING_ON_SNOW_LEOPARD) +#if USE(AUTOCORRECTION_PANEL) if (!isViewVisible() || !isViewInWindow()) return; m_correctionPanel.show(m_wkView, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings); @@ -474,14 +490,14 @@ void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRe void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingAlternativeText reason) { -#if !defined(BUILDING_ON_SNOW_LEOPARD) +#if USE(AUTOCORRECTION_PANEL) m_correctionPanel.dismiss(reason); #endif } String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason) { -#if !defined(BUILDING_ON_SNOW_LEOPARD) +#if USE(AUTOCORRECTION_PANEL) return m_correctionPanel.dismiss(reason); #else return String(); @@ -529,4 +545,35 @@ bool PageClientImpl::executeSavedCommandBySelector(const String& selectorString) return [m_wkView _executeSavedCommandBySelector:NSSelectorFromString(selectorString)]; } +#if USE(DICTATION_ALTERNATIVES) +uint64_t PageClientImpl::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives) +{ + return m_alternativeTextUIController->addAlternatives(alternatives); +} + +void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext) +{ + m_alternativeTextUIController->removeAlternatives(dictationContext); +} + +void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) +{ + if (!isViewVisible() || !isViewInWindow()) + return; + m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString* acceptedAlternative){ + [m_wkView handleAcceptedAlternativeText:acceptedAlternative]; + }); +} + +Vector<String> PageClientImpl::dictationAlternatives(uint64_t dictationContext) +{ + return m_alternativeTextUIController->alternativesForContext(dictationContext); +} + +void PageClientImpl::dismissDictationAlternativeUI() +{ + m_alternativeTextUIController->dismissAlternatives(); +} +#endif + } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm index 2c4341b5d..3daa08c37 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm @@ -215,11 +215,17 @@ static inline NSURL *autoreleased(WKURLRef url) case WKPaginationModeUnpaginated: mode = kWKPaginationModeUnpaginated; break; - case WKPaginationModeHorizontal: - mode = kWKPaginationModeHorizontal; + case WKPaginationModeLeftToRight: + mode = kWKPaginationModeLeftToRight; break; - case WKPaginationModeVertical: - mode = kWKPaginationModeVertical; + case WKPaginationModeRightToLeft: + mode = kWKPaginationModeRightToLeft; + break; + case WKPaginationModeTopToBottom: + mode = kWKPaginationModeTopToBottom; + break; + case WKPaginationModeBottomToTop: + mode = kWKPaginationModeBottomToTop; break; default: return; @@ -233,10 +239,14 @@ static inline NSURL *autoreleased(WKURLRef url) switch (WKPageGetPaginationMode(self._pageRef)) { case kWKPaginationModeUnpaginated: return WKPaginationModeUnpaginated; - case kWKPaginationModeHorizontal: - return WKPaginationModeHorizontal; - case kWKPaginationModeVertical: - return WKPaginationModeVertical; + case kWKPaginationModeLeftToRight: + return WKPaginationModeLeftToRight; + case kWKPaginationModeRightToLeft: + return WKPaginationModeRightToLeft; + case kWKPaginationModeTopToBottom: + return WKPaginationModeTopToBottom; + case kWKPaginationModeBottomToTop: + return WKPaginationModeBottomToTop; } ASSERT_NOT_REACHED(); diff --git a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h index c362c55c2..48fcb12f0 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h +++ b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h @@ -27,8 +27,10 @@ enum { WKPaginationModeUnpaginated, - WKPaginationModeHorizontal, - WKPaginationModeVertical, + WKPaginationModeLeftToRight, + WKPaginationModeRightToLeft, + WKPaginationModeTopToBottom, + WKPaginationModeBottomToTop, }; typedef NSUInteger WKBrowsingContextPaginationMode; diff --git a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.h b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.h index 91c93e592..d28beaca2 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.h +++ b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.h @@ -26,6 +26,8 @@ #ifndef WKTextInputWindowController_h #define WKTextInputWindowController_h +#if USE(APPKIT) + @class WKTextInputPanel; @interface WKTextInputWindowController : NSObject { @@ -42,4 +44,6 @@ @end +#endif // USE(APPKIT) + #endif // WKTextInputWindowController_h diff --git a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm index 2be0cfd3c..8834dcd33 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm @@ -26,6 +26,8 @@ #import "config.h" #import "WKTextInputWindowController.h" +#if USE(APPKIT) + #import <WebKitSystemInterface.h> @interface WKTextInputView : NSTextView { @@ -199,3 +201,5 @@ } @end + +#endif // USE(APPKIT) diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm index f03b9a899..aa8dc8521 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKView.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm @@ -26,7 +26,13 @@ #import "config.h" #import "WKView.h" +#if USE(DICTATION_ALTERNATIVES) +#import <AppKit/NSTextAlternatives.h> +#import <AppKit/NSAttributedString.h> +#endif + #import "AttributedString.h" +#import "ColorSpaceData.h" #import "DataReference.h" #import "DrawingAreaProxyImpl.h" #import "EditorState.h" @@ -73,6 +79,7 @@ #import <WebCore/Region.h> #import <WebCore/RunLoop.h> #import <WebCore/SharedBuffer.h> +#import <WebCore/TextAlternativeWithRange.h> #import <WebCore/WebCoreNSStringExtras.h> #import <WebCore/FileSystem.h> #import <WebKitSystemInterface.h> @@ -201,6 +208,9 @@ struct WKViewInterpretKeyEventsParameters { // We use this flag to determine when we need to paint the background (white or clear) // when the web process is unresponsive or takes too long to paint. BOOL _windowHasValidBackingStore; + + RetainPtr<NSColorSpace> _colorSpace; + RefPtr<WebCore::Image> _promisedImage; String _promisedFilename; String _promisedURL; @@ -1173,7 +1183,12 @@ static const short kIOHIDEventTypeScroll = 6; NSString *text; bool isFromInputMethod = _data->_page->editorState().hasComposition; + Vector<TextAlternativeWithRange> dictationAlternatives; + if (isAttributedString) { +#if USE(DICTATION_ALTERNATIVES) + collectDictationTextAlternatives(string, dictationAlternatives); +#endif // FIXME: We ignore most attributes from the string, so for example inserting from Character Palette loses font and glyph variation data. text = [string string]; } else @@ -1195,7 +1210,11 @@ static const short kIOHIDEventTypeScroll = 6; String eventText = text; eventText.replace(NSBackTabCharacter, NSTabCharacter); // same thing is done in KeyEventMac.mm in WebCore - bool eventHandled = _data->_page->insertText(eventText, replacementRange.location, NSMaxRange(replacementRange)); + bool eventHandled; + if (!dictationAlternatives.isEmpty()) + eventHandled = _data->_page->insertDictatedText(eventText, replacementRange.location, NSMaxRange(replacementRange), dictationAlternatives); + else + eventHandled = _data->_page->insertText(eventText, replacementRange.location, NSMaxRange(replacementRange)); if (parameters) parameters->eventInterpretationHadSideEffects |= eventHandled; @@ -1447,7 +1466,11 @@ static const short kIOHIDEventTypeScroll = 6; if (!validAttributes) { validAttributes = [[NSArray alloc] initWithObjects: NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName, - NSMarkedClauseSegmentAttributeName, nil]; + NSMarkedClauseSegmentAttributeName, +#if USE(DICTATION_ALTERNATIVES) + NSTextAlternativesAttributeName, +#endif + nil]; // NSText also supports the following attributes, but it's // hard to tell which are really required for text input to // work well; I have not seen any input method make use of them yet. @@ -1876,9 +1899,9 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl // update the active state. if ([self window]) { _data->_windowHasValidBackingStore = NO; + [self _updateWindowVisibility]; _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive); _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow); - [self _updateWindowVisibility]; [self _updateWindowAndViewFrames]; if (!_data->_flagsChangedEventMonitor) { @@ -1967,27 +1990,29 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl - (void)_windowDidOrderOffScreen:(NSNotification *)notification { + [self _updateWindowVisibility]; + // We want to make sure to update the active state while hidden, so since the view is about to be hidden, // we hide it first and then update the active state. _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible); _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive); - [self _updateWindowVisibility]; } - (void)_windowDidOrderOnScreen:(NSNotification *)notification { + [self _updateWindowVisibility]; + // We want to make sure to update the active state while hidden, so since the view is about to become visible, // we update the active state first and then make it visible. _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive); _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible); - [self _updateWindowVisibility]; } - (void)_windowDidChangeBackingProperties:(NSNotification *)notification { - CGFloat oldBackingScaleFactor = [[notification.userInfo objectForKey:backingPropertyOldScaleFactorKey] doubleValue]; + CGFloat oldBackingScaleFactor = [[notification.userInfo objectForKey:backingPropertyOldScaleFactorKey] doubleValue]; CGFloat newBackingScaleFactor = [self _intrinsicDeviceScaleFactor]; - if (oldBackingScaleFactor == newBackingScaleFactor) + if (oldBackingScaleFactor == newBackingScaleFactor) return; _data->_windowHasValidBackingStore = NO; @@ -2072,6 +2097,17 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible); } +- (void)viewDidChangeBackingProperties +{ + NSColorSpace *colorSpace = [[self window] colorSpace]; + if ([colorSpace isEqualTo:_data->_colorSpace.get()]) + return; + + _data->_colorSpace = nullptr; + if (DrawingAreaProxy *drawingArea = _data->_page->drawingArea()) + drawingArea->colorSpaceDidChange(); +} + - (void)_accessibilityRegisterUIProcessTokens { // Initialize remote accessibility when the window connection has been established. @@ -2227,6 +2263,21 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I return [[self window] firstResponder] == self; } +- (WebKit::ColorSpaceData)_colorSpace +{ + if (!_data->_colorSpace) { + if ([self window]) + _data->_colorSpace = [[self window] colorSpace]; + else + _data->_colorSpace = [[NSScreen mainScreen] colorSpace]; + } + + ColorSpaceData colorSpaceData; + colorSpaceData.cgColorSpace = [_data->_colorSpace.get() CGColorSpace]; + + return colorSpaceData; +} + - (void)_processDidCrash { if (_data->_layerHostingView) @@ -2660,10 +2711,10 @@ static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension if (!matchesExtensionOrEquivalent(filename, extension)) filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension]; - [pasteboard setString:url forType:NSURLPboardType]; + [pasteboard setString:visibleUrl forType:NSStringPboardType]; [pasteboard setString:visibleUrl forType:PasteboardTypes::WebURLPboardType]; [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType]; - [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:url], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType]; + [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:visibleUrl], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType]; [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType]; if (archiveBuffer) @@ -2874,9 +2925,19 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path) return _data->_spellCheckerDocumentTag; } -- (void)handleCorrectionPanelResult:(NSString*)result +- (void)handleAcceptedAlternativeText:(NSString*)text +{ + _data->_page->handleAlternativeTextUIResult(text); +} + +- (void)_setSuppressVisibilityUpdates:(BOOL)suppressVisibilityUpdates +{ + _data->_page->setSuppressVisibilityUpdates(suppressVisibilityUpdates); +} + +- (BOOL)_suppressVisibilityUpdates { - _data->_page->handleAlternativeTextUIResult(result); + return _data->_page->suppressVisibilityUpdates(); } @end diff --git a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h index 6b6eb6bf4..2e99e7976 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h +++ b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h @@ -43,6 +43,7 @@ namespace WebKit { class DrawingAreaProxy; class FindIndicator; class LayerTreeContext; + struct ColorSpaceData; struct EditorState; } @@ -87,6 +88,8 @@ namespace WebKit { - (void)_didChangeScrollbarsForMainFrame; +- (WebKit::ColorSpaceData)_colorSpace; + #if ENABLE(FULLSCREEN_API) - (BOOL)hasFullScreenWindowController; - (WKFullScreenWindowController*)fullScreenWindowController; @@ -96,6 +99,9 @@ namespace WebKit { - (void)_cacheWindowBottomCornerRect; - (NSInteger)spellCheckerDocumentTag; -- (void)handleCorrectionPanelResult:(NSString*)result; +- (void)handleAcceptedAlternativeText:(NSString*)text; + +- (void)_setSuppressVisibilityUpdates:(BOOL)suppressVisibilityUpdates; +- (BOOL)_suppressVisibilityUpdates; @end |