Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 | 500 |
| 501 - (void)insertTextInternal:(id)text { | 501 - (void)insertTextInternal:(id)text { |
| 502 if (!hostedView_) | 502 if (!hostedView_) |
| 503 return; | 503 return; |
| 504 | 504 |
| 505 if ([text isKindOfClass:[NSAttributedString class]]) | 505 if ([text isKindOfClass:[NSAttributedString class]]) |
| 506 text = [text string]; | 506 text = [text string]; |
| 507 | 507 |
| 508 bool isCharacterEvent = keyDownEvent_ && [text length] == 1; | 508 bool isCharacterEvent = keyDownEvent_ && [text length] == 1; |
| 509 | 509 |
| 510 // Pass the character event to the View hierarchy. Cases this handles (non- | |
| 511 // exhaustive)- | |
| 512 // - Space key presses on controls. Unlike Tab and newline which have | |
| 513 // corresponding action messages, an insertText: message is generated for | |
| 514 // the Space key (insertText:replacementRange: when there's an active | |
| 515 // input context). | |
| 516 // - Menu mnemonic selection. | |
| 517 // Currently there seems to be no use case to pass non-character events | |
| 518 // routed from insertText: handlers, to the View hierarchy. | |
| 519 if (isCharacterEvent) { | |
| 520 ui::KeyEvent charEvent = GetCharacterEventFromNSEvent(keyDownEvent_); | |
| 521 [self handleKeyEvent:&charEvent]; | |
| 522 keyDownEvent_ = nil; // Handled. | |
| 523 } | |
| 524 | |
| 510 // Forward the |text| to |textInputClient_| if no menu is active. | 525 // Forward the |text| to |textInputClient_| if no menu is active. |
| 511 if (textInputClient_ && ![self activeMenuController]) { | 526 if (textInputClient_ && ![self activeMenuController]) { |
| 512 // If a single character is inserted by keyDown's call to | 527 // If a single character is inserted by keyDown's call to |
| 513 // interpretKeyEvents: then use InsertChar() to allow editing events to be | 528 // interpretKeyEvents: then use InsertChar() to allow editing events to be |
| 514 // merged. We use ui::VKEY_UNKNOWN as the key code since it's not feasible | 529 // merged. We use ui::VKEY_UNKNOWN as the key code since it's not feasible |
| 515 // to determine the correct key code for each unicode character. Also a | 530 // to determine the correct key code for each unicode character. Also a |
| 516 // correct keycode is not needed in the current context. Send ui::EF_NONE as | 531 // correct keycode is not needed in the current context. Send ui::EF_NONE as |
| 517 // the key modifier since |text| already accounts for the pressed key | 532 // the key modifier since |text| already accounts for the pressed key |
| 518 // modifiers. | 533 // modifiers. |
| 519 | 534 |
| 520 // Also, note we don't use |keyDownEvent_| to generate the synthetic | 535 // Also, note we don't use |keyDownEvent_| to generate the synthetic |
| 521 // ui::KeyEvent since for text inserted using an IME, [keyDownEvent_ | 536 // ui::KeyEvent since for text inserted using an IME, [keyDownEvent_ |
| 522 // characters] might not be the same as |text|. This is because | 537 // characters] might not be the same as |text|. This is because |
| 523 // |keyDownEvent_| will correspond to the event that caused the composition | 538 // |keyDownEvent_| will correspond to the event that caused the composition |
| 524 // text to be confirmed, say, Return key press. | 539 // text to be confirmed, say, Return key press. |
| 525 if (isCharacterEvent) { | 540 if (isCharacterEvent) { |
| 526 textInputClient_->InsertChar(ui::KeyEvent([text characterAtIndex:0], | 541 textInputClient_->InsertChar(ui::KeyEvent([text characterAtIndex:0], |
| 527 ui::VKEY_UNKNOWN, ui::EF_NONE)); | 542 ui::VKEY_UNKNOWN, ui::EF_NONE)); |
| 528 } else { | 543 } else { |
| 529 textInputClient_->InsertText(base::SysNSStringToUTF16(text)); | 544 textInputClient_->InsertText(base::SysNSStringToUTF16(text)); |
| 530 } | 545 } |
| 531 | |
| 532 keyDownEvent_ = nil; // Handled. | |
| 533 return; | |
| 534 } | |
| 535 | |
| 536 // Only handle the case where no. of characters is 1. Cases not handled (not | |
| 537 // an exhaustive list): | |
| 538 // - |text| contains a unicode surrogate pair, i.e. a single grapheme which | |
| 539 // requires two 16 bit characters. Currently Views menu only supports | |
|
karandeepb
2017/01/11 06:00:58
Also, modified this comment.
| |
| 540 // mnemonics using a single 16 bit character, so it is ok to ignore this | |
| 541 // case. | |
| 542 // - Programmatically created events. | |
| 543 // - Input from IME. But this case should not occur since inputContext is | |
| 544 // nil. | |
| 545 if (isCharacterEvent) { | |
| 546 ui::KeyEvent charEvent = GetCharacterEventFromNSEvent(keyDownEvent_); | |
| 547 [self handleKeyEvent:&charEvent]; | |
| 548 keyDownEvent_ = nil; // Handled. | 546 keyDownEvent_ = nil; // Handled. |
| 549 } | 547 } |
| 550 } | 548 } |
| 551 | 549 |
| 552 - (views::DragDropClientMac*)dragDropClient { | 550 - (views::DragDropClientMac*)dragDropClient { |
| 553 views::BridgedNativeWidget* bridge = | 551 views::BridgedNativeWidget* bridge = |
| 554 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); | 552 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); |
| 555 return bridge ? bridge->drag_drop_client() : nullptr; | 553 return bridge ? bridge->drag_drop_client() : nullptr; |
| 556 } | 554 } |
| 557 | 555 |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1478 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1481 } | 1479 } |
| 1482 | 1480 |
| 1483 - (id)accessibilityFocusedUIElement { | 1481 - (id)accessibilityFocusedUIElement { |
| 1484 if (!hostedView_) | 1482 if (!hostedView_) |
| 1485 return nil; | 1483 return nil; |
| 1486 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1484 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
| 1487 } | 1485 } |
| 1488 | 1486 |
| 1489 @end | 1487 @end |
| OLD | NEW |