| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) { | 186 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) { |
| 187 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8). | 187 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8). |
| 188 Element* div = insertHTMLElement( | 188 Element* div = insertHTMLElement( |
| 189 "<div id='sample' contenteditable>🏆</div>", "sample"); | 189 "<div id='sample' contenteditable>🏆</div>", "sample"); |
| 190 | 190 |
| 191 Vector<CompositionUnderline> underlines; | 191 Vector<CompositionUnderline> underlines; |
| 192 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 192 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 193 | 193 |
| 194 document().updateStyleAndLayout(); | 194 document().updateStyleAndLayout(); |
| 195 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 195 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
| 196 EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode()); | |
| 197 EXPECT_EQ(2, frame() | 196 EXPECT_EQ(2, frame() |
| 198 .selection() | 197 .selection() |
| 199 .computeVisibleSelectionInDOMTreeDeprecated() | 198 .computeVisibleSelectionInDOMTreeDeprecated() |
| 199 .start() |
| 200 .computeOffsetInContainerNode()); |
| 201 EXPECT_EQ(2, frame() |
| 202 .selection() |
| 203 .computeVisibleSelectionInDOMTreeDeprecated() |
| 200 .end() | 204 .end() |
| 201 .computeOffsetInContainerNode()); | 205 .computeOffsetInContainerNode()); |
| 202 | 206 |
| 203 controller().setComposition(String("a"), underlines, 1, 1); | 207 controller().setComposition(String("a"), underlines, 1, 1); |
| 204 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data()); | 208 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data()); |
| 205 | 209 |
| 206 controller().setComposition(String("ab"), underlines, 2, 2); | 210 controller().setComposition(String("ab"), underlines, 2, 2); |
| 207 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data()); | 211 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data()); |
| 208 } | 212 } |
| 209 | 213 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 342 |
| 339 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { | 343 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { |
| 340 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", | 344 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", |
| 341 "sample"); | 345 "sample"); |
| 342 | 346 |
| 343 Vector<CompositionUnderline> underlines; | 347 Vector<CompositionUnderline> underlines; |
| 344 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 348 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 345 controller().setCompositionFromExistingText(underlines, 0, 5); | 349 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 346 | 350 |
| 347 controller().finishComposingText(InputMethodController::KeepSelection); | 351 controller().finishComposingText(InputMethodController::KeepSelection); |
| 348 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); | |
| 349 EXPECT_EQ(0, frame() | 352 EXPECT_EQ(0, frame() |
| 350 .selection() | 353 .selection() |
| 351 .computeVisibleSelectionInDOMTreeDeprecated() | 354 .computeVisibleSelectionInDOMTreeDeprecated() |
| 355 .start() |
| 356 .computeOffsetInContainerNode()); |
| 357 EXPECT_EQ(0, frame() |
| 358 .selection() |
| 359 .computeVisibleSelectionInDOMTreeDeprecated() |
| 352 .end() | 360 .end() |
| 353 .computeOffsetInContainerNode()); | 361 .computeOffsetInContainerNode()); |
| 354 } | 362 } |
| 355 | 363 |
| 356 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { | 364 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { |
| 357 HTMLInputElement* input = | 365 HTMLInputElement* input = |
| 358 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 366 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
| 359 | 367 |
| 360 input->setValue("foo "); | 368 input->setValue("foo "); |
| 361 document().updateStyleAndLayout(); | 369 document().updateStyleAndLayout(); |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 | 1206 |
| 1199 controller().commitText(String("string"), underlines, 0); | 1207 controller().commitText(String("string"), underlines, 0); |
| 1200 | 1208 |
| 1201 ASSERT_EQ(1u, document().markers().markers().size()); | 1209 ASSERT_EQ(1u, document().markers().markers().size()); |
| 1202 | 1210 |
| 1203 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); | 1211 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); |
| 1204 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); | 1212 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); |
| 1205 } | 1213 } |
| 1206 | 1214 |
| 1207 } // namespace blink | 1215 } // namespace blink |
| OLD | NEW |