OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 DCHECK(!document().needsLayoutTreeUpdate()); | 161 DCHECK(!document().needsLayoutTreeUpdate()); |
162 | 162 |
163 Element* const editable = rootEditableElement(); | 163 Element* const editable = rootEditableElement(); |
164 if (!editable) | 164 if (!editable) |
165 return; | 165 return; |
166 | 166 |
167 const VisiblePosition position = | 167 const VisiblePosition position = |
168 visiblePositionForContentsPoint(point, frame()); | 168 visiblePositionForContentsPoint(point, frame()); |
169 SelectionInDOMTree::Builder builder; | 169 SelectionInDOMTree::Builder builder; |
170 builder.setIsDirectional(selection().isDirectional()); | 170 builder.setIsDirectional(selection().isDirectional()); |
| 171 builder.setIsHandleVisible(true); |
171 if (position.isNotNull()) | 172 if (position.isNotNull()) |
172 builder.collapse(position.toPositionWithAffinity()); | 173 builder.collapse(position.toPositionWithAffinity()); |
173 setSelection(builder.build(), | 174 setSelection(builder.build(), CloseTyping | ClearTypingStyle | UserTriggered); |
174 CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible); | |
175 } | 175 } |
176 | 176 |
177 template <typename Strategy> | 177 template <typename Strategy> |
178 void FrameSelection::setSelectionAlgorithm( | 178 void FrameSelection::setSelectionAlgorithm( |
179 const VisibleSelectionTemplate<Strategy>& newSelection, | 179 const VisibleSelectionTemplate<Strategy>& newSelection, |
| 180 HandleVisibility handleVisibility, |
180 SetSelectionOptions options, | 181 SetSelectionOptions options, |
181 CursorAlignOnScroll align, | 182 CursorAlignOnScroll align, |
182 TextGranularity granularity) { | 183 TextGranularity granularity) { |
183 DCHECK(isAvailable()); | 184 DCHECK(isAvailable()); |
184 DCHECK(newSelection.isValidFor(document())); | 185 DCHECK(newSelection.isValidFor(document())); |
185 const Document& currentDocument = document(); | 186 const Document& currentDocument = document(); |
186 if (m_granularityStrategy && | 187 if (m_granularityStrategy && |
187 (options & FrameSelection::DoNotClearStrategy) == 0) | 188 (options & FrameSelection::DoNotClearStrategy) == 0) |
188 m_granularityStrategy->Clear(); | 189 m_granularityStrategy->Clear(); |
189 bool closeTyping = options & CloseTyping; | 190 bool closeTyping = options & CloseTyping; |
190 bool shouldClearTypingStyle = options & ClearTypingStyle; | 191 bool shouldClearTypingStyle = options & ClearTypingStyle; |
191 const HandleVisibility handleVisibility = options & HandleVisible | |
192 ? HandleVisibility::Visible | |
193 : HandleVisibility::NotVisible; | |
194 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 192 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
195 | 193 |
196 // TODO(editing-dev): We should rename variable |s| to another name to avoid | 194 // TODO(editing-dev): We should rename variable |s| to another name to avoid |
197 // using one letter variable name. | 195 // using one letter variable name. |
198 VisibleSelectionTemplate<Strategy> s = newSelection; | 196 VisibleSelectionTemplate<Strategy> s = newSelection; |
199 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 197 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
200 s.setIsDirectional(true); | 198 s.setIsDirectional(true); |
201 | 199 |
202 m_granularity = granularity; | 200 m_granularity = granularity; |
203 | 201 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 CursorAlignOnScroll align, | 295 CursorAlignOnScroll align, |
298 TextGranularity granularity) { | 296 TextGranularity granularity) { |
299 if (!newSelection.isNone()) { | 297 if (!newSelection.isNone()) { |
300 // TODO(editing-dev): The use of | 298 // TODO(editing-dev): The use of |
301 // updateStyleAndLayoutIgnorePendingStylesheets | 299 // updateStyleAndLayoutIgnorePendingStylesheets |
302 // needs to be audited. See http://crbug.com/590369 for more details. | 300 // needs to be audited. See http://crbug.com/590369 for more details. |
303 newSelection.base() | 301 newSelection.base() |
304 .document() | 302 .document() |
305 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 303 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
306 } | 304 } |
307 setSelection(createVisibleSelection(newSelection), options, align, | 305 setSelection(createVisibleSelection(newSelection), |
308 granularity); | 306 newSelection.isHandleVisible() ? HandleVisibility::Visible |
| 307 : HandleVisibility::NotVisible, |
| 308 options, align, granularity); |
309 } | 309 } |
310 | 310 |
311 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| | 311 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| |
312 // as primary function instead of wrapper. | 312 // as primary function instead of wrapper. |
313 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, | 313 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, |
314 SetSelectionOptions options, | 314 SetSelectionOptions options, |
315 CursorAlignOnScroll align, | 315 CursorAlignOnScroll align, |
316 TextGranularity granularity) { | 316 TextGranularity granularity) { |
317 if (!newSelection.isNone()) { | 317 if (!newSelection.isNone()) { |
318 // TODO(editing-dev): The use of | 318 // TODO(editing-dev): The use of |
319 // updateStyleAndLayoutIgnorePendingStylesheets | 319 // updateStyleAndLayoutIgnorePendingStylesheets |
320 // needs to be audited. See http://crbug.com/590369 for more details. | 320 // needs to be audited. See http://crbug.com/590369 for more details. |
321 newSelection.base() | 321 newSelection.base() |
322 .document() | 322 .document() |
323 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 323 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
324 } | 324 } |
325 setSelection(createVisibleSelection(newSelection), options, align, | 325 setSelection(createVisibleSelection(newSelection), |
326 granularity); | 326 newSelection.isHandleVisible() ? HandleVisibility::Visible |
| 327 : HandleVisibility::NotVisible, |
| 328 options, align, granularity); |
327 } | 329 } |
328 | 330 |
329 void FrameSelection::setSelection(const VisibleSelection& newSelection, | 331 void FrameSelection::setSelection(const VisibleSelection& newSelection, |
| 332 HandleVisibility handleVisibility, |
330 SetSelectionOptions options, | 333 SetSelectionOptions options, |
331 CursorAlignOnScroll align, | 334 CursorAlignOnScroll align, |
332 TextGranularity granularity) { | 335 TextGranularity granularity) { |
333 setSelectionAlgorithm<EditingStrategy>(newSelection, options, align, | 336 setSelectionAlgorithm<EditingStrategy>(newSelection, handleVisibility, |
334 granularity); | 337 options, align, granularity); |
| 338 } |
| 339 |
| 340 void FrameSelection::setSelection(const VisibleSelection& newSelection, |
| 341 SetSelectionOptions options) { |
| 342 setSelection(newSelection, HandleVisibility::NotVisible, options); |
335 } | 343 } |
336 | 344 |
337 void FrameSelection::setSelection( | 345 void FrameSelection::setSelection( |
338 const VisibleSelectionInFlatTree& newSelection, | 346 const VisibleSelectionInFlatTree& newSelection, |
| 347 HandleVisibility handleVisibility, |
339 SetSelectionOptions options, | 348 SetSelectionOptions options, |
340 CursorAlignOnScroll align, | 349 CursorAlignOnScroll align, |
341 TextGranularity granularity) { | 350 TextGranularity granularity) { |
342 setSelectionAlgorithm<EditingInFlatTreeStrategy>(newSelection, options, align, | 351 setSelectionAlgorithm<EditingInFlatTreeStrategy>( |
343 granularity); | 352 newSelection, handleVisibility, options, align, granularity); |
| 353 } |
| 354 |
| 355 void FrameSelection::setSelection( |
| 356 const VisibleSelectionInFlatTree& newSelection, |
| 357 SetSelectionOptions options) { |
| 358 setSelection(newSelection, HandleVisibility::NotVisible, options); |
344 } | 359 } |
345 | 360 |
346 static bool removingNodeRemovesPosition(Node& node, const Position& position) { | 361 static bool removingNodeRemovesPosition(Node& node, const Position& position) { |
347 if (!position.anchorNode()) | 362 if (!position.anchorNode()) |
348 return false; | 363 return false; |
349 | 364 |
350 if (position.anchorNode() == node) | 365 if (position.anchorNode() == node) |
351 return true; | 366 return true; |
352 | 367 |
353 if (!node.isElementNode()) | 368 if (!node.isElementNode()) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 699 |
685 bool FrameSelection::modify(EAlteration alter, | 700 bool FrameSelection::modify(EAlteration alter, |
686 unsigned verticalDistance, | 701 unsigned verticalDistance, |
687 VerticalDirection direction) { | 702 VerticalDirection direction) { |
688 SelectionModifier selectionModifier(*frame(), selection()); | 703 SelectionModifier selectionModifier(*frame(), selection()); |
689 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, | 704 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, |
690 direction)) { | 705 direction)) { |
691 return false; | 706 return false; |
692 } | 707 } |
693 | 708 |
694 setSelection(selectionModifier.selection(), | 709 setSelection(selectionModifier.selection(), HandleVisibility::NotVisible, |
695 CloseTyping | ClearTypingStyle | UserTriggered, | 710 CloseTyping | ClearTypingStyle | UserTriggered, |
696 alter == AlterationMove ? CursorAlignOnScroll::Always | 711 alter == AlterationMove ? CursorAlignOnScroll::Always |
697 : CursorAlignOnScroll::IfNeeded); | 712 : CursorAlignOnScroll::IfNeeded); |
698 | 713 |
699 m_granularity = CharacterGranularity; | 714 m_granularity = CharacterGranularity; |
700 | 715 |
701 return true; | 716 return true; |
702 } | 717 } |
703 | 718 |
704 void FrameSelection::clear() { | 719 void FrameSelection::clear() { |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); | 1367 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); |
1353 return m_granularityStrategy.get(); | 1368 return m_granularityStrategy.get(); |
1354 } | 1369 } |
1355 | 1370 |
1356 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { | 1371 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { |
1357 if (isNone()) | 1372 if (isNone()) |
1358 return; | 1373 return; |
1359 | 1374 |
1360 VisibleSelection newSelection = | 1375 VisibleSelection newSelection = |
1361 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1376 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1362 setSelection(newSelection, | 1377 setSelection(newSelection, HandleVisibility::Visible, |
1363 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1378 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1364 FrameSelection::DoNotClearStrategy | UserTriggered | | 1379 FrameSelection::DoNotClearStrategy | UserTriggered, |
1365 FrameSelection::HandleVisible, | |
1366 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1380 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1367 } | 1381 } |
1368 | 1382 |
1369 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take | 1383 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take |
1370 // two |IntPoint| instead of two |VisiblePosition| like | 1384 // two |IntPoint| instead of two |VisiblePosition| like |
1371 // |moveRangeSelectionExtent()|. | 1385 // |moveRangeSelectionExtent()|. |
1372 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1386 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1373 const VisiblePosition& extentPosition, | 1387 const VisiblePosition& extentPosition, |
1374 TextGranularity granularity) { | 1388 TextGranularity granularity) { |
1375 VisibleSelection newSelection = createVisibleSelection( | 1389 VisibleSelection newSelection = createVisibleSelection( |
1376 SelectionInDOMTree::Builder() | 1390 SelectionInDOMTree::Builder() |
1377 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), | 1391 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), |
1378 extentPosition.deepEquivalent()) | 1392 extentPosition.deepEquivalent()) |
1379 .setAffinity(basePosition.affinity()) | 1393 .setAffinity(basePosition.affinity()) |
1380 .setGranularity(granularity) | 1394 .setGranularity(granularity) |
1381 .build()); | 1395 .build()); |
1382 | 1396 |
1383 if (newSelection.isNone()) | 1397 if (newSelection.isNone()) |
1384 return; | 1398 return; |
1385 | 1399 |
1386 SetSelectionOptions options = CloseTyping | ClearTypingStyle; | 1400 setSelection(newSelection, m_handleVisibility, CloseTyping | ClearTypingStyle, |
1387 if (isHandleVisible()) | 1401 CursorAlignOnScroll::IfNeeded, granularity); |
1388 options |= HandleVisible; | |
1389 setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, | |
1390 granularity); | |
1391 } | 1402 } |
1392 | 1403 |
1393 void FrameSelection::updateIfNeeded() { | 1404 void FrameSelection::updateIfNeeded() { |
1394 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 1405 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
1395 m_selectionEditor->updateIfNeeded(); | 1406 m_selectionEditor->updateIfNeeded(); |
1396 } | 1407 } |
1397 | 1408 |
1398 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1409 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1399 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1410 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1400 : CaretVisibility::Hidden); | 1411 : CaretVisibility::Hidden); |
(...skipping 28 matching lines...) Expand all Loading... |
1429 } | 1440 } |
1430 | 1441 |
1431 void showTree(const blink::FrameSelection* sel) { | 1442 void showTree(const blink::FrameSelection* sel) { |
1432 if (sel) | 1443 if (sel) |
1433 sel->showTreeForThis(); | 1444 sel->showTreeForThis(); |
1434 else | 1445 else |
1435 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1446 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1436 } | 1447 } |
1437 | 1448 |
1438 #endif | 1449 #endif |
OLD | NEW |