| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/input/EventHandler.h" | 5 #include "core/input/EventHandler.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/Editor.h" | 9 #include "core/editing/Editor.h" |
| 10 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 "height: 30px; } </style>" | 149 "height: 30px; } </style>" |
| 150 "<body contenteditable='true'><span class='line' id='line'>One Two " | 150 "<body contenteditable='true'><span class='line' id='line'>One Two " |
| 151 "Three</span></body>"); | 151 "Three</span></body>"); |
| 152 | 152 |
| 153 Node* line = document().getElementById("line")->firstChild(); | 153 Node* line = document().getElementById("line")->firstChild(); |
| 154 | 154 |
| 155 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); | 155 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); |
| 156 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 156 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 157 ASSERT_TRUE( | 157 ASSERT_TRUE( |
| 158 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 158 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 159 EXPECT_EQ(Position(line, 0), selection().start()); | 159 EXPECT_EQ(Position(line, 0), |
| 160 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 160 | 161 |
| 161 // Multi-tap events on editable elements should trigger selection, just | 162 // Multi-tap events on editable elements should trigger selection, just |
| 162 // like multi-click events. | 163 // like multi-click events. |
| 163 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); | 164 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); |
| 164 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); | 165 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); |
| 165 ASSERT_TRUE( | 166 ASSERT_TRUE( |
| 166 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); | 167 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 167 EXPECT_EQ(Position(line, 0), selection().start()); | 168 EXPECT_EQ(Position(line, 0), |
| 169 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 168 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { | 170 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { |
| 169 EXPECT_EQ(Position(line, 4), | 171 EXPECT_EQ(Position(line, 4), |
| 170 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 172 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 171 EXPECT_EQ("One ", WebString(selection().selectedText()).utf8()); | 173 EXPECT_EQ("One ", WebString(selection().selectedText()).utf8()); |
| 172 } else { | 174 } else { |
| 173 EXPECT_EQ(Position(line, 3), | 175 EXPECT_EQ(Position(line, 3), |
| 174 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 176 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 175 EXPECT_EQ("One", WebString(selection().selectedText()).utf8()); | 177 EXPECT_EQ("One", WebString(selection().selectedText()).utf8()); |
| 176 } | 178 } |
| 177 | 179 |
| 178 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); | 180 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); |
| 179 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); | 181 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); |
| 180 ASSERT_TRUE( | 182 ASSERT_TRUE( |
| 181 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); | 183 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 182 EXPECT_EQ(Position(line, 0), selection().start()); | 184 EXPECT_EQ(Position(line, 0), |
| 185 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 183 EXPECT_EQ(Position(line, 13), | 186 EXPECT_EQ(Position(line, 13), |
| 184 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 187 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 185 EXPECT_EQ("One Two Three", WebString(selection().selectedText()).utf8()); | 188 EXPECT_EQ("One Two Three", WebString(selection().selectedText()).utf8()); |
| 186 } | 189 } |
| 187 | 190 |
| 188 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { | 191 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { |
| 189 setHtmlInnerHTML( | 192 setHtmlInnerHTML( |
| 190 "<style> body { margin: 0px; } .line { display: block; width: 300px; " | 193 "<style> body { margin: 0px; } .line { display: block; width: 300px; " |
| 191 "height: 30px; } </style>" | 194 "height: 30px; } </style>" |
| 192 "<span class='line' id='line'>One Two Three</span>"); | 195 "<span class='line' id='line'>One Two Three</span>"); |
| 193 | 196 |
| 194 Node* line = document().getElementById("line")->firstChild(); | 197 Node* line = document().getElementById("line")->firstChild(); |
| 195 | 198 |
| 196 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); | 199 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); |
| 197 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 200 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 198 ASSERT_TRUE( | 201 ASSERT_TRUE( |
| 199 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 202 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 200 EXPECT_EQ(Position(line, 0), selection().start()); | 203 EXPECT_EQ(Position(line, 0), |
| 204 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 201 | 205 |
| 202 // As the text is readonly, multi-tap events should not trigger selection. | 206 // As the text is readonly, multi-tap events should not trigger selection. |
| 203 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); | 207 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); |
| 204 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); | 208 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); |
| 205 ASSERT_TRUE( | 209 ASSERT_TRUE( |
| 206 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 210 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 207 EXPECT_EQ(Position(line, 0), selection().start()); | 211 EXPECT_EQ(Position(line, 0), |
| 212 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 208 | 213 |
| 209 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); | 214 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); |
| 210 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); | 215 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); |
| 211 ASSERT_TRUE( | 216 ASSERT_TRUE( |
| 212 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 217 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 213 EXPECT_EQ(Position(line, 0), selection().start()); | 218 EXPECT_EQ(Position(line, 0), |
| 219 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 214 } | 220 } |
| 215 | 221 |
| 216 TEST_F(EventHandlerTest, draggedInlinePositionTest) { | 222 TEST_F(EventHandlerTest, draggedInlinePositionTest) { |
| 217 setHtmlInnerHTML( | 223 setHtmlInnerHTML( |
| 218 "<style>" | 224 "<style>" |
| 219 "body { margin: 0px; }" | 225 "body { margin: 0px; }" |
| 220 ".line { font-family: sans-serif; background: blue; width: 300px; " | 226 ".line { font-family: sans-serif; background: blue; width: 300px; " |
| 221 "height: 30px; font-size: 40px; margin-left: 250px; }" | 227 "height: 30px; font-size: 40px; margin-left: 250px; }" |
| 222 "</style>" | 228 "</style>" |
| 223 "<div style='width: 300px; height: 100px;'>" | 229 "<div style='width: 300px; height: 100px;'>" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 455 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 450 TimeTicks::Now().InSeconds()); | 456 TimeTicks::Now().InSeconds()); |
| 451 mouseUpEvent.setFrameScale(1); | 457 mouseUpEvent.setFrameScale(1); |
| 452 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 458 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 453 DragOperationNone); | 459 DragOperationNone); |
| 454 | 460 |
| 455 // This test passes if it doesn't crash. | 461 // This test passes if it doesn't crash. |
| 456 } | 462 } |
| 457 | 463 |
| 458 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |