| 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 "bindings/core/v8/ExceptionStatePlaceholder.h" | 5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/dom/Text.h" | 8 #include "core/dom/Text.h" |
| 9 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return text; | 114 return text; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void GranularityStrategyTest::setInnerHTML(const char* htmlContent) { | 117 void GranularityStrategyTest::setInnerHTML(const char* htmlContent) { |
| 118 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent)); | 118 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent)); |
| 119 document().view()->updateAllLifecyclePhases(); | 119 document().view()->updateAllLifecyclePhases(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void GranularityStrategyTest::parseText(Text* text) { | 122 void GranularityStrategyTest::parseText(Text* text) { |
| 123 TextNodeVector textNodes; | 123 TextNodeVector textNodes; |
| 124 textNodes.append(text); | 124 textNodes.push_back(text); |
| 125 parseText(textNodes); | 125 parseText(textNodes); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void GranularityStrategyTest::parseText(const TextNodeVector& textNodes) { | 128 void GranularityStrategyTest::parseText(const TextNodeVector& textNodes) { |
| 129 bool wordStarted = false; | 129 bool wordStarted = false; |
| 130 int wordStartIndex = 0; | 130 int wordStartIndex = 0; |
| 131 for (auto& text : textNodes) { | 131 for (auto& text : textNodes) { |
| 132 int wordStartIndexOffset = m_letterPos.size(); | 132 int wordStartIndexOffset = m_letterPos.size(); |
| 133 String str = text->wholeText(); | 133 String str = text->wholeText(); |
| 134 for (size_t i = 0; i < str.length(); i++) { | 134 for (size_t i = 0; i < str.length(); i++) { |
| 135 m_letterPos.append(visiblePositionToContentsPoint( | 135 m_letterPos.push_back(visiblePositionToContentsPoint( |
| 136 createVisiblePosition(Position(text, i)))); | 136 createVisiblePosition(Position(text, i)))); |
| 137 char c = str[i]; | 137 char c = str[i]; |
| 138 if (isASCIIAlphanumeric(c) && !wordStarted) { | 138 if (isASCIIAlphanumeric(c) && !wordStarted) { |
| 139 wordStartIndex = i + wordStartIndexOffset; | 139 wordStartIndex = i + wordStartIndexOffset; |
| 140 wordStarted = true; | 140 wordStarted = true; |
| 141 } else if (!isASCIIAlphanumeric(c) && wordStarted) { | 141 } else if (!isASCIIAlphanumeric(c) && wordStarted) { |
| 142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + | 142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + |
| 143 m_letterPos[i + wordStartIndexOffset].x()) / | 143 m_letterPos[i + wordStartIndexOffset].x()) / |
| 144 2, | 144 2, |
| 145 m_letterPos[wordStartIndex].y()); | 145 m_letterPos[wordStartIndex].y()); |
| 146 m_wordMiddles.append(wordMiddle); | 146 m_wordMiddles.push_back(wordMiddle); |
| 147 wordStarted = false; | 147 wordStarted = false; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 if (wordStarted) { | 151 if (wordStarted) { |
| 152 const auto& lastNode = textNodes.back(); | 152 const auto& lastNode = textNodes.back(); |
| 153 int xEnd = visiblePositionToContentsPoint( | 153 int xEnd = visiblePositionToContentsPoint( |
| 154 createVisiblePosition( | 154 createVisiblePosition( |
| 155 Position(lastNode, lastNode->wholeText().length()))) | 155 Position(lastNode, lastNode->wholeText().length()))) |
| 156 .x(); | 156 .x(); |
| 157 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, | 157 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, |
| 158 m_letterPos[wordStartIndex].y()); | 158 m_letterPos[wordStartIndex].y()); |
| 159 m_wordMiddles.append(wordMiddle); | 159 m_wordMiddles.push_back(wordMiddle); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 Text* GranularityStrategyTest::setupTranslateZ(String str) { | 163 Text* GranularityStrategyTest::setupTranslateZ(String str) { |
| 164 setInnerHTML( | 164 setInnerHTML( |
| 165 "<html>" | 165 "<html>" |
| 166 "<head>" | 166 "<head>" |
| 167 "<style>" | 167 "<style>" |
| 168 "div {" | 168 "div {" |
| 169 "transform: translateZ(0);" | 169 "transform: translateZ(0);" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 div->appendChild(span); | 249 div->appendChild(span); |
| 250 span->appendChild(text2); | 250 span->appendChild(text2); |
| 251 div->appendChild(text3); | 251 div->appendChild(text3); |
| 252 | 252 |
| 253 document().view()->updateAllLifecyclePhases(); | 253 document().view()->updateAllLifecyclePhases(); |
| 254 | 254 |
| 255 Vector<IntPoint> letterPos; | 255 Vector<IntPoint> letterPos; |
| 256 Vector<IntPoint> wordMiddlePos; | 256 Vector<IntPoint> wordMiddlePos; |
| 257 | 257 |
| 258 TextNodeVector textNodes; | 258 TextNodeVector textNodes; |
| 259 textNodes.append(text1); | 259 textNodes.push_back(text1); |
| 260 textNodes.append(text2); | 260 textNodes.push_back(text2); |
| 261 textNodes.append(text3); | 261 textNodes.push_back(text3); |
| 262 parseText(textNodes); | 262 parseText(textNodes); |
| 263 | 263 |
| 264 Position p1; | 264 Position p1; |
| 265 Position p2; | 265 Position p2; |
| 266 if (selBegin < str1.length()) | 266 if (selBegin < str1.length()) |
| 267 p1 = Position(text1, selBegin); | 267 p1 = Position(text1, selBegin); |
| 268 else if (selBegin < str1.length() + str2.length()) | 268 else if (selBegin < str1.length() + str2.length()) |
| 269 p1 = Position(text2, selBegin - str1.length()); | 269 p1 = Position(text2, selBegin - str1.length()); |
| 270 else | 270 else |
| 271 p1 = Position(text3, selBegin - str1.length() - str2.length()); | 271 p1 = Position(text3, selBegin - str1.length() - str2.length()); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 selection().setSelection( | 701 selection().setSelection( |
| 702 SelectionInDOMTree::Builder() | 702 SelectionInDOMTree::Builder() |
| 703 .setBaseAndExtent(Position(text, 15), Position(text, 22)) | 703 .setBaseAndExtent(Position(text, 15), Position(text, 22)) |
| 704 .build()); | 704 .build()); |
| 705 EXPECT_EQ_SELECTED_TEXT("mnopqr "); | 705 EXPECT_EQ_SELECTED_TEXT("mnopqr "); |
| 706 selection().moveRangeSelectionExtent(m_wordMiddles[4]); | 706 selection().moveRangeSelectionExtent(m_wordMiddles[4]); |
| 707 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); | 707 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); |
| 708 } | 708 } |
| 709 | 709 |
| 710 } // namespace blink | 710 } // namespace blink |
| OLD | NEW |