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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 // TODO(editing-dev): This should be done in FlatTree world. | 957 // TODO(editing-dev): This should be done in FlatTree world. |
958 void FrameSelection::RevealSelection(const ScrollAlignment& alignment, | 958 void FrameSelection::RevealSelection(const ScrollAlignment& alignment, |
959 RevealExtentOption reveal_extent_option) { | 959 RevealExtentOption reveal_extent_option) { |
960 DCHECK(IsAvailable()); | 960 DCHECK(IsAvailable()); |
961 | 961 |
962 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 962 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
963 // needs to be audited. See http://crbug.com/590369 for more details. | 963 // needs to be audited. See http://crbug.com/590369 for more details. |
964 // Calculation of absolute caret bounds requires clean layout. | 964 // Calculation of absolute caret bounds requires clean layout. |
965 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 965 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
966 | 966 |
967 const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree(); | |
968 const Position& start = selection.Start(); | |
969 DCHECK(start.AnchorNode()); | |
970 if (!start.AnchorNode() || !start.AnchorNode()->GetLayoutObject()) | |
971 return; | |
972 | |
967 LayoutRect rect; | 973 LayoutRect rect; |
yosin_UTC9
2017/07/07 05:12:51
Let's move this switch-statement into a function i
| |
968 | 974 switch (selection.GetSelectionType()) { |
969 switch (ComputeVisibleSelectionInDOMTree().GetSelectionType()) { | |
970 case kNoSelection: | 975 case kNoSelection: |
971 return; | 976 return; |
972 case kCaretSelection: | 977 case kCaretSelection: |
973 rect = LayoutRect(AbsoluteCaretBounds()); | 978 rect = LayoutRect(AbsoluteCaretBounds()); |
974 break; | 979 break; |
975 case kRangeSelection: | 980 case kRangeSelection: { |
976 rect = LayoutRect( | 981 rect = LayoutRect( |
977 reveal_extent_option == kRevealExtent | 982 reveal_extent_option == kRevealExtent |
978 ? AbsoluteCaretBoundsOf(CreateVisiblePosition( | 983 ? AbsoluteCaretBoundsOf(CreateVisiblePosition(selection.Extent())) |
979 ComputeVisibleSelectionInDOMTree().Extent())) | |
980 : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree())); | 984 : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree())); |
981 break; | 985 break; |
986 } | |
982 } | 987 } |
983 | 988 |
984 Position start = ComputeVisibleSelectionInDOMTree().Start(); | 989 // FIXME: This code only handles scrolling the startContainer's layer, but |
985 DCHECK(start.AnchorNode()); | 990 // the selection rect could intersect more than just that. |
986 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { | 991 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
987 // FIXME: This code only handles scrolling the startContainer's layer, but | 992 document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
988 // the selection rect could intersect more than just that. | 993 if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
989 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) | 994 rect, alignment, alignment)) |
990 document_loader->GetInitialScrollState().was_scrolled_by_user = true; | 995 return; |
991 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( | 996 |
992 rect, alignment, alignment)) | 997 UpdateAppearance(); |
993 UpdateAppearance(); | |
994 } | |
995 } | 998 } |
996 | 999 |
997 void FrameSelection::SetSelectionFromNone() { | 1000 void FrameSelection::SetSelectionFromNone() { |
998 // Put a caret inside the body if the entire frame is editable (either the | 1001 // Put a caret inside the body if the entire frame is editable (either the |
999 // entire WebView is editable or designMode is on for this document). | 1002 // entire WebView is editable or designMode is on for this document). |
1000 | 1003 |
1001 Document* document = frame_->GetDocument(); | 1004 Document* document = frame_->GetDocument(); |
1002 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || | 1005 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || |
1003 !(blink::HasEditableStyle(*document))) | 1006 !(blink::HasEditableStyle(*document))) |
1004 return; | 1007 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 } | 1185 } |
1183 | 1186 |
1184 void showTree(const blink::FrameSelection* sel) { | 1187 void showTree(const blink::FrameSelection* sel) { |
1185 if (sel) | 1188 if (sel) |
1186 sel->ShowTreeForThis(); | 1189 sel->ShowTreeForThis(); |
1187 else | 1190 else |
1188 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1191 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1189 } | 1192 } |
1190 | 1193 |
1191 #endif | 1194 #endif |
OLD | NEW |