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" | |
11 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
12 #include "core/events/MouseEvent.h" | 11 #include "core/events/MouseEvent.h" |
13 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
14 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
15 #include "core/frame/Settings.h" | 14 #include "core/frame/Settings.h" |
16 #include "core/html/HTMLInputElement.h" | 15 #include "core/html/HTMLInputElement.h" |
17 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 #include <memory> | 18 #include <memory> |
20 | 19 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); | 372 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); |
374 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 373 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); |
375 | 374 |
376 // Without previous composition. | 375 // Without previous composition. |
377 controller().setComposition("", underlines0, -1, -1); | 376 controller().setComposition("", underlines0, -1, -1); |
378 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 377 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
379 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 378 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
380 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 379 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
381 } | 380 } |
382 | 381 |
383 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) | |
384 { | |
385 Element* div = insertHTMLElement( | |
386 "<div id='sample' contenteditable='true'></div>", | |
387 "sample"); | |
388 | |
389 Vector<CompositionUnderline> underlines; | |
390 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | |
391 controller().setComposition("hello", underlines, 5, 5); | |
392 EXPECT_STREQ("hello", div->innerText().utf8().data()); | |
393 EXPECT_EQ(5u, controller().getSelectionOffsets().start()); | |
394 EXPECT_EQ(5u, controller().getSelectionOffsets().end()); | |
395 | |
396 frame().editor().insertLineBreak(); | |
397 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); | |
398 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | |
399 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | |
400 } | |
401 | |
402 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) | 382 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) |
403 { | 383 { |
404 document().settings()->setScriptEnabled(true); | 384 document().settings()->setScriptEnabled(true); |
405 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
e'></div>", "sample"); | 385 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
e'></div>", "sample"); |
406 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 386 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
407 script->setInnerHTML( | 387 script->setInnerHTML( |
408 "document.getElementById('sample').addEventListener('beforeinput', funct
ion(event) {" | 388 "document.getElementById('sample').addEventListener('beforeinput', funct
ion(event) {" |
409 " document.title = `beforeinput.isComposing:${event.isComposing};`;" | 389 " document.title = `beforeinput.isComposing:${event.isComposing};`;" |
410 "});" | 390 "});" |
411 "document.getElementById('sample').addEventListener('input', function(ev
ent) {" | 391 "document.getElementById('sample').addEventListener('input', function(ev
ent) {" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 document().setTitle(emptyString()); | 438 document().setTitle(emptyString()); |
459 controller().setComposition("ni", underlines, 0, 1); | 439 controller().setComposition("ni", underlines, 0, 1); |
460 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); | 440 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
461 | 441 |
462 document().setTitle(emptyString()); | 442 document().setTitle(emptyString()); |
463 controller().confirmComposition(); | 443 controller().confirmComposition(); |
464 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); | 444 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
465 } | 445 } |
466 | 446 |
467 } // namespace blink | 447 } // namespace blink |
OLD | NEW |