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

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

Issue 2019233003: MacViews: Fix crash caused due to nil TextInputClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if (menuController && menuController->owner() == widget) { 72 if (menuController && menuController->owner() == widget) {
73 if (menuController->OnWillDispatchKeyEvent(0, key_code) == 73 if (menuController->OnWillDispatchKeyEvent(0, key_code) ==
74 ui::POST_DISPATCH_NONE) 74 ui::POST_DISPATCH_NONE)
75 return true; 75 return true;
76 } 76 }
77 return false; 77 return false;
78 } 78 }
79 79
80 // Returns true if |client| has RTL text. 80 // Returns true if |client| has RTL text.
81 bool IsTextRTL(const ui::TextInputClient* client) { 81 bool IsTextRTL(const ui::TextInputClient* client) {
82 DCHECK(client);
tapted 2016/05/30 10:31:54 I think it's nicer for this just to return false,
82 gfx::Range text_range; 83 gfx::Range text_range;
83 base::string16 text; 84 base::string16 text;
84 return client->GetTextRange(&text_range) && 85 return client->GetTextRange(&text_range) &&
85 client->GetTextFromRange(text_range, &text) && 86 client->GetTextFromRange(text_range, &text) &&
86 base::i18n::GetStringDirection(text) == base::i18n::RIGHT_TO_LEFT; 87 base::i18n::GetStringDirection(text) == base::i18n::RIGHT_TO_LEFT;
87 } 88 }
88 89
89 // Returns the boundary rectangle for composition characters in the 90 // Returns the boundary rectangle for composition characters in the
90 // |requested_range|. Sets |actual_range| corresponding to the returned 91 // |requested_range|. Sets |actual_range| corresponding to the returned
91 // rectangle. For cases, where there is no composition text or the 92 // rectangle. For cases, where there is no composition text or the
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // direct insertText: through doCommandBySelector:, so this is still needed to 644 // direct insertText: through doCommandBySelector:, so this is still needed to
644 // handle the case when inputContext: is nil. When inputContext: returns non-nil 645 // handle the case when inputContext: is nil. When inputContext: returns non-nil
645 // text goes directly to insertText:replacementRange:. 646 // text goes directly to insertText:replacementRange:.
646 - (void)insertText:(id)text { 647 - (void)insertText:(id)text {
647 [self insertText:text replacementRange:NSMakeRange(NSNotFound, 0)]; 648 [self insertText:text replacementRange:NSMakeRange(NSNotFound, 0)];
648 } 649 }
649 650
650 // Selection movement and scrolling. 651 // Selection movement and scrolling.
651 652
652 - (void)moveForward:(id)sender { 653 - (void)moveForward:(id)sender {
654 if (!textInputClient_)
655 return;
653 IsTextRTL(textInputClient_) ? [self moveLeft:sender] 656 IsTextRTL(textInputClient_) ? [self moveLeft:sender]
654 : [self moveRight:sender]; 657 : [self moveRight:sender];
655 } 658 }
656 659
657 - (void)moveRight:(id)sender { 660 - (void)moveRight:(id)sender {
658 [self handleAction:IDS_MOVE_RIGHT 661 [self handleAction:IDS_MOVE_RIGHT
659 keyCode:ui::VKEY_RIGHT 662 keyCode:ui::VKEY_RIGHT
660 domCode:ui::DomCode::ARROW_RIGHT 663 domCode:ui::DomCode::ARROW_RIGHT
661 eventFlags:0]; 664 eventFlags:0];
662 } 665 }
663 666
664 - (void)moveBackward:(id)sender { 667 - (void)moveBackward:(id)sender {
668 if (!textInputClient_)
669 return;
665 IsTextRTL(textInputClient_) ? [self moveRight:sender] 670 IsTextRTL(textInputClient_) ? [self moveRight:sender]
666 : [self moveLeft:sender]; 671 : [self moveLeft:sender];
667 } 672 }
668 673
669 - (void)moveLeft:(id)sender { 674 - (void)moveLeft:(id)sender {
670 [self handleAction:IDS_MOVE_LEFT 675 [self handleAction:IDS_MOVE_LEFT
671 keyCode:ui::VKEY_LEFT 676 keyCode:ui::VKEY_LEFT
672 domCode:ui::DomCode::ARROW_LEFT 677 domCode:ui::DomCode::ARROW_LEFT
673 eventFlags:0]; 678 eventFlags:0];
674 } 679 }
675 680
676 - (void)moveUp:(id)sender { 681 - (void)moveUp:(id)sender {
677 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE 682 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE
678 keyCode:ui::VKEY_UP 683 keyCode:ui::VKEY_UP
679 domCode:ui::DomCode::ARROW_UP 684 domCode:ui::DomCode::ARROW_UP
680 eventFlags:0]; 685 eventFlags:0];
681 } 686 }
682 687
683 - (void)moveDown:(id)sender { 688 - (void)moveDown:(id)sender {
684 [self handleAction:IDS_MOVE_TO_END_OF_LINE 689 [self handleAction:IDS_MOVE_TO_END_OF_LINE
685 keyCode:ui::VKEY_DOWN 690 keyCode:ui::VKEY_DOWN
686 domCode:ui::DomCode::ARROW_DOWN 691 domCode:ui::DomCode::ARROW_DOWN
687 eventFlags:0]; 692 eventFlags:0];
688 } 693 }
689 694
690 - (void)moveWordForward:(id)sender { 695 - (void)moveWordForward:(id)sender {
696 if (!textInputClient_)
697 return;
691 IsTextRTL(textInputClient_) ? [self moveWordLeft:sender] 698 IsTextRTL(textInputClient_) ? [self moveWordLeft:sender]
692 : [self moveWordRight:sender]; 699 : [self moveWordRight:sender];
693 } 700 }
694 701
695 - (void)moveWordBackward:(id)sender { 702 - (void)moveWordBackward:(id)sender {
703 if (!textInputClient_)
704 return;
696 IsTextRTL(textInputClient_) ? [self moveWordRight:sender] 705 IsTextRTL(textInputClient_) ? [self moveWordRight:sender]
697 : [self moveWordLeft:sender]; 706 : [self moveWordLeft:sender];
698 } 707 }
699 708
700 - (void)moveToBeginningOfLine:(id)sender { 709 - (void)moveToBeginningOfLine:(id)sender {
701 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE 710 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE
702 keyCode:ui::VKEY_HOME 711 keyCode:ui::VKEY_HOME
703 domCode:ui::DomCode::HOME 712 domCode:ui::DomCode::HOME
704 eventFlags:0]; 713 eventFlags:0];
705 } 714 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 750 }
742 751
743 - (void)pageUp:(id)sender { 752 - (void)pageUp:(id)sender {
744 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE 753 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE
745 keyCode:ui::VKEY_PRIOR 754 keyCode:ui::VKEY_PRIOR
746 domCode:ui::DomCode::PAGE_UP 755 domCode:ui::DomCode::PAGE_UP
747 eventFlags:0]; 756 eventFlags:0];
748 } 757 }
749 758
750 - (void)moveBackwardAndModifySelection:(id)sender { 759 - (void)moveBackwardAndModifySelection:(id)sender {
760 if (!textInputClient_)
761 return;
751 IsTextRTL(textInputClient_) ? [self moveRightAndModifySelection:sender] 762 IsTextRTL(textInputClient_) ? [self moveRightAndModifySelection:sender]
752 : [self moveLeftAndModifySelection:sender]; 763 : [self moveLeftAndModifySelection:sender];
753 } 764 }
754 765
755 - (void)moveForwardAndModifySelection:(id)sender { 766 - (void)moveForwardAndModifySelection:(id)sender {
767 if (!textInputClient_)
768 return;
756 IsTextRTL(textInputClient_) ? [self moveLeftAndModifySelection:sender] 769 IsTextRTL(textInputClient_) ? [self moveLeftAndModifySelection:sender]
757 : [self moveRightAndModifySelection:sender]; 770 : [self moveRightAndModifySelection:sender];
758 } 771 }
759 772
760 - (void)moveWordForwardAndModifySelection:(id)sender { 773 - (void)moveWordForwardAndModifySelection:(id)sender {
774 if (!textInputClient_)
775 return;
761 IsTextRTL(textInputClient_) ? [self moveWordLeftAndModifySelection:sender] 776 IsTextRTL(textInputClient_) ? [self moveWordLeftAndModifySelection:sender]
762 : [self moveWordRightAndModifySelection:sender]; 777 : [self moveWordRightAndModifySelection:sender];
763 } 778 }
764 779
765 - (void)moveWordBackwardAndModifySelection:(id)sender { 780 - (void)moveWordBackwardAndModifySelection:(id)sender {
781 if (!textInputClient_)
782 return;
766 IsTextRTL(textInputClient_) ? [self moveWordRightAndModifySelection:sender] 783 IsTextRTL(textInputClient_) ? [self moveWordRightAndModifySelection:sender]
767 : [self moveWordLeftAndModifySelection:sender]; 784 : [self moveWordLeftAndModifySelection:sender];
768 } 785 }
769 786
770 - (void)moveUpAndModifySelection:(id)sender { 787 - (void)moveUpAndModifySelection:(id)sender {
771 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION 788 [self handleAction:IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION
772 keyCode:ui::VKEY_UP 789 keyCode:ui::VKEY_UP
773 domCode:ui::DomCode::ARROW_UP 790 domCode:ui::DomCode::ARROW_UP
774 eventFlags:ui::EF_SHIFT_DOWN]; 791 eventFlags:ui::EF_SHIFT_DOWN];
775 } 792 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 } 898 }
882 899
883 - (void)moveWordLeftAndModifySelection:(id)sender { 900 - (void)moveWordLeftAndModifySelection:(id)sender {
884 [self handleAction:IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION 901 [self handleAction:IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION
885 keyCode:ui::VKEY_LEFT 902 keyCode:ui::VKEY_LEFT
886 domCode:ui::DomCode::ARROW_LEFT 903 domCode:ui::DomCode::ARROW_LEFT
887 eventFlags:ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN]; 904 eventFlags:ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN];
888 } 905 }
889 906
890 - (void)moveToLeftEndOfLine:(id)sender { 907 - (void)moveToLeftEndOfLine:(id)sender {
908 if (!textInputClient_)
909 return;
891 IsTextRTL(textInputClient_) ? [self moveToEndOfLine:sender] 910 IsTextRTL(textInputClient_) ? [self moveToEndOfLine:sender]
892 : [self moveToBeginningOfLine:sender]; 911 : [self moveToBeginningOfLine:sender];
893 } 912 }
894 913
895 - (void)moveToRightEndOfLine:(id)sender { 914 - (void)moveToRightEndOfLine:(id)sender {
915 if (!textInputClient_)
916 return;
896 IsTextRTL(textInputClient_) ? [self moveToBeginningOfLine:sender] 917 IsTextRTL(textInputClient_) ? [self moveToBeginningOfLine:sender]
897 : [self moveToEndOfLine:sender]; 918 : [self moveToEndOfLine:sender];
898 } 919 }
899 920
900 - (void)moveToLeftEndOfLineAndModifySelection:(id)sender { 921 - (void)moveToLeftEndOfLineAndModifySelection:(id)sender {
922 if (!textInputClient_)
923 return;
901 IsTextRTL(textInputClient_) 924 IsTextRTL(textInputClient_)
902 ? [self moveToEndOfLineAndModifySelection:sender] 925 ? [self moveToEndOfLineAndModifySelection:sender]
903 : [self moveToBeginningOfLineAndModifySelection:sender]; 926 : [self moveToBeginningOfLineAndModifySelection:sender];
904 } 927 }
905 928
906 - (void)moveToRightEndOfLineAndModifySelection:(id)sender { 929 - (void)moveToRightEndOfLineAndModifySelection:(id)sender {
930 if (!textInputClient_)
931 return;
907 IsTextRTL(textInputClient_) 932 IsTextRTL(textInputClient_)
908 ? [self moveToBeginningOfLineAndModifySelection:sender] 933 ? [self moveToBeginningOfLineAndModifySelection:sender]
909 : [self moveToEndOfLineAndModifySelection:sender]; 934 : [self moveToEndOfLineAndModifySelection:sender];
910 } 935 }
911 936
912 // Deletions. 937 // Deletions.
913 938
914 - (void)deleteForward:(id)sender { 939 - (void)deleteForward:(id)sender {
915 [self handleAction:IDS_DELETE_FORWARD 940 [self handleAction:IDS_DELETE_FORWARD
916 keyCode:ui::VKEY_DELETE 941 keyCode:ui::VKEY_DELETE
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1210 }
1186 1211
1187 return [super accessibilityAttributeValue:attribute]; 1212 return [super accessibilityAttributeValue:attribute];
1188 } 1213 }
1189 1214
1190 - (id)accessibilityHitTest:(NSPoint)point { 1215 - (id)accessibilityHitTest:(NSPoint)point {
1191 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1216 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1192 } 1217 }
1193 1218
1194 @end 1219 @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