Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2972153002: Refactor FrameSelection::RevealSelection (Closed)
Patch Set: clang fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (selection.GetSelectionType() == kNoSelection)
969 return;
970
967 LayoutRect rect; 971 LayoutRect rect;
968 972 switch (selection.GetSelectionType()) {
969 switch (ComputeVisibleSelectionInDOMTree().GetSelectionType()) {
970 case kNoSelection:
971 return;
972 case kCaretSelection: 973 case kCaretSelection:
973 rect = LayoutRect(AbsoluteCaretBounds()); 974 rect = LayoutRect(AbsoluteCaretBounds());
974 break; 975 break;
975 case kRangeSelection: 976 case kRangeSelection: {
976 rect = LayoutRect( 977 rect = LayoutRect(
977 reveal_extent_option == kRevealExtent 978 reveal_extent_option == kRevealExtent
978 ? AbsoluteCaretBoundsOf(CreateVisiblePosition( 979 ? AbsoluteCaretBoundsOf(CreateVisiblePosition(selection.Extent()))
979 ComputeVisibleSelectionInDOMTree().Extent()))
980 : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree())); 980 : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree()));
981 break; 981 break;
982 }
983 default:
984 NOTREACHED();
985 break;
982 } 986 }
983 987
984 Position start = ComputeVisibleSelectionInDOMTree().Start(); 988 // FIXME: This code only handles scrolling the startContainer's layer, but
989 // the selection rect could intersect more than just that.
990 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader())
991 document_loader->GetInitialScrollState().was_scrolled_by_user = true;
992 const Position& start = selection.Start();
985 DCHECK(start.AnchorNode()); 993 DCHECK(start.AnchorNode());
986 if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { 994 DCHECK(start.AnchorNode()->GetLayoutObject());
987 // FIXME: This code only handles scrolling the startContainer's layer, but 995 if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible(
988 // the selection rect could intersect more than just that. 996 rect, alignment, alignment))
989 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) 997 return;
990 document_loader->GetInitialScrollState().was_scrolled_by_user = true; 998
991 if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( 999 UpdateAppearance();
992 rect, alignment, alignment))
993 UpdateAppearance();
994 }
995 } 1000 }
996 1001
997 void FrameSelection::SetSelectionFromNone() { 1002 void FrameSelection::SetSelectionFromNone() {
998 // Put a caret inside the body if the entire frame is editable (either the 1003 // 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). 1004 // entire WebView is editable or designMode is on for this document).
1000 1005
1001 Document* document = frame_->GetDocument(); 1006 Document* document = frame_->GetDocument();
1002 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() || 1007 if (!ComputeVisibleSelectionInDOMTreeDeprecated().IsNone() ||
1003 !(blink::HasEditableStyle(*document))) 1008 !(blink::HasEditableStyle(*document)))
1004 return; 1009 return;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 } 1187 }
1183 1188
1184 void showTree(const blink::FrameSelection* sel) { 1189 void showTree(const blink::FrameSelection* sel) {
1185 if (sel) 1190 if (sel)
1186 sel->ShowTreeForThis(); 1191 sel->ShowTreeForThis();
1187 else 1192 else
1188 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1193 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1189 } 1194 }
1190 1195
1191 #endif 1196 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698