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 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #include <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 // itself. But we are owned by |cocoa_view_|, which may be retained | 1012 // itself. But we are owned by |cocoa_view_|, which may be retained |
1013 // by some other code. Examples are WebContentsViewMac's | 1013 // by some other code. Examples are WebContentsViewMac's |
1014 // |latent_focus_view_| and TabWindowController's | 1014 // |latent_focus_view_| and TabWindowController's |
1015 // |cachedContentView_|. | 1015 // |cachedContentView_|. |
1016 render_widget_host_ = NULL; | 1016 render_widget_host_ = NULL; |
1017 } | 1017 } |
1018 | 1018 |
1019 // Called from the renderer to tell us what the tooltip text should be. It | 1019 // Called from the renderer to tell us what the tooltip text should be. It |
1020 // calls us frequently so we need to cache the value to prevent doing a lot | 1020 // calls us frequently so we need to cache the value to prevent doing a lot |
1021 // of repeat work. | 1021 // of repeat work. |
1022 void RenderWidgetHostViewMac::SetTooltipText(const string16& tooltip_text) { | 1022 void RenderWidgetHostViewMac::SetTooltipText( |
| 1023 const base::string16& tooltip_text) { |
1023 if (tooltip_text != tooltip_text_ && [[cocoa_view_ window] isKeyWindow]) { | 1024 if (tooltip_text != tooltip_text_ && [[cocoa_view_ window] isKeyWindow]) { |
1024 tooltip_text_ = tooltip_text; | 1025 tooltip_text_ = tooltip_text; |
1025 | 1026 |
1026 // Clamp the tooltip length to kMaxTooltipLength. It's a DOS issue on | 1027 // Clamp the tooltip length to kMaxTooltipLength. It's a DOS issue on |
1027 // Windows; we're just trying to be polite. Don't persist the trimmed | 1028 // Windows; we're just trying to be polite. Don't persist the trimmed |
1028 // string, as then the comparison above will always fail and we'll try to | 1029 // string, as then the comparison above will always fail and we'll try to |
1029 // set it again every single time the mouse moves. | 1030 // set it again every single time the mouse moves. |
1030 string16 display_text = tooltip_text_; | 1031 base::string16 display_text = tooltip_text_; |
1031 if (tooltip_text_.length() > kMaxTooltipLength) | 1032 if (tooltip_text_.length() > kMaxTooltipLength) |
1032 display_text = tooltip_text_.substr(0, kMaxTooltipLength); | 1033 display_text = tooltip_text_.substr(0, kMaxTooltipLength); |
1033 | 1034 |
1034 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); | 1035 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); |
1035 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 1036 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
1036 } | 1037 } |
1037 } | 1038 } |
1038 | 1039 |
1039 bool RenderWidgetHostViewMac::SupportsSpeech() const { | 1040 bool RenderWidgetHostViewMac::SupportsSpeech() const { |
1040 return [NSApp respondsToSelector:@selector(speakString:)] && | 1041 return [NSApp respondsToSelector:@selector(speakString:)] && |
(...skipping 12 matching lines...) Expand all Loading... |
1053 | 1054 |
1054 void RenderWidgetHostViewMac::StopSpeaking() { | 1055 void RenderWidgetHostViewMac::StopSpeaking() { |
1055 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1056 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
1056 [NSApp stopSpeaking:cocoa_view_]; | 1057 [NSApp stopSpeaking:cocoa_view_]; |
1057 } | 1058 } |
1058 | 1059 |
1059 // | 1060 // |
1060 // RenderWidgetHostViewCocoa uses the stored selection text, | 1061 // RenderWidgetHostViewCocoa uses the stored selection text, |
1061 // which implements NSServicesRequests protocol. | 1062 // which implements NSServicesRequests protocol. |
1062 // | 1063 // |
1063 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, | 1064 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, |
1064 size_t offset, | 1065 size_t offset, |
1065 const gfx::Range& range) { | 1066 const gfx::Range& range) { |
1066 if (range.is_empty() || text.empty()) { | 1067 if (range.is_empty() || text.empty()) { |
1067 selected_text_.clear(); | 1068 selected_text_.clear(); |
1068 } else { | 1069 } else { |
1069 size_t pos = range.GetMin() - offset; | 1070 size_t pos = range.GetMin() - offset; |
1070 size_t n = range.length(); | 1071 size_t n = range.length(); |
1071 | 1072 |
1072 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 1073 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
1073 if (pos >= text.length()) { | 1074 if (pos >= text.length()) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 // necessary to avoid double processing. | 1239 // necessary to avoid double processing. |
1239 // Also check the native type, since NSFlagsChanged is considered a key event | 1240 // Also check the native type, since NSFlagsChanged is considered a key event |
1240 // for WebKit purposes, but isn't considered a key event by the OS. | 1241 // for WebKit purposes, but isn't considered a key event by the OS. |
1241 if (event.type == WebInputEvent::RawKeyDown && | 1242 if (event.type == WebInputEvent::RawKeyDown && |
1242 [event.os_event type] == NSKeyDown) | 1243 [event.os_event type] == NSKeyDown) |
1243 return [cocoa_view_ postProcessEventForPluginIme:event.os_event]; | 1244 return [cocoa_view_ postProcessEventForPluginIme:event.os_event]; |
1244 return false; | 1245 return false; |
1245 } | 1246 } |
1246 | 1247 |
1247 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( | 1248 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( |
1248 const string16& text, int plugin_id) { | 1249 const base::string16& text, int plugin_id) { |
1249 if (render_widget_host_) { | 1250 if (render_widget_host_) { |
1250 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( | 1251 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( |
1251 render_widget_host_->GetRoutingID(), text, plugin_id)); | 1252 render_widget_host_->GetRoutingID(), text, plugin_id)); |
1252 } | 1253 } |
1253 } | 1254 } |
1254 | 1255 |
1255 void RenderWidgetHostViewMac::CompositorSwapBuffers( | 1256 void RenderWidgetHostViewMac::CompositorSwapBuffers( |
1256 uint64 surface_handle, | 1257 uint64 surface_handle, |
1257 const gfx::Size& size, | 1258 const gfx::Size& size, |
1258 float surface_scale_factor, | 1259 float surface_scale_factor, |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 if (mouse_locked_) | 1739 if (mouse_locked_) |
1739 return true; | 1740 return true; |
1740 | 1741 |
1741 mouse_locked_ = true; | 1742 mouse_locked_ = true; |
1742 | 1743 |
1743 // Lock position of mouse cursor and hide it. | 1744 // Lock position of mouse cursor and hide it. |
1744 CGAssociateMouseAndMouseCursorPosition(NO); | 1745 CGAssociateMouseAndMouseCursorPosition(NO); |
1745 [NSCursor hide]; | 1746 [NSCursor hide]; |
1746 | 1747 |
1747 // Clear the tooltip window. | 1748 // Clear the tooltip window. |
1748 SetTooltipText(string16()); | 1749 SetTooltipText(base::string16()); |
1749 | 1750 |
1750 return true; | 1751 return true; |
1751 } | 1752 } |
1752 | 1753 |
1753 void RenderWidgetHostViewMac::UnlockMouse() { | 1754 void RenderWidgetHostViewMac::UnlockMouse() { |
1754 if (!mouse_locked_) | 1755 if (!mouse_locked_) |
1755 return; | 1756 return; |
1756 mouse_locked_ = false; | 1757 mouse_locked_ = false; |
1757 | 1758 |
1758 // Unlock position of mouse cursor and unhide it. | 1759 // Unlock position of mouse cursor and unhide it. |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 // Sends the updated marked text to the renderer so it can update the | 2393 // Sends the updated marked text to the renderer so it can update the |
2393 // composition node in WebKit. | 2394 // composition node in WebKit. |
2394 // When marked text is available, |selectedRange_| will be the range being | 2395 // When marked text is available, |selectedRange_| will be the range being |
2395 // selected inside the marked text. | 2396 // selected inside the marked text. |
2396 widgetHost->ImeSetComposition(markedText_, underlines_, | 2397 widgetHost->ImeSetComposition(markedText_, underlines_, |
2397 selectedRange_.location, | 2398 selectedRange_.location, |
2398 NSMaxRange(selectedRange_)); | 2399 NSMaxRange(selectedRange_)); |
2399 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { | 2400 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { |
2400 if (unmarkTextCalled_) { | 2401 if (unmarkTextCalled_) { |
2401 widgetHost->ImeConfirmComposition( | 2402 widgetHost->ImeConfirmComposition( |
2402 string16(), gfx::Range::InvalidRange(), false); | 2403 base::string16(), gfx::Range::InvalidRange(), false); |
2403 } else { | 2404 } else { |
2404 widgetHost->ImeCancelComposition(); | 2405 widgetHost->ImeCancelComposition(); |
2405 } | 2406 } |
2406 } | 2407 } |
2407 | 2408 |
2408 // If the key event was handled by the input method but it also generated some | 2409 // If the key event was handled by the input method but it also generated some |
2409 // edit commands, then we need to send the real key event and corresponding | 2410 // edit commands, then we need to send the real key event and corresponding |
2410 // edit commands here. This usually occurs when the input method wants to | 2411 // edit commands here. This usually occurs when the input method wants to |
2411 // finish current composition session but still wants the application to | 2412 // finish current composition session but still wants the application to |
2412 // handle the key event. See http://crbug.com/48161 for reference. | 2413 // handle the key event. See http://crbug.com/48161 for reference. |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3505 // text when it cancels an ongoing composition, i.e. I have never seen an | 3506 // text when it cancels an ongoing composition, i.e. I have never seen an |
3506 // input method calls this method. | 3507 // input method calls this method. |
3507 hasMarkedText_ = NO; | 3508 hasMarkedText_ = NO; |
3508 markedText_.clear(); | 3509 markedText_.clear(); |
3509 underlines_.clear(); | 3510 underlines_.clear(); |
3510 | 3511 |
3511 // If we are handling a key down event, then ConfirmComposition() will be | 3512 // If we are handling a key down event, then ConfirmComposition() will be |
3512 // called in keyEvent: method. | 3513 // called in keyEvent: method. |
3513 if (!handlingKeyDown_) { | 3514 if (!handlingKeyDown_) { |
3514 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3515 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
3515 string16(), gfx::Range::InvalidRange(), false); | 3516 base::string16(), gfx::Range::InvalidRange(), false); |
3516 } else { | 3517 } else { |
3517 unmarkTextCalled_ = YES; | 3518 unmarkTextCalled_ = YES; |
3518 } | 3519 } |
3519 } | 3520 } |
3520 | 3521 |
3521 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange | 3522 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange |
3522 replacementRange:(NSRange)replacementRange { | 3523 replacementRange:(NSRange)replacementRange { |
3523 // An input method updates the composition string. | 3524 // An input method updates the composition string. |
3524 // We send the given text and range to the renderer so it can update the | 3525 // We send the given text and range to the renderer so it can update the |
3525 // composition node of WebKit. | 3526 // composition node of WebKit. |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3743 // Should not call [self unmarkText] here, because it'll send unnecessary | 3744 // Should not call [self unmarkText] here, because it'll send unnecessary |
3744 // cancel composition IPC message to the renderer. | 3745 // cancel composition IPC message to the renderer. |
3745 } | 3746 } |
3746 | 3747 |
3747 - (void)confirmComposition { | 3748 - (void)confirmComposition { |
3748 if (!hasMarkedText_) | 3749 if (!hasMarkedText_) |
3749 return; | 3750 return; |
3750 | 3751 |
3751 if (renderWidgetHostView_->render_widget_host_) | 3752 if (renderWidgetHostView_->render_widget_host_) |
3752 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3753 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
3753 string16(), gfx::Range::InvalidRange(), false); | 3754 base::string16(), gfx::Range::InvalidRange(), false); |
3754 | 3755 |
3755 [self cancelComposition]; | 3756 [self cancelComposition]; |
3756 } | 3757 } |
3757 | 3758 |
3758 - (void)setPluginImeActive:(BOOL)active { | 3759 - (void)setPluginImeActive:(BOOL)active { |
3759 if (active == pluginImeActive_) | 3760 if (active == pluginImeActive_) |
3760 return; | 3761 return; |
3761 | 3762 |
3762 pluginImeActive_ = active; | 3763 pluginImeActive_ = active; |
3763 if (!active) { | 3764 if (!active) { |
3764 [[ComplexTextInputPanel sharedComplexTextInputPanel] cancelComposition]; | 3765 [[ComplexTextInputPanel sharedComplexTextInputPanel] cancelComposition]; |
3765 renderWidgetHostView_->PluginImeCompositionCompleted( | 3766 renderWidgetHostView_->PluginImeCompositionCompleted( |
3766 string16(), focusedPluginIdentifier_); | 3767 base::string16(), focusedPluginIdentifier_); |
3767 } | 3768 } |
3768 } | 3769 } |
3769 | 3770 |
3770 - (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId { | 3771 - (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId { |
3771 if (focused) | 3772 if (focused) |
3772 focusedPluginIdentifier_ = pluginId; | 3773 focusedPluginIdentifier_ = pluginId; |
3773 else if (focusedPluginIdentifier_ == pluginId) | 3774 else if (focusedPluginIdentifier_ == pluginId) |
3774 focusedPluginIdentifier_ = -1; | 3775 focusedPluginIdentifier_ = -1; |
3775 | 3776 |
3776 // Whenever plugin focus changes, plugin IME resets. | 3777 // Whenever plugin focus changes, plugin IME resets. |
(...skipping 14 matching lines...) Expand all Loading... |
3791 base::SysNSStringToUTF16(composited_string), focusedPluginIdentifier_); | 3792 base::SysNSStringToUTF16(composited_string), focusedPluginIdentifier_); |
3792 pluginImeActive_ = NO; | 3793 pluginImeActive_ = NO; |
3793 } | 3794 } |
3794 return handled; | 3795 return handled; |
3795 } | 3796 } |
3796 | 3797 |
3797 - (void)checkForPluginImeCancellation { | 3798 - (void)checkForPluginImeCancellation { |
3798 if (pluginImeActive_ && | 3799 if (pluginImeActive_ && |
3799 ![[ComplexTextInputPanel sharedComplexTextInputPanel] inComposition]) { | 3800 ![[ComplexTextInputPanel sharedComplexTextInputPanel] inComposition]) { |
3800 renderWidgetHostView_->PluginImeCompositionCompleted( | 3801 renderWidgetHostView_->PluginImeCompositionCompleted( |
3801 string16(), focusedPluginIdentifier_); | 3802 base::string16(), focusedPluginIdentifier_); |
3802 pluginImeActive_ = NO; | 3803 pluginImeActive_ = NO; |
3803 } | 3804 } |
3804 } | 3805 } |
3805 | 3806 |
3806 // Overriding a NSResponder method to support application services. | 3807 // Overriding a NSResponder method to support application services. |
3807 | 3808 |
3808 - (id)validRequestorForSendType:(NSString*)sendType | 3809 - (id)validRequestorForSendType:(NSString*)sendType |
3809 returnType:(NSString*)returnType { | 3810 returnType:(NSString*)returnType { |
3810 id requestor = nil; | 3811 id requestor = nil; |
3811 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; | 3812 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3931 return YES; | 3932 return YES; |
3932 } | 3933 } |
3933 | 3934 |
3934 - (BOOL)isOpaque { | 3935 - (BOOL)isOpaque { |
3935 if (renderWidgetHostView_->use_core_animation_) | 3936 if (renderWidgetHostView_->use_core_animation_) |
3936 return YES; | 3937 return YES; |
3937 return [super isOpaque]; | 3938 return [super isOpaque]; |
3938 } | 3939 } |
3939 | 3940 |
3940 @end | 3941 @end |
OLD | NEW |