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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 211 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
212 // |Editor| class. | 212 // |Editor| class. |
213 if (close_typing) | 213 if (close_typing) |
214 TypingCommand::CloseTyping(frame_); | 214 TypingCommand::CloseTyping(frame_); |
215 | 215 |
216 if (should_clear_typing_style) | 216 if (should_clear_typing_style) |
217 frame_->GetEditor().ClearTypingStyle(); | 217 frame_->GetEditor().ClearTypingStyle(); |
218 | 218 |
219 const SelectionInDOMTree old_selection_in_dom_tree = | 219 const SelectionInDOMTree old_selection_in_dom_tree = |
220 selection_editor_->GetSelectionInDOMTree(); | 220 selection_editor_->GetSelectionInDOMTree(); |
221 if (old_selection_in_dom_tree == new_selection) | 221 if (old_selection_in_dom_tree == new_selection) { |
222 // Even if DOM representation of text selection is not changed, | |
223 // selectionStart / selectionEnd IDL attributes of a text control can be | |
224 // changed. | |
yoichio
2017/05/12 01:54:00
Could you explain why?
tkent
2017/05/12 02:01:01
e.g.
DIV id=inner-editor
#text "line-1\n"
#te
| |
225 NotifyTextControlOfSelectionChange( | |
yosin_UTC9
2017/05/12 01:37:00
Can we update cached selection in "webkitEditableC
tkent
2017/05/12 02:01:01
Patch Set 3 follows it.
Yes, handling in TextCont
| |
226 SelectionOptionsToUserTriggered(options)); | |
222 return false; | 227 return false; |
228 } | |
223 selection_editor_->SetSelection(new_selection); | 229 selection_editor_->SetSelection(new_selection); |
224 ScheduleVisualUpdateForPaintInvalidationIfNeeded(); | 230 ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
225 | 231 |
226 const Document& current_document = GetDocument(); | 232 const Document& current_document = GetDocument(); |
227 // TODO(yosin): We should get rid of unsued |options| for | 233 // TODO(yosin): We should get rid of unsued |options| for |
228 // |Editor::respondToChangedSelection()|. | 234 // |Editor::respondToChangedSelection()|. |
229 // Note: Since, setting focus can modify DOM tree, we should use | 235 // Note: Since, setting focus can modify DOM tree, we should use |
230 // |oldSelection| before setting focus | 236 // |oldSelection| before setting focus |
231 frame_->GetEditor().RespondToChangedSelection( | 237 frame_->GetEditor().RespondToChangedSelection( |
232 old_selection_in_dom_tree.ComputeStartPosition(), options); | 238 old_selection_in_dom_tree.ComputeStartPosition(), options); |
(...skipping 29 matching lines...) Expand all Loading... | |
262 SelectFrameElementInParentIfFullySelected(); | 268 SelectFrameElementInParentIfFullySelected(); |
263 if (!IsAvailable() || GetDocument() != current_document) { | 269 if (!IsAvailable() || GetDocument() != current_document) { |
264 // editing/selection/selectallchildren-crash.html and | 270 // editing/selection/selectallchildren-crash.html and |
265 // editing/selection/longpress-selection-in-iframe-removed-crash.html | 271 // editing/selection/longpress-selection-in-iframe-removed-crash.html |
266 // reach here. | 272 // reach here. |
267 return; | 273 return; |
268 } | 274 } |
269 } | 275 } |
270 | 276 |
271 EUserTriggered user_triggered = SelectionOptionsToUserTriggered(options); | 277 EUserTriggered user_triggered = SelectionOptionsToUserTriggered(options); |
272 NotifyLayoutObjectOfSelectionChange(user_triggered); | 278 NotifyTextControlOfSelectionChange(user_triggered); |
273 if (user_triggered == kUserTriggered) { | 279 if (user_triggered == kUserTriggered) { |
274 ScrollAlignment alignment; | 280 ScrollAlignment alignment; |
275 | 281 |
276 if (frame_->GetEditor() | 282 if (frame_->GetEditor() |
277 .Behavior() | 283 .Behavior() |
278 .ShouldCenterAlignWhenSelectionIsRevealed()) | 284 .ShouldCenterAlignWhenSelectionIsRevealed()) |
279 alignment = (align == CursorAlignOnScroll::kAlways) | 285 alignment = (align == CursorAlignOnScroll::kAlways) |
280 ? ScrollAlignment::kAlignCenterAlways | 286 ? ScrollAlignment::kAlignCenterAlways |
281 : ScrollAlignment::kAlignCenterIfNeeded; | 287 : ScrollAlignment::kAlignCenterIfNeeded; |
282 else | 288 else |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 // |root| may be detached due to selectstart event. | 707 // |root| may be detached due to selectstart event. |
702 if (!root->isConnected() || expected_document != root->GetDocument()) | 708 if (!root->isConnected() || expected_document != root->GetDocument()) |
703 return; | 709 return; |
704 } | 710 } |
705 | 711 |
706 SetSelection(SelectionInDOMTree::Builder() | 712 SetSelection(SelectionInDOMTree::Builder() |
707 .SelectAllChildren(*root) | 713 .SelectAllChildren(*root) |
708 .SetIsHandleVisible(IsHandleVisible()) | 714 .SetIsHandleVisible(IsHandleVisible()) |
709 .Build()); | 715 .Build()); |
710 SelectFrameElementInParentIfFullySelected(); | 716 SelectFrameElementInParentIfFullySelected(); |
711 NotifyLayoutObjectOfSelectionChange(kUserTriggered); | 717 NotifyTextControlOfSelectionChange(kUserTriggered); |
712 } | 718 } |
713 | 719 |
714 bool FrameSelection::SetSelectedRange(const EphemeralRange& range, | 720 bool FrameSelection::SetSelectedRange(const EphemeralRange& range, |
715 TextAffinity affinity, | 721 TextAffinity affinity, |
716 SelectionDirectionalMode directional, | 722 SelectionDirectionalMode directional, |
717 SetSelectionOptions options) { | 723 SetSelectionOptions options) { |
718 if (range.IsNull()) | 724 if (range.IsNull()) |
719 return false; | 725 return false; |
720 SetSelection(SelectionInDOMTree::Builder() | 726 SetSelection(SelectionInDOMTree::Builder() |
721 .SetBaseAndExtent(range) | 727 .SetBaseAndExtent(range) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 void FrameSelection::DidLayout() { | 839 void FrameSelection::DidLayout() { |
834 UpdateAppearance(); | 840 UpdateAppearance(); |
835 } | 841 } |
836 | 842 |
837 void FrameSelection::UpdateAppearance() { | 843 void FrameSelection::UpdateAppearance() { |
838 DCHECK(!frame_->ContentLayoutItem().IsNull()); | 844 DCHECK(!frame_->ContentLayoutItem().IsNull()); |
839 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); | 845 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
840 layout_selection_->SetHasPendingSelection(); | 846 layout_selection_->SetHasPendingSelection(); |
841 } | 847 } |
842 | 848 |
843 void FrameSelection::NotifyLayoutObjectOfSelectionChange( | 849 void FrameSelection::NotifyTextControlOfSelectionChange( |
844 EUserTriggered user_triggered) { | 850 EUserTriggered user_triggered) { |
845 TextControlElement* text_control = | 851 TextControlElement* text_control = |
846 EnclosingTextControl(GetSelectionInDOMTree().Base()); | 852 EnclosingTextControl(GetSelectionInDOMTree().Base()); |
847 if (!text_control) | 853 if (!text_control) |
848 return; | 854 return; |
849 text_control->SelectionChanged(user_triggered == kUserTriggered); | 855 text_control->SelectionChanged(user_triggered == kUserTriggered); |
850 } | 856 } |
851 | 857 |
852 // Helper function that tells whether a particular node is an element that has | 858 // Helper function that tells whether a particular node is an element that has |
853 // an entire LocalFrame and FrameView, a <frame>, <iframe>, or <object>. | 859 // an entire LocalFrame and FrameView, a <frame>, <iframe>, or <object>. |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1218 } | 1224 } |
1219 | 1225 |
1220 void showTree(const blink::FrameSelection* sel) { | 1226 void showTree(const blink::FrameSelection* sel) { |
1221 if (sel) | 1227 if (sel) |
1222 sel->ShowTreeForThis(); | 1228 sel->ShowTreeForThis(); |
1223 else | 1229 else |
1224 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1230 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1225 } | 1231 } |
1226 | 1232 |
1227 #endif | 1233 #endif |
OLD | NEW |