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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()); | 196 EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode()); |
197 EXPECT_EQ(2, frame().selection().end().computeOffsetInContainerNode()); | 197 EXPECT_EQ(2, frame() |
| 198 .selection() |
| 199 .computeVisibleSelectionInDOMTreeDeprecated() |
| 200 .end() |
| 201 .computeOffsetInContainerNode()); |
198 | 202 |
199 controller().setComposition(String("a"), underlines, 1, 1); | 203 controller().setComposition(String("a"), underlines, 1, 1); |
200 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data()); | 204 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data()); |
201 | 205 |
202 controller().setComposition(String("ab"), underlines, 2, 2); | 206 controller().setComposition(String("ab"), underlines, 2, 2); |
203 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data()); | 207 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data()); |
204 } | 208 } |
205 | 209 |
206 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { | 210 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { |
207 Element* div = insertHTMLElement( | 211 Element* div = insertHTMLElement( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { | 339 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { |
336 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", | 340 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", |
337 "sample"); | 341 "sample"); |
338 | 342 |
339 Vector<CompositionUnderline> underlines; | 343 Vector<CompositionUnderline> underlines; |
340 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 344 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
341 controller().setCompositionFromExistingText(underlines, 0, 5); | 345 controller().setCompositionFromExistingText(underlines, 0, 5); |
342 | 346 |
343 controller().finishComposingText(InputMethodController::KeepSelection); | 347 controller().finishComposingText(InputMethodController::KeepSelection); |
344 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); | 348 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); |
345 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); | 349 EXPECT_EQ(0, frame() |
| 350 .selection() |
| 351 .computeVisibleSelectionInDOMTreeDeprecated() |
| 352 .end() |
| 353 .computeOffsetInContainerNode()); |
346 } | 354 } |
347 | 355 |
348 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { | 356 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { |
349 HTMLInputElement* input = | 357 HTMLInputElement* input = |
350 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 358 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
351 | 359 |
352 input->setValue("foo "); | 360 input->setValue("foo "); |
353 document().updateStyleAndLayout(); | 361 document().updateStyleAndLayout(); |
354 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 362 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
355 EXPECT_STREQ("foo ", input->value().utf8().data()); | 363 EXPECT_STREQ("foo ", input->value().utf8().data()); |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 | 1198 |
1191 controller().commitText(String("string"), underlines, 0); | 1199 controller().commitText(String("string"), underlines, 0); |
1192 | 1200 |
1193 ASSERT_EQ(1u, document().markers().markers().size()); | 1201 ASSERT_EQ(1u, document().markers().markers().size()); |
1194 | 1202 |
1195 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); | 1203 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); |
1196 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); | 1204 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); |
1197 } | 1205 } |
1198 | 1206 |
1199 } // namespace blink | 1207 } // namespace blink |
OLD | NEW |