Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: ui/views/cocoa/bridged_content_view.mm

Issue 2180873002: MacViews: Change insertTextInternal to correctly handle IME character input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if ([text isKindOfClass:[NSAttributedString class]]) 431 if ([text isKindOfClass:[NSAttributedString class]])
432 text = [text string]; 432 text = [text string];
433 433
434 bool isCharacterEvent = keyDownEvent_ && [text length] == 1; 434 bool isCharacterEvent = keyDownEvent_ && [text length] == 1;
435 435
436 // Forward the |text| to |textInputClient_| if no menu is active. 436 // Forward the |text| to |textInputClient_| if no menu is active.
437 if (textInputClient_ && ![self activeMenuController]) { 437 if (textInputClient_ && ![self activeMenuController]) {
438 // If a single character is inserted by keyDown's call to 438 // If a single character is inserted by keyDown's call to
439 // interpretKeyEvents: then use InsertChar() to allow editing events to be 439 // interpretKeyEvents: then use InsertChar() to allow editing events to be
440 // merged. 440 // merged.
441 if (isCharacterEvent) 441 // Note we don't use |keyDownEvent_| to generate the synthetic ui::KeyEvent
442 textInputClient_->InsertChar(GetCharacterEventFromNSEvent(keyDownEvent_)); 442 // since for text inserted using an IME, [keyDownEvent_ characters] might
443 else 443 // not be the same as |text|. This is because |keyDownEvent_| will
444 // correspond to the event that caused the composition text to be confirmed,
445 // say, Return key press.
446 if (isCharacterEvent) {
447 textInputClient_->InsertChar(ui::KeyEvent([text characterAtIndex:0],
448 ui::VKEY_UNKNOWN, ui::EF_NONE));
tapted 2016/07/26 06:04:17 Perhaps comment about VKEY_UNKNOWN? E.g. before r
karandeepb 2016/07/27 04:47:32 Done. I guess this is fine, Else will have to expo
449 } else {
444 textInputClient_->InsertText(base::SysNSStringToUTF16(text)); 450 textInputClient_->InsertText(base::SysNSStringToUTF16(text));
451 }
445 return; 452 return;
446 } 453 }
447 454
448 // Only handle the case where no. of characters is 1. Cases not handled (not 455 // Only handle the case where no. of characters is 1. Cases not handled (not
449 // an exhaustive list): 456 // an exhaustive list):
450 // - |text| contains a unicode surrogate pair, i.e. a single grapheme which 457 // - |text| contains a unicode surrogate pair, i.e. a single grapheme which
451 // requires two 16 bit characters. Currently Views menu only supports 458 // requires two 16 bit characters. Currently Views menu only supports
452 // mnemonics using a single 16 bit character, so it is ok to ignore this 459 // mnemonics using a single 16 bit character, so it is ok to ignore this
453 // case. 460 // case.
454 // - Programmatically created events. 461 // - Programmatically created events.
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 } 1288 }
1282 1289
1283 return [super accessibilityAttributeValue:attribute]; 1290 return [super accessibilityAttributeValue:attribute];
1284 } 1291 }
1285 1292
1286 - (id)accessibilityHitTest:(NSPoint)point { 1293 - (id)accessibilityHitTest:(NSPoint)point {
1287 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1294 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1288 } 1295 }
1289 1296
1290 @end 1297 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698