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_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 @"moveToLeftEndOfLineAndModifySelection:", | 105 @"moveToLeftEndOfLineAndModifySelection:", |
106 @"moveToRightEndOfLineAndModifySelection:" | 106 @"moveToRightEndOfLineAndModifySelection:" |
107 ]; | 107 ]; |
108 | 108 |
109 NSArray* const kDeleteActions = @[ | 109 NSArray* const kDeleteActions = @[ |
110 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", | 110 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", |
111 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", | 111 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", |
112 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" | 112 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" |
113 ]; | 113 ]; |
114 | 114 |
115 NSArray* const kMiscActions = @[ @"insertText:", @"cancelOperation:" ]; | 115 NSArray* const kMiscActions = |
116 @[ @"insertText:", @"cancelOperation:", @"transpose:" ]; | |
116 | 117 |
117 // Empty range shortcut for readibility. | 118 // Empty range shortcut for readibility. |
118 NSRange EmptyRange() { | 119 NSRange EmptyRange() { |
119 return NSMakeRange(NSNotFound, 0); | 120 return NSMakeRange(NSNotFound, 0); |
120 } | 121 } |
121 | 122 |
122 // Sets |composition_text| as the composition text with caret placed at | 123 // Sets |composition_text| as the composition text with caret placed at |
123 // |caret_pos| and updates |caret_range|. | 124 // |caret_pos| and updates |caret_range|. |
124 void SetCompositionText(ui::TextInputClient* client, | 125 void SetCompositionText(ui::TextInputClient* client, |
125 const base::string16& composition_text, | 126 const base::string16& composition_text, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 view_->AddChildView(textfield); | 355 view_->AddChildView(textfield); |
355 textfield->SetBoundsRect(init_params_.bounds); | 356 textfield->SetBoundsRect(init_params_.bounds); |
356 | 357 |
357 // Request focus so the InputMethod can dispatch events to the RootView, and | 358 // Request focus so the InputMethod can dispatch events to the RootView, and |
358 // have them delivered to the textfield. Note that focusing a textfield | 359 // have them delivered to the textfield. Note that focusing a textfield |
359 // schedules a task to flash the cursor, so this requires |message_loop_|. | 360 // schedules a task to flash the cursor, so this requires |message_loop_|. |
360 textfield->RequestFocus(); | 361 textfield->RequestFocus(); |
361 | 362 |
362 [ns_view_ setTextInputClient:textfield]; | 363 [ns_view_ setTextInputClient:textfield]; |
363 | 364 |
364 // Initialize the dummy text view. | 365 // Initialize the dummy text view. Initializing this with NSZeroRect causes |
365 dummy_text_view_.reset([[NSTextView alloc] initWithFrame:NSZeroRect]); | 366 // weird NSTextView behavior on OSX 10.9. |
367 dummy_text_view_.reset( | |
368 [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); | |
tapted
2016/06/29 07:06:14
probs need to rebase this bit
karandeepb
2016/06/29 07:33:45
Done.
| |
366 [dummy_text_view_ setString:SysUTF16ToNSString(text)]; | 369 [dummy_text_view_ setString:SysUTF16ToNSString(text)]; |
367 } | 370 } |
368 | 371 |
369 void BridgedNativeWidgetTest::InstallTextField(const base::string16& text) { | 372 void BridgedNativeWidgetTest::InstallTextField(const base::string16& text) { |
370 InstallTextField(text, ui::TEXT_INPUT_TYPE_TEXT); | 373 InstallTextField(text, ui::TEXT_INPUT_TYPE_TEXT); |
371 } | 374 } |
372 | 375 |
373 void BridgedNativeWidgetTest::InstallTextField(const std::string& text) { | 376 void BridgedNativeWidgetTest::InstallTextField(const std::string& text) { |
374 InstallTextField(base::ASCIIToUTF16(text), ui::TEXT_INPUT_TYPE_TEXT); | 377 InstallTextField(base::ASCIIToUTF16(text), ui::TEXT_INPUT_TYPE_TEXT); |
375 } | 378 } |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfParagraph) { | 997 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfParagraph) { |
995 TestDeleteBeginning(@selector(deleteToBeginningOfParagraph:)); | 998 TestDeleteBeginning(@selector(deleteToBeginningOfParagraph:)); |
996 } | 999 } |
997 | 1000 |
998 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { | 1001 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { |
999 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); | 1002 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); |
1000 } | 1003 } |
1001 | 1004 |
1002 // Test move commands against expectations set by |dummy_text_view_|. | 1005 // Test move commands against expectations set by |dummy_text_view_|. |
1003 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { | 1006 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { |
1004 // Broken on 10.9. http://crbug.com/621734. | |
1005 if (base::mac::IsOSMavericks()) | |
1006 return; | |
1007 TestEditingCommands(kMoveActions); | 1007 TestEditingCommands(kMoveActions); |
1008 } | 1008 } |
1009 | 1009 |
1010 // Todo(karandeepb): Enable this test once the behavior of all move and select | 1010 // Todo(karandeepb): Enable this test once the behavior of all move and select |
1011 // commands are fixed. | 1011 // commands are fixed. |
1012 // Test move and select commands against expectations set by |dummy_text_view_|. | 1012 // Test move and select commands against expectations set by |dummy_text_view_|. |
1013 TEST_F(BridgedNativeWidgetTest, | 1013 TEST_F(BridgedNativeWidgetTest, |
1014 TextInput_MoveAndSelectEditingCommands_DISABLED) { | 1014 TextInput_MoveAndSelectEditingCommands_DISABLED) { |
1015 TestEditingCommands(kSelectActions); | 1015 TestEditingCommands(kSelectActions); |
1016 } | 1016 } |
1017 | 1017 |
1018 // Test delete commands against expectations set by |dummy_text_view_|. | 1018 // Test delete commands against expectations set by |dummy_text_view_|. |
1019 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { | 1019 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { |
1020 // Broken on 10.9. http://crbug.com/621734. | |
1021 if (base::mac::IsOSMavericks()) | |
1022 return; | |
1023 TestEditingCommands(kDeleteActions); | 1020 TestEditingCommands(kDeleteActions); |
1024 } | 1021 } |
1025 | 1022 |
1026 // Test that we don't crash during an action message even if the TextInputClient | 1023 // Test that we don't crash during an action message even if the TextInputClient |
1027 // is nil. Regression test for crbug.com/615745. | 1024 // is nil. Regression test for crbug.com/615745. |
1028 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { | 1025 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { |
1029 [ns_view_ setTextInputClient:nil]; | 1026 [ns_view_ setTextInputClient:nil]; |
1030 NSMutableArray* selectors = [NSMutableArray array]; | 1027 NSMutableArray* selectors = [NSMutableArray array]; |
1031 [selectors addObjectsFromArray:kMoveActions]; | 1028 [selectors addObjectsFromArray:kMoveActions]; |
1032 [selectors addObjectsFromArray:kSelectActions]; | 1029 [selectors addObjectsFromArray:kSelectActions]; |
1033 [selectors addObjectsFromArray:kDeleteActions]; | 1030 [selectors addObjectsFromArray:kDeleteActions]; |
1034 [selectors addObjectsFromArray:kMiscActions]; | 1031 [selectors addObjectsFromArray:kMiscActions]; |
1035 | 1032 |
1036 for (NSString* selector in selectors) | 1033 for (NSString* selector in selectors) |
1037 [ns_view_ doCommandBySelector:NSSelectorFromString(selector)]; | 1034 [ns_view_ doCommandBySelector:NSSelectorFromString(selector)]; |
1038 } | 1035 } |
1039 | 1036 |
1037 // Test transpose command against expectations set by |dummy_text_view_|. | |
1038 TEST_F(BridgedNativeWidgetTest, TextInput_Transpose) { | |
1039 TestEditingCommands(@[ @"transpose:" ]); | |
1040 } | |
1041 | |
1040 // Test firstRectForCharacterRange:actualRange for cases where query range is | 1042 // Test firstRectForCharacterRange:actualRange for cases where query range is |
1041 // empty or outside composition range. | 1043 // empty or outside composition range. |
1042 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { | 1044 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { |
1043 InstallTextField(""); | 1045 InstallTextField(""); |
1044 ui::TextInputClient* client = [ns_view_ textInputClient]; | 1046 ui::TextInputClient* client = [ns_view_ textInputClient]; |
1045 | 1047 |
1046 // No composition. Ensure bounds and range corresponding to the current caret | 1048 // No composition. Ensure bounds and range corresponding to the current caret |
1047 // position are returned. | 1049 // position are returned. |
1048 // Initially selection range will be [0, 0]. | 1050 // Initially selection range will be [0, 0]. |
1049 NSRange caret_range = NSMakeRange(0, 0); | 1051 NSRange caret_range = NSMakeRange(0, 0); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1196 [center postNotificationName:NSWindowDidExitFullScreenNotification |
1195 object:window]; | 1197 object:window]; |
1196 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1198 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
1197 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1199 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
1198 | 1200 |
1199 widget_->CloseNow(); | 1201 widget_->CloseNow(); |
1200 } | 1202 } |
1201 | 1203 |
1202 } // namespace test | 1204 } // namespace test |
1203 } // namespace views | 1205 } // namespace views |
OLD | NEW |