| 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 <memory> | 7 #include <memory> |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/Range.h" | 10 #include "core/dom/Range.h" |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 CreateHTMLWithCompositionInputEventListeners(); | 1265 CreateHTMLWithCompositionInputEventListeners(); |
| 1266 | 1266 |
| 1267 // Simulate composition in the |contentEditable|. | 1267 // Simulate composition in the |contentEditable|. |
| 1268 Vector<CompositionUnderline> underlines; | 1268 Vector<CompositionUnderline> underlines; |
| 1269 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1269 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1270 | 1270 |
| 1271 // Insert empty text without previous composition. | 1271 // Insert empty text without previous composition. |
| 1272 GetDocument().setTitle(g_empty_string); | 1272 GetDocument().setTitle(g_empty_string); |
| 1273 GetDocument().UpdateStyleAndLayout(); | 1273 GetDocument().UpdateStyleAndLayout(); |
| 1274 Controller().CommitText("", underlines, 0); | 1274 Controller().CommitText("", underlines, 0); |
| 1275 EXPECT_STREQ("", GetDocument().title().Utf8().Data()); | 1275 EXPECT_STREQ("beforeinput.data:;", GetDocument().title().Utf8().Data()); |
| 1276 | 1276 |
| 1277 GetDocument().setTitle(g_empty_string); | 1277 GetDocument().setTitle(g_empty_string); |
| 1278 Controller().SetComposition("n", underlines, 1, 1); | 1278 Controller().SetComposition("n", underlines, 1, 1); |
| 1279 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1279 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| 1280 GetDocument().title().Utf8().Data()); | 1280 GetDocument().title().Utf8().Data()); |
| 1281 | 1281 |
| 1282 // Insert empty text with previous composition. | 1282 // Insert empty text with previous composition. |
| 1283 GetDocument().setTitle(g_empty_string); | 1283 GetDocument().setTitle(g_empty_string); |
| 1284 GetDocument().UpdateStyleAndLayout(); | 1284 GetDocument().UpdateStyleAndLayout(); |
| 1285 Controller().CommitText("", underlines, 1); | 1285 Controller().CommitText("", underlines, 1); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 EXPECT_STREQ(" text blah", div->innerHTML().Utf8().Data()); | 1500 EXPECT_STREQ(" text blah", div->innerHTML().Utf8().Data()); |
| 1501 | 1501 |
| 1502 // Delete "blah" | 1502 // Delete "blah" |
| 1503 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | 1503 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); |
| 1504 Controller().CommitText(String(""), empty_underlines, 0); | 1504 Controller().CommitText(String(""), empty_underlines, 0); |
| 1505 | 1505 |
| 1506 // The space at the end of the string should have been converted to an nbsp | 1506 // The space at the end of the string should have been converted to an nbsp |
| 1507 EXPECT_STREQ(" text ", div->innerHTML().Utf8().Data()); | 1507 EXPECT_STREQ(" text ", div->innerHTML().Utf8().Data()); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 TEST_F(InputMethodControllerTest, CommitEmptyTextDeletesSelection) { |
| 1511 HTMLInputElement* input = |
| 1512 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample")); |
| 1513 |
| 1514 input->setValue("Abc Def Ghi"); |
| 1515 GetDocument().UpdateStyleAndLayout(); |
| 1516 Vector<CompositionUnderline> empty_underlines; |
| 1517 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 8)); |
| 1518 Controller().CommitText(String(""), empty_underlines, 0); |
| 1519 EXPECT_STREQ("Abc Ghi", input->value().Utf8().Data()); |
| 1520 |
| 1521 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 7)); |
| 1522 Controller().CommitText(String("1"), empty_underlines, 0); |
| 1523 EXPECT_STREQ("Abc 1", input->value().Utf8().Data()); |
| 1524 } |
| 1525 |
| 1510 static String GetMarkedText( | 1526 static String GetMarkedText( |
| 1511 DocumentMarkerController& document_marker_controller, | 1527 DocumentMarkerController& document_marker_controller, |
| 1512 Node* node, | 1528 Node* node, |
| 1513 int marker_index) { | 1529 int marker_index) { |
| 1514 DocumentMarker* marker = document_marker_controller.Markers()[marker_index]; | 1530 DocumentMarker* marker = document_marker_controller.Markers()[marker_index]; |
| 1515 return node->textContent().Substring( | 1531 return node->textContent().Substring( |
| 1516 marker->StartOffset(), marker->EndOffset() - marker->StartOffset()); | 1532 marker->StartOffset(), marker->EndOffset() - marker->StartOffset()); |
| 1517 } | 1533 } |
| 1518 | 1534 |
| 1519 TEST_F(InputMethodControllerTest, | 1535 TEST_F(InputMethodControllerTest, |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 // Set selection before BODY(editable). | 1988 // Set selection before BODY(editable). |
| 1973 GetFrame().Selection().SetSelection( | 1989 GetFrame().Selection().SetSelection( |
| 1974 SelectionInDOMTree::Builder() | 1990 SelectionInDOMTree::Builder() |
| 1975 .Collapse(Position(GetDocument().documentElement(), 0)) | 1991 .Collapse(Position(GetDocument().documentElement(), 0)) |
| 1976 .Build()); | 1992 .Build()); |
| 1977 | 1993 |
| 1978 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); | 1994 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); |
| 1979 } | 1995 } |
| 1980 | 1996 |
| 1981 } // namespace blink | 1997 } // namespace blink |
| OLD | NEW |