| 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 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai
ntOffset, const LayoutRect& clipRect) | 1294 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai
ntOffset, const LayoutRect& clipRect) |
| 1295 { | 1295 { |
| 1296 if (m_selection.isCaret() && m_shouldPaintCaret) { | 1296 if (m_selection.isCaret() && m_shouldPaintCaret) { |
| 1297 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st
art(), m_selection.affinity())); | 1297 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st
art(), m_selection.affinity())); |
| 1298 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai
ntOffset, clipRect); | 1298 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai
ntOffset, clipRect); |
| 1299 } | 1299 } |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 bool FrameSelection::contains(const LayoutPoint& point) | 1302 template <typename Strategy> |
| 1303 bool FrameSelection::containsAlgorithm(const LayoutPoint& point) |
| 1303 { | 1304 { |
| 1305 using PositionType = typename Strategy::PositionType; |
| 1306 |
| 1304 Document* document = m_frame->document(); | 1307 Document* document = m_frame->document(); |
| 1305 | 1308 |
| 1306 // Treat a collapsed selection like no selection. | 1309 // Treat a collapsed selection like no selection. |
| 1307 if (!isRange()) | 1310 if (!isRange()) |
| 1308 return false; | 1311 return false; |
| 1309 if (!document->layoutView()) | 1312 if (!document->layoutView()) |
| 1310 return false; | 1313 return false; |
| 1311 | 1314 |
| 1312 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | 1315 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
| 1313 HitTestResult result(request, point); | 1316 HitTestResult result(request, point); |
| 1314 document->layoutView()->hitTest(result); | 1317 document->layoutView()->hitTest(result); |
| 1315 Node* innerNode = result.innerNode(); | 1318 Node* innerNode = result.innerNode(); |
| 1316 if (!innerNode || !innerNode->layoutObject()) | 1319 if (!innerNode || !innerNode->layoutObject()) |
| 1317 return false; | 1320 return false; |
| 1318 | 1321 |
| 1319 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(resul
t.localPoint())); | 1322 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(resul
t.localPoint())); |
| 1320 if (visiblePos.isNull()) | 1323 if (visiblePos.isNull()) |
| 1321 return false; | 1324 return false; |
| 1322 | 1325 |
| 1323 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull()
) | 1326 VisiblePosition visibleStart = Strategy::selectionVisibleStart(m_selection); |
| 1327 VisiblePosition visibleEnd = Strategy::selectionVisibleEnd(m_selection); |
| 1328 if (visibleStart.isNull() || visibleEnd.isNull()) |
| 1324 return false; | 1329 return false; |
| 1325 | 1330 |
| 1326 Position start(m_selection.visibleStart().deepEquivalent()); | 1331 PositionType start(Strategy::toPositionType(visibleStart.deepEquivalent())); |
| 1327 Position end(m_selection.visibleEnd().deepEquivalent()); | 1332 PositionType end(Strategy::toPositionType(visibleEnd.deepEquivalent())); |
| 1328 Position p(visiblePos.deepEquivalent()); | 1333 PositionType pos(Strategy::toPositionType(visiblePos.deepEquivalent())); |
| 1334 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0; |
| 1335 } |
| 1329 | 1336 |
| 1330 return comparePositions(start, p) <= 0 && comparePositions(p, end) <= 0; | 1337 bool FrameSelection::contains(const LayoutPoint& point) |
| 1338 { |
| 1339 return containsAlgorithm<VisibleSelection::InDOMTree>(point); |
| 1331 } | 1340 } |
| 1332 | 1341 |
| 1333 // Workaround for the fact that it's hard to delete a frame. | 1342 // Workaround for the fact that it's hard to delete a frame. |
| 1334 // Call this after doing user-triggered selections to make it easy to delete the
frame you entirely selected. | 1343 // Call this after doing user-triggered selections to make it easy to delete the
frame you entirely selected. |
| 1335 // Can't do this implicitly as part of every setSelection call because in some c
ontexts it might not be good | 1344 // Can't do this implicitly as part of every setSelection call because in some c
ontexts it might not be good |
| 1336 // for the focus to move to another frame. So instead we call it from places whe
re we are selecting with the | 1345 // for the focus to move to another frame. So instead we call it from places whe
re we are selecting with the |
| 1337 // mouse or the keyboard after setting the selection. | 1346 // mouse or the keyboard after setting the selection. |
| 1338 void FrameSelection::selectFrameElementInParentIfFullySelected() | 1347 void FrameSelection::selectFrameElementInParentIfFullySelected() |
| 1339 { | 1348 { |
| 1340 // Find the parent frame; if there is none, then we have nothing to do. | 1349 // Find the parent frame; if there is none, then we have nothing to do. |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1991 | 2000 |
| 1992 void showTree(const blink::FrameSelection* sel) | 2001 void showTree(const blink::FrameSelection* sel) |
| 1993 { | 2002 { |
| 1994 if (sel) | 2003 if (sel) |
| 1995 sel->showTreeForThis(); | 2004 sel->showTreeForThis(); |
| 1996 else | 2005 else |
| 1997 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); | 2006 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); |
| 1998 } | 2007 } |
| 1999 | 2008 |
| 2000 #endif | 2009 #endif |
| OLD | NEW |