Chromium Code Reviews| 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 <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 | 10 |
| (...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2094 DCHECK(!handlingKeyDown_); | 2094 DCHECK(!handlingKeyDown_); |
| 2095 | 2095 |
| 2096 // Tells insertText: and doCommandBySelector: that we are handling a key | 2096 // Tells insertText: and doCommandBySelector: that we are handling a key |
| 2097 // down event. | 2097 // down event. |
| 2098 handlingKeyDown_ = YES; | 2098 handlingKeyDown_ = YES; |
| 2099 | 2099 |
| 2100 // These variables might be set when handling the keyboard event. | 2100 // These variables might be set when handling the keyboard event. |
| 2101 // Clear them here so that we can know whether they have changed afterwards. | 2101 // Clear them here so that we can know whether they have changed afterwards. |
| 2102 textToBeInserted_.clear(); | 2102 textToBeInserted_.clear(); |
| 2103 markedText_.clear(); | 2103 markedText_.clear(); |
| 2104 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); | |
| 2104 underlines_.clear(); | 2105 underlines_.clear(); |
| 2105 unmarkTextCalled_ = NO; | 2106 unmarkTextCalled_ = NO; |
| 2106 hasEditCommands_ = NO; | 2107 hasEditCommands_ = NO; |
| 2107 editCommands_.clear(); | 2108 editCommands_.clear(); |
| 2108 | 2109 |
| 2109 // Before doing anything with a key down, check to see if plugin IME has been | 2110 // Before doing anything with a key down, check to see if plugin IME has been |
| 2110 // cancelled, since the plugin host needs to be informed of that before | 2111 // cancelled, since the plugin host needs to be informed of that before |
| 2111 // receiving the keydown. | 2112 // receiving the keydown. |
| 2112 if ([theEvent type] == NSKeyDown) | 2113 if ([theEvent type] == NSKeyDown) |
| 2113 [self checkForPluginImeCancellation]; | 2114 [self checkForPluginImeCancellation]; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2177 widgetHost->ImeConfirmComposition( | 2178 widgetHost->ImeConfirmComposition( |
| 2178 textToBeInserted_, gfx::Range::InvalidRange(), false); | 2179 textToBeInserted_, gfx::Range::InvalidRange(), false); |
| 2179 textInserted = YES; | 2180 textInserted = YES; |
| 2180 } | 2181 } |
| 2181 | 2182 |
| 2182 // Updates or cancels the composition. If some text has been inserted, then | 2183 // Updates or cancels the composition. If some text has been inserted, then |
| 2183 // we don't need to cancel the composition explicitly. | 2184 // we don't need to cancel the composition explicitly. |
| 2184 if (hasMarkedText_ && markedText_.length()) { | 2185 if (hasMarkedText_ && markedText_.length()) { |
| 2185 // Sends the updated marked text to the renderer so it can update the | 2186 // Sends the updated marked text to the renderer so it can update the |
| 2186 // composition node in WebKit. | 2187 // composition node in WebKit. |
| 2187 // When marked text is available, |selectedRange_| will be the range being | 2188 // When marked text is available, |markedTextSelectedRange_| will be the |
| 2188 // selected inside the marked text. | 2189 // range being selected inside the marked text. |
| 2189 widgetHost->ImeSetComposition(markedText_, underlines_, | 2190 widgetHost->ImeSetComposition(markedText_, underlines_, |
| 2190 selectedRange_.location, | 2191 markedTextSelectedRange_.location, |
| 2191 NSMaxRange(selectedRange_)); | 2192 NSMaxRange(markedTextSelectedRange_)); |
| 2192 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { | 2193 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { |
| 2193 if (unmarkTextCalled_) { | 2194 if (unmarkTextCalled_) { |
| 2194 widgetHost->ImeConfirmComposition( | 2195 widgetHost->ImeConfirmComposition( |
| 2195 base::string16(), gfx::Range::InvalidRange(), false); | 2196 base::string16(), gfx::Range::InvalidRange(), false); |
| 2196 } else { | 2197 } else { |
| 2197 widgetHost->ImeCancelComposition(); | 2198 widgetHost->ImeCancelComposition(); |
| 2198 } | 2199 } |
| 2199 } | 2200 } |
| 2200 | 2201 |
| 2201 // If the key event was handled by the input method but it also generated some | 2202 // If the key event was handled by the input method but it also generated some |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2856 actualRange:(NSRangePointer)actualRange { | 2857 actualRange:(NSRangePointer)actualRange { |
| 2857 NSRect rect = [self firstViewRectForCharacterRange:theRange | 2858 NSRect rect = [self firstViewRectForCharacterRange:theRange |
| 2858 actualRange:actualRange]; | 2859 actualRange:actualRange]; |
| 2859 | 2860 |
| 2860 // Convert into screen coordinates for return. | 2861 // Convert into screen coordinates for return. |
| 2861 rect = [self convertRect:rect toView:nil]; | 2862 rect = [self convertRect:rect toView:nil]; |
| 2862 rect.origin = [[self window] convertBaseToScreen:rect.origin]; | 2863 rect.origin = [[self window] convertBaseToScreen:rect.origin]; |
| 2863 return rect; | 2864 return rect; |
| 2864 } | 2865 } |
| 2865 | 2866 |
| 2867 - (NSRange)selectedRange { | |
| 2868 if (hasMarkedText_) | |
| 2869 return NSMakeRange(NSMaxRange(markedRange_), 0); | |
|
James Su
2015/07/17 03:47:37
I'm not sure if this logic is necessary. The devel
Andre
2015/07/17 18:05:44
Thanks James.
This is actually the main fix for th
James Su
2015/07/18 02:26:33
Can you investigate the root cause of this issue?
| |
| 2870 | |
| 2871 return selectedRange_; | |
| 2872 } | |
| 2873 | |
| 2866 - (NSRange)markedRange { | 2874 - (NSRange)markedRange { |
| 2867 // An input method calls this method to check if an application really has | 2875 // An input method calls this method to check if an application really has |
| 2868 // a text being composed when hasMarkedText call returns true. | 2876 // a text being composed when hasMarkedText call returns true. |
| 2869 // Returns the range saved in the setMarkedText method so the input method | 2877 // Returns the range saved in the setMarkedText method so the input method |
| 2870 // calls the setMarkedText method and we can update the composition node | 2878 // calls the setMarkedText method and we can update the composition node |
| 2871 // there. (When this method returns an empty range, the input method doesn't | 2879 // there. (When this method returns an empty range, the input method doesn't |
| 2872 // call the setMarkedText method.) | 2880 // call the setMarkedText method.) |
| 2873 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); | 2881 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); |
| 2874 } | 2882 } |
| 2875 | 2883 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2915 } | 2923 } |
| 2916 | 2924 |
| 2917 - (void)unmarkText { | 2925 - (void)unmarkText { |
| 2918 // Delete the composition node of the renderer and finish an ongoing | 2926 // Delete the composition node of the renderer and finish an ongoing |
| 2919 // composition. | 2927 // composition. |
| 2920 // It seems an input method calls the setMarkedText method and set an empty | 2928 // It seems an input method calls the setMarkedText method and set an empty |
| 2921 // text when it cancels an ongoing composition, i.e. I have never seen an | 2929 // text when it cancels an ongoing composition, i.e. I have never seen an |
| 2922 // input method calls this method. | 2930 // input method calls this method. |
| 2923 hasMarkedText_ = NO; | 2931 hasMarkedText_ = NO; |
| 2924 markedText_.clear(); | 2932 markedText_.clear(); |
| 2933 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); | |
| 2925 underlines_.clear(); | 2934 underlines_.clear(); |
| 2926 | 2935 |
| 2927 // If we are handling a key down event, then ConfirmComposition() will be | 2936 // If we are handling a key down event, then ConfirmComposition() will be |
| 2928 // called in keyEvent: method. | 2937 // called in keyEvent: method. |
| 2929 if (!handlingKeyDown_) { | 2938 if (!handlingKeyDown_) { |
| 2930 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 2939 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 2931 base::string16(), gfx::Range::InvalidRange(), false); | 2940 base::string16(), gfx::Range::InvalidRange(), false); |
| 2932 } else { | 2941 } else { |
| 2933 unmarkTextCalled_ = YES; | 2942 unmarkTextCalled_ = YES; |
| 2934 } | 2943 } |
| 2935 } | 2944 } |
| 2936 | 2945 |
| 2937 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange | 2946 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange |
| 2938 replacementRange:(NSRange)replacementRange { | 2947 replacementRange:(NSRange)replacementRange { |
| 2939 // An input method updates the composition string. | 2948 // An input method updates the composition string. |
| 2940 // We send the given text and range to the renderer so it can update the | 2949 // We send the given text and range to the renderer so it can update the |
| 2941 // composition node of WebKit. | 2950 // composition node of WebKit. |
| 2942 // TODO(suzhe): It's hard for us to support replacementRange without accessing | 2951 // TODO(suzhe): It's hard for us to support replacementRange without accessing |
| 2943 // the full web content. | 2952 // the full web content. |
| 2944 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; | 2953 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; |
| 2945 NSString* im_text = isAttributedString ? [string string] : string; | 2954 NSString* im_text = isAttributedString ? [string string] : string; |
| 2946 int length = [im_text length]; | 2955 int length = [im_text length]; |
| 2947 | 2956 |
| 2948 // |markedRange_| will get set on a callback from ImeSetComposition(). | 2957 // |markedRange_| will get set on a callback from ImeSetComposition(). |
| 2949 selectedRange_ = newSelRange; | 2958 markedTextSelectedRange_ = newSelRange; |
| 2950 markedText_ = base::SysNSStringToUTF16(im_text); | 2959 markedText_ = base::SysNSStringToUTF16(im_text); |
| 2951 hasMarkedText_ = (length > 0); | 2960 hasMarkedText_ = (length > 0); |
| 2952 | 2961 |
| 2953 underlines_.clear(); | 2962 underlines_.clear(); |
| 2954 if (isAttributedString) { | 2963 if (isAttributedString) { |
| 2955 ExtractUnderlines(string, &underlines_); | 2964 ExtractUnderlines(string, &underlines_); |
| 2956 } else { | 2965 } else { |
| 2957 // Use a thin black underline by default. | 2966 // Use a thin black underline by default. |
| 2958 underlines_.push_back(blink::WebCompositionUnderline( | 2967 underlines_.push_back(blink::WebCompositionUnderline( |
| 2959 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 2968 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3304 | 3313 |
| 3305 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3314 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3306 // regions that are not draggable. (See ControlRegionView in | 3315 // regions that are not draggable. (See ControlRegionView in |
| 3307 // native_app_window_cocoa.mm). This requires the render host view to be | 3316 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3308 // draggable by default. | 3317 // draggable by default. |
| 3309 - (BOOL)mouseDownCanMoveWindow { | 3318 - (BOOL)mouseDownCanMoveWindow { |
| 3310 return YES; | 3319 return YES; |
| 3311 } | 3320 } |
| 3312 | 3321 |
| 3313 @end | 3322 @end |
| OLD | NEW |