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 #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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 109 controller().setCompositionFromExistingText(underlines, 0, 5); | 109 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 110 | 110 |
| 111 Range* range = controller().compositionRange(); | 111 Range* range = controller().compositionRange(); |
| 112 EXPECT_EQ(0, range->startOffset()); | 112 EXPECT_EQ(0, range->startOffset()); |
| 113 EXPECT_EQ(5, range->endOffset()); | 113 EXPECT_EQ(5, range->endOffset()); |
| 114 | 114 |
| 115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
| 116 EXPECT_EQ(0u, plainTextRange.start()); | 116 EXPECT_EQ(0u, plainTextRange.start()); |
| 117 EXPECT_EQ(5u, plainTextRange.end()); | 117 EXPECT_EQ(5u, plainTextRange.end()); |
| 118 | |
| 119 controller().setComposition(String("hellobar"), underlines, 8, 8); | |
| 120 range = controller().compositionRange(); | |
| 121 EXPECT_EQ(0, range->startOffset()); | |
| 122 EXPECT_EQ(8, range->endOffset()); | |
| 123 } | |
| 124 | |
| 125 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) | |
| 126 { | |
| 127 // (UTF16) 0xac000 0xb098 0xb2e4 0xb77c = "가나다라" | |
|
aelias_OOO_until_Jul13
2016/09/27 04:55:58
Can you also add a simpler test case appending and
yabinh
2016/09/27 08:47:20
Done.
| |
| 128 Element* div = insertHTMLElement( | |
| 129 "<div id='sample' contenteditable='true'><b>가나</b>다&#x b77c</div>", "sample"); | |
| 130 | |
| 131 Vector<CompositionUnderline> underlines; | |
| 132 underlines.append(CompositionUnderline(0, 4, Color(255, 0, 0), false, 0)); | |
| 133 controller().setCompositionFromExistingText(underlines, 0, 4); | |
| 134 | |
| 135 // (UTF8) 0xEAB080 0xEB8298 0xEB8BA4 0xEB9E8C = "가나다람" | |
| 136 controller().setComposition(String::fromUTF8("\xea\xb0\x80\xeb\x82\x98\xeb\x 8b\xa4\xeb\x9e\x8c"), underlines, 4, 4); | |
| 137 EXPECT_STREQ("<b>가나</b>다람", div->innerHTML().utf8().data()); | |
| 138 | |
| 139 // (UTF8) 0xEAB080 0xEB8298 0xEB8BA4 0xeb9dbc = "가나다라" | |
| 140 controller().setComposition(String::fromUTF8("\xea\xb0\x80\xeb\x82\x98\xeb\x 8b\xa4\xeb\x9d\xbc"), underlines, 4, 4); | |
| 141 EXPECT_STREQ("<b>가나</b>다라", div->innerHTML().utf8().data()); | |
| 118 } | 142 } |
| 119 | 143 |
| 120 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) | 144 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) |
| 121 { | 145 { |
| 122 insertHTMLElement( | 146 insertHTMLElement( |
| 123 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); | 147 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); |
| 124 | 148 |
| 125 Vector<CompositionUnderline> underlines; | 149 Vector<CompositionUnderline> underlines; |
| 126 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 150 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 127 controller().setCompositionFromExistingText(underlines, 0, 5); | 151 controller().setCompositionFromExistingText(underlines, 0, 5); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 Vector<CompositionUnderline> underlines; | 502 Vector<CompositionUnderline> underlines; |
| 479 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 503 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 480 editable->focus(); | 504 editable->focus(); |
| 481 | 505 |
| 482 document().setTitle(emptyString()); | 506 document().setTitle(emptyString()); |
| 483 controller().setComposition("n", underlines, 0, 1); | 507 controller().setComposition("n", underlines, 0, 1); |
| 484 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata()); | 508 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata()); |
| 485 | 509 |
| 486 document().setTitle(emptyString()); | 510 document().setTitle(emptyString()); |
| 487 controller().setComposition("ni", underlines, 0, 1); | 511 controller().setComposition("ni", underlines, 0, 1); |
| 488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); | 512 EXPECT_STREQ("beforeinput.data:i;input.data:i;", document().title().utf8().d ata()); |
| 489 | 513 |
| 490 document().setTitle(emptyString()); | 514 document().setTitle(emptyString()); |
| 491 controller().finishComposingText(InputMethodController::KeepSelection); | 515 controller().finishComposingText(InputMethodController::KeepSelection); |
| 492 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); | 516 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); |
| 493 } | 517 } |
| 494 | 518 |
| 495 } // namespace blink | 519 } // namespace blink |
| OLD | NEW |