| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 void GranularityStrategyTest::parseText(std::vector<Text*> textNodes) | 119 void GranularityStrategyTest::parseText(std::vector<Text*> textNodes) |
| 120 { | 120 { |
| 121 bool wordStarted = false; | 121 bool wordStarted = false; |
| 122 int wordStartIndex = 0; | 122 int wordStartIndex = 0; |
| 123 for (Text* text : textNodes) { | 123 for (Text* text : textNodes) { |
| 124 int wordStartIndexOffset = m_letterPos.size(); | 124 int wordStartIndexOffset = m_letterPos.size(); |
| 125 WTF::String str = text->wholeText(); | 125 WTF::String str = text->wholeText(); |
| 126 for (size_t i = 0; i < str.length(); i++) { | 126 for (size_t i = 0; i < str.length(); i++) { |
| 127 m_letterPos.push_back(visiblePositionToContentsPoint(VisiblePosition
(Position(text, i)))); | 127 m_letterPos.push_back(visiblePositionToContentsPoint(createVisiblePo
sition(Position(text, i)))); |
| 128 char c = str.characterAt(i); | 128 char c = str.characterAt(i); |
| 129 if (isASCIIAlphanumeric(c) && !wordStarted) { | 129 if (isASCIIAlphanumeric(c) && !wordStarted) { |
| 130 wordStartIndex = i + wordStartIndexOffset; | 130 wordStartIndex = i + wordStartIndexOffset; |
| 131 wordStarted = true; | 131 wordStarted = true; |
| 132 } else if (!isASCIIAlphanumeric(c) && wordStarted) { | 132 } else if (!isASCIIAlphanumeric(c) && wordStarted) { |
| 133 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + m_letterP
os[i + wordStartIndexOffset].x()) / 2, m_letterPos[wordStartIndex].y()); | 133 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + m_letterP
os[i + wordStartIndexOffset].x()) / 2, m_letterPos[wordStartIndex].y()); |
| 134 m_wordMiddles.push_back(wordMiddle); | 134 m_wordMiddles.push_back(wordMiddle); |
| 135 wordStarted = false; | 135 wordStarted = false; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 if (wordStarted) { | 139 if (wordStarted) { |
| 140 Text* lastNode = textNodes[textNodes.size() - 1]; | 140 Text* lastNode = textNodes[textNodes.size() - 1]; |
| 141 int xEnd = visiblePositionToContentsPoint(VisiblePosition(Position(lastN
ode, lastNode->wholeText().length()))).x(); | 141 int xEnd = visiblePositionToContentsPoint(createVisiblePosition(Position
(lastNode, lastNode->wholeText().length()))).x(); |
| 142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett
erPos[wordStartIndex].y()); | 142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett
erPos[wordStartIndex].y()); |
| 143 m_wordMiddles.push_back(wordMiddle); | 143 m_wordMiddles.push_back(wordMiddle); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::setupTranslateZ(WTF::Strin
g str) | 147 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::setupTranslateZ(WTF::Strin
g str) |
| 148 { | 148 { |
| 149 setInnerHTML( | 149 setInnerHTML( |
| 150 "<html>" | 150 "<html>" |
| 151 "<head>" | 151 "<head>" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 TEST_F(GranularityStrategyTest, Character) | 477 TEST_F(GranularityStrategyTest, Character) |
| 478 { | 478 { |
| 479 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy
::Character); | 479 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy
::Character); |
| 480 dummyPageHolder().frame().settings()->setDefaultFontSize(12); | 480 dummyPageHolder().frame().settings()->setDefaultFontSize(12); |
| 481 // "Foo Bar Baz," | 481 // "Foo Bar Baz," |
| 482 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); | 482 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); |
| 483 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m
eans end). | 483 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m
eans end). |
| 484 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); | 484 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); |
| 485 EXPECT_EQ_SELECTED_TEXT("a"); | 485 EXPECT_EQ_SELECTED_TEXT("a"); |
| 486 // "Foo B^ar B|>az," | 486 // "Foo B^ar B|>az," |
| 487 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(VisibleP
osition(Position(text, 9)))); | 487 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi
siblePosition(Position(text, 9)))); |
| 488 EXPECT_EQ_SELECTED_TEXT("ar B"); | 488 EXPECT_EQ_SELECTED_TEXT("ar B"); |
| 489 // "F<|oo B^ar Baz," | 489 // "F<|oo B^ar Baz," |
| 490 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(VisibleP
osition(Position(text, 1)))); | 490 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi
siblePosition(Position(text, 1)))); |
| 491 EXPECT_EQ_SELECTED_TEXT("oo B"); | 491 EXPECT_EQ_SELECTED_TEXT("oo B"); |
| 492 } | 492 } |
| 493 | 493 |
| 494 // DirectionGranularityStrategy strategy on rotated text should revert to the | 494 // DirectionGranularityStrategy strategy on rotated text should revert to the |
| 495 // same behavior as CharacterGranularityStrategy | 495 // same behavior as CharacterGranularityStrategy |
| 496 TEST_F(GranularityStrategyTest, DirectionRotate) | 496 TEST_F(GranularityStrategyTest, DirectionRotate) |
| 497 { | 497 { |
| 498 RefPtrWillBeRawPtr<Text> text = setupRotate("Foo Bar Baz,"); | 498 RefPtrWillBeRawPtr<Text> text = setupRotate("Foo Bar Baz,"); |
| 499 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m
eans end). | 499 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m
eans end). |
| 500 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); | 500 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 | 652 |
| 653 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, | 653 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, |
| 654 // > means end). | 654 // > means end). |
| 655 selection().setSelection(VisibleSelection(Position(text, 15), Position(text,
22))); | 655 selection().setSelection(VisibleSelection(Position(text, 15), Position(text,
22))); |
| 656 EXPECT_EQ_SELECTED_TEXT("mnopqr "); | 656 EXPECT_EQ_SELECTED_TEXT("mnopqr "); |
| 657 selection().moveRangeSelectionExtent(m_wordMiddles[4]); | 657 selection().moveRangeSelectionExtent(m_wordMiddles[4]); |
| 658 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); | 658 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); |
| 659 } | 659 } |
| 660 | 660 |
| 661 } // namespace blink | 661 } // namespace blink |
| OLD | NEW |