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

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

Issue 1182253004: Templatize FrameSelection::contains function (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-18T14:44:59 Created 5 years, 6 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 | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/VisibleSelection.h » ('j') | 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 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1286 }
1287 1287
1288 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect) 1288 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect)
1289 { 1289 {
1290 if (m_selection.isCaret() && m_shouldPaintCaret) { 1290 if (m_selection.isCaret() && m_shouldPaintCaret) {
1291 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st art(), m_selection.affinity())); 1291 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st art(), m_selection.affinity()));
1292 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect); 1292 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect);
1293 } 1293 }
1294 } 1294 }
1295 1295
1296 bool FrameSelection::contains(const LayoutPoint& point) 1296 template <typename Strategy>
yoichio 2015/06/18 07:59:14 VisibleSelection::InDOMTree does not look like oth
1297 bool FrameSelection::containsAlgorithm(const LayoutPoint& point)
1297 { 1298 {
1299 using PositionType = typename Strategy::PositionType;
1300
1298 Document* document = m_frame->document(); 1301 Document* document = m_frame->document();
1299 1302
1300 // Treat a collapsed selection like no selection. 1303 // Treat a collapsed selection like no selection.
1301 if (!isRange()) 1304 if (!isRange())
1302 return false; 1305 return false;
1303 if (!document->layoutView()) 1306 if (!document->layoutView())
1304 return false; 1307 return false;
1305 1308
1306 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); 1309 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
1307 HitTestResult result(request, point); 1310 HitTestResult result(request, point);
1308 document->layoutView()->hitTest(result); 1311 document->layoutView()->hitTest(result);
1309 Node* innerNode = result.innerNode(); 1312 Node* innerNode = result.innerNode();
1310 if (!innerNode || !innerNode->layoutObject()) 1313 if (!innerNode || !innerNode->layoutObject())
1311 return false; 1314 return false;
1312 1315
1313 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(resul t.localPoint())); 1316 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(resul t.localPoint()));
1314 if (visiblePos.isNull()) 1317 if (visiblePos.isNull())
1315 return false; 1318 return false;
1316 1319
1317 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull() ) 1320 VisiblePosition visibleStart = Strategy::selectionVisibleStart(m_selection);
1321 VisiblePosition visibleEnd = Strategy::selectionVisibleEnd(m_selection);
1322 if (visibleStart.isNull() || visibleEnd.isNull())
1318 return false; 1323 return false;
1319 1324
1320 Position start(m_selection.visibleStart().deepEquivalent()); 1325 PositionType start(Strategy::toPositionType(visibleStart.deepEquivalent()));
1321 Position end(m_selection.visibleEnd().deepEquivalent()); 1326 PositionType end(Strategy::toPositionType(visibleEnd.deepEquivalent()));
1322 Position p(visiblePos.deepEquivalent()); 1327 PositionType pos(Strategy::toPositionType(visiblePos.deepEquivalent()));
1328 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0;
1329 }
1323 1330
1324 return comparePositions(start, p) <= 0 && comparePositions(p, end) <= 0; 1331 bool FrameSelection::contains(const LayoutPoint& point)
1332 {
1333 return containsAlgorithm<VisibleSelection::InDOMTree>(point);
1325 } 1334 }
1326 1335
1327 // Workaround for the fact that it's hard to delete a frame. 1336 // Workaround for the fact that it's hard to delete a frame.
1328 // Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected. 1337 // Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected.
1329 // Can't do this implicitly as part of every setSelection call because in some c ontexts it might not be good 1338 // Can't do this implicitly as part of every setSelection call because in some c ontexts it might not be good
1330 // for the focus to move to another frame. So instead we call it from places whe re we are selecting with the 1339 // for the focus to move to another frame. So instead we call it from places whe re we are selecting with the
1331 // mouse or the keyboard after setting the selection. 1340 // mouse or the keyboard after setting the selection.
1332 void FrameSelection::selectFrameElementInParentIfFullySelected() 1341 void FrameSelection::selectFrameElementInParentIfFullySelected()
1333 { 1342 {
1334 // Find the parent frame; if there is none, then we have nothing to do. 1343 // Find the parent frame; if there is none, then we have nothing to do.
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 1982
1974 void showTree(const blink::FrameSelection* sel) 1983 void showTree(const blink::FrameSelection* sel)
1975 { 1984 {
1976 if (sel) 1985 if (sel)
1977 sel->showTreeForThis(); 1986 sel->showTreeForThis();
1978 else 1987 else
1979 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1988 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1980 } 1989 }
1981 1990
1982 #endif 1991 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/VisibleSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698