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 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 "<div id='sample' contentEditable='true'></div>", "sample"); | 845 "<div id='sample' contentEditable='true'></div>", "sample"); |
| 846 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 846 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
| 847 script->setInnerHTML( | 847 script->setInnerHTML( |
| 848 "document.getElementById('sample').addEventListener('beforeinput', " | 848 "document.getElementById('sample').addEventListener('beforeinput', " |
| 849 "function(event) {" | 849 "function(event) {" |
| 850 " document.title = `beforeinput.data:${event.data};`;" | 850 " document.title = `beforeinput.data:${event.data};`;" |
| 851 "});" | 851 "});" |
| 852 "document.getElementById('sample').addEventListener('input', " | 852 "document.getElementById('sample').addEventListener('input', " |
| 853 "function(event) {" | 853 "function(event) {" |
| 854 " document.title += `input.data:${event.data};`;" | 854 " document.title += `input.data:${event.data};`;" |
| 855 "});" | |
| 856 "document.getElementById('sample').addEventListener('compositionend', " | |
| 857 "function(event) {" | |
| 858 " if (getSelection().anchorOffset != event.data.length)" | |
|
yosin_UTC9
2016/11/11 04:17:46
nit: We should have {} for then-clause.
| |
| 859 " document.title += 'Wrong selection! Expected ' " | |
|
yosin_UTC9
2016/11/11 04:17:46
Can we have a test case for this?
BTW, I don't th
yabinh
2016/11/11 05:23:52
How about this:
document.title += `selectionOffse
| |
| 860 " + event.data.length + ', but got '" | |
| 861 " + getSelection().anchorOffset + '!';" | |
| 862 " document.title += `compositionend.data:${event.data};`;" | |
| 855 "});", | 863 "});", |
| 856 ASSERT_NO_EXCEPTION); | 864 ASSERT_NO_EXCEPTION); |
| 857 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); | 865 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| 858 document().view()->updateAllLifecyclePhases(); | 866 document().view()->updateAllLifecyclePhases(); |
| 859 | 867 |
| 860 // Simulate composition in the |contentEditable|. | 868 // Simulate composition in the |contentEditable|. |
| 861 Vector<CompositionUnderline> underlines; | 869 Vector<CompositionUnderline> underlines; |
| 862 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 870 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 863 editable->focus(); | 871 editable->focus(); |
| 864 | 872 |
| 873 // Create new composition. | |
| 865 document().setTitle(emptyString()); | 874 document().setTitle(emptyString()); |
| 875 controller().setComposition("n", underlines, 1, 1); | |
| 876 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | |
| 877 document().title().utf8().data()); | |
| 878 | |
| 879 // Update the existing composition. | |
| 880 // TODO(yabinh): should be "beforeinput.data:ni;input.data:ni;". | |
| 881 document().setTitle(emptyString()); | |
| 882 controller().setComposition("ni", underlines, 2, 2); | |
| 883 EXPECT_STREQ("beforeinput.data:i;input.data:i;", | |
| 884 document().title().utf8().data()); | |
| 885 | |
| 886 // Confirm the ongoing composition. | |
| 887 document().setTitle(emptyString()); | |
| 888 controller().finishComposingText(InputMethodController::KeepSelection); | |
| 889 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;compositionend.data:ni;", | |
| 890 document().title().utf8().data()); | |
| 891 | |
| 892 // Delete the existing composition. | |
| 893 document().setTitle(emptyString()); | |
| 894 document().updateStyleAndLayout(); | |
| 895 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 896 controller().setComposition("n", underlines, 1, 1); | |
| 897 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | |
| 898 document().title().utf8().data()); | |
| 899 document().setTitle(emptyString()); | |
| 900 controller().setComposition("", underlines, 0, 0); | |
| 901 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | |
| 902 document().title().utf8().data()); | |
| 903 | |
| 904 // Insert new text without previous composition. | |
| 905 document().setTitle(emptyString()); | |
| 906 controller().commitText("hello", 0); | |
| 907 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | |
| 908 document().title().utf8().data()); | |
| 909 | |
| 910 // Insert new text with previous composition. | |
| 911 document().setTitle(emptyString()); | |
| 912 document().updateStyleAndLayout(); | |
| 913 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 866 controller().setComposition("n", underlines, 0, 1); | 914 controller().setComposition("n", underlines, 0, 1); |
| 867 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 915 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| 868 document().title().utf8().data()); | 916 document().title().utf8().data()); |
| 869 | |
| 870 document().setTitle(emptyString()); | 917 document().setTitle(emptyString()); |
| 871 controller().setComposition("ni", underlines, 0, 1); | 918 controller().commitText("abc", 0); |
| 872 EXPECT_STREQ("beforeinput.data:i;input.data:i;", | 919 EXPECT_STREQ("beforeinput.data:abc;input.data:abc;compositionend.data:abc;", |
| 873 document().title().utf8().data()); | |
| 874 | |
| 875 document().setTitle(emptyString()); | |
| 876 controller().finishComposingText(InputMethodController::KeepSelection); | |
| 877 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", | |
| 878 document().title().utf8().data()); | 920 document().title().utf8().data()); |
| 879 } | 921 } |
| 880 | 922 |
| 881 } // namespace blink | 923 } // namespace blink |
| OLD | NEW |