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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 Element* const editable = rootEditableElement(); | 159 Element* const editable = rootEditableElement(); |
160 if (!editable) | 160 if (!editable) |
161 return; | 161 return; |
162 | 162 |
163 const VisiblePosition position = | 163 const VisiblePosition position = |
164 visiblePositionForContentsPoint(point, frame()); | 164 visiblePositionForContentsPoint(point, frame()); |
165 SelectionInDOMTree::Builder builder; | 165 SelectionInDOMTree::Builder builder; |
166 builder.setIsDirectional(selection().isDirectional()); | 166 builder.setIsDirectional(selection().isDirectional()); |
167 if (position.isNotNull()) | 167 if (position.isNotNull()) |
168 builder.collapse(position.toPositionWithAffinity()); | 168 builder.collapse(position.toPositionWithAffinity()); |
169 setSelection(builder.build(), CloseTyping | ClearTypingStyle | UserTriggered); | 169 setSelection(builder.build(), |
170 CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible); | |
170 } | 171 } |
171 | 172 |
172 template <typename Strategy> | 173 template <typename Strategy> |
173 void FrameSelection::setSelectionAlgorithm( | 174 void FrameSelection::setSelectionAlgorithm( |
174 const VisibleSelectionTemplate<Strategy>& newSelection, | 175 const VisibleSelectionTemplate<Strategy>& newSelection, |
175 SetSelectionOptions options, | 176 SetSelectionOptions options, |
176 CursorAlignOnScroll align, | 177 CursorAlignOnScroll align, |
177 TextGranularity granularity) { | 178 TextGranularity granularity) { |
178 DCHECK(isAvailable()); | 179 DCHECK(isAvailable()); |
179 DCHECK(newSelection.isValidFor(document())); | 180 DCHECK(newSelection.isValidFor(document())); |
180 const Document& currentDocument = document(); | 181 const Document& currentDocument = document(); |
181 if (m_granularityStrategy && | 182 if (m_granularityStrategy && |
182 (options & FrameSelection::DoNotClearStrategy) == 0) | 183 (options & FrameSelection::DoNotClearStrategy) == 0) |
183 m_granularityStrategy->Clear(); | 184 m_granularityStrategy->Clear(); |
184 bool closeTyping = options & CloseTyping; | 185 bool closeTyping = options & CloseTyping; |
185 bool shouldClearTypingStyle = options & ClearTypingStyle; | 186 bool shouldClearTypingStyle = options & ClearTypingStyle; |
187 const HandleVisibility handleVisibility = options & HandleVisible | |
188 ? HandleVisibility::Visible | |
189 : HandleVisibility::NotVisible; | |
186 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 190 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
187 | 191 |
188 // TODO(editing-dev): We should rename variable |s| to another name to avoid | 192 // TODO(editing-dev): We should rename variable |s| to another name to avoid |
189 // using one letter variable name. | 193 // using one letter variable name. |
190 VisibleSelectionTemplate<Strategy> s = newSelection; | 194 VisibleSelectionTemplate<Strategy> s = newSelection; |
191 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 195 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
192 s.setIsDirectional(true); | 196 s.setIsDirectional(true); |
193 | 197 |
194 m_granularity = granularity; | 198 m_granularity = granularity; |
195 | 199 |
196 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 200 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
197 // |Editor| class. | 201 // |Editor| class. |
198 if (closeTyping) | 202 if (closeTyping) |
199 TypingCommand::closeTyping(m_frame); | 203 TypingCommand::closeTyping(m_frame); |
200 | 204 |
201 if (shouldClearTypingStyle) | 205 if (shouldClearTypingStyle) |
202 clearTypingStyle(); | 206 clearTypingStyle(); |
203 | 207 |
204 if (m_selectionEditor->visibleSelection<Strategy>() == s) { | 208 if (m_selectionEditor->visibleSelection<Strategy>() == s && |
209 m_handleVisibility == handleVisibility) { | |
205 // Even if selection was not changed, selection offsets may have been | 210 // Even if selection was not changed, selection offsets may have been |
206 // changed. | 211 // changed. |
207 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); | 212 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); |
208 notifyLayoutObjectOfSelectionChange(userTriggered); | 213 notifyLayoutObjectOfSelectionChange(userTriggered); |
209 return; | 214 return; |
210 } | 215 } |
211 | 216 |
212 const VisibleSelectionTemplate<Strategy> oldSelection = | 217 const VisibleSelectionTemplate<Strategy> oldSelection = |
213 visibleSelection<Strategy>(); | 218 visibleSelection<Strategy>(); |
214 const Position& oldSelectionStart = selection().start(); | 219 const Position& oldSelectionStart = selection().start(); |
215 | 220 |
221 m_handleVisibility = handleVisibility; | |
216 m_selectionEditor->setVisibleSelection(s, options); | 222 m_selectionEditor->setVisibleSelection(s, options); |
217 m_frameCaret->setCaretRectNeedsUpdate(); | 223 m_frameCaret->setCaretRectNeedsUpdate(); |
218 | 224 |
219 if (!s.isNone() && !(options & DoNotSetFocus)) { | 225 if (!s.isNone() && !(options & DoNotSetFocus)) { |
220 setFocusedNodeIfNeeded(); | 226 setFocusedNodeIfNeeded(); |
221 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and | 227 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and |
222 // "FocusIn", |m_frame| may associate to another document. | 228 // "FocusIn", |m_frame| may associate to another document. |
223 if (!isAvailable() || document() != currentDocument) { | 229 if (!isAvailable() || document() != currentDocument) { |
224 // Once we get test case to reach here, we should change this | 230 // Once we get test case to reach here, we should change this |
225 // if-statement to |DCHECK()|. | 231 // if-statement to |DCHECK()|. |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 | 742 |
737 void FrameSelection::dataWillChange(const CharacterData& node) { | 743 void FrameSelection::dataWillChange(const CharacterData& node) { |
738 m_frameCaret->dataWillChange(node); | 744 m_frameCaret->dataWillChange(node); |
739 } | 745 } |
740 | 746 |
741 void FrameSelection::paintCaret(GraphicsContext& context, | 747 void FrameSelection::paintCaret(GraphicsContext& context, |
742 const LayoutPoint& paintOffset) { | 748 const LayoutPoint& paintOffset) { |
743 m_frameCaret->paintCaret(context, paintOffset); | 749 m_frameCaret->paintCaret(context, paintOffset); |
744 } | 750 } |
745 | 751 |
746 bool FrameSelection::contains(const LayoutPoint& point) { | 752 bool FrameSelection::contains(const HitTestResult& result) { |
747 if (document().layoutViewItem().isNull()) | |
748 return false; | |
749 | |
750 // Treat a collapsed selection like no selection. | 753 // Treat a collapsed selection like no selection. |
751 const VisibleSelectionInFlatTree& visibleSelection = | 754 const VisibleSelectionInFlatTree& visibleSelection = |
752 this->visibleSelection<EditingInFlatTreeStrategy>(); | 755 this->visibleSelection<EditingInFlatTreeStrategy>(); |
753 if (!visibleSelection.isRange()) | 756 if (!visibleSelection.isRange()) |
754 return false; | 757 return false; |
755 | 758 |
756 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | |
757 HitTestResult result(request, point); | |
758 document().layoutViewItem().hitTest(result); | |
759 Node* innerNode = result.innerNode(); | 759 Node* innerNode = result.innerNode(); |
760 if (!innerNode || !innerNode->layoutObject()) | 760 if (!innerNode || !innerNode->layoutObject()) |
761 return false; | 761 return false; |
762 | 762 |
763 const VisiblePositionInFlatTree& visiblePos = | 763 const VisiblePositionInFlatTree& visiblePos = |
764 createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>( | 764 createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>( |
765 innerNode->layoutObject()->positionForPoint(result.localPoint()))); | 765 innerNode->layoutObject()->positionForPoint(result.localPoint()))); |
766 if (visiblePos.isNull()) | 766 if (visiblePos.isNull()) |
767 return false; | 767 return false; |
768 | 768 |
769 const VisiblePositionInFlatTree& visibleStart = | 769 const VisiblePositionInFlatTree& visibleStart = |
770 visibleSelection.visibleStart(); | 770 visibleSelection.visibleStart(); |
771 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd(); | 771 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd(); |
772 if (visibleStart.isNull() || visibleEnd.isNull()) | 772 if (visibleStart.isNull() || visibleEnd.isNull()) |
773 return false; | 773 return false; |
774 | 774 |
775 const PositionInFlatTree& start = visibleStart.deepEquivalent(); | 775 const PositionInFlatTree& start = visibleStart.deepEquivalent(); |
776 const PositionInFlatTree& end = visibleEnd.deepEquivalent(); | 776 const PositionInFlatTree& end = visibleEnd.deepEquivalent(); |
777 const PositionInFlatTree& pos = visiblePos.deepEquivalent(); | 777 const PositionInFlatTree& pos = visiblePos.deepEquivalent(); |
778 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0; | 778 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0; |
779 } | 779 } |
780 | 780 |
781 bool FrameSelection::contains(const LayoutPoint& pointInContent) { | |
yosin_UTC9
2016/11/24 02:29:04
Could you move |FrameSelection::contains()| change
| |
782 if (document().layoutViewItem().isNull()) | |
783 return false; | |
784 | |
785 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | |
786 HitTestResult result(request, pointInContent); | |
787 document().layoutViewItem().hitTest(result); | |
788 | |
789 return contains(result); | |
790 } | |
791 | |
781 // Workaround for the fact that it's hard to delete a frame. | 792 // Workaround for the fact that it's hard to delete a frame. |
782 // Call this after doing user-triggered selections to make it easy to delete the | 793 // Call this after doing user-triggered selections to make it easy to delete the |
783 // frame you entirely selected. Can't do this implicitly as part of every | 794 // frame you entirely selected. Can't do this implicitly as part of every |
784 // setSelection call because in some contexts it might not be good for the focus | 795 // setSelection call because in some contexts it might not be good for the focus |
785 // to move to another frame. So instead we call it from places where we are | 796 // to move to another frame. So instead we call it from places where we are |
786 // selecting with the mouse or the keyboard after setting the selection. | 797 // selecting with the mouse or the keyboard after setting the selection. |
787 void FrameSelection::selectFrameElementInParentIfFullySelected() { | 798 void FrameSelection::selectFrameElementInParentIfFullySelected() { |
788 // Find the parent frame; if there is none, then we have nothing to do. | 799 // Find the parent frame; if there is none, then we have nothing to do. |
789 Frame* parent = m_frame->tree().parent(); | 800 Frame* parent = m_frame->tree().parent(); |
790 if (!parent) | 801 if (!parent) |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 } | 1341 } |
1331 | 1342 |
1332 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { | 1343 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { |
1333 if (isNone()) | 1344 if (isNone()) |
1334 return; | 1345 return; |
1335 | 1346 |
1336 VisibleSelection newSelection = | 1347 VisibleSelection newSelection = |
1337 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1348 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1338 setSelection(newSelection, | 1349 setSelection(newSelection, |
1339 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1350 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1340 FrameSelection::DoNotClearStrategy | UserTriggered, | 1351 FrameSelection::DoNotClearStrategy | UserTriggered | |
1352 FrameSelection::HandleVisible, | |
1341 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1353 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1342 } | 1354 } |
1343 | 1355 |
1344 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take | 1356 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take |
1345 // two |IntPoint| instead of two |VisiblePosition| like | 1357 // two |IntPoint| instead of two |VisiblePosition| like |
1346 // |moveRangeSelectionExtent()|. | 1358 // |moveRangeSelectionExtent()|. |
1347 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1359 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1348 const VisiblePosition& extentPosition, | 1360 const VisiblePosition& extentPosition, |
1349 TextGranularity granularity) { | 1361 TextGranularity granularity) { |
1350 VisibleSelection newSelection = createVisibleSelection( | 1362 VisibleSelection newSelection = createVisibleSelection( |
1351 SelectionInDOMTree::Builder() | 1363 SelectionInDOMTree::Builder() |
1352 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), | 1364 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), |
1353 extentPosition.deepEquivalent()) | 1365 extentPosition.deepEquivalent()) |
1354 .setAffinity(basePosition.affinity()) | 1366 .setAffinity(basePosition.affinity()) |
1355 .setGranularity(granularity) | 1367 .setGranularity(granularity) |
1356 .build()); | 1368 .build()); |
1357 | 1369 |
1358 if (newSelection.isNone()) | 1370 if (newSelection.isNone()) |
1359 return; | 1371 return; |
1360 | 1372 |
1361 setSelection(newSelection, CloseTyping | ClearTypingStyle, | 1373 SetSelectionOptions options = CloseTyping | ClearTypingStyle; |
1362 CursorAlignOnScroll::IfNeeded, granularity); | 1374 if (isHandleVisible()) |
1375 options |= HandleVisible; | |
1376 setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, | |
1377 granularity); | |
1363 } | 1378 } |
1364 | 1379 |
1365 void FrameSelection::updateIfNeeded() { | 1380 void FrameSelection::updateIfNeeded() { |
1366 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 1381 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
1367 m_selectionEditor->updateIfNeeded(); | 1382 m_selectionEditor->updateIfNeeded(); |
1368 } | 1383 } |
1369 | 1384 |
1370 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1385 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1371 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1386 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1372 : CaretVisibility::Hidden); | 1387 : CaretVisibility::Hidden); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 } | 1420 } |
1406 | 1421 |
1407 void showTree(const blink::FrameSelection* sel) { | 1422 void showTree(const blink::FrameSelection* sel) { |
1408 if (sel) | 1423 if (sel) |
1409 sel->showTreeForThis(); | 1424 sel->showTreeForThis(); |
1410 else | 1425 else |
1411 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1426 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1412 } | 1427 } |
1413 | 1428 |
1414 #endif | 1429 #endif |
OLD | NEW |