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 #include "core/editing/InputMethodController.h" | 5 #include "core/editing/InputMethodController.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
9 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
10 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { | 277 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { |
278 Element* div = insertHTMLElement( | 278 Element* div = insertHTMLElement( |
279 "<div id='sample' " | 279 "<div id='sample' " |
280 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", | 280 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", |
281 "sample"); | 281 "sample"); |
282 | 282 |
283 Vector<CompositionUnderline> underlines; | 283 Vector<CompositionUnderline> underlines; |
284 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 284 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); |
285 controller().setCompositionFromExistingText(underlines, 3, 12); | 285 controller().setCompositionFromExistingText(underlines, 3, 12); |
286 | 286 |
287 controller().commitText(String("123789"), 0); | 287 controller().commitText(String("123789"), underlines, 0); |
288 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); | 288 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); |
289 } | 289 } |
290 | 290 |
291 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { | 291 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { |
292 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", | 292 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", |
293 "sample"); | 293 "sample"); |
294 | 294 |
295 Vector<CompositionUnderline> underlines; | 295 Vector<CompositionUnderline> underlines; |
296 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 296 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
297 controller().setCompositionFromExistingText(underlines, 0, 5); | 297 controller().setCompositionFromExistingText(underlines, 0, 5); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 frame().editor().insertLineBreak(); | 884 frame().editor().insertLineBreak(); |
885 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); | 885 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); |
886 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 886 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
887 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 887 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
888 } | 888 } |
889 | 889 |
890 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { | 890 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { |
891 Element* div = | 891 Element* div = |
892 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); | 892 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); |
893 | 893 |
894 controller().commitText("hello", 0); | 894 Vector<CompositionUnderline> underlines; |
| 895 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 896 controller().commitText("hello", underlines, 0); |
895 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 897 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
896 | 898 |
897 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 899 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
898 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 900 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
899 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 901 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
900 | 902 |
901 frame().editor().insertLineBreak(); | 903 frame().editor().insertLineBreak(); |
902 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); | 904 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); |
903 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 905 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
904 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 906 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { | 999 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { |
998 createHTMLWithCompositionInputEventListeners(); | 1000 createHTMLWithCompositionInputEventListeners(); |
999 | 1001 |
1000 // Simulate composition in the |contentEditable|. | 1002 // Simulate composition in the |contentEditable|. |
1001 Vector<CompositionUnderline> underlines; | 1003 Vector<CompositionUnderline> underlines; |
1002 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1004 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
1003 | 1005 |
1004 // Insert new text without previous composition. | 1006 // Insert new text without previous composition. |
1005 document().setTitle(emptyString()); | 1007 document().setTitle(emptyString()); |
1006 document().updateStyleAndLayout(); | 1008 document().updateStyleAndLayout(); |
1007 controller().commitText("hello", 0); | 1009 controller().commitText("hello", underlines, 0); |
1008 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 1010 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
1009 document().title().utf8().data()); | 1011 document().title().utf8().data()); |
1010 | 1012 |
1011 document().setTitle(emptyString()); | 1013 document().setTitle(emptyString()); |
1012 controller().setComposition("n", underlines, 1, 1); | 1014 controller().setComposition("n", underlines, 1, 1); |
1013 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1015 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
1014 document().title().utf8().data()); | 1016 document().title().utf8().data()); |
1015 | 1017 |
1016 // Insert new text with previous composition. | 1018 // Insert new text with previous composition. |
1017 document().setTitle(emptyString()); | 1019 document().setTitle(emptyString()); |
1018 document().updateStyleAndLayout(); | 1020 document().updateStyleAndLayout(); |
1019 controller().commitText("hello", 1); | 1021 controller().commitText("hello", underlines, 1); |
1020 EXPECT_STREQ( | 1022 EXPECT_STREQ( |
1021 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", | 1023 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
1022 document().title().utf8().data()); | 1024 document().title().utf8().data()); |
1023 } | 1025 } |
1024 | 1026 |
1025 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { | 1027 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { |
1026 createHTMLWithCompositionInputEventListeners(); | 1028 createHTMLWithCompositionInputEventListeners(); |
1027 | 1029 |
1028 // Simulate composition in the |contentEditable|. | 1030 // Simulate composition in the |contentEditable|. |
1029 Vector<CompositionUnderline> underlines; | 1031 Vector<CompositionUnderline> underlines; |
1030 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1032 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
1031 | 1033 |
1032 // Insert empty text without previous composition. | 1034 // Insert empty text without previous composition. |
1033 document().setTitle(emptyString()); | 1035 document().setTitle(emptyString()); |
1034 document().updateStyleAndLayout(); | 1036 document().updateStyleAndLayout(); |
1035 controller().commitText("", 0); | 1037 controller().commitText("", underlines, 0); |
1036 EXPECT_STREQ("", document().title().utf8().data()); | 1038 EXPECT_STREQ("", document().title().utf8().data()); |
1037 | 1039 |
1038 document().setTitle(emptyString()); | 1040 document().setTitle(emptyString()); |
1039 controller().setComposition("n", underlines, 1, 1); | 1041 controller().setComposition("n", underlines, 1, 1); |
1040 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1042 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
1041 document().title().utf8().data()); | 1043 document().title().utf8().data()); |
1042 | 1044 |
1043 // Insert empty text with previous composition. | 1045 // Insert empty text with previous composition. |
1044 document().setTitle(emptyString()); | 1046 document().setTitle(emptyString()); |
1045 document().updateStyleAndLayout(); | 1047 document().updateStyleAndLayout(); |
1046 controller().commitText("", 1); | 1048 controller().commitText("", underlines, 1); |
1047 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | 1049 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
1048 document().title().utf8().data()); | 1050 document().title().utf8().data()); |
1049 } | 1051 } |
1050 | 1052 |
1051 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { | 1053 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { |
1052 createHTMLWithCompositionEndEventListener(CaretSelection); | 1054 createHTMLWithCompositionEndEventListener(CaretSelection); |
1053 | 1055 |
1054 // Simulate composition in the |contentEditable|. | 1056 // Simulate composition in the |contentEditable|. |
1055 Vector<CompositionUnderline> underlines; | 1057 Vector<CompositionUnderline> underlines; |
1056 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1058 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
(...skipping 16 matching lines...) Expand all Loading... |
1073 | 1075 |
1074 // Simulate composition in the |contentEditable|. | 1076 // Simulate composition in the |contentEditable|. |
1075 Vector<CompositionUnderline> underlines; | 1077 Vector<CompositionUnderline> underlines; |
1076 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1078 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
1077 | 1079 |
1078 controller().setComposition("n", underlines, 1, 1); | 1080 controller().setComposition("n", underlines, 1, 1); |
1079 | 1081 |
1080 // Insert new text with previous composition. Note that it moves the caret to | 1082 // Insert new text with previous composition. Note that it moves the caret to |
1081 // [4,4] before firing 'compositonend' event. | 1083 // [4,4] before firing 'compositonend' event. |
1082 document().updateStyleAndLayout(); | 1084 document().updateStyleAndLayout(); |
1083 controller().commitText("hello", -1); | 1085 controller().commitText("hello", underlines, -1); |
1084 document().updateStyleAndLayout(); | 1086 document().updateStyleAndLayout(); |
1085 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 1087 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
1086 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 1088 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
1087 } | 1089 } |
1088 | 1090 |
1089 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { | 1091 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { |
1090 createHTMLWithCompositionEndEventListener(RangeSelection); | 1092 createHTMLWithCompositionEndEventListener(RangeSelection); |
1091 | 1093 |
1092 // Simulate composition in the |contentEditable|. | 1094 // Simulate composition in the |contentEditable|. |
1093 Vector<CompositionUnderline> underlines; | 1095 Vector<CompositionUnderline> underlines; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); | 1142 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); |
1141 | 1143 |
1142 document().getElementById("b")->focus(); | 1144 document().getElementById("b")->focus(); |
1143 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1145 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
1144 | 1146 |
1145 controller().finishComposingText(InputMethodController::KeepSelection); | 1147 controller().finishComposingText(InputMethodController::KeepSelection); |
1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1148 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
1147 } | 1149 } |
1148 | 1150 |
1149 } // namespace blink | 1151 } // namespace blink |
OLD | NEW |