Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: Source/WebCore/editing/mac/AlternativeTextUIController.mm

Issue 13936003: Remove the now unused editing/mac (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge ToT diffs Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #import "config.h"
27 #import "AlternativeTextUIController.h"
28
29 #if USE(DICTATION_ALTERNATIVES)
30 #import <AppKit/NSSpellChecker.h>
31 #import <AppKit/NSTextAlternatives.h>
32 #import <AppKit/NSView.h>
33
34 namespace WebCore {
35
36 uint64_t AlternativeTextUIController::AlernativeTextContextController::addAltern atives(const RetainPtr<NSTextAlternatives>& alternatives)
37 {
38 uint64_t context = reinterpret_cast<uint64_t>(alternatives.get());
39 if (!context)
40 return invalidContext;
41 if (alternativesForContext(context))
42 return context;
43
44 HashMapType::AddResult result = m_alternativesObjectMap.add(context, alterna tives);
45 return result.isNewEntry ? context : invalidContext;
46 }
47
48 NSTextAlternatives* AlternativeTextUIController::AlernativeTextContextController ::alternativesForContext(uint64_t context)
49 {
50 HashMapType::const_iterator itr = m_alternativesObjectMap.find(context);
51 if (itr == m_alternativesObjectMap.end())
52 return NULL;
53 return itr->value.get();
54 }
55
56 void AlternativeTextUIController::AlernativeTextContextController::removeAlterna tivesForContext(uint64_t context)
57 {
58 m_alternativesObjectMap.remove(context);
59 }
60
61 void AlternativeTextUIController::AlernativeTextContextController::clear()
62 {
63 m_alternativesObjectMap.clear();
64 }
65
66 uint64_t AlternativeTextUIController::addAlternatives(const RetainPtr<NSTextAlte rnatives>& alternatives)
67 {
68 return m_contextController.addAlternatives(alternatives);
69 }
70
71 Vector<String> AlternativeTextUIController::alternativesForContext(uint64_t cont ext)
72 {
73 NSTextAlternatives* textAlternatives = m_contextController.alternativesForCo ntext(context);
74 Vector<String> alternativeStrings;
75 for (NSString* string in textAlternatives.alternativeStrings)
76 alternativeStrings.append(string);
77 return alternativeStrings;
78 }
79
80 void AlternativeTextUIController::clear()
81 {
82 return m_contextController.clear();
83 }
84
85 void AlternativeTextUIController::showAlternatives(NSView* view, const FloatRect & boundingBoxOfPrimaryString, uint64_t context, void(^acceptanceHandler)(NSStrin g*))
86 {
87 dismissAlternatives();
88 if (!view)
89 return;
90
91 m_view = view;
92 NSTextAlternatives* alternatives = m_contextController.alternativesForContex t(context);
93 if (!alternatives)
94 return;
95
96 [[NSSpellChecker sharedSpellChecker] showCorrectionIndicatorOfType:NSCorrect ionIndicatorTypeGuesses primaryString:alternatives.primaryString alternativeStri ngs:alternatives.alternativeStrings forStringInRect:boundingBoxOfPrimaryString v iew:m_view.get() completionHandler:^(NSString* acceptedString) {
97 if (acceptedString) {
98 handleAcceptedAlternative(acceptedString, context, alternatives);
99 acceptanceHandler(acceptedString);
100 }
101 }];
102 }
103
104 void AlternativeTextUIController::handleAcceptedAlternative(NSString* acceptedAl ternative, uint64_t context, NSTextAlternatives* alternatives)
105 {
106 [alternatives noteSelectedAlternativeString:acceptedAlternative];
107 m_contextController.removeAlternativesForContext(context);
108 m_view.clear();
109 }
110
111 void AlternativeTextUIController::dismissAlternatives()
112 {
113 if (!m_view)
114 return;
115 [[NSSpellChecker sharedSpellChecker] dismissCorrectionIndicatorForView:m_vie w.get()];
116 }
117
118 void AlternativeTextUIController::removeAlternatives(uint64_t context)
119 {
120 m_contextController.removeAlternativesForContext(context);
121 }
122 }
123 #endif // USE(DICTATION_ALTERNATIVES)
OLDNEW
« no previous file with comments | « Source/WebCore/editing/mac/AlternativeTextUIController.h ('k') | Source/WebCore/editing/mac/EditorMac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698