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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (position.isNotNull()) | 171 if (position.isNotNull()) |
172 builder.collapse(position.toPositionWithAffinity()); | 172 builder.collapse(position.toPositionWithAffinity()); |
173 setSelection(builder.build(), | 173 setSelection(builder.setIsHandleVisible(true).build(), |
174 CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible); | 174 CloseTyping | ClearTypingStyle | UserTriggered); |
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 bool isHandleVisible, | |
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 const HandleVisibility handleVisibility = isHandleVisible |
192 ? HandleVisibility::Visible | 193 ? HandleVisibility::Visible |
193 : HandleVisibility::NotVisible; | 194 : HandleVisibility::NotVisible; |
194 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 195 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
195 | 196 |
196 // TODO(editing-dev): We should rename variable |s| to another name to avoid | 197 // TODO(editing-dev): We should rename variable |s| to another name to avoid |
197 // using one letter variable name. | 198 // using one letter variable name. |
198 VisibleSelectionTemplate<Strategy> s = newSelection; | 199 VisibleSelectionTemplate<Strategy> s = newSelection; |
199 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 200 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
200 s.setIsDirectional(true); | 201 s.setIsDirectional(true); |
201 | 202 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 CursorAlignOnScroll align, | 298 CursorAlignOnScroll align, |
298 TextGranularity granularity) { | 299 TextGranularity granularity) { |
299 if (!newSelection.isNone()) { | 300 if (!newSelection.isNone()) { |
300 // TODO(editing-dev): The use of | 301 // TODO(editing-dev): The use of |
301 // updateStyleAndLayoutIgnorePendingStylesheets | 302 // updateStyleAndLayoutIgnorePendingStylesheets |
302 // needs to be audited. See http://crbug.com/590369 for more details. | 303 // needs to be audited. See http://crbug.com/590369 for more details. |
303 newSelection.base() | 304 newSelection.base() |
304 .document() | 305 .document() |
305 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 306 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
306 } | 307 } |
307 setSelection(createVisibleSelection(newSelection), options, align, | 308 setSelection(createVisibleSelection(newSelection), |
308 granularity); | 309 newSelection.isHandleVisible(), options, align, granularity); |
309 } | 310 } |
310 | 311 |
311 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| | 312 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| |
312 // as primary function instead of wrapper. | 313 // as primary function instead of wrapper. |
313 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, | 314 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, |
314 SetSelectionOptions options, | 315 SetSelectionOptions options, |
315 CursorAlignOnScroll align, | 316 CursorAlignOnScroll align, |
316 TextGranularity granularity) { | 317 TextGranularity granularity) { |
317 if (!newSelection.isNone()) { | 318 if (!newSelection.isNone()) { |
318 // TODO(editing-dev): The use of | 319 // TODO(editing-dev): The use of |
319 // updateStyleAndLayoutIgnorePendingStylesheets | 320 // updateStyleAndLayoutIgnorePendingStylesheets |
320 // needs to be audited. See http://crbug.com/590369 for more details. | 321 // needs to be audited. See http://crbug.com/590369 for more details. |
321 newSelection.base() | 322 newSelection.base() |
322 .document() | 323 .document() |
323 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 324 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
324 } | 325 } |
325 setSelection(createVisibleSelection(newSelection), options, align, | 326 setSelection(createVisibleSelection(newSelection), |
326 granularity); | 327 newSelection.isHandleVisible(), options, align, granularity); |
327 } | 328 } |
328 | 329 |
329 void FrameSelection::setSelection(const VisibleSelection& newSelection, | 330 void FrameSelection::setSelection(const VisibleSelection& newSelection, |
331 bool isHandleVisible, | |
330 SetSelectionOptions options, | 332 SetSelectionOptions options, |
331 CursorAlignOnScroll align, | 333 CursorAlignOnScroll align, |
332 TextGranularity granularity) { | 334 TextGranularity granularity) { |
333 setSelectionAlgorithm<EditingStrategy>(newSelection, options, align, | 335 setSelectionAlgorithm<EditingStrategy>(newSelection, isHandleVisible, options, |
334 granularity); | 336 align, granularity); |
335 } | 337 } |
336 | 338 |
337 void FrameSelection::setSelection( | 339 void FrameSelection::setSelection( |
338 const VisibleSelectionInFlatTree& newSelection, | 340 const VisibleSelectionInFlatTree& newSelection, |
341 bool isHandleVisible, | |
339 SetSelectionOptions options, | 342 SetSelectionOptions options, |
340 CursorAlignOnScroll align, | 343 CursorAlignOnScroll align, |
341 TextGranularity granularity) { | 344 TextGranularity granularity) { |
342 setSelectionAlgorithm<EditingInFlatTreeStrategy>(newSelection, options, align, | 345 setSelectionAlgorithm<EditingInFlatTreeStrategy>( |
343 granularity); | 346 newSelection, isHandleVisible, options, align, granularity); |
344 } | 347 } |
345 | 348 |
346 static bool removingNodeRemovesPosition(Node& node, const Position& position) { | 349 static bool removingNodeRemovesPosition(Node& node, const Position& position) { |
347 if (!position.anchorNode()) | 350 if (!position.anchorNode()) |
348 return false; | 351 return false; |
349 | 352 |
350 if (position.anchorNode() == node) | 353 if (position.anchorNode() == node) |
351 return true; | 354 return true; |
352 | 355 |
353 if (!node.isElementNode()) | 356 if (!node.isElementNode()) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 | 687 |
685 bool FrameSelection::modify(EAlteration alter, | 688 bool FrameSelection::modify(EAlteration alter, |
686 unsigned verticalDistance, | 689 unsigned verticalDistance, |
687 VerticalDirection direction) { | 690 VerticalDirection direction) { |
688 SelectionModifier selectionModifier(*frame(), selection()); | 691 SelectionModifier selectionModifier(*frame(), selection()); |
689 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, | 692 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, |
690 direction)) { | 693 direction)) { |
691 return false; | 694 return false; |
692 } | 695 } |
693 | 696 |
694 setSelection(selectionModifier.selection(), | 697 setSelection(selectionModifier.selection(), false, |
695 CloseTyping | ClearTypingStyle | UserTriggered, | 698 CloseTyping | ClearTypingStyle | UserTriggered, |
696 alter == AlterationMove ? CursorAlignOnScroll::Always | 699 alter == AlterationMove ? CursorAlignOnScroll::Always |
697 : CursorAlignOnScroll::IfNeeded); | 700 : CursorAlignOnScroll::IfNeeded); |
698 | 701 |
699 m_granularity = CharacterGranularity; | 702 m_granularity = CharacterGranularity; |
700 | 703 |
701 return true; | 704 return true; |
702 } | 705 } |
703 | 706 |
704 void FrameSelection::clear() { | 707 void FrameSelection::clear() { |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); | 1351 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); |
1349 return m_granularityStrategy.get(); | 1352 return m_granularityStrategy.get(); |
1350 } | 1353 } |
1351 | 1354 |
1352 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { | 1355 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { |
1353 if (isNone()) | 1356 if (isNone()) |
1354 return; | 1357 return; |
1355 | 1358 |
1356 VisibleSelection newSelection = | 1359 VisibleSelection newSelection = |
1357 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1360 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1358 setSelection(newSelection, | 1361 setSelection(newSelection, isHandleVisible(), |
yosin_UTC9
2017/01/25 04:01:08
Once we use |HandleVisibility| as parameter, we ca
| |
1359 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1362 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1360 FrameSelection::DoNotClearStrategy | UserTriggered | | 1363 FrameSelection::DoNotClearStrategy | UserTriggered, |
1361 FrameSelection::HandleVisible, | |
1362 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1364 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1363 } | 1365 } |
1364 | 1366 |
1365 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take | 1367 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take |
1366 // two |IntPoint| instead of two |VisiblePosition| like | 1368 // two |IntPoint| instead of two |VisiblePosition| like |
1367 // |moveRangeSelectionExtent()|. | 1369 // |moveRangeSelectionExtent()|. |
1368 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1370 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1369 const VisiblePosition& extentPosition, | 1371 const VisiblePosition& extentPosition, |
1370 TextGranularity granularity) { | 1372 TextGranularity granularity) { |
1371 VisibleSelection newSelection = createVisibleSelection( | 1373 VisibleSelection newSelection = createVisibleSelection( |
1372 SelectionInDOMTree::Builder() | 1374 SelectionInDOMTree::Builder() |
1373 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), | 1375 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), |
1374 extentPosition.deepEquivalent()) | 1376 extentPosition.deepEquivalent()) |
1375 .setAffinity(basePosition.affinity()) | 1377 .setAffinity(basePosition.affinity()) |
1376 .setGranularity(granularity) | 1378 .setGranularity(granularity) |
1377 .build()); | 1379 .build()); |
1378 | 1380 |
1379 if (newSelection.isNone()) | 1381 if (newSelection.isNone()) |
1380 return; | 1382 return; |
1381 | 1383 |
1382 SetSelectionOptions options = CloseTyping | ClearTypingStyle; | 1384 setSelection(newSelection, isHandleVisible(), CloseTyping | ClearTypingStyle, |
yosin_UTC9
2017/01/25 04:01:08
Once we use |HandleVisibility| as parameter, we ca
| |
1383 if (isHandleVisible()) | 1385 CursorAlignOnScroll::IfNeeded, granularity); |
1384 options |= HandleVisible; | |
1385 setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, | |
1386 granularity); | |
1387 } | 1386 } |
1388 | 1387 |
1389 void FrameSelection::updateIfNeeded() { | 1388 void FrameSelection::updateIfNeeded() { |
1390 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 1389 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
1391 m_selectionEditor->updateIfNeeded(); | 1390 m_selectionEditor->updateIfNeeded(); |
1392 } | 1391 } |
1393 | 1392 |
1394 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1393 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1395 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1394 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1396 : CaretVisibility::Hidden); | 1395 : CaretVisibility::Hidden); |
(...skipping 28 matching lines...) Expand all Loading... | |
1425 } | 1424 } |
1426 | 1425 |
1427 void showTree(const blink::FrameSelection* sel) { | 1426 void showTree(const blink::FrameSelection* sel) { |
1428 if (sel) | 1427 if (sel) |
1429 sel->showTreeForThis(); | 1428 sel->showTreeForThis(); |
1430 else | 1429 else |
1431 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1430 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1432 } | 1431 } |
1433 | 1432 |
1434 #endif | 1433 #endif |
OLD | NEW |