| 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 LocalFrameView* view = frame_->View(); | 940 LocalFrameView* view = frame_->View(); |
| 941 LayoutViewItem layout_view = frame_->ContentLayoutItem(); | 941 LayoutViewItem layout_view = frame_->ContentLayoutItem(); |
| 942 | 942 |
| 943 if (!view || layout_view.IsNull()) | 943 if (!view || layout_view.IsNull()) |
| 944 return LayoutRect(); | 944 return LayoutRect(); |
| 945 | 945 |
| 946 view->UpdateLifecycleToLayoutClean(); | 946 view->UpdateLifecycleToLayoutClean(); |
| 947 return LayoutRect(layout_selection_->SelectionBounds()); | 947 return LayoutRect(layout_selection_->SelectionBounds()); |
| 948 } | 948 } |
| 949 | 949 |
| 950 static IntRect AbsoluteSelectionBoundsOf( | 950 IntRect FrameSelection::ComputeRectToScroll( |
| 951 const VisibleSelectionInFlatTree& selection) { | 951 RevealExtentOption reveal_extent_option) { |
| 952 return ComputeTextRect( | 952 const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree(); |
| 953 EphemeralRangeInFlatTree(selection.Start(), selection.End())); | 953 LayoutRect rect; |
| 954 switch (selection.GetSelectionType()) { |
| 955 case kCaretSelection: |
| 956 return AbsoluteCaretBounds(); |
| 957 case kRangeSelection: { |
| 958 if (reveal_extent_option == kRevealExtent) |
| 959 return AbsoluteCaretBoundsOf(CreateVisiblePosition(selection.Extent())); |
| 960 layout_selection_->SetHasPendingSelection(); |
| 961 return layout_selection_->SelectionBounds(); |
| 962 } |
| 963 default: |
| 964 NOTREACHED(); |
| 965 return {}; |
| 966 } |
| 954 } | 967 } |
| 955 | 968 |
| 956 // TODO(editing-dev): This should be done in FlatTree world. | 969 // TODO(editing-dev): This should be done in FlatTree world. |
| 957 void FrameSelection::RevealSelection(const ScrollAlignment& alignment, | 970 void FrameSelection::RevealSelection(const ScrollAlignment& alignment, |
| 958 RevealExtentOption reveal_extent_option) { | 971 RevealExtentOption reveal_extent_option) { |
| 959 DCHECK(IsAvailable()); | 972 DCHECK(IsAvailable()); |
| 960 | 973 |
| 961 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 974 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 962 // needs to be audited. See http://crbug.com/590369 for more details. | 975 // needs to be audited. See http://crbug.com/590369 for more details. |
| 963 // Calculation of absolute caret bounds requires clean layout. | 976 // Calculation of absolute caret bounds requires clean layout. |
| 964 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 977 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 965 | 978 |
| 966 const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree(); | 979 const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree(); |
| 967 if (selection.GetSelectionType() == kNoSelection) | 980 if (selection.GetSelectionType() == kNoSelection) |
| 968 return; | 981 return; |
| 969 | 982 |
| 970 LayoutRect rect; | |
| 971 switch (selection.GetSelectionType()) { | |
| 972 case kCaretSelection: | |
| 973 rect = LayoutRect(AbsoluteCaretBounds()); | |
| 974 break; | |
| 975 case kRangeSelection: { | |
| 976 rect = LayoutRect( | |
| 977 reveal_extent_option == kRevealExtent | |
| 978 ? AbsoluteCaretBoundsOf(CreateVisiblePosition(selection.Extent())) | |
| 979 : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree())); | |
| 980 break; | |
| 981 } | |
| 982 default: | |
| 983 NOTREACHED(); | |
| 984 break; | |
| 985 } | |
| 986 | |
| 987 // FIXME: This code only handles scrolling the startContainer's layer, but | 983 // FIXME: This code only handles scrolling the startContainer's layer, but |
| 988 // the selection rect could intersect more than just that. | 984 // the selection rect could intersect more than just that. |
| 989 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) | 985 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
| 990 document_loader->GetInitialScrollState().was_scrolled_by_user = true; | 986 document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| 991 const Position& start = selection.Start(); | 987 const Position& start = selection.Start(); |
| 992 DCHECK(start.AnchorNode()); | 988 DCHECK(start.AnchorNode()); |
| 993 DCHECK(start.AnchorNode()->GetLayoutObject()); | 989 DCHECK(start.AnchorNode()->GetLayoutObject()); |
| 994 if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( | 990 if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
| 995 rect, alignment, alignment)) | 991 LayoutRect(ComputeRectToScroll(reveal_extent_option)), alignment, |
| 992 alignment)) |
| 996 return; | 993 return; |
| 997 | 994 |
| 998 UpdateAppearance(); | 995 UpdateAppearance(); |
| 999 } | 996 } |
| 1000 | 997 |
| 1001 void FrameSelection::SetSelectionFromNone() { | 998 void FrameSelection::SetSelectionFromNone() { |
| 1002 // Put a caret inside the body if the entire frame is editable (either the | 999 // Put a caret inside the body if the entire frame is editable (either the |
| 1003 // entire WebView is editable or designMode is on for this document). | 1000 // entire WebView is editable or designMode is on for this document). |
| 1004 | 1001 |
| 1005 Document* document = frame_->GetDocument(); | 1002 Document* document = frame_->GetDocument(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 } | 1197 } |
| 1201 | 1198 |
| 1202 void showTree(const blink::FrameSelection* sel) { | 1199 void showTree(const blink::FrameSelection* sel) { |
| 1203 if (sel) | 1200 if (sel) |
| 1204 sel->ShowTreeForThis(); | 1201 sel->ShowTreeForThis(); |
| 1205 else | 1202 else |
| 1206 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1203 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
| 1207 } | 1204 } |
| 1208 | 1205 |
| 1209 #endif | 1206 #endif |
| OLD | NEW |