OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 using content::RenderViewHostImpl; | 58 using content::RenderViewHostImpl; |
59 using content::RenderWidgetHostImpl; | 59 using content::RenderWidgetHostImpl; |
60 using content::RenderWidgetHostViewMac; | 60 using content::RenderWidgetHostViewMac; |
61 using content::RenderWidgetHostViewMacEditCommandHelper; | 61 using content::RenderWidgetHostViewMacEditCommandHelper; |
62 using WebKit::WebInputEvent; | 62 using WebKit::WebInputEvent; |
63 using WebKit::WebInputEventFactory; | 63 using WebKit::WebInputEventFactory; |
64 using WebKit::WebMouseEvent; | 64 using WebKit::WebMouseEvent; |
65 using WebKit::WebMouseWheelEvent; | 65 using WebKit::WebMouseWheelEvent; |
66 using WebKit::WebGestureEvent; | 66 using WebKit::WebGestureEvent; |
67 | 67 |
68 // These are not documented, so use only after checking -respondsToSelector:. | |
69 @interface NSApplication (UndocumentedSpeechMethods) | |
70 - (void)speakString:(NSString*)string; | |
71 - (void)stopSpeaking:(id)sender; | |
72 - (BOOL)isSpeaking; | |
73 @end | |
74 | |
68 // Declare things that are part of the 10.7 SDK. | 75 // Declare things that are part of the 10.7 SDK. |
69 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 76 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
70 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 77 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
71 @interface NSEvent (LionAPI) | 78 @interface NSEvent (LionAPI) |
72 + (id)addLocalMonitorForEventsMatchingMask:(NSEventMask)mask | 79 + (id)addLocalMonitorForEventsMatchingMask:(NSEventMask)mask |
73 handler:(NSEvent* (^)(NSEvent*))block; | 80 handler:(NSEvent* (^)(NSEvent*))block; |
74 + (void)removeMonitor:(id)eventMonitor; | 81 + (void)removeMonitor:(id)eventMonitor; |
75 @end | 82 @end |
76 | 83 |
77 @interface NSScreen (LionAPI) | 84 @interface NSScreen (LionAPI) |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 // set it again every single time the mouse moves. | 746 // set it again every single time the mouse moves. |
740 string16 display_text = tooltip_text_; | 747 string16 display_text = tooltip_text_; |
741 if (tooltip_text_.length() > kMaxTooltipLength) | 748 if (tooltip_text_.length() > kMaxTooltipLength) |
742 display_text = tooltip_text_.substr(0, kMaxTooltipLength); | 749 display_text = tooltip_text_.substr(0, kMaxTooltipLength); |
743 | 750 |
744 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); | 751 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); |
745 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 752 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
746 } | 753 } |
747 } | 754 } |
748 | 755 |
756 void RenderWidgetHostViewMac::SpeakText(const string16& text) { | |
757 [NSApp speakString:base::SysUTF16ToNSString(text)]; | |
Nico
2012/07/27 22:44:26
"These are not documented, so use only after check
Alexei Svitkine (slow)
2012/07/27 22:49:48
We wouldn't get here unless respondsToSelector: is
Nico
2012/07/27 22:57:56
Comment sounds good.
Alexei Svitkine (slow)
2012/07/28 15:29:12
Done.
| |
758 } | |
759 | |
749 // | 760 // |
750 // RenderWidgetHostViewCocoa uses the stored selection text, | 761 // RenderWidgetHostViewCocoa uses the stored selection text, |
751 // which implements NSServicesRequests protocol. | 762 // which implements NSServicesRequests protocol. |
752 // | 763 // |
753 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, | 764 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, |
754 size_t offset, | 765 size_t offset, |
755 const ui::Range& range) { | 766 const ui::Range& range) { |
756 if (range.is_empty() || text.empty()) { | 767 if (range.is_empty() || text.empty()) { |
757 selected_text_.clear(); | 768 selected_text_.clear(); |
758 } else { | 769 } else { |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2329 @selector(validateUserInterfaceItem:isValidItem:)]) { | 2340 @selector(validateUserInterfaceItem:isValidItem:)]) { |
2330 BOOL valid; | 2341 BOOL valid; |
2331 BOOL known = [delegate_ validateUserInterfaceItem:item | 2342 BOOL known = [delegate_ validateUserInterfaceItem:item |
2332 isValidItem:&valid]; | 2343 isValidItem:&valid]; |
2333 if (known) | 2344 if (known) |
2334 return valid; | 2345 return valid; |
2335 } | 2346 } |
2336 | 2347 |
2337 SEL action = [item action]; | 2348 SEL action = [item action]; |
2338 | 2349 |
2350 if (action == @selector(stopSpeaking:)) { | |
2351 return [NSApp respondsToSelector:@selector(isSpeaking)] && | |
2352 [NSApp isSpeaking]; | |
2353 } | |
2354 if (action == @selector(startSpeaking:)) { | |
2355 return [NSApp respondsToSelector:@selector(speakString:)] && | |
2356 renderWidgetHostView_->render_widget_host_->IsRenderView(); | |
2357 } | |
2358 | |
2339 // For now, these actions are always enabled for render view, | 2359 // For now, these actions are always enabled for render view, |
2340 // this is sub-optimal. | 2360 // this is sub-optimal. |
2341 // TODO(suzhe): Plumb the "can*" methods up from WebCore. | 2361 // TODO(suzhe): Plumb the "can*" methods up from WebCore. |
2342 if (action == @selector(undo:) || | 2362 if (action == @selector(undo:) || |
2343 action == @selector(redo:) || | 2363 action == @selector(redo:) || |
2344 action == @selector(cut:) || | 2364 action == @selector(cut:) || |
2345 action == @selector(copy:) || | 2365 action == @selector(copy:) || |
2346 action == @selector(copyToFindPboard:) || | 2366 action == @selector(copyToFindPboard:) || |
2347 action == @selector(paste:) || | 2367 action == @selector(paste:) || |
2348 action == @selector(pasteAndMatchStyle:)) { | 2368 action == @selector(pasteAndMatchStyle:)) { |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3061 } | 3081 } |
3062 } | 3082 } |
3063 | 3083 |
3064 - (void)pasteAndMatchStyle:(id)sender { | 3084 - (void)pasteAndMatchStyle:(id)sender { |
3065 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { | 3085 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { |
3066 static_cast<RenderViewHostImpl*>( | 3086 static_cast<RenderViewHostImpl*>( |
3067 renderWidgetHostView_->render_widget_host_)->PasteAndMatchStyle(); | 3087 renderWidgetHostView_->render_widget_host_)->PasteAndMatchStyle(); |
3068 } | 3088 } |
3069 } | 3089 } |
3070 | 3090 |
3091 - (void)startSpeaking:(id)sender { | |
3092 if (renderWidgetHostView_->render_widget_host_->IsRenderView()) { | |
3093 static_cast<RenderViewHostImpl*>( | |
3094 renderWidgetHostView_->render_widget_host_)->SpeakSelection(); | |
3095 } | |
3096 } | |
3097 | |
3098 - (void)stopSpeaking:(id)sender { | |
3099 [NSApp stopSpeaking:sender]; | |
Nico
2012/07/27 22:44:26
ditto
Alexei Svitkine (slow)
2012/07/27 22:49:48
same reply
| |
3100 } | |
3101 | |
3071 - (void)cancelComposition { | 3102 - (void)cancelComposition { |
3072 if (!hasMarkedText_) | 3103 if (!hasMarkedText_) |
3073 return; | 3104 return; |
3074 | 3105 |
3075 // Cancel the ongoing composition. [NSInputManager markedTextAbandoned:] | 3106 // Cancel the ongoing composition. [NSInputManager markedTextAbandoned:] |
3076 // doesn't call any NSTextInput functions, such as setMarkedText or | 3107 // doesn't call any NSTextInput functions, such as setMarkedText or |
3077 // insertText. So, we need to send an IPC message to a renderer so it can | 3108 // insertText. So, we need to send an IPC message to a renderer so it can |
3078 // delete the composition node. | 3109 // delete the composition node. |
3079 NSInputManager *currentInputManager = [NSInputManager currentInputManager]; | 3110 NSInputManager *currentInputManager = [NSInputManager currentInputManager]; |
3080 [currentInputManager markedTextAbandoned:self]; | 3111 [currentInputManager markedTextAbandoned:self]; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3212 if (!string) return NO; | 3243 if (!string) return NO; |
3213 | 3244 |
3214 // If the user is currently using an IME, confirm the IME input, | 3245 // If the user is currently using an IME, confirm the IME input, |
3215 // and then insert the text from the service, the same as TextEdit and Safari. | 3246 // and then insert the text from the service, the same as TextEdit and Safari. |
3216 [self confirmComposition]; | 3247 [self confirmComposition]; |
3217 [self insertText:string]; | 3248 [self insertText:string]; |
3218 return YES; | 3249 return YES; |
3219 } | 3250 } |
3220 | 3251 |
3221 @end | 3252 @end |
OLD | NEW |