| 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 // No focused element means document root has focus. |
| 340 const Element* const focus = GetDocument().FocusedElement() |
| 341 ? GetDocument().FocusedElement() |
| 342 : GetDocument().documentElement(); |
| 343 |
| 344 // Protection against LayoutTests/editing/selection/selection-crash.html |
| 345 if (!focus) { |
| 346 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| 347 text_control_focused_ = false; |
| 348 return; |
| 349 } |
| 350 |
| 351 // Hide the selection when focus goes away from a text-field and into |
| 352 // something that is not a text-field. When focus enters another text-field we |
| 353 // do not need to update appearance; the appearance is updated when the new |
| 354 // selection is set. |
| 355 if (text_control_focused_ && !focus->IsTextControl()) |
| 356 UpdateAppearance(LayoutSelection::PaintHint::kHide); |
| 357 text_control_focused_ = focus->IsTextControl(); |
| 339 } | 358 } |
| 340 | 359 |
| 341 static DispatchEventResult DispatchSelectStart( | 360 static DispatchEventResult DispatchSelectStart( |
| 342 const VisibleSelection& selection) { | 361 const VisibleSelection& selection) { |
| 343 Node* select_start_target = selection.Extent().ComputeContainerNode(); | 362 Node* select_start_target = selection.Extent().ComputeContainerNode(); |
| 344 if (!select_start_target) | 363 if (!select_start_target) |
| 345 return DispatchEventResult::kNotCanceled; | 364 return DispatchEventResult::kNotCanceled; |
| 346 | 365 |
| 347 return select_start_target->DispatchEvent( | 366 return select_start_target->DispatchEvent( |
| 348 Event::CreateCancelableBubble(EventTypeNames::selectstart)); | 367 Event::CreateCancelableBubble(EventTypeNames::selectstart)); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 785 |
| 767 bool FrameSelection::NeedsLayoutSelectionUpdate() const { | 786 bool FrameSelection::NeedsLayoutSelectionUpdate() const { |
| 768 return layout_selection_->HasPendingSelection(); | 787 return layout_selection_->HasPendingSelection(); |
| 769 } | 788 } |
| 770 | 789 |
| 771 void FrameSelection::CommitAppearanceIfNeeded(LayoutView& layout_view) { | 790 void FrameSelection::CommitAppearanceIfNeeded(LayoutView& layout_view) { |
| 772 return layout_selection_->Commit(layout_view); | 791 return layout_selection_->Commit(layout_view); |
| 773 } | 792 } |
| 774 | 793 |
| 775 void FrameSelection::DidLayout() { | 794 void FrameSelection::DidLayout() { |
| 776 UpdateAppearance(); | 795 // Upon relayout, a hidden selection must be kept hidden and a visible |
| 796 // selection must be kept visible. |
| 797 UpdateAppearance(LayoutSelection::PaintHint::kKeep); |
| 777 } | 798 } |
| 778 | 799 |
| 779 void FrameSelection::UpdateAppearance() { | 800 void FrameSelection::UpdateAppearance(LayoutSelection::PaintHint hint) { |
| 780 DCHECK(!frame_->ContentLayoutItem().IsNull()); | 801 DCHECK(!frame_->ContentLayoutItem().IsNull()); |
| 781 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); | 802 frame_caret_->ScheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| 782 layout_selection_->SetHasPendingSelection(); | 803 layout_selection_->SetHasPendingSelection(hint); |
| 783 } | 804 } |
| 784 | 805 |
| 785 void FrameSelection::NotifyLayoutObjectOfSelectionChange( | 806 void FrameSelection::NotifyLayoutObjectOfSelectionChange( |
| 786 EUserTriggered user_triggered) { | 807 EUserTriggered user_triggered) { |
| 787 TextControlElement* text_control = | 808 TextControlElement* text_control = |
| 788 EnclosingTextControl(GetSelectionInDOMTree().Base()); | 809 EnclosingTextControl(GetSelectionInDOMTree().Base()); |
| 789 if (!text_control) | 810 if (!text_control) |
| 790 return; | 811 return; |
| 791 text_control->SelectionChanged(user_triggered == kUserTriggered); | 812 text_control->SelectionChanged(user_triggered == kUserTriggered); |
| 792 } | 813 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 | 982 |
| 962 Position start = ComputeVisibleSelectionInDOMTreeDeprecated().Start(); | 983 Position start = ComputeVisibleSelectionInDOMTreeDeprecated().Start(); |
| 963 DCHECK(start.AnchorNode()); | 984 DCHECK(start.AnchorNode()); |
| 964 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { | 985 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { |
| 965 // FIXME: This code only handles scrolling the startContainer's layer, but | 986 // FIXME: This code only handles scrolling the startContainer's layer, but |
| 966 // the selection rect could intersect more than just that. | 987 // the selection rect could intersect more than just that. |
| 967 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) | 988 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
| 968 document_loader->GetInitialScrollState().was_scrolled_by_user = true; | 989 document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| 969 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( | 990 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
| 970 rect, alignment, alignment)) | 991 rect, alignment, alignment)) |
| 971 UpdateAppearance(); | 992 UpdateAppearance(LayoutSelection::PaintHint::kPaint); |
| 972 } | 993 } |
| 973 } | 994 } |
| 974 | 995 |
| 975 void FrameSelection::SetSelectionFromNone() { | 996 void FrameSelection::SetSelectionFromNone() { |
| 976 // Put a caret inside the body if the entire frame is editable (either the | 997 // Put a caret inside the body if the entire frame is editable (either the |
| 977 // entire WebView is editable or designMode is on for this document). | 998 // entire WebView is editable or designMode is on for this document). |
| 978 | 999 |
| 979 Document* document = frame_->GetDocument(); | 1000 Document* document = frame_->GetDocument(); |
| 980 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || | 1001 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || |
| 981 !(blink::HasEditableStyle(*document))) | 1002 !(blink::HasEditableStyle(*document))) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 } | 1181 } |
| 1161 | 1182 |
| 1162 void showTree(const blink::FrameSelection* sel) { | 1183 void showTree(const blink::FrameSelection* sel) { |
| 1163 if (sel) | 1184 if (sel) |
| 1164 sel->ShowTreeForThis(); | 1185 sel->ShowTreeForThis(); |
| 1165 else | 1186 else |
| 1166 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1187 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
| 1167 } | 1188 } |
| 1168 | 1189 |
| 1169 #endif | 1190 #endif |
| OLD | NEW |