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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 Element* const editable = rootEditableElement(); | 157 Element* const editable = rootEditableElement(); |
158 if (!editable) | 158 if (!editable) |
159 return; | 159 return; |
160 | 160 |
161 const VisiblePosition position = | 161 const VisiblePosition position = |
162 visiblePositionForContentsPoint(point, frame()); | 162 visiblePositionForContentsPoint(point, frame()); |
163 SelectionInDOMTree::Builder builder; | 163 SelectionInDOMTree::Builder builder; |
164 builder.setIsDirectional(selection().isDirectional()); | 164 builder.setIsDirectional(selection().isDirectional()); |
165 if (position.isNotNull()) | 165 if (position.isNotNull()) |
166 builder.collapse(position.toPositionWithAffinity()); | 166 builder.collapse(position.toPositionWithAffinity()); |
167 setSelection(builder.build(), CloseTyping | ClearTypingStyle | UserTriggered); | 167 setSelection(builder.build(), |
| 168 CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible); |
168 } | 169 } |
169 | 170 |
170 template <typename Strategy> | 171 template <typename Strategy> |
171 void FrameSelection::setSelectionAlgorithm( | 172 void FrameSelection::setSelectionAlgorithm( |
172 const VisibleSelectionTemplate<Strategy>& newSelection, | 173 const VisibleSelectionTemplate<Strategy>& newSelection, |
173 SetSelectionOptions options, | 174 SetSelectionOptions options, |
174 CursorAlignOnScroll align, | 175 CursorAlignOnScroll align, |
175 TextGranularity granularity) { | 176 TextGranularity granularity) { |
176 DCHECK(isAvailable()); | 177 DCHECK(isAvailable()); |
177 DCHECK(newSelection.isValidFor(document())); | 178 DCHECK(newSelection.isValidFor(document())); |
178 const Document& currentDocument = document(); | 179 const Document& currentDocument = document(); |
179 if (m_granularityStrategy && | 180 if (m_granularityStrategy && |
180 (options & FrameSelection::DoNotClearStrategy) == 0) | 181 (options & FrameSelection::DoNotClearStrategy) == 0) |
181 m_granularityStrategy->Clear(); | 182 m_granularityStrategy->Clear(); |
182 bool closeTyping = options & CloseTyping; | 183 bool closeTyping = options & CloseTyping; |
183 bool shouldClearTypingStyle = options & ClearTypingStyle; | 184 bool shouldClearTypingStyle = options & ClearTypingStyle; |
| 185 const HandleVisibility handleVisibility = options & HandleVisible |
| 186 ? HandleVisibility::Visible |
| 187 : HandleVisibility::NotVisible; |
184 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 188 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
185 | 189 |
186 // TODO(editing-dev): We should rename variable |s| to another name to avoid | 190 // TODO(editing-dev): We should rename variable |s| to another name to avoid |
187 // using one letter variable name. | 191 // using one letter variable name. |
188 VisibleSelectionTemplate<Strategy> s = newSelection; | 192 VisibleSelectionTemplate<Strategy> s = newSelection; |
189 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 193 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
190 s.setIsDirectional(true); | 194 s.setIsDirectional(true); |
191 | 195 |
192 m_granularity = granularity; | 196 m_granularity = granularity; |
193 | 197 |
194 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 198 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
195 // |Editor| class. | 199 // |Editor| class. |
196 if (closeTyping) | 200 if (closeTyping) |
197 TypingCommand::closeTyping(m_frame); | 201 TypingCommand::closeTyping(m_frame); |
198 | 202 |
199 if (shouldClearTypingStyle) | 203 if (shouldClearTypingStyle) |
200 clearTypingStyle(); | 204 clearTypingStyle(); |
201 | 205 |
202 if (m_selectionEditor->visibleSelection<Strategy>() == s) { | 206 if (m_selectionEditor->visibleSelection<Strategy>() == s && |
| 207 m_handleVisibility == handleVisibility) { |
203 // Even if selection was not changed, selection offsets may have been | 208 // Even if selection was not changed, selection offsets may have been |
204 // changed. | 209 // changed. |
205 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); | 210 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); |
206 notifyLayoutObjectOfSelectionChange(userTriggered); | 211 notifyLayoutObjectOfSelectionChange(userTriggered); |
207 return; | 212 return; |
208 } | 213 } |
209 | 214 |
210 const VisibleSelectionTemplate<Strategy> oldSelection = | 215 const VisibleSelectionTemplate<Strategy> oldSelection = |
211 visibleSelection<Strategy>(); | 216 visibleSelection<Strategy>(); |
212 const Position& oldSelectionStart = selection().start(); | 217 const Position& oldSelectionStart = selection().start(); |
213 | 218 |
| 219 m_handleVisibility = handleVisibility; |
214 m_selectionEditor->setVisibleSelection(s, options); | 220 m_selectionEditor->setVisibleSelection(s, options); |
215 m_frameCaret->setCaretRectNeedsUpdate(); | 221 m_frameCaret->setCaretRectNeedsUpdate(); |
216 | 222 |
217 if (!s.isNone() && !(options & DoNotSetFocus)) { | 223 if (!s.isNone() && !(options & DoNotSetFocus)) { |
218 setFocusedNodeIfNeeded(); | 224 setFocusedNodeIfNeeded(); |
219 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and | 225 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and |
220 // "FocusIn", |m_frame| may associate to another document. | 226 // "FocusIn", |m_frame| may associate to another document. |
221 if (!isAvailable() || document() != currentDocument) { | 227 if (!isAvailable() || document() != currentDocument) { |
222 // Once we get test case to reach here, we should change this | 228 // Once we get test case to reach here, we should change this |
223 // if-statement to |DCHECK()|. | 229 // if-statement to |DCHECK()|. |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 } | 1336 } |
1331 | 1337 |
1332 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { | 1338 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { |
1333 if (isNone()) | 1339 if (isNone()) |
1334 return; | 1340 return; |
1335 | 1341 |
1336 VisibleSelection newSelection = | 1342 VisibleSelection newSelection = |
1337 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1343 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1338 setSelection(newSelection, | 1344 setSelection(newSelection, |
1339 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1345 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1340 FrameSelection::DoNotClearStrategy | UserTriggered, | 1346 FrameSelection::DoNotClearStrategy | UserTriggered | |
| 1347 FrameSelection::HandleVisible, |
1341 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1348 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1342 } | 1349 } |
1343 | 1350 |
1344 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take | 1351 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take |
1345 // two |IntPoint| instead of two |VisiblePosition| like | 1352 // two |IntPoint| instead of two |VisiblePosition| like |
1346 // |moveRangeSelectionExtent()|. | 1353 // |moveRangeSelectionExtent()|. |
1347 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1354 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1348 const VisiblePosition& extentPosition, | 1355 const VisiblePosition& extentPosition, |
1349 TextGranularity granularity) { | 1356 TextGranularity granularity) { |
1350 VisibleSelection newSelection = createVisibleSelection( | 1357 VisibleSelection newSelection = createVisibleSelection( |
1351 SelectionInDOMTree::Builder() | 1358 SelectionInDOMTree::Builder() |
1352 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), | 1359 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), |
1353 extentPosition.deepEquivalent()) | 1360 extentPosition.deepEquivalent()) |
1354 .setAffinity(basePosition.affinity()) | 1361 .setAffinity(basePosition.affinity()) |
1355 .setGranularity(granularity) | 1362 .setGranularity(granularity) |
1356 .build()); | 1363 .build()); |
1357 | 1364 |
1358 if (newSelection.isNone()) | 1365 if (newSelection.isNone()) |
1359 return; | 1366 return; |
1360 | 1367 |
1361 setSelection(newSelection, CloseTyping | ClearTypingStyle, | 1368 SetSelectionOptions options = CloseTyping | ClearTypingStyle; |
1362 CursorAlignOnScroll::IfNeeded, granularity); | 1369 if (isHandleVisible()) |
| 1370 options |= HandleVisible; |
| 1371 setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, |
| 1372 granularity); |
1363 } | 1373 } |
1364 | 1374 |
1365 void FrameSelection::updateIfNeeded() { | 1375 void FrameSelection::updateIfNeeded() { |
1366 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 1376 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
1367 m_selectionEditor->updateIfNeeded(); | 1377 m_selectionEditor->updateIfNeeded(); |
1368 } | 1378 } |
1369 | 1379 |
1370 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1380 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1371 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1381 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1372 : CaretVisibility::Hidden); | 1382 : CaretVisibility::Hidden); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 } | 1415 } |
1406 | 1416 |
1407 void showTree(const blink::FrameSelection* sel) { | 1417 void showTree(const blink::FrameSelection* sel) { |
1408 if (sel) | 1418 if (sel) |
1409 sel->showTreeForThis(); | 1419 sel->showTreeForThis(); |
1410 else | 1420 else |
1411 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1421 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1412 } | 1422 } |
1413 | 1423 |
1414 #endif | 1424 #endif |
OLD | NEW |