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 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2143 // Tells insertText: and doCommandBySelector: that we are handling a key | 2143 // Tells insertText: and doCommandBySelector: that we are handling a key |
| 2144 // down event. | 2144 // down event. |
| 2145 handlingKeyDown_ = YES; | 2145 handlingKeyDown_ = YES; |
| 2146 | 2146 |
| 2147 // These variables might be set when handling the keyboard event. | 2147 // These variables might be set when handling the keyboard event. |
| 2148 // Clear them here so that we can know whether they have changed afterwards. | 2148 // Clear them here so that we can know whether they have changed afterwards. |
| 2149 textToBeInserted_.clear(); | 2149 textToBeInserted_.clear(); |
| 2150 markedText_.clear(); | 2150 markedText_.clear(); |
| 2151 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); | 2151 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); |
| 2152 underlines_.clear(); | 2152 underlines_.clear(); |
| 2153 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange(); | |
| 2153 unmarkTextCalled_ = NO; | 2154 unmarkTextCalled_ = NO; |
| 2154 hasEditCommands_ = NO; | 2155 hasEditCommands_ = NO; |
| 2155 editCommands_.clear(); | 2156 editCommands_.clear(); |
| 2156 | 2157 |
| 2157 // Before doing anything with a key down, check to see if plugin IME has been | 2158 // Before doing anything with a key down, check to see if plugin IME has been |
| 2158 // cancelled, since the plugin host needs to be informed of that before | 2159 // cancelled, since the plugin host needs to be informed of that before |
| 2159 // receiving the keydown. | 2160 // receiving the keydown. |
| 2160 if ([theEvent type] == NSKeyDown) | 2161 if ([theEvent type] == NSKeyDown) |
| 2161 [self checkForPluginImeCancellation]; | 2162 [self checkForPluginImeCancellation]; |
| 2162 | 2163 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2228 } | 2229 } |
| 2229 | 2230 |
| 2230 // Updates or cancels the composition. If some text has been inserted, then | 2231 // Updates or cancels the composition. If some text has been inserted, then |
| 2231 // we don't need to cancel the composition explicitly. | 2232 // we don't need to cancel the composition explicitly. |
| 2232 if (hasMarkedText_ && markedText_.length()) { | 2233 if (hasMarkedText_ && markedText_.length()) { |
| 2233 // Sends the updated marked text to the renderer so it can update the | 2234 // Sends the updated marked text to the renderer so it can update the |
| 2234 // composition node in WebKit. | 2235 // composition node in WebKit. |
| 2235 // When marked text is available, |markedTextSelectedRange_| will be the | 2236 // When marked text is available, |markedTextSelectedRange_| will be the |
| 2236 // range being selected inside the marked text. | 2237 // range being selected inside the marked text. |
| 2237 widgetHost->ImeSetComposition(markedText_, underlines_, | 2238 widgetHost->ImeSetComposition(markedText_, underlines_, |
| 2239 setMarkedTextReplacementRange_, | |
| 2238 markedTextSelectedRange_.location, | 2240 markedTextSelectedRange_.location, |
| 2239 NSMaxRange(markedTextSelectedRange_)); | 2241 NSMaxRange(markedTextSelectedRange_)); |
| 2240 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { | 2242 } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { |
| 2241 if (unmarkTextCalled_) { | 2243 if (unmarkTextCalled_) { |
| 2242 widgetHost->ImeConfirmComposition( | 2244 widgetHost->ImeConfirmComposition( |
| 2243 base::string16(), gfx::Range::InvalidRange(), false); | 2245 base::string16(), gfx::Range::InvalidRange(), false); |
| 2244 } else { | 2246 } else { |
| 2245 widgetHost->ImeCancelComposition(); | 2247 widgetHost->ImeCancelComposition(); |
| 2246 } | 2248 } |
| 2247 } | 2249 } |
| 2248 | 2250 |
| 2251 // Clear information got from |interpretKeyEvents:| | |
|
erikchen
2016/01/26 18:25:01
s/got//
| |
| 2252 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange(); | |
| 2253 | |
| 2249 // If the key event was handled by the input method but it also generated some | 2254 // If the key event was handled by the input method but it also generated some |
| 2250 // edit commands, then we need to send the real key event and corresponding | 2255 // edit commands, then we need to send the real key event and corresponding |
| 2251 // edit commands here. This usually occurs when the input method wants to | 2256 // edit commands here. This usually occurs when the input method wants to |
| 2252 // finish current composition session but still wants the application to | 2257 // finish current composition session but still wants the application to |
| 2253 // handle the key event. See http://crbug.com/48161 for reference. | 2258 // handle the key event. See http://crbug.com/48161 for reference. |
| 2254 if (delayEventUntilAfterImeCompostion) { | 2259 if (delayEventUntilAfterImeCompostion) { |
| 2255 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event | 2260 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event |
| 2256 // with windowsKeyCode == 0xE5 has already been sent to webkit. | 2261 // with windowsKeyCode == 0xE5 has already been sent to webkit. |
| 2257 // So before sending the real key down event, we need to send a fake key up | 2262 // So before sending the real key down event, we need to send a fake key up |
| 2258 // event to balance it. | 2263 // event to balance it. |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3090 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 3095 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 3091 } | 3096 } |
| 3092 | 3097 |
| 3093 // If we are handling a key down event, then SetComposition() will be | 3098 // If we are handling a key down event, then SetComposition() will be |
| 3094 // called in keyEvent: method. | 3099 // called in keyEvent: method. |
| 3095 // Input methods of Mac use setMarkedText calls with an empty text to cancel | 3100 // Input methods of Mac use setMarkedText calls with an empty text to cancel |
| 3096 // an ongoing composition. So, we should check whether or not the given text | 3101 // an ongoing composition. So, we should check whether or not the given text |
| 3097 // is empty to update the input method state. (Our input method backend can | 3102 // is empty to update the input method state. (Our input method backend can |
| 3098 // automatically cancels an ongoing composition when we send an empty text. | 3103 // automatically cancels an ongoing composition when we send an empty text. |
| 3099 // So, it is OK to send an empty text to the renderer.) | 3104 // So, it is OK to send an empty text to the renderer.) |
| 3100 if (!handlingKeyDown_) { | 3105 if (handlingKeyDown_) { |
| 3106 setMarkedTextReplacementRange_ = gfx::Range(replacementRange); | |
| 3107 } else { | |
| 3101 renderWidgetHostView_->render_widget_host_->ImeSetComposition( | 3108 renderWidgetHostView_->render_widget_host_->ImeSetComposition( |
| 3102 markedText_, underlines_, | 3109 markedText_, underlines_, gfx::Range(replacementRange), |
| 3103 newSelRange.location, NSMaxRange(newSelRange)); | 3110 newSelRange.location, NSMaxRange(newSelRange)); |
| 3104 } | 3111 } |
| 3105 } | 3112 } |
| 3106 | 3113 |
| 3107 - (void)doCommandBySelector:(SEL)selector { | 3114 - (void)doCommandBySelector:(SEL)selector { |
| 3108 // An input method calls this function to dispatch an editing command to be | 3115 // An input method calls this function to dispatch an editing command to be |
| 3109 // handled by this view. | 3116 // handled by this view. |
| 3110 if (selector == @selector(noop:)) | 3117 if (selector == @selector(noop:)) |
| 3111 return; | 3118 return; |
| 3112 | 3119 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3436 | 3443 |
| 3437 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3444 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3438 // regions that are not draggable. (See ControlRegionView in | 3445 // regions that are not draggable. (See ControlRegionView in |
| 3439 // native_app_window_cocoa.mm). This requires the render host view to be | 3446 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3440 // draggable by default. | 3447 // draggable by default. |
| 3441 - (BOOL)mouseDownCanMoveWindow { | 3448 - (BOOL)mouseDownCanMoveWindow { |
| 3442 return YES; | 3449 return YES; |
| 3443 } | 3450 } |
| 3444 | 3451 |
| 3445 @end | 3452 @end |
| OLD | NEW |