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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 // "FocusIn", |m_frame| may associate to another document. | 243 // "FocusIn", |m_frame| may associate to another document. |
244 if (!IsAvailable() || GetDocument() != current_document) { | 244 if (!IsAvailable() || GetDocument() != current_document) { |
245 // Once we get test case to reach here, we should change this | 245 // Once we get test case to reach here, we should change this |
246 // if-statement to |DCHECK()|. | 246 // if-statement to |DCHECK()|. |
247 NOTREACHED(); | 247 NOTREACHED(); |
248 return; | 248 return; |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 frame_caret_->StopCaretBlinkTimer(); | 252 frame_caret_->StopCaretBlinkTimer(); |
253 UpdateAppearance(); | 253 UpdateAppearance(LayoutSelection::PaintHint::kPaint); |
254 | 254 |
255 // Always clear the x position used for vertical arrow navigation. | 255 // Always clear the x position used for vertical arrow navigation. |
256 // It will be restored by the vertical arrow navigation code if necessary. | 256 // It will be restored by the vertical arrow navigation code if necessary. |
257 x_pos_for_vertical_arrow_navigation_ = NoXPosForVerticalArrowNavigation(); | 257 x_pos_for_vertical_arrow_navigation_ = NoXPosForVerticalArrowNavigation(); |
258 | 258 |
259 // TODO(yosin): Can we move this to at end of this function? | 259 // TODO(yosin): Can we move this to at end of this function? |
260 // This may dispatch a synchronous focus-related events. | 260 // This may dispatch a synchronous focus-related events. |
261 if (!(options & kDoNotSetFocus)) { | 261 if (!(options & kDoNotSetFocus)) { |
262 SelectFrameElementInParentIfFullySelected(); | 262 SelectFrameElementInParentIfFullySelected(); |
263 if (!IsAvailable() || GetDocument() != current_document) { | 263 if (!IsAvailable() || GetDocument() != current_document) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 328 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
329 // |Editor| class. | 329 // |Editor| class. |
330 if (!GetDocument().IsRunningExecCommand()) | 330 if (!GetDocument().IsRunningExecCommand()) |
331 TypingCommand::CloseTyping(frame_); | 331 TypingCommand::CloseTyping(frame_); |
332 } | 332 } |
333 | 333 |
334 void FrameSelection::DidChangeFocus() { | 334 void FrameSelection::DidChangeFocus() { |
335 // Hits in | 335 // Hits in |
336 // virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disable d.html | 336 // virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disable d.html |
337 DisableCompositingQueryAsserts disabler; | 337 DisableCompositingQueryAsserts disabler; |
338 UpdateAppearance(); | 338 |
339 const Element* focus = GetDocument().FocusedElement(); | |
yosin_UTC9
2017/04/13 09:31:50
Since Document::FocusedElement() is simple getter.
hugoh_UTC2
2017/04/14 01:34:47
Done. (But the comment must go above the ternary o
| |
340 if (!focus) { | |
341 // No focused element means document root has focus. | |
342 focus = GetDocument().documentElement(); | |
343 if (!focus) | |
344 return; | |
yosin_UTC9
2017/04/13 09:31:50
We still need to call
frame_caret_->ScheduleVisual
hugoh_UTC2
2017/04/14 01:34:47
Done.
| |
345 } | |
346 // Hide the selection when focus goes away from a text-field and into | |
347 // something that is not a text-field. When focus enters another text-field we | |
348 // do not need to update appearance; the appearance is updated when the new | |
349 // selection is set. | |
350 if (text_control_focus_ && !focus->IsTextControl()) | |
351 UpdateAppearance(LayoutSelection::PaintHint::kHide); | |
352 text_control_focus_ = focus->IsTextControl(); | |
339 } | 353 } |
340 | 354 |
341 static DispatchEventResult DispatchSelectStart( | 355 static DispatchEventResult DispatchSelectStart( |
342 const VisibleSelection& selection) { | 356 const VisibleSelection& selection) { |
343 Node* select_start_target = selection.Extent().ComputeContainerNode(); | 357 Node* select_start_target = selection.Extent().ComputeContainerNode(); |
344 if (!select_start_target) | 358 if (!select_start_target) |
345 return DispatchEventResult::kNotCanceled; | 359 return DispatchEventResult::kNotCanceled; |
346 | 360 |
347 return select_start_target->DispatchEvent( | 361 return select_start_target->DispatchEvent( |
348 Event::CreateCancelableBubble(EventTypeNames::selectstart)); | 362 Event::CreateCancelableBubble(EventTypeNames::selectstart)); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 | 780 |
767 bool FrameSelection::IsAppearanceDirty() const { | 781 bool FrameSelection::IsAppearanceDirty() const { |
768 return layout_selection_->HasPendingSelection(); | 782 return layout_selection_->HasPendingSelection(); |
769 } | 783 } |
770 | 784 |
771 void FrameSelection::CommitAppearanceIfNeeded(LayoutView& layout_view) { | 785 void FrameSelection::CommitAppearanceIfNeeded(LayoutView& layout_view) { |
772 return layout_selection_->Commit(layout_view); | 786 return layout_selection_->Commit(layout_view); |
773 } | 787 } |
774 | 788 |
775 void FrameSelection::DidLayout() { | 789 void FrameSelection::DidLayout() { |
776 UpdateAppearance(); | 790 // Upon relayout, a hidden selection must be kept hidden and a visible |
791 // selection must be kept visible. | |
792 UpdateAppearance(LayoutSelection::PaintHint::kKeep); | |
777 } | 793 } |
778 | 794 |
779 void FrameSelection::UpdateAppearance() { | 795 void FrameSelection::UpdateAppearance(LayoutSelection::PaintHint hint) { |
780 DCHECK(!frame_->ContentLayoutItem().IsNull()); | 796 DCHECK(!frame_->ContentLayoutItem().IsNull()); |
781 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); | 797 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
782 layout_selection_->SetHasPendingSelection(); | 798 layout_selection_->SetHasPendingSelection(hint); |
783 } | 799 } |
784 | 800 |
785 void FrameSelection::NotifyLayoutObjectOfSelectionChange( | 801 void FrameSelection::NotifyLayoutObjectOfSelectionChange( |
786 EUserTriggered user_triggered) { | 802 EUserTriggered user_triggered) { |
787 TextControlElement* text_control = | 803 TextControlElement* text_control = |
788 EnclosingTextControl(GetSelectionInDOMTree().Base()); | 804 EnclosingTextControl(GetSelectionInDOMTree().Base()); |
789 if (!text_control) | 805 if (!text_control) |
790 return; | 806 return; |
791 text_control->SelectionChanged(user_triggered == kUserTriggered); | 807 text_control->SelectionChanged(user_triggered == kUserTriggered); |
792 } | 808 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 | 979 |
964 Position start = ComputeVisibleSelectionInDOMTreeDeprecated().Start(); | 980 Position start = ComputeVisibleSelectionInDOMTreeDeprecated().Start(); |
965 DCHECK(start.AnchorNode()); | 981 DCHECK(start.AnchorNode()); |
966 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { | 982 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { |
967 // FIXME: This code only handles scrolling the startContainer's layer, but | 983 // FIXME: This code only handles scrolling the startContainer's layer, but |
968 // the selection rect could intersect more than just that. | 984 // the selection rect could intersect more than just that. |
969 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) | 985 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
970 document_loader->GetInitialScrollState().was_scrolled_by_user = true; | 986 document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
971 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( | 987 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
972 rect, alignment, alignment)) | 988 rect, alignment, alignment)) |
973 UpdateAppearance(); | 989 UpdateAppearance(LayoutSelection::PaintHint::kPaint); |
974 } | 990 } |
975 } | 991 } |
976 | 992 |
977 void FrameSelection::SetSelectionFromNone() { | 993 void FrameSelection::SetSelectionFromNone() { |
978 // Put a caret inside the body if the entire frame is editable (either the | 994 // Put a caret inside the body if the entire frame is editable (either the |
979 // entire WebView is editable or designMode is on for this document). | 995 // entire WebView is editable or designMode is on for this document). |
980 | 996 |
981 Document* document = frame_->GetDocument(); | 997 Document* document = frame_->GetDocument(); |
982 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || | 998 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || |
983 !(blink::HasEditableStyle(*document))) | 999 !(blink::HasEditableStyle(*document))) |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 } | 1178 } |
1163 | 1179 |
1164 void showTree(const blink::FrameSelection* sel) { | 1180 void showTree(const blink::FrameSelection* sel) { |
1165 if (sel) | 1181 if (sel) |
1166 sel->ShowTreeForThis(); | 1182 sel->ShowTreeForThis(); |
1167 else | 1183 else |
1168 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1184 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1169 } | 1185 } |
1170 | 1186 |
1171 #endif | 1187 #endif |
OLD | NEW |