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) {" | |
|
yosin_UTC9
2016/11/15 02:27:05
nit: s/function(event)/event =>/
More ES6-ish ;-)
yabinh
2016/11/15 19:47:36
Done.
Also applied the same style in other place.
| |
| 858 " document.title += `compositionend.data:${event.data};`;" | |
| 859 // Reset the selection to [0,0] on receiving 'compositonend' event. | |
| 860 " var node = document.getElementById('sample').firstChild;" | |
|
yosin_UTC9
2016/11/15 02:27:04
nit: s/var/const/
yabinh
2016/11/15 19:47:36
Done.
| |
| 861 " var range = document.createRange();" | |
|
yosin_UTC9
2016/11/15 02:27:05
Just write as below:
getSeleciton().collapse(node,
yabinh
2016/11/15 19:47:36
Done.
| |
| 862 " range.setStart(node, 0);" | |
| 863 " range.setEnd(node, 0);" | |
| 864 " var selection = getSelection();" | |
| 865 " selection.removeAllRanges();" | |
| 866 " selection.addRange(range);" | |
| 855 "});", | 867 "});", |
| 856 ASSERT_NO_EXCEPTION); | 868 ASSERT_NO_EXCEPTION); |
| 857 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); | 869 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| 858 document().view()->updateAllLifecyclePhases(); | 870 document().view()->updateAllLifecyclePhases(); |
| 859 | 871 |
| 860 // Simulate composition in the |contentEditable|. | 872 // Simulate composition in the |contentEditable|. |
| 861 Vector<CompositionUnderline> underlines; | 873 Vector<CompositionUnderline> underlines; |
| 862 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 874 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 863 editable->focus(); | 875 editable->focus(); |
| 864 | 876 |
| 877 // Create new composition. | |
| 865 document().setTitle(emptyString()); | 878 document().setTitle(emptyString()); |
| 866 controller().setComposition("n", underlines, 0, 1); | 879 controller().setComposition("n", underlines, 1, 1); |
| 867 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 880 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| 868 document().title().utf8().data()); | 881 document().title().utf8().data()); |
| 869 | 882 |
| 883 // Update the existing composition. | |
| 884 // TODO(yabinh): should be "beforeinput.data:ni;input.data:ni;". | |
| 870 document().setTitle(emptyString()); | 885 document().setTitle(emptyString()); |
| 871 controller().setComposition("ni", underlines, 0, 1); | 886 controller().setComposition("ni", underlines, 2, 2); |
| 872 EXPECT_STREQ("beforeinput.data:i;input.data:i;", | 887 EXPECT_STREQ("beforeinput.data:i;input.data:i;", |
| 873 document().title().utf8().data()); | 888 document().title().utf8().data()); |
| 874 | 889 |
| 890 // Confirm the ongoing composition. | |
| 875 document().setTitle(emptyString()); | 891 document().setTitle(emptyString()); |
| 876 controller().finishComposingText(InputMethodController::KeepSelection); | 892 controller().finishComposingText(InputMethodController::KeepSelection); |
| 877 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", | 893 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;compositionend.data:ni;", |
| 878 document().title().utf8().data()); | 894 document().title().utf8().data()); |
| 895 document().updateStyleAndLayout(); | |
| 896 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | |
| 897 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | |
| 898 | |
| 899 // Delete the existing composition. | |
| 900 document().setTitle(emptyString()); | |
| 901 controller().setComposition("n", underlines, 1, 1); | |
| 902 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | |
| 903 document().title().utf8().data()); | |
| 904 document().setTitle(emptyString()); | |
| 905 controller().setComposition("", underlines, 0, 0); | |
| 906 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | |
| 907 document().title().utf8().data()); | |
| 908 document().updateStyleAndLayout(); | |
| 909 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | |
| 910 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | |
| 911 | |
| 912 // Insert new text without previous composition. | |
| 913 document().setTitle(emptyString()); | |
| 914 controller().commitText("hello", 0); | |
| 915 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | |
| 916 document().title().utf8().data()); | |
| 917 | |
| 918 // Insert new text with previous composition. | |
| 919 document().setTitle(emptyString()); | |
| 920 controller().setComposition("n", underlines, 1, 1); | |
| 921 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | |
| 922 document().title().utf8().data()); | |
| 923 document().setTitle(emptyString()); | |
| 924 controller().commitText("abc", 0); | |
| 925 EXPECT_STREQ("beforeinput.data:abc;input.data:abc;compositionend.data:abc;", | |
| 926 document().title().utf8().data()); | |
| 927 document().updateStyleAndLayout(); | |
| 928 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | |
| 929 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | |
| 879 } | 930 } |
| 880 | 931 |
| 881 } // namespace blink | 932 } // namespace blink |
| OLD | NEW |