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