| 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 <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 // can just send a keypress event which is fabricated by changing the type of | 2175 // can just send a keypress event which is fabricated by changing the type of |
| 2176 // the keydown event, so that we can retain all necessary informations, such | 2176 // the keydown event, so that we can retain all necessary informations, such |
| 2177 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to | 2177 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to |
| 2178 // prevent the browser from handling it again. | 2178 // prevent the browser from handling it again. |
| 2179 // Note that, |textToBeInserted_| is a UTF-16 string, but it's fine to only | 2179 // Note that, |textToBeInserted_| is a UTF-16 string, but it's fine to only |
| 2180 // handle BMP characters here, as we can always insert non-BMP characters as | 2180 // handle BMP characters here, as we can always insert non-BMP characters as |
| 2181 // text. | 2181 // text. |
| 2182 BOOL textInserted = NO; | 2182 BOOL textInserted = NO; |
| 2183 if (textToBeInserted_.length() > | 2183 if (textToBeInserted_.length() > |
| 2184 ((hasMarkedText_ || oldHasMarkedText) ? 0u : 1u)) { | 2184 ((hasMarkedText_ || oldHasMarkedText) ? 0u : 1u)) { |
| 2185 widgetHost->ImeCommitText(textToBeInserted_, gfx::Range::InvalidRange(), 0); | 2185 widgetHost->ImeCommitText(textToBeInserted_, |
| 2186 std::vector<blink::WebCompositionUnderline>(), |
| 2187 gfx::Range::InvalidRange(), 0); |
| 2186 textInserted = YES; | 2188 textInserted = YES; |
| 2187 } | 2189 } |
| 2188 | 2190 |
| 2189 // Updates or cancels the composition. If some text has been inserted, then | 2191 // Updates or cancels the composition. If some text has been inserted, then |
| 2190 // we don't need to cancel the composition explicitly. | 2192 // we don't need to cancel the composition explicitly. |
| 2191 if (hasMarkedText_ && markedText_.length()) { | 2193 if (hasMarkedText_ && markedText_.length()) { |
| 2192 // Sends the updated marked text to the renderer so it can update the | 2194 // Sends the updated marked text to the renderer so it can update the |
| 2193 // composition node in WebKit. | 2195 // composition node in WebKit. |
| 2194 // When marked text is available, |markedTextSelectedRange_| will be the | 2196 // When marked text is available, |markedTextSelectedRange_| will be the |
| 2195 // range being selected inside the marked text. | 2197 // range being selected inside the marked text. |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3228 // TODO(suzhe): It's hard for us to support replacementRange without accessing | 3230 // TODO(suzhe): It's hard for us to support replacementRange without accessing |
| 3229 // the full web content. | 3231 // the full web content. |
| 3230 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; | 3232 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; |
| 3231 NSString* im_text = isAttributedString ? [string string] : string; | 3233 NSString* im_text = isAttributedString ? [string string] : string; |
| 3232 if (handlingKeyDown_) { | 3234 if (handlingKeyDown_) { |
| 3233 textToBeInserted_.append(base::SysNSStringToUTF16(im_text)); | 3235 textToBeInserted_.append(base::SysNSStringToUTF16(im_text)); |
| 3234 } else { | 3236 } else { |
| 3235 gfx::Range replacement_range(replacementRange); | 3237 gfx::Range replacement_range(replacementRange); |
| 3236 if (renderWidgetHostView_->GetActiveWidget()) { | 3238 if (renderWidgetHostView_->GetActiveWidget()) { |
| 3237 renderWidgetHostView_->GetActiveWidget()->ImeCommitText( | 3239 renderWidgetHostView_->GetActiveWidget()->ImeCommitText( |
| 3238 base::SysNSStringToUTF16(im_text), replacement_range, 0); | 3240 base::SysNSStringToUTF16(im_text), |
| 3241 std::vector<blink::WebCompositionUnderline>(), replacement_range, 0); |
| 3239 } | 3242 } |
| 3240 } | 3243 } |
| 3241 | 3244 |
| 3242 // Inserting text will delete all marked text automatically. | 3245 // Inserting text will delete all marked text automatically. |
| 3243 hasMarkedText_ = NO; | 3246 hasMarkedText_ = NO; |
| 3244 } | 3247 } |
| 3245 | 3248 |
| 3246 - (void)insertText:(id)string { | 3249 - (void)insertText:(id)string { |
| 3247 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 3250 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
| 3248 } | 3251 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3443 | 3446 |
| 3444 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3447 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3445 // regions that are not draggable. (See ControlRegionView in | 3448 // regions that are not draggable. (See ControlRegionView in |
| 3446 // native_app_window_cocoa.mm). This requires the render host view to be | 3449 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3447 // draggable by default. | 3450 // draggable by default. |
| 3448 - (BOOL)mouseDownCanMoveWindow { | 3451 - (BOOL)mouseDownCanMoveWindow { |
| 3449 return YES; | 3452 return YES; |
| 3450 } | 3453 } |
| 3451 | 3454 |
| 3452 @end | 3455 @end |
| OLD | NEW |