WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Minor Adjustment
bug-83047-20120418200412.patch (text/plain), 76.13 KB, created by
Jia Pu
on 2012-04-18 20:04:13 PDT
(
hide
)
Description:
Minor Adjustment
Filename:
MIME Type:
Creator:
Jia Pu
Created:
2012-04-18 20:04:13 PDT
Size:
76.13 KB
patch
obsolete
>Subversion Revision: 114585 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index bc853951ab36e2256f7d573a0dd658ca9201e3fb..ad2bcf0dae9153975076827608a62dab071c58a4 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,48 @@ >+2012-04-18 Jia Pu <jpu@apple.com> >+ >+ On OS X, mark text with dictation alternative with blue underline. >+ https://bugs.webkit.org/show_bug.cgi?id=83047 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Tests: platform/mac/editing/input/edit-dictated-text-with-alternative.html >+ platform/mac/editing/input/insert-dictated-text.html >+ >+ This is the follow up patch mentioned in the ChangeLog of bug 83549. This patch added an OS X specific >+ functionality related to dictated text input. Majority of following changes are active only on OS X. >+ >+ New classes DictationAlternativeController and TextAlternativeWithRange are added here since they are used >+ by both WebKit and WebKit2. >+ >+ * WebCore.exp.in: >+ * WebCore.xcodeproj/project.pbxproj: >+ * editing/AlternativeTextController.cpp: >+ (WebCore::AlternativeTextController::removeDictationAlternativesForMarker): This new function notifies >+ WebKit layer to remove dictation alternative data when a DictationAlernatives marker is removed. >+ * editing/AlternativeTextController.h: >+ * editing/Editor.cpp: >+ (WebCore::Editor::updateMarkersForWordsAffectedByEditing): Renamed existing respondToChangedSelection() >+ function to avoid having two funcations with same name and signature. >+ * editing/mac/DictationAlternativeController.h: Added. >+ (WebCore::DictationAlternativeController::DictationAlternativeController): >+ (WebCore::DictationAlternativeController::DictationContextController): >+ * editing/mac/DictationAlternativeController.mm: Added. >+ (WebCore::DictationAlternativeController::DictationContextController::addAlternatives): >+ (WebCore::DictationAlternativeController::DictationContextController::alternativesForDictationContext): >+ (WebCore::DictationAlternativeController::DictationContextController::removeAlternativesForDictationContext): >+ (WebCore::DictationAlternativeController::DictationContextController::clear): >+ (WebCore::DictationAlternativeController::addAlternatives): >+ (WebCore::DictationAlternativeController::clear): >+ (WebCore::DictationAlternativeController::showAlternatives): >+ (WebCore::DictationAlternativeController::handleAcceptedAlternative): >+ (WebCore::DictationAlternativeController::dismissAlternatives): >+ (WebCore::DictationAlternativeController::removeAlternatives): >+ * editing/mac/TextAlternativeWithRange.h: Added. >+ (WebCore::TextAlternativeWithRange::TextAlternativeWithRange): >+ * editing/mac/TextAlternativeWithRange.mm: Added. >+ (WebCore::collectDictationTextAlternatives): Function used by both WebKit and WebKit2. >+ * page/AlternativeTextClient.h: >+ > 2012-04-18 David Reveman <reveman@chromium.org> > > [Chromium] Solid color layers should respect opacity value. >diff --git a/Source/WebKit/mac/ChangeLog b/Source/WebKit/mac/ChangeLog >index 39906917e7b73177d7512f73c856988a482685af..62cdafcff738354893b925bda99c6a1a853f03f1 100644 >--- a/Source/WebKit/mac/ChangeLog >+++ b/Source/WebKit/mac/ChangeLog >@@ -1,3 +1,31 @@ >+2012-04-18 Jia Pu <jpu@apple.com> >+ >+ On OS X, mark text with dictation alternative with blue underline. >+ https://bugs.webkit.org/show_bug.cgi?id=83047 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Also see WebCore/ChangeLog. >+ This patch added an OS X specific functionality related to dictated text input. >+ It shouldn't change behaviors on other platforms. >+ >+ * WebCoreSupport/CorrectionPanel.mm: >+ (CorrectionPanel::handleAcceptedReplacement): >+ * WebCoreSupport/WebAlternativeTextClient.h: >+ * WebCoreSupport/WebAlternativeTextClient.mm: >+ (WebAlternativeTextClient::removeDictationAlternatives): >+ * WebView/WebHTMLView.mm: >+ (-[WebHTMLView insertText:]): >+ * WebView/WebView.mm: >+ (-[WebView handleAcceptedAlternativeText:]): >+ (-[WebView _getWebCoreDictationAlternatives:fromTextAlternatives:]): >+ (-[WebView _removeDictationAlternatives:]): >+ * WebView/WebViewData.h: >+ * WebView/WebViewData.mm: >+ (-[WebViewPrivate init]): >+ * WebView/WebViewInternal.h: >+ * WebView/WebViewPrivate.h: >+ > 2012-04-18 Jer Noble <jer.noble@apple.com> > > Full Screen mode does not preserve CALayer ordering after exiting. >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index 32bd7930ab48187132b94b7d83e243d94ea7f135..9aef63d8d6edc5c18a662d070628a70fc89a9fc3 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,44 @@ >+2012-04-18 Jia Pu <jpu@apple.com> >+ >+ On OS X, mark text with dictation alternative with blue underline. >+ https://bugs.webkit.org/show_bug.cgi?id=83047 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Also see WebCore/ChangeLog. >+ This patch added an OS X specific functionality related to dictated text input. >+ It shouldn't change behaviors on other platforms. >+ >+ * Shared/WebCoreArgumentCoders.cpp: >+ * Shared/WebCoreArgumentCoders.h: >+ * UIProcess/API/mac/PageClientImpl.h: >+ (PageClientImpl): >+ * UIProcess/API/mac/PageClientImpl.mm: >+ (WebKit::PageClientImpl::PageClientImpl): >+ (WebKit::PageClientImpl::pageClosed): >+ (WebKit::PageClientImpl::addDictationAlternatives): >+ (WebKit::PageClientImpl::removeDictationAlternatives): >+ * UIProcess/API/mac/WKView.mm: >+ (-[WKView insertText:replacementRange:]): >+ (-[WKView handleAcceptedAlternativeText:]): >+ * UIProcess/API/mac/WKViewInternal.h: >+ * UIProcess/PageClient.h: >+ * UIProcess/WebPageProxy.cpp: >+ (WebKit::WebPageProxy::removeDictationAlternatives): >+ * UIProcess/WebPageProxy.h: >+ * UIProcess/WebPageProxy.messages.in: >+ * UIProcess/mac/CorrectionPanel.mm: >+ (WebKit::CorrectionPanel::handleAcceptedReplacement): >+ * UIProcess/mac/WebPageProxyMac.mm: >+ (WebKit::WebPageProxy::insertDictatedText): >+ * WebProcess/WebCoreSupport/WebAlternativeTextClient.h: >+ * WebProcess/WebCoreSupport/mac/WebAlternativeTextClient.cpp: >+ (WebKit::WebAlternativeTextClient::removeDictationAlternatives): >+ * WebProcess/WebPage/WebPage.h: >+ * WebProcess/WebPage/WebPage.messages.in: >+ * WebProcess/WebPage/mac/WebPageMac.mm: >+ (WebKit::WebPage::insertDictatedText): >+ > 2012-04-18 Jer Noble <jer.noble@apple.com> > > Full Screen mode does not preserve CALayer ordering after exiting. >diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in >index 1129775dd3d0dc0e16006f959d6c2f1d2383d4a7..3d825f9ce37d702e37f788920cec45d4e6e711a8 100644 >--- a/Source/WebCore/WebCore.exp.in >+++ b/Source/WebCore/WebCore.exp.in >@@ -2179,3 +2179,10 @@ __ZNK7WebCore4Node31numberOfScopedHTMLStyleChildrenEv > #if ENABLE(SHADOW_DOM) > __ZN7WebCore22RuntimeEnabledFeatures18isShadowDOMEnabledE > #endif >+ >+#if PLATFORM(MAC) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION) >+__ZN7WebCore30DictationAlternativeController15addAlternativesERKN3WTF9RetainPtrI18NSTextAlternativesEE >+__ZN7WebCore30DictationAlternativeController18removeAlternativesEy >+__ZN7WebCore30DictationAlternativeController5clearEv >+__ZN7WebCore32collectDictationTextAlternativesEP18NSAttributedStringRN3WTF6VectorINS_24TextAlternativeWithRangeELm0EEE >+#endif >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 15b88043adce936c4f2dfa149127d9cae2438051..b542b93f191f0f3c27986baa0d4da10e2abf7abd 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -5751,6 +5751,10 @@ > CECADFCD1537791D00E37068 /* TextInsertionBaseCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CECADFCB1537791D00E37068 /* TextInsertionBaseCommand.cpp */; }; > CECADFCE1537791D00E37068 /* TextInsertionBaseCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = CECADFCC1537791D00E37068 /* TextInsertionBaseCommand.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CECCFC3B141973D5002A0AC1 /* DecodeEscapeSequences.h in Headers */ = {isa = PBXBuildFile; fileRef = CECCFC3A141973D5002A0AC1 /* DecodeEscapeSequences.h */; }; >+ CED0DA33153F8A0200186436 /* TextAlternativeWithRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = CED0DA32153F8A0200186436 /* TextAlternativeWithRange.mm */; }; >+ CED5B84A153F669200A9DDE8 /* DictationAlternativeController.h in Headers */ = {isa = PBXBuildFile; fileRef = CED5B848153F669200A9DDE8 /* DictationAlternativeController.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ CED5B84B153F669300A9DDE8 /* DictationAlternativeController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CED5B849153F669200A9DDE8 /* DictationAlternativeController.mm */; }; >+ CED5B850153F7D5600A9DDE8 /* TextAlternativeWithRange.h in Headers */ = {isa = PBXBuildFile; fileRef = CED5B84F153F7D5600A9DDE8 /* TextAlternativeWithRange.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CEDA12D7152CA1CB00D9E08D /* AlternativeTextClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; > CEF418CE1179678C009D112C /* ViewportArguments.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEF418CC1179678C009D112C /* ViewportArguments.cpp */; }; > CEF418CF1179678C009D112C /* ViewportArguments.h in Headers */ = {isa = PBXBuildFile; fileRef = CEF418CD1179678C009D112C /* ViewportArguments.h */; settings = {ATTRIBUTES = (Private, ); }; }; >@@ -12875,6 +12879,10 @@ > CECADFCB1537791D00E37068 /* TextInsertionBaseCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextInsertionBaseCommand.cpp; sourceTree = "<group>"; }; > CECADFCC1537791D00E37068 /* TextInsertionBaseCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextInsertionBaseCommand.h; sourceTree = "<group>"; }; > CECCFC3A141973D5002A0AC1 /* DecodeEscapeSequences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecodeEscapeSequences.h; sourceTree = "<group>"; }; >+ CED0DA32153F8A0200186436 /* TextAlternativeWithRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TextAlternativeWithRange.mm; path = mac/TextAlternativeWithRange.mm; sourceTree = "<group>"; }; >+ CED5B848153F669200A9DDE8 /* DictationAlternativeController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DictationAlternativeController.h; path = mac/DictationAlternativeController.h; sourceTree = "<group>"; }; >+ CED5B849153F669200A9DDE8 /* DictationAlternativeController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DictationAlternativeController.mm; path = mac/DictationAlternativeController.mm; sourceTree = "<group>"; }; >+ CED5B84F153F7D5600A9DDE8 /* TextAlternativeWithRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextAlternativeWithRange.h; path = mac/TextAlternativeWithRange.h; sourceTree = "<group>"; }; > CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlternativeTextClient.h; sourceTree = "<group>"; }; > CEF418CC1179678C009D112C /* ViewportArguments.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ViewportArguments.cpp; sourceTree = "<group>"; }; > CEF418CD1179678C009D112C /* ViewportArguments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewportArguments.h; sourceTree = "<group>"; }; >@@ -20476,8 +20484,12 @@ > ED501DC90B249F3900AE18D9 /* mac */ = { > isa = PBXGroup; > children = ( >+ CED5B849153F669200A9DDE8 /* DictationAlternativeController.mm */, >+ CED5B848153F669200A9DDE8 /* DictationAlternativeController.h */, > ED501DC50B249F2900AE18D9 /* EditorMac.mm */, > 4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */, >+ CED0DA32153F8A0200186436 /* TextAlternativeWithRange.mm */, >+ CED5B84F153F7D5600A9DDE8 /* TextAlternativeWithRange.h */, > ); > name = mac; > sourceTree = "<group>"; >@@ -24796,6 +24808,8 @@ > CECADFC7153778FF00E37068 /* DictationAlternative.h in Headers */, > CECADFC9153778FF00E37068 /* DictationCommand.h in Headers */, > CECADFCE1537791D00E37068 /* TextInsertionBaseCommand.h in Headers */, >+ CED5B84A153F669200A9DDE8 /* DictationAlternativeController.h in Headers */, >+ CED5B850153F7D5600A9DDE8 /* TextAlternativeWithRange.h in Headers */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >@@ -27807,6 +27821,8 @@ > CECADFC6153778FF00E37068 /* DictationAlternative.cpp in Sources */, > CECADFC8153778FF00E37068 /* DictationCommand.cpp in Sources */, > CECADFCD1537791D00E37068 /* TextInsertionBaseCommand.cpp in Sources */, >+ CED5B84B153F669300A9DDE8 /* DictationAlternativeController.mm in Sources */, >+ CED0DA33153F8A0200186436 /* TextAlternativeWithRange.mm in Sources */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >diff --git a/Source/WebCore/editing/AlternativeTextController.cpp b/Source/WebCore/editing/AlternativeTextController.cpp >index 8d09ff1b998471ea61f389268e4924f704cf13b1..0dc55e620086d8bf74f18647e5f98ce824a7be1c 100644 >--- a/Source/WebCore/editing/AlternativeTextController.cpp >+++ b/Source/WebCore/editing/AlternativeTextController.cpp >@@ -624,4 +624,16 @@ bool AlternativeTextController::insertDictatedText(const String& text, const Vec > return event->defaultHandled(); > } > >+void AlternativeTextController::removeDictationAlternativesForMarker(DocumentMarker* marker) >+{ >+ if (!marker) >+ return; >+ ASSERT(marker->type() == DocumentMarker::DictationAlternatives); >+#if USE(DICTATION_ALTERNATIVES) >+ DictationMarkerDetails* details = static_cast<DictationMarkerDetails*>(marker->details()); >+ if (AlternativeTextClient* client = alternativeTextClient()) >+ client->removeDictationAlternatives(details->dictationContext()); >+#endif >+} >+ > } // namespace WebCore >diff --git a/Source/WebCore/editing/AlternativeTextController.h b/Source/WebCore/editing/AlternativeTextController.h >index 28449efd93e5740a09e35b654b89b50c79808d9b..f52e80b88bffe6f5bed356b9e19aa346aa3345ad 100644 >--- a/Source/WebCore/editing/AlternativeTextController.h >+++ b/Source/WebCore/editing/AlternativeTextController.h >@@ -130,6 +130,7 @@ public: > void deletedAutocorrectionAtPosition(const Position&, const String& originalString) UNLESS_ENABLED({ UNUSED_PARAM(originalString); }) > > bool insertDictatedText(const String&, const Vector<DictationAlternative>&, Event*); >+ void removeDictationAlternativesForMarker(DocumentMarker*); > > private: > #if USE(AUTOCORRECTION_PANEL) >diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp >index 294eb94b527b869a92354cac6d991aaa2eff2424..c5bf4a0f590ac3a22c536c076ec684a09aa7bc05 100644 >--- a/Source/WebCore/editing/Editor.cpp >+++ b/Source/WebCore/editing/Editor.cpp >@@ -2258,6 +2258,10 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA > Document* document = m_frame->document(); > RefPtr<Range> wordRange = Range::create(document, startOfFirstWord.deepEquivalent(), endOfLastWord.deepEquivalent()); > >+ Vector<DocumentMarker*> markers = document->markers()->markersInRange(wordRange.get(), DocumentMarker::DictationAlternatives); >+ for (size_t i = 0; i < markers.size(); ++i) >+ m_alternativeTextController->removeDictationAlternativesForMarker(markers[i]); >+ > document->markers()->removeMarkers(wordRange.get(), DocumentMarker::Spelling | DocumentMarker::CorrectionIndicator | DocumentMarker::SpellCheckingExemption | DocumentMarker::DictationAlternatives, DocumentMarkerController::RemovePartiallyOverlappingMarker); > document->markers()->clearDescriptionOnMarkersIntersectingRange(wordRange.get(), DocumentMarker::Replacement); > } >diff --git a/Source/WebCore/editing/mac/DictationAlternativeController.h b/Source/WebCore/editing/mac/DictationAlternativeController.h >new file mode 100644 >index 0000000000000000000000000000000000000000..67ee2a930b2b5663b593de91c466b45b854580da >--- /dev/null >+++ b/Source/WebCore/editing/mac/DictationAlternativeController.h >@@ -0,0 +1,73 @@ >+/* >+ * Copyright (C) 2012 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 DictationAlternativeController_h >+#define DictationAlternativeController_h >+ >+#include "AlternativeTextClient.h" >+#include "FloatRect.h" >+#include "TextAlternativeWithRange.h" >+#include <wtf/HashMap.h> >+#include <wtf/RetainPtr.h> >+ >+#if USE(DICTATION_ALTERNATIVES) >+OBJC_CLASS NSTextAlternatives; >+OBJC_CLASS NSView; >+ >+namespace WebCore { >+class DictationContextController; >+ >+class DictationAlternativeController { >+public: >+ DictationAlternativeController() { } >+ // Returns a dictation context ID. >+ uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&); >+ void clear(); >+ void showAlternatives(NSView*, const WebCore::FloatRect& boundingBoxOfDictatedString, uint64_t dictationContext, void(^acceptanceHandler)(NSString*)); >+ void dismissAlternatives(); >+ void removeAlternatives(uint64_t dictationContext); >+ >+private: >+ void handleAcceptedAlternative(NSString* acceptedAlternative, uint64_t dictationContext, NSTextAlternatives*); >+ >+ class DictationContextController { >+ public: >+ DictationContextController() { } >+ uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&); >+ void clear(); >+ NSTextAlternatives* alternativesForDictationContext(uint64_t dictationContext); >+ void removeAlternativesForDictationContext(uint64_t dictationContext); >+ static const uint64_t invalidContext = 0; >+ private: >+ typedef HashMap<uint64_t, RetainPtr<NSTextAlternatives> > HashMapType; >+ HashMapType m_alternativesObjectMap; >+ }; >+ >+ DictationContextController m_contextController; >+ RetainPtr<NSView> m_view; >+}; >+} >+#endif >+#endif // DictationAlternativeController_h >diff --git a/Source/WebCore/editing/mac/DictationAlternativeController.mm b/Source/WebCore/editing/mac/DictationAlternativeController.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..70e8c358506623bc84b5d0aefc9233910abb73b4 >--- /dev/null >+++ b/Source/WebCore/editing/mac/DictationAlternativeController.mm >@@ -0,0 +1,114 @@ >+/* >+ * Copyright (C) 2012 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 "DictationAlternativeController.h" >+ >+#if USE(DICTATION_ALTERNATIVES) >+ >+#import <AppKit/NSSpellChecker.h> >+#import <AppKit/NSTextAlternatives.h> >+#import <AppKit/NSView.h> >+ >+namespace WebCore { >+uint64_t DictationAlternativeController::DictationContextController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives) >+{ >+ uint64_t context = reinterpret_cast<uintptr_t>(alternatives.get()); >+ if (!context) >+ return invalidContext; >+ if (alternativesForDictationContext(context)) >+ return context; >+ >+ HashMapType::AddResult result = m_alternativesObjectMap.add(context, alternatives); >+ return result.isNewEntry ? context : invalidContext; >+} >+ >+NSTextAlternatives* DictationAlternativeController::DictationContextController::alternativesForDictationContext(uint64_t dictationContext) >+{ >+ HashMapType::const_iterator itr = m_alternativesObjectMap.find(dictationContext); >+ if (itr == m_alternativesObjectMap.end()) >+ return NULL; >+ return itr->second.get(); >+} >+ >+void DictationAlternativeController::DictationContextController::removeAlternativesForDictationContext(uint64_t dictationContext) >+{ >+ m_alternativesObjectMap.remove(dictationContext); >+} >+ >+void DictationAlternativeController::DictationContextController::clear() >+{ >+ m_alternativesObjectMap.clear(); >+} >+ >+uint64_t DictationAlternativeController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives) >+{ >+ return m_contextController.addAlternatives(alternatives); >+} >+ >+void DictationAlternativeController::clear() >+{ >+ return m_contextController.clear(); >+} >+ >+void DictationAlternativeController::showAlternatives(NSView* view, const WebCore::FloatRect& boundingBoxOfDictatedString, uint64_t dictationContext, void(^acceptanceHandler)(NSString*)) >+{ >+ dismissAlternatives(); >+ if (!view) >+ return; >+ m_view = view; >+ NSTextAlternatives* alternatives = m_contextController.alternativesForDictationContext(dictationContext); >+ if (!alternatives) >+ return; >+ NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; >+ [spellChecker showCorrectionIndicatorOfType:NSCorrectionIndicatorTypeGuesses primaryString:alternatives.primaryString alternativeStrings:alternatives.alternativeStrings forStringInRect:boundingBoxOfDictatedString view:m_view.get() completionHandler:^(NSString* acceptedString) { >+ if (acceptedString) { >+ handleAcceptedAlternative(acceptedString, dictationContext, alternatives); >+ acceptanceHandler(acceptedString); >+ } >+ }]; >+} >+ >+void DictationAlternativeController::handleAcceptedAlternative(NSString* acceptedAlternative, uint64_t dictationContext, NSTextAlternatives* alternatives) >+{ >+ [alternatives noteSelectedAlternativeString:acceptedAlternative]; >+ m_contextController.removeAlternativesForDictationContext(dictationContext); >+ m_view.clear(); >+} >+ >+void DictationAlternativeController::dismissAlternatives() >+{ >+ if (!m_view) >+ return; >+ [[NSSpellChecker sharedSpellChecker] dismissCorrectionIndicatorForView:m_view.get()]; >+} >+ >+void DictationAlternativeController::removeAlternatives(uint64_t dictationContext) >+{ >+ m_contextController.removeAlternativesForDictationContext(dictationContext); >+} >+ >+} >+#endif >diff --git a/Source/WebCore/editing/mac/TextAlternativeWithRange.h b/Source/WebCore/editing/mac/TextAlternativeWithRange.h >new file mode 100644 >index 0000000000000000000000000000000000000000..5f0422dcd5e9e5f61271bc0e15edfcf32fd38031 >--- /dev/null >+++ b/Source/WebCore/editing/mac/TextAlternativeWithRange.h >@@ -0,0 +1,55 @@ >+/* >+ * Copyright (C) 2012 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 TextAlternativeWithRange_h >+#define TextAlternativeWithRange_h >+ >+#include "AlternativeTextClient.h" >+#include <wtf/RetainPtr.h> >+ >+#if USE(DICTATION_ALTERNATIVES) >+OBJC_CLASS NSTextAlternatives; >+#endif >+ >+namespace WebCore { >+#if USE(DICTATION_ALTERNATIVES) >+struct TextAlternativeWithRange { >+ TextAlternativeWithRange(NSTextAlternatives* anAlternative, NSRange aRange) >+ : range(aRange) >+ , alternative(anAlternative) >+ { } >+ >+ NSRange range; >+ RetainPtr<NSTextAlternatives> alternative; >+}; >+ >+void collectDictationTextAlternatives(NSAttributedString*, Vector<TextAlternativeWithRange>& alternatives); >+#else >+struct TextAlternativeWithRange { }; >+#endif >+ >+} >+ >+#endif // TextAlternativeWithRange_h >diff --git a/Source/WebCore/editing/mac/TextAlternativeWithRange.mm b/Source/WebCore/editing/mac/TextAlternativeWithRange.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..7d1d6cd2cb7a080e1f57eadf5b6c07dc215cc7b1 >--- /dev/null >+++ b/Source/WebCore/editing/mac/TextAlternativeWithRange.mm >@@ -0,0 +1,48 @@ >+/* >+ * Copyright (C) 2012 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. >+ */ >+ >+#include "config.h" >+#include "TextAlternativeWithRange.h" >+ >+#if USE(DICTATION_ALTERNATIVES) >+#import <AppKit/NSTextAlternatives.h> >+ >+namespace WebCore { >+void collectDictationTextAlternatives(NSAttributedString *string, Vector<TextAlternativeWithRange>& alternatives) { >+ NSRange effectiveRange = NSMakeRange(0, 0); >+ NSUInteger length = [string length]; >+ do { >+ NSDictionary *attributes = [string attributesAtIndex:effectiveRange.location effectiveRange:&effectiveRange]; >+ if (!attributes) >+ break; >+ NSTextAlternatives *textAlternatives = [attributes objectForKey:NSTextAlternativesAttributeName]; >+ if (textAlternatives) >+ alternatives.append(TextAlternativeWithRange(textAlternatives, effectiveRange)); >+ effectiveRange.location = NSMaxRange(effectiveRange); >+ } while (effectiveRange.location < length); >+} >+}; >+ >+#endif // USE(DICTATION_ALTERNATIVES) >diff --git a/Source/WebCore/page/AlternativeTextClient.h b/Source/WebCore/page/AlternativeTextClient.h >index f5ae67d0ed9fdc6fbf4707376663b92ac9315cbc..e999d056d29c3cc544cd6d6a235f038806a33357 100644 >--- a/Source/WebCore/page/AlternativeTextClient.h >+++ b/Source/WebCore/page/AlternativeTextClient.h >@@ -31,6 +31,11 @@ > #include <wtf/Vector.h> > #include <wtf/text/WTFString.h> > >+#if PLATFORM(MAC) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION) >+// Some platforms provide UI for suggesting alternative dictation text. >+#define WTF_USE_DICTATION_ALTERNATIVES 1 >+#endif // PLATFORM(MAC) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION) >+ > namespace WebCore { > > enum ReasonForDismissingAlternativeText { >@@ -57,6 +62,7 @@ public: > virtual void dismissAlternative(ReasonForDismissingAlternativeText) = 0; > virtual String dismissAlternativeSoon(ReasonForDismissingAlternativeText) = 0; > virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0; >+ virtual void removeDictationAlternatives(uint64_t dictationContext) = 0; > }; > > } >diff --git a/Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm b/Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm >index 6583cee662111076c1e024726eecbb0a8f540790..6810a2780b9f396da0d322bd63acf6012a9e308e 100644 >--- a/Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm >+++ b/Source/WebKit/mac/WebCoreSupport/CorrectionPanel.mm >@@ -25,7 +25,6 @@ > #import "CorrectionPanel.h" > > #import "WebViewInternal.h" >-#import "WebViewPrivate.h" > > #if USE(AUTOCORRECTION_PANEL) > using namespace WebCore; >@@ -131,7 +130,7 @@ void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, N > break; > } > >- [m_view.get() handleCorrectionPanelResult:acceptedReplacement]; >+ [m_view.get() handleAcceptedAlternativeText:acceptedReplacement]; > m_view.clear(); > if (acceptedReplacement) > m_resultForDismissal.adoptNS([acceptedReplacement copy]); >diff --git a/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.h b/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.h >index 7edface0ae346814197cdb156d6bb36cd6b1d1d7..f4c2bf57205932eb8ce22325b8482c9a3e7cae40 100644 >--- a/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.h >+++ b/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.h >@@ -40,6 +40,7 @@ public: > virtual void dismissAlternative(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual String dismissAlternativeSoon(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual void recordAutocorrectionResponse(WebCore::AutocorrectionResponseType, const String& replacedString, const String& replacementString) OVERRIDE; >+ virtual void removeDictationAlternatives(uint64_t dictationContext) OVERRIDE; > private: > WebView* m_webView; > #if USE(AUTOCORRECTION_PANEL) >diff --git a/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm b/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm >index 6972fb4ba932e24cdbb0499ce48ef6ea24ed52cd..35933bd23f9a5b0144aac6b46cfc4d2e7bb10fc2 100644 >--- a/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm >+++ b/Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm >@@ -25,6 +25,8 @@ > > #include "WebAlternativeTextClient.h" > >+#include "WebViewInternal.h" >+ > using namespace WebCore; > > WebAlternativeTextClient::WebAlternativeTextClient(WebView* webView) >@@ -69,3 +71,12 @@ void WebAlternativeTextClient::recordAutocorrectionResponse(AutocorrectionRespon > CorrectionPanel::recordAutocorrectionResponse(m_webView, response, replacedString, replacementString); > #endif > } >+ >+void WebAlternativeTextClient::removeDictationAlternatives(uint64_t dictationContext) >+{ >+#if USE(DICTATION_ALTERNATIVES) >+ [m_webView _removeDictationAlternatives:dictationContext]; >+#else >+ UNUSED_PARAM(dictationContext); >+#endif >+} >diff --git a/Source/WebKit/mac/WebView/WebHTMLView.mm b/Source/WebKit/mac/WebView/WebHTMLView.mm >index a9b291e499f80297cc75679f390ef6bde061c4a4..c8611fd48d2e5b4651c1a28f99e7380a8ceb359a 100644 >--- a/Source/WebKit/mac/WebView/WebHTMLView.mm >+++ b/Source/WebKit/mac/WebView/WebHTMLView.mm >@@ -113,6 +113,7 @@ > #import <WebCore/SimpleFontData.h> > #import <WebCore/StylePropertySet.h> > #import <WebCore/Text.h> >+#import <WebCore/TextAlternativeWithRange.h> > #import <WebCore/WebCoreObjCExtras.h> > #import <WebCore/WebFontCache.h> > #import <WebCore/WebNSAttributedStringExtras.h> >@@ -5904,7 +5905,14 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde > NSRange replacementRange = { NSNotFound, 0 }; > bool isFromInputMethod = coreFrame && coreFrame->editor()->hasComposition(); > >+ Vector<DictationAlternative> dictationAlternativeLocations; > if (isAttributedString) { >+#if USE(DICTATION_ALTERNATIVES) >+ Vector<TextAlternativeWithRange> textAlternatives; >+ collectDictationTextAlternatives(string, textAlternatives); >+ if (textAlternatives.size()) >+ [[self _webView] _getWebCoreDictationAlternatives:dictationAlternativeLocations fromTextAlternatives:textAlternatives]; >+#endif > // FIXME: We ignore most attributes from the string, so for example inserting from Character Palette loses font and glyph variation data. > // It does not look like any input methods ever use insertText: with attributes other than NSTextInputReplacementRangeAttributeName. > text = [string string]; >@@ -5943,7 +5951,11 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde > if (!coreFrame->editor()->hasComposition()) { > // An insertText: might be handled by other responders in the chain if we don't handle it. > // One example is space bar that results in scrolling down the page. >- eventHandled = coreFrame->editor()->insertText(eventText, event); >+ >+ if (dictationAlternativeLocations.size()) >+ eventHandled = coreFrame->editor()->insertDictatedText(eventText, dictationAlternativeLocations, event); >+ else >+ eventHandled = coreFrame->editor()->insertText(eventText, event); > } else { > eventHandled = true; > coreFrame->editor()->confirmComposition(eventText); >diff --git a/Source/WebKit/mac/WebView/WebView.mm b/Source/WebKit/mac/WebView/WebView.mm >index 4fb5df95dedd3b5be2fb1e4069fb8149ac199442..4bc4c752a8098bba262ee7cee7616cfff82a2a70 100644 >--- a/Source/WebKit/mac/WebView/WebView.mm >+++ b/Source/WebKit/mac/WebView/WebView.mm >@@ -115,6 +115,7 @@ > #import <WebCore/ColorMac.h> > #import <WebCore/CSSComputedStyleDeclaration.h> > #import <WebCore/Cursor.h> >+#import <WebCore/DictationAlternativeController.h> > #import <WebCore/Document.h> > #import <WebCore/DocumentLoader.h> > #import <WebCore/DragController.h> >@@ -162,6 +163,7 @@ > #import <WebCore/SecurityOrigin.h> > #import <WebCore/SecurityPolicy.h> > #import <WebCore/Settings.h> >+#import <WebCore/TextAlternativeWithRange.h> > #import <WebCore/TextResourceDecoder.h> > #import <WebCore/ThreadCheck.h> > #import <WebCore/WebCoreObjCExtras.h> >@@ -5499,16 +5501,6 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue jsValu > > #endif > >-#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) >-- (void)handleCorrectionPanelResult:(NSString*)result >-{ >- WebFrame *webFrame = [self _selectedOrMainFrame]; >- Frame* coreFrame = core(webFrame); >- if (coreFrame) >- coreFrame->editor()->handleAlternativeTextUIResult(result); >-} >-#endif >- > @end > > @implementation WebView (WebViewUndoableEditing) >@@ -6368,6 +6360,33 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity > } > #endif > >+#if USE(AUTOCORRECTION_PANEL) >+- (void)handleAcceptedAlternativeText:(NSString*)text >+{ >+ WebFrame *webFrame = [self _selectedOrMainFrame]; >+ Frame* coreFrame = core(webFrame); >+ if (coreFrame) >+ coreFrame->editor()->handleAlternativeTextUIResult(text); >+} >+#endif >+ >+#if USE(DICTATION_ALTERNATIVES) >+- (void)_getWebCoreDictationAlternatives:(Vector<DictationAlternative>&)alternatives fromTextAlternatives:(const Vector<TextAlternativeWithRange>&)alternativesWithRange >+{ >+ for (size_t i = 0; i < alternativesWithRange.size(); ++i) { >+ const TextAlternativeWithRange& alternativeWithRange = alternativesWithRange[i]; >+ uint64_t dictationContext = _private->m_dictationAlternativeController->addAlternatives(alternativeWithRange.alternative); >+ if (dictationContext) >+ alternatives.append(DictationAlternative(alternativeWithRange.range.location, alternativeWithRange.range.length, dictationContext)); >+ } >+} >+ >+- (void)_removeDictationAlternatives:(uint64_t)dictationContext >+{ >+ _private->m_dictationAlternativeController->removeAlternatives(dictationContext); >+} >+#endif >+ > - (NSPoint)_convertPointFromRootView:(NSPoint)point > { > return NSMakePoint(point.x, [self bounds].size.height - point.y); >diff --git a/Source/WebKit/mac/WebView/WebViewData.h b/Source/WebKit/mac/WebView/WebViewData.h >index ea2bfcf6074e9a511c3c3eae2db4ff5e5ec3c4f6..d384f87c7fa3a1384961c538edb2eddfbecc5bfc 100644 >--- a/Source/WebKit/mac/WebView/WebViewData.h >+++ b/Source/WebKit/mac/WebView/WebViewData.h >@@ -29,6 +29,7 @@ > > #import "WebTypesInternal.h" > #import "WebDelegateImplementationCaching.h" >+#import <WebCore/AlternativeTextClient.h> > #import <WebCore/LayerFlushScheduler.h> > #import <WebCore/LayerFlushSchedulerClient.h> > #import <WebCore/PlatformString.h> >@@ -38,8 +39,9 @@ > #import <wtf/RetainPtr.h> > > namespace WebCore { >- class HistoryItem; >- class Page; >+class DictationAlternativeController; >+class HistoryItem; >+class Page; > } > > @class WebInspector; >@@ -200,5 +202,9 @@ private: > int validationMessageTimerMagnification; > > float customDeviceScaleFactor; >+ >+#if USE(DICTATION_ALTERNATIVES) >+ OwnPtr<WebCore::DictationAlternativeController> m_dictationAlternativeController; >+#endif > } > @end >diff --git a/Source/WebKit/mac/WebView/WebViewData.mm b/Source/WebKit/mac/WebView/WebViewData.mm >index 0b8117a09706d5b6ec4e6457c3398e47626c58ba..90ace1381e91d3785b4e2cf7787e55a70c0d2c51 100644 >--- a/Source/WebKit/mac/WebView/WebViewData.mm >+++ b/Source/WebKit/mac/WebView/WebViewData.mm >@@ -31,6 +31,7 @@ > > #import "WebKitLogging.h" > #import "WebPreferenceKeysPrivate.h" >+#import <WebCore/DictationAlternativeController.h> > #import <WebCore/WebCoreObjCExtras.h> > #import <WebCore/HistoryItem.h> > #import <WebCore/RunLoop.h> >@@ -100,6 +101,10 @@ LayerFlushController::LayerFlushController(WebView* webView) > > pluginDatabaseClientCount++; > >+#if USE(DICTATION_ALTERNATIVES) >+ m_dictationAlternativeController = adoptPtr(new WebCore::DictationAlternativeController); >+#endif >+ > return self; > } > >diff --git a/Source/WebKit/mac/WebView/WebViewInternal.h b/Source/WebKit/mac/WebView/WebViewInternal.h >index 02cc550106b044fbc177c9f59a1f83f590de50b0..c20dd937b12bdd1c8f29fb4f477ab6771e4ba144 100644 >--- a/Source/WebKit/mac/WebView/WebViewInternal.h >+++ b/Source/WebKit/mac/WebView/WebViewInternal.h >@@ -34,20 +34,26 @@ > #import "WebTypesInternal.h" > > #ifdef __cplusplus >+#import <WebCore/AlternativeTextClient.h> > #import <WebCore/FindOptions.h> >+#import <WebCore/FloatRect.h> > #import <WebCore/WebCoreKeyboardUIMode.h> > > #include <wtf/Forward.h> >+#include <wtf/RetainPtr.h> > > namespace WebCore { >- class Element; >- class Frame; >- class HistoryItem; >- class KURL; >- class KeyboardEvent; >- class Page; >- class RenderBox; >- class Node; >+class Element; >+class Event; >+class Frame; >+class HistoryItem; >+class KURL; >+class KeyboardEvent; >+class Page; >+class RenderBox; >+class Node; >+struct DictationAlternative; >+struct TextAlternativeWithRange; > } > #endif > >@@ -95,6 +101,15 @@ WebCore::FindOptions coreOptions(WebFindOptions options); > - (void)_scheduleGlibContextIterations; > #endif > >+#if USE(AUTOCORRECTION_PANEL) >+- (void)handleAcceptedAlternativeText:(NSString*)text; >+#endif >+ >+#if USE(DICTATION_ALTERNATIVES) >+- (void)_getWebCoreDictationAlternatives:(Vector<WebCore::DictationAlternative>&)alternatives fromTextAlternatives:(const Vector<WebCore::TextAlternativeWithRange>&)alternativesWithRange; >+- (void)_removeDictationAlternatives:(uint64_t)dictationContext; >+#endif >+ > @end > > #endif >diff --git a/Source/WebKit/mac/WebView/WebViewPrivate.h b/Source/WebKit/mac/WebView/WebViewPrivate.h >index 02f7bcc4567d765c7bd3a434f25726a6103e3130..8289b12c188bedaf051046fa68222752ee98dd5c 100644 >--- a/Source/WebKit/mac/WebView/WebViewPrivate.h >+++ b/Source/WebKit/mac/WebView/WebViewPrivate.h >@@ -687,9 +687,6 @@ Could be worth adding to the API. > - (void)setAutomaticSpellingCorrectionEnabled:(BOOL)flag; > - (void)toggleAutomaticSpellingCorrection:(id)sender; > #endif >-#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) >-- (void)handleCorrectionPanelResult:(NSString*)result; >-#endif > @end > > @interface WebView (WebViewEditingInMail) >diff --git a/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp b/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp >index c6a1673b4cd454241390fba9e6b8b557b2c250d3..7ce7ba51c01f0a64a11081352d62d7fb396e0f83 100644 >--- a/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp >+++ b/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp >@@ -31,6 +31,7 @@ > #include <WebCore/Credential.h> > #include <WebCore/Cursor.h> > #include <WebCore/DatabaseDetails.h> >+#include <WebCore/DictationAlternative.h> > #include <WebCore/DragSession.h> > #include <WebCore/Editor.h> > #include <WebCore/FileChooser.h> >@@ -531,6 +532,24 @@ bool ArgumentCoder<DatabaseDetails>::decode(ArgumentDecoder* decoder, DatabaseDe > return true; > } > >+void ArgumentCoder<DictationAlternative>::encode(ArgumentEncoder* encoder, const DictationAlternative& dictationAlternative) >+{ >+ encoder->encode(dictationAlternative.rangeStart); >+ encoder->encode(dictationAlternative.rangeLength); >+ encoder->encode(dictationAlternative.dictationContext); >+} >+ >+bool ArgumentCoder<DictationAlternative>::decode(ArgumentDecoder* decoder, DictationAlternative& dictationAlternative) >+{ >+ if (!decoder->decode(dictationAlternative.rangeStart)) >+ return false; >+ if (!decoder->decode(dictationAlternative.rangeLength)) >+ return false; >+ if (!decoder->decode(dictationAlternative.dictationContext)) >+ return false; >+ return true; >+} >+ > > void ArgumentCoder<FileChooserSettings>::encode(ArgumentEncoder* encoder, const FileChooserSettings& settings) > { >diff --git a/Source/WebKit2/Shared/WebCoreArgumentCoders.h b/Source/WebKit2/Shared/WebCoreArgumentCoders.h >index 033e1794cbc27d8cd7989806bac23b88192b3dd8..d029e65e58d23870ef48cb19f9c2e22b4f0c9922 100644 >--- a/Source/WebKit2/Shared/WebCoreArgumentCoders.h >+++ b/Source/WebKit2/Shared/WebCoreArgumentCoders.h >@@ -50,6 +50,7 @@ namespace WebCore { > class ResourceRequest; > class ResourceResponse; > struct CompositionUnderline; >+ struct DictationAlternative; > struct DragSession; > struct FileChooserSettings; > struct GrammarDetail; >@@ -203,6 +204,11 @@ template<> struct ArgumentCoder<WebCore::DatabaseDetails> { > static bool decode(ArgumentDecoder*, WebCore::DatabaseDetails&); > }; > >+template<> struct ArgumentCoder<WebCore::DictationAlternative> { >+ static void encode(ArgumentEncoder*, const WebCore::DictationAlternative&); >+ static bool decode(ArgumentDecoder*, WebCore::DictationAlternative&); >+}; >+ > template<> struct ArgumentCoder<WebCore::FileChooserSettings> { > static void encode(ArgumentEncoder*, const WebCore::FileChooserSettings&); > static bool decode(ArgumentDecoder*, WebCore::FileChooserSettings&); >diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h >index a9d7a9fa946c97c838739cb06e4d2e2448f50b6a..5239b01ed62396b070588b3d23679f6b714c8141 100644 >--- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h >+++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h >@@ -30,6 +30,12 @@ > #include "PageClient.h" > #include <wtf/RetainPtr.h> > >+namespace WebCore { >+#if USE(DICTATION_ALTERNATIVES) >+class DictationAlternativeController; >+#endif >+} >+ > @class WKEditorUndoTargetObjC; > @class WKView; > >@@ -129,11 +135,17 @@ private: > > virtual WKView* wkView() const { return m_wkView; } > >+ virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&); >+ virtual void removeDictationAlternatives(uint64_t dictationContext); >+ > WKView* m_wkView; > RetainPtr<WKEditorUndoTargetObjC> m_undoTarget; > #if !defined(BUILDING_ON_SNOW_LEOPARD) > CorrectionPanel m_correctionPanel; > #endif >+#if USE(DICTATION_ALTERNATIVES) >+ OwnPtr<WebCore::DictationAlternativeController> m_dictationAlternativeController; >+#endif > }; > > } // namespace WebKit >diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm >index 72ea3493e1a67943d56e7b55e947cb309d5c3f84..9cdae15583739836c9325065052e5c84174faeb2 100644 >--- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm >+++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm >@@ -26,6 +26,9 @@ > #import "config.h" > #import "PageClientImpl.h" > >+#if USE(DICTATION_ALTERNATIVES) >+#import <AppKit/NSTextAlternatives.h> >+#endif > #import "DataReference.h" > #import "DictionaryPopupInfo.h" > #import "FindIndicator.h" >@@ -39,6 +42,7 @@ > #import "WebPopupMenuProxyMac.h" > #import <WebCore/BitmapImage.h> > #import <WebCore/Cursor.h> >+#import <WebCore/DictationAlternativeController.h> > #import <WebCore/FloatRect.h> > #import <WebCore/FoundationExtras.h> > #import <WebCore/GraphicsContext.h> >@@ -122,6 +126,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_dictationAlternativeController(adoptPtr(new DictationAlternativeController)) >+#endif > { > } > >@@ -209,10 +216,13 @@ void PageClientImpl::processDidCrash() > { > [m_wkView _processDidCrash]; > } >- >+ > void PageClientImpl::pageClosed() > { > [m_wkView _pageClosed]; >+#if USE(DICTATION_ALTERNATIVES) >+ m_dictationAlternativeController->clear(); >+#endif > } > > void PageClientImpl::didRelaunchProcess() >@@ -529,4 +539,20 @@ bool PageClientImpl::executeSavedCommandBySelector(const String& selectorString) > return [m_wkView _executeSavedCommandBySelector:NSSelectorFromString(selectorString)]; > } > >+uint64_t PageClientImpl::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives) >+{ >+#if USE(DICTATION_ALTERNATIVES) >+ return m_dictationAlternativeController->addAlternatives(alternatives); >+#else >+ return 0; >+#endif >+} >+ >+void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext) >+{ >+#if USE(DICTATION_ALTERNATIVES) >+ m_dictationAlternativeController->removeAlternatives(dictationContext); >+#endif >+} >+ > } // namespace WebKit >diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm >index c32f90048994dbdbea435074237a99191361a199..4286aa8b9d2b75f952a724e2d345bac3af2318fb 100644 >--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm >+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm >@@ -26,6 +26,11 @@ > #import "config.h" > #import "WKView.h" > >+#if USE(DICTATION_ALTERNATIVES) >+#import <AppKit/NSTextAlternatives.h> >+#import <AppKit/NSAttributedString.h> >+#endif >+ > #import "AttributedString.h" > #import "DataReference.h" > #import "DrawingAreaProxyImpl.h" >@@ -73,6 +78,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> >@@ -1167,7 +1173,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 >@@ -1187,7 +1198,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.size()) >+ 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; >@@ -2856,9 +2871,9 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path) > return _data->_spellCheckerDocumentTag; > } > >-- (void)handleCorrectionPanelResult:(NSString*)result >+- (void)handleAcceptedAlternativeText:(NSString*)text > { >- _data->_page->handleAlternativeTextUIResult(result); >+ _data->_page->handleAlternativeTextUIResult(text); > } > > @end >diff --git a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h >index 6b6eb6bf41d1914d3d6d06f0f232630c392b805b..43c6e2baaa050de4b6205884d62e7a2316135e8c 100644 >--- a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h >+++ b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h >@@ -96,6 +96,6 @@ namespace WebKit { > - (void)_cacheWindowBottomCornerRect; > > - (NSInteger)spellCheckerDocumentTag; >-- (void)handleCorrectionPanelResult:(NSString*)result; >+- (void)handleAcceptedAlternativeText:(NSString*)text; > > @end >diff --git a/Source/WebKit2/UIProcess/PageClient.h b/Source/WebKit2/UIProcess/PageClient.h >index 7c815101dfa72dd493a94069efa5225dd1f27835..4e02be69a08da5b97a74444e3bc228cc6f85b90c 100644 >--- a/Source/WebKit2/UIProcess/PageClient.h >+++ b/Source/WebKit2/UIProcess/PageClient.h >@@ -37,6 +37,7 @@ > #include "PluginComplexTextInputState.h" > > OBJC_CLASS WKView; >+OBJC_CLASS NSTextAlternatives; > #endif > > namespace WebCore { >@@ -192,6 +193,9 @@ public: > virtual void recommendedScrollbarStyleDidChange(int32_t newStyle) = 0; > > virtual WKView* wkView() const = 0; >+ >+ virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) = 0; >+ virtual void removeDictationAlternatives(uint64_t dictationContext) = 0; > #endif > > virtual void didChangeScrollbarsForMainFrame() const = 0; >diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp >index 7cc30f40e148f25aa9479cd810d92ed24d8341d3..7a0fc9c1a464e602c2209fda50e7265febaa5922 100644 >--- a/Source/WebKit2/UIProcess/WebPageProxy.cpp >+++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp >@@ -3767,6 +3767,14 @@ void WebPageProxy::handleAlternativeTextUIResult(const String& result) > process()->send(Messages::WebPage::HandleAlternativeTextUIResult(result), m_pageID, 0); > #endif > } >+ >+#if USE(DICTATION_ALTERNATIVES) >+void WebPageProxy::removeDictationAlternatives(uint64_t dictationContext) >+{ >+ m_pageClient->removeDictationAlternatives(dictationContext); >+} >+#endif >+ > #endif // PLATFORM(MAC) > > } // namespace WebKit >diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h >index b1e7eea05be59e4ad8d90cc43b2e710bb8e7c365..20c60ccb4ca7a6fa84a1323977460215cc7d1e79 100644 >--- a/Source/WebKit2/UIProcess/WebPageProxy.h >+++ b/Source/WebKit2/UIProcess/WebPageProxy.h >@@ -58,6 +58,7 @@ > #include "WebPopupMenuProxy.h" > #include "WebResourceLoadClient.h" > #include "WebUIClient.h" >+#include <WebCore/AlternativeTextClient.h> > #include <WebCore/DragActions.h> > #include <WebCore/DragSession.h> > #include <WebCore/HitTestResult.h> >@@ -91,6 +92,7 @@ namespace WebCore { > class IntSize; > class ProtectionSpace; > struct FileChooserSettings; >+ struct TextAlternativeWithRange; > struct TextCheckingResult; > struct ViewportAttributes; > struct WindowFeatures; >@@ -347,6 +349,7 @@ public: > void confirmComposition(); > void cancelComposition(); > bool insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd); >+ bool insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives); > void getMarkedRange(uint64_t& location, uint64_t& length); > void getSelectedRange(uint64_t& location, uint64_t& length); > void getAttributedSubstringFromRange(uint64_t location, uint64_t length, AttributedString&); >@@ -878,6 +881,9 @@ private: > void dismissCorrectionPanelSoon(int32_t reason, String& result); > void recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString); > #endif // !defined(BUILDING_ON_SNOW_LEOPARD) >+#if USE(DICTATION_ALTERNATIVES) >+ void removeDictationAlternatives(uint64_t dictationContext); >+#endif > #endif // PLATFORM(MAC) > > void clearLoadDependentCallbacks(); >diff --git a/Source/WebKit2/UIProcess/WebPageProxy.messages.in b/Source/WebKit2/UIProcess/WebPageProxy.messages.in >index d71811551d43a027e668abc8d2f9d9c8363f6e5c..d1e11e10c7671c2f0521db7ba480d62c6a8ffde1 100644 >--- a/Source/WebKit2/UIProcess/WebPageProxy.messages.in >+++ b/Source/WebKit2/UIProcess/WebPageProxy.messages.in >@@ -278,6 +278,10 @@ messages -> WebPageProxy { > RecordAutocorrectionResponse(int32_t responseType, String replacedString, String replacementString); > #endif > >+#if USE(DICTATION_ALTERNATIVES) >+ RemoveDictationAlternatives(uint64_t dictationContext); >+#endif >+ > #if PLATFORM(WIN) > # Windows 7 Gesture Messages > SetGestureReachedScrollingLimit(bool limitReached) >diff --git a/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm b/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm >index 94171f737ab36d5ffda587678d2fd86004574458..09641cd083bad14ae3e6b40bf04603c36aacbf64 100644 >--- a/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm >+++ b/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm >@@ -137,7 +137,7 @@ void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, N > break; > } > >- [m_view.get() handleCorrectionPanelResult:acceptedReplacement]; >+ [m_view.get() handleAcceptedAlternativeText:acceptedReplacement]; > m_view.clear(); > if (acceptedReplacement) > m_resultForDismissal.adoptNS([acceptedReplacement copy]); >diff --git a/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm b/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm >index 35847182e140b7d84d098346b68b73eb1a0864f0..6789ad9de0bb262cf39af2e14270328765a079a6 100644 >--- a/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm >+++ b/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm >@@ -38,7 +38,9 @@ > #import "TextChecker.h" > #import "WebPageMessages.h" > #import "WebProcessProxy.h" >+#import <WebCore/DictationAlternative.h> > #import <WebCore/SharedBuffer.h> >+#import <WebCore/TextAlternativeWithRange.h> > #import <WebKitSystemInterface.h> > #import <wtf/text/StringConcatenate.h> > >@@ -198,6 +200,35 @@ bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart > return handled; > } > >+bool WebPageProxy::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange) >+{ >+#if USE(DICTATION_ALTERNATIVES) >+ if (dictationAlternativesWithRange.isEmpty()) >+ return insertText(text, replacementRangeStart, replacementRangeEnd); >+ >+ if (!isValid()) >+ return true; >+ >+ Vector<DictationAlternative> dictationAlternatives; >+ >+ for (size_t i = 0; i < dictationAlternativesWithRange.size(); ++i) { >+ const TextAlternativeWithRange& alternativeWithRange = dictationAlternativesWithRange[i]; >+ uint64_t dictationContext = m_pageClient->addDictationAlternatives(alternativeWithRange.alternative); >+ if (dictationContext) >+ dictationAlternatives.append(DictationAlternative(alternativeWithRange.range.location, alternativeWithRange.range.length, dictationContext)); >+ } >+ >+ if (dictationAlternatives.isEmpty()) >+ return insertText(text, replacementRangeStart, replacementRangeEnd); >+ >+ bool handled = true; >+ process()->sendSync(Messages::WebPage::InsertDictatedText(text, replacementRangeStart, replacementRangeEnd, dictationAlternatives), Messages::WebPage::InsertDictatedText::Reply(handled, m_editorState), m_pageID); >+ return handled; >+#else >+ return insertText(text, replacementRangeStart, replacementRangeEnd); >+#endif >+} >+ > void WebPageProxy::getMarkedRange(uint64_t& location, uint64_t& length) > { > location = NSNotFound; >diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebAlternativeTextClient.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebAlternativeTextClient.h >index b805adaf5812af5f23cec4a1b5c92d7c6936e2c4..817b03c4a20baef68376851d528360df8b11c7e5 100644 >--- a/Source/WebKit2/WebProcess/WebCoreSupport/WebAlternativeTextClient.h >+++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebAlternativeTextClient.h >@@ -41,6 +41,7 @@ public: > virtual void dismissAlternative(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual String dismissAlternativeSoon(WebCore::ReasonForDismissingAlternativeText) OVERRIDE; > virtual void recordAutocorrectionResponse(WebCore::AutocorrectionResponseType, const String& replacedString, const String& replacementString) OVERRIDE; >+ virtual void removeDictationAlternatives(uint64_t dictationContext) OVERRIDE; > private: > WebPage *m_page; > }; >diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebAlternativeTextClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebAlternativeTextClient.cpp >index 6abb693541d0856ee01fdc63e818f985664f60da..8748e70535f1a582d01f6b03a03ee4b264e45557 100644 >--- a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebAlternativeTextClient.cpp >+++ b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebAlternativeTextClient.cpp >@@ -76,4 +76,13 @@ void WebAlternativeTextClient::recordAutocorrectionResponse(AutocorrectionRespon > #endif > } > >+void WebAlternativeTextClient::removeDictationAlternatives(uint64_t dictationContext) >+{ >+#if USE(DICTATION_ALTERNATIVES) >+ m_page->send(Messages::WebPageProxy::RemoveDictationAlternatives(dictationContext)); >+#else >+ UNUSED_PARAM(dictationContext); >+#endif >+} >+ > } >diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h >index a3bda29c67e0973a83d53989832edb6923b65675..2c4ab80ddac0fd435fd9a44d9cfb9635db48c70f 100644 >--- a/Source/WebKit2/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h >@@ -48,6 +48,7 @@ > #include "SandboxExtension.h" > #include "ShareableBitmap.h" > #include "WebUndoStep.h" >+#include <WebCore/DictationAlternative.h> > #include <WebCore/DragData.h> > #include <WebCore/Editor.h> > #include <WebCore/FrameLoaderTypes.h> >@@ -414,7 +415,7 @@ public: > void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&, bool& result); > void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, bool& result); > bool performNonEditingBehaviorForSelector(const String&); >- >+ void insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState); > #elif PLATFORM(WIN) > void confirmComposition(const String& compositionString); > void setComposition(const WTF::String& compositionString, const WTF::Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition); >@@ -496,7 +497,6 @@ public: > > void unmarkAllMisspellings(); > void unmarkAllBadGrammar(); >- > #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD) > void handleAlternativeTextUIResult(const String&); > #endif >diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in >index a7fdee89c7cebb8395fc074ebf1c150e6608990d..207b761eb33adaf3416555ca39ff7c51064bb485 100644 >--- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in >@@ -245,6 +245,7 @@ messages -> WebPage { > ExecuteKeypressCommands(Vector<WebCore::KeypressCommand> savedCommands) -> (bool handled, WebKit::EditorState newState) > ShouldDelayWindowOrderingEvent(WebKit::WebMouseEvent event) -> (bool result) > AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -> (bool result) >+ InsertDictatedText(WTF::String text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, WTF::Vector<WebCore::DictationAlternative> dictationAlternatives) -> (bool handled, WebKit::EditorState newState) > #endif > #if PLATFORM(WIN) > // FIXME: Unify with Mac counterparts. >diff --git a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm >index 745b20bf10a25a5d8b12d33fd28a4823e3b979ed..96ef481765447f0f0b4790815b6ef934c5b2b937 100644 >--- a/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm >+++ b/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm >@@ -290,6 +290,21 @@ void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uin > newState = editorState(); > } > >+void WebPage::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState) >+{ >+ Frame* frame = m_page->focusController()->focusedOrMainFrame(); >+ >+ if (replacementRangeStart != NSNotFound) { >+ RefPtr<Range> replacementRange = convertToRange(frame, NSMakeRange(replacementRangeStart, replacementRangeEnd - replacementRangeStart)); >+ if (replacementRange) >+ frame->selection()->setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY)); >+ } >+ >+ ASSERT(!frame->editor()->hasComposition()); >+ handled = frame->editor()->insertDictatedText(text, dictationAlternativeLocations, m_keyboardEventBeingInterpreted); >+ newState = editorState(); >+} >+ > void WebPage::getMarkedRange(uint64_t& location, uint64_t& length) > { > location = NSNotFound; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index e0597102daf3ba866ff0afafaeef3cf1b76943f4..954ad01b3d374cc7ac67be04acd308061a6e327e 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,17 @@ >+2012-04-18 Jia Pu <jpu@apple.com> >+ >+ On OS X, mark text with dictation alternative with blue underline. >+ https://bugs.webkit.org/show_bug.cgi?id=83047 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Added interface to simulate dictated text input. >+ >+ * DumpRenderTree/mac/TextInputController.m: >+ (+[TextInputController isSelectorExcludedFromWebScript:]): >+ (+[TextInputController webScriptNameForSelector:]): >+ (-[TextInputController dictatedStringWithPrimaryString:alternative:alternativeOffset:alternativeLength:]): >+ > 2012-04-18 Dirk Pranke <dpranke@chromium.org> > > Fix crash in chromium.py after r114877. >diff --git a/Tools/DumpRenderTree/mac/TextInputController.m b/Tools/DumpRenderTree/mac/TextInputController.m >index f78079446369e78c9f48ce0815ef1ccc8df0b99d..afeb16e4d242b2b6020c02e441ae83d740e932f3 100644 >--- a/Tools/DumpRenderTree/mac/TextInputController.m >+++ b/Tools/DumpRenderTree/mac/TextInputController.m >@@ -31,6 +31,10 @@ > > #import "DumpRenderTreeMac.h" > #import <AppKit/NSInputManager.h> >+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION) >+#define SUPPORT_DICTATION_ALTERNATIVES >+#import <AppKit/NSTextAlternatives.h> >+#endif > #import <WebKit/WebDocument.h> > #import <WebKit/WebFrame.h> > #import <WebKit/WebFramePrivate.h> >@@ -170,7 +174,8 @@ + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector > || aSelector == @selector(characterIndexForPointX:Y:) > || aSelector == @selector(validAttributesForMarkedText) > || aSelector == @selector(attributedStringWithString:) >- || aSelector == @selector(setInputMethodHandler:)) >+ || aSelector == @selector(setInputMethodHandler:) >+ || aSelector == @selector(dictatedStringWithPrimaryString:alternative:alternativeOffset:alternativeLength:)) > return NO; > return YES; > } >@@ -194,7 +199,9 @@ + (NSString *)webScriptNameForSelector:(SEL)aSelector > else if (aSelector == @selector(attributedStringWithString:)) > return @"makeAttributedString"; // just a factory method, doesn't call into NSTextInput > else if (aSelector == @selector(setInputMethodHandler:)) >- return @"setInputMethodHandler"; >+ return @"setInputMethodHandler"; >+ else if (aSelector == @selector(dictatedStringWithPrimaryString:alternative:alternativeOffset:alternativeLength:)) >+ return @"makeDictatedString"; > > return nil; > } >@@ -375,6 +382,27 @@ - (NSMutableAttributedString *)attributedStringWithString:(NSString *)aString > return [[[NSMutableAttributedString alloc] initWithString:aString] autorelease]; > } > >+- (NSMutableAttributedString*)dictatedStringWithPrimaryString:(NSString*)aString alternative:(NSString*)alternative alternativeOffset:(int)offset alternativeLength:(int)length >+{ >+#if defined(SUPPORT_DICTATION_ALTERNATIVES) >+ NSMutableAttributedString* dictatedString = [self attributedStringWithString:aString]; >+ NSRange rangeWithAlternative = NSMakeRange((NSUInteger)offset, (NSUInteger)length); >+ NSString* subStringWithAlternative = [aString substringWithRange:rangeWithAlternative]; >+ if (!subStringWithAlternative) >+ return nil; >+ >+ NSTextAlternatives* alternativeObject = [[[NSTextAlternatives alloc] initWithPrimaryString:subStringWithAlternative alternativeStrings:[NSArray arrayWithObject:alternative]] autorelease]; >+ if (!alternativeObject) >+ return nil; >+ >+ [dictatedString addAttribute:NSTextAlternativesAttributeName value:alternativeObject range:rangeWithAlternative]; >+ >+ return dictatedString; >+#else >+ return nil; >+#endif >+} >+ > - (void)setInputMethodHandler:(WebScriptObject *)handler > { > if (inputMethodHandler == handler) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 798c87159dc28ee8a7ab3ec9ff9a4a9f8ed9467f..bedb8ed58c6de523a49b77986f0bd668fd3d8bc6 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,18 @@ >+2012-04-18 Jia Pu <jpu@apple.com> >+ >+ On OS X, mark text with dictation alternative with blue underline. >+ https://bugs.webkit.org/show_bug.cgi?id=83047 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * platform/mac-leopard/Skipped: >+ * platform/mac-lion/Skipped: >+ * platform/mac-snowleopard/Skipped: >+ * platform/mac/editing/input/edit-dictated-text-with-alternative-expected.txt: Added. >+ * platform/mac/editing/input/edit-dictated-text-with-alternative.html: Added. >+ * platform/mac/editing/input/insert-dictated-text-expected.txt: Added. >+ * platform/mac/editing/input/insert-dictated-text.html: Added. >+ > 2012-04-18 Philippe Normand <pnormand@igalia.com> > > Unreviewed, GTK test_expectations update. >diff --git a/LayoutTests/platform/mac-leopard/Skipped b/LayoutTests/platform/mac-leopard/Skipped >index db371a07590bc58fe2eb6e7ceb20ac42b505d872..59c3fe0091a90bb123f5dad6e1ac3a544cf63e43 100644 >--- a/LayoutTests/platform/mac-leopard/Skipped >+++ b/LayoutTests/platform/mac-leopard/Skipped >@@ -219,6 +219,10 @@ http/tests/security/webgl-remote-read-remote-image-allowed.html > http/tests/security/webgl-remote-read-remote-image-allowed-with-credentials.html > http/tests/security/webgl-remote-read-remote-image-blocked-no-crossorigin.html > >+# Dictated text input is not supported on this platform >+platform/mac/editing/input/edit-dictated-text-with-alternative.html >+platform/mac/editing/input/insert-dictated-text.html >+ > ########################################################## > # Tests below this point are failing only on some slaves. > # http://webkit.org/b/56551 covers the general issue. >diff --git a/LayoutTests/platform/mac-lion/Skipped b/LayoutTests/platform/mac-lion/Skipped >index 702b78c8b209c624b830a1afae89d366c9eff840..9d8259a1b1987cb26be7cfd6c8a972bacbc96ae6 100644 >--- a/LayoutTests/platform/mac-lion/Skipped >+++ b/LayoutTests/platform/mac-lion/Skipped >@@ -38,6 +38,10 @@ editing/pasteboard/5478250.html > # https://bugs.webkit.org/show_bug.cgi?id=82079 > editing/inserting/insert-bg-font.html > >+# Dictated text input is not supported on this platform >+platform/mac/editing/input/edit-dictated-text-with-alternative.html >+platform/mac/editing/input/insert-dictated-text.html >+ > # --- Math ML --- > > # These have different metrics, and require investigation >diff --git a/LayoutTests/platform/mac-snowleopard/Skipped b/LayoutTests/platform/mac-snowleopard/Skipped >index f4c44c6552c9469dac902303d0ba54c31f284cc4..f9d597790cdca44de34e94a91e6d95e706b516db 100644 >--- a/LayoutTests/platform/mac-snowleopard/Skipped >+++ b/LayoutTests/platform/mac-snowleopard/Skipped >@@ -197,3 +197,7 @@ fast/hidpi > # Frame::findString does nothing on pages that prevent selection > # https://bugs.webkit.org/show_bug.cgi?id=40361 > editing/text-iterator/findString-selection-disabled.html >+ >+# Dictated text input is not supported on this platform >+platform/mac/editing/input/edit-dictated-text-with-alternative.html >+platform/mac/editing/input/insert-dictated-text.html >diff --git a/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative-expected.txt b/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..b57c78ca638b57f8945b9e018d5c09c96dffa463 >--- /dev/null >+++ b/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative-expected.txt >@@ -0,0 +1,8 @@ >+Editing text that has DictationAlternatives marker whould cause the marker to be removed. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+this is a tex >+PASS markedText is "" >+ >+TEST COMPLETE >diff --git a/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative.html b/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative.html >new file mode 100644 >index 0000000000000000000000000000000000000000..c7f00790366265f0d0ebb0cbd6aba61602de9d3d >--- /dev/null >+++ b/LayoutTests/platform/mac/editing/input/edit-dictated-text-with-alternative.html >@@ -0,0 +1,59 @@ >+<html> >+<head> >+<script src="../../../../fast/js/resources/js-test-pre.js"></script> >+<style> >+body { margin: 0; padding: 0 } >+</style> >+</head> >+<body> >+<pre id="description"></pre> >+<div id="test" contenteditable></div> >+<p id="console"></p> >+<script type="text/javascript"> >+ description("Editing text that has DictationAlternatives marker whould cause the marker to be removed."); >+ >+ var console_messages = document.createElement("ol"); >+ >+ function log(message) >+ { >+ var item = document.createElement("li"); >+ item.appendChild(document.createTextNode(message)); >+ console_messages.appendChild(item); >+ } >+ >+ if (window.layoutTestController) { >+ >+ try { >+ >+ layoutTestController.dumpAsText(); >+ var testArea = document.getElementById("test"); >+ testArea.focus(); >+ >+ var dictatedString = textInputController.makeDictatedString("this is a text", "test", 10, 4); >+ document.execCommand("SelectAll"); >+ textInputController.insertText(dictatedString); >+ textInputController.doCommand("deleteBackward:"); >+ >+ var markedText = ""; >+ if (window.internals) { >+ var testText = testArea.firstChild; >+ var marked = internals.markerRangeForNode(testText, "DictationAlternatives", 0); >+ if (marked) >+ markedText = marked.toString(); >+ } >+ >+ shouldBeEqualToString("markedText", ""); >+ document.write("TEST COMPLETE"); >+ >+ } catch (ex) { >+ document.write("Exception: " + ex.description); >+ } >+ >+ document.getElementById("console").appendChild(console_messages); >+ >+ } else { >+ document.write("(cannot run interactively)"); >+ } >+</script> >+</body> >+</html> >diff --git a/LayoutTests/platform/mac/editing/input/insert-dictated-text-expected.txt b/LayoutTests/platform/mac/editing/input/insert-dictated-text-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..bd461732eeef33f20f08070f511d9dcfc020ba01 >--- /dev/null >+++ b/LayoutTests/platform/mac/editing/input/insert-dictated-text-expected.txt >@@ -0,0 +1,8 @@ >+When inserting dictated text, range of text that has alternative text is attached as DictationAlternatives marker. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+this is a text >+PASS markedText is "text" >+ >+TEST COMPLETE >diff --git a/LayoutTests/platform/mac/editing/input/insert-dictated-text.html b/LayoutTests/platform/mac/editing/input/insert-dictated-text.html >new file mode 100644 >index 0000000000000000000000000000000000000000..e2a1e43bd99e3d25e02083030be7f32f8c5d4414 >--- /dev/null >+++ b/LayoutTests/platform/mac/editing/input/insert-dictated-text.html >@@ -0,0 +1,58 @@ >+<html> >+<head> >+<script src="../../../../fast/js/resources/js-test-pre.js"></script> >+<style> >+body { margin: 0; padding: 0 } >+</style> >+</head> >+<body> >+<pre id="description"></pre> >+<div id="test" contenteditable></div> >+<p id="console"></p> >+<script type="text/javascript"> >+ description("When inserting dictated text, range of text that has alternative text is attached as DictationAlternatives marker."); >+ >+ var console_messages = document.createElement("ol"); >+ >+ function log(message) >+ { >+ var item = document.createElement("li"); >+ item.appendChild(document.createTextNode(message)); >+ console_messages.appendChild(item); >+ } >+ >+ if (window.layoutTestController) { >+ >+ try { >+ >+ layoutTestController.dumpAsText(); >+ var testArea = document.getElementById("test"); >+ testArea.focus(); >+ >+ var dictatedString = textInputController.makeDictatedString("this is a text", "test", 10, 4); >+ document.execCommand("SelectAll"); >+ textInputController.insertText(dictatedString); >+ >+ var markedText = ""; >+ if (window.internals) { >+ var testText = testArea.firstChild; >+ var marked = internals.markerRangeForNode(testText, "DictationAlternatives", 0); >+ if (marked) >+ markedText = marked.toString(); >+ } >+ >+ shouldBeEqualToString("markedText", "text"); >+ document.write("TEST COMPLETE"); >+ >+ } catch (ex) { >+ document.write("Exception: " + ex.description); >+ } >+ >+ document.getElementById("console").appendChild(console_messages); >+ >+ } else { >+ document.write("(cannot run interactively)"); >+ } >+</script> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 83047
:
137438
|
137464
|
137472
|
137822
|
137825
|
137834
|
146978
|
146995
|
147251
|
147351
|
147463
|
147479