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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 else | 291 else |
292 alignment = (align == AlignCursorOnScrollAlways) ? ScrollAlignment::
alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded; | 292 alignment = (align == AlignCursorOnScrollAlways) ? ScrollAlignment::
alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded; |
293 | 293 |
294 revealSelection(alignment, RevealExtent); | 294 revealSelection(alignment, RevealExtent); |
295 } | 295 } |
296 | 296 |
297 notifyAccessibilityForSelectionChange(); | 297 notifyAccessibilityForSelectionChange(); |
298 m_frame->domWindow()->enqueueDocumentEvent(Event::create(EventTypeNames::sel
ectionchange)); | 298 m_frame->domWindow()->enqueueDocumentEvent(Event::create(EventTypeNames::sel
ectionchange)); |
299 } | 299 } |
300 | 300 |
301 static bool removingNodeRemovesPosition(Node* node, const Position& position) | 301 static bool removingNodeRemovesPosition(Node& node, const Position& position) |
302 { | 302 { |
303 if (!position.anchorNode()) | 303 if (!position.anchorNode()) |
304 return false; | 304 return false; |
305 | 305 |
306 if (position.anchorNode() == node) | 306 if (position.anchorNode() == node) |
307 return true; | 307 return true; |
308 | 308 |
309 if (!node->isElementNode()) | 309 if (!node.isElementNode()) |
310 return false; | 310 return false; |
311 | 311 |
312 Element* element = toElement(node); | 312 Element& element = toElement(node); |
313 return element->containsIncludingShadowDOM(position.anchorNode()); | 313 return element.containsIncludingShadowDOM(position.anchorNode()); |
314 } | 314 } |
315 | 315 |
316 static void clearRenderViewSelection(const Position& position) | 316 static void clearRenderViewSelection(const Position& position) |
317 { | 317 { |
318 RefPtr<Document> document = position.document(); | 318 RefPtr<Document> document = position.document(); |
319 document->updateStyleIfNeeded(); | 319 document->updateStyleIfNeeded(); |
320 if (RenderView* view = document->renderView()) | 320 if (RenderView* view = document->renderView()) |
321 view->clearSelection(); | 321 view->clearSelection(); |
322 } | 322 } |
323 | 323 |
324 void FrameSelection::nodeWillBeRemoved(Node* node) | 324 void FrameSelection::nodeWillBeRemoved(Node& node) |
325 { | 325 { |
326 // There can't be a selection inside a fragment, so if a fragment's node is
being removed, | 326 // There can't be a selection inside a fragment, so if a fragment's node is
being removed, |
327 // the selection in the document that created the fragment needs no adjustme
nt. | 327 // the selection in the document that created the fragment needs no adjustme
nt. |
328 if (isNone() || (node && !node->inDocument())) | 328 if (isNone() || !node.inDocument()) |
329 return; | 329 return; |
330 | 330 |
331 respondToNodeModification(node, removingNodeRemovesPosition(node, m_selectio
n.base()), removingNodeRemovesPosition(node, m_selection.extent()), | 331 respondToNodeModification(node, removingNodeRemovesPosition(node, m_selectio
n.base()), removingNodeRemovesPosition(node, m_selection.extent()), |
332 removingNodeRemovesPosition(node, m_selection.start()), removingNodeRemo
vesPosition(node, m_selection.end())); | 332 removingNodeRemovesPosition(node, m_selection.start()), removingNodeRemo
vesPosition(node, m_selection.end())); |
333 } | 333 } |
334 | 334 |
335 void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, boo
l extentRemoved, bool startRemoved, bool endRemoved) | 335 void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, boo
l extentRemoved, bool startRemoved, bool endRemoved) |
336 { | 336 { |
337 bool clearRenderTreeSelection = false; | 337 bool clearRenderTreeSelection = false; |
338 bool clearDOMTreeSelection = false; | 338 bool clearDOMTreeSelection = false; |
339 | 339 |
340 if (startRemoved || endRemoved) { | 340 if (startRemoved || endRemoved) { |
341 Position start = m_selection.start(); | 341 Position start = m_selection.start(); |
342 Position end = m_selection.end(); | 342 Position end = m_selection.end(); |
343 if (startRemoved) | 343 if (startRemoved) |
344 updatePositionForNodeRemoval(start, node); | 344 updatePositionForNodeRemoval(start, &node); |
345 if (endRemoved) | 345 if (endRemoved) |
346 updatePositionForNodeRemoval(end, node); | 346 updatePositionForNodeRemoval(end, &node); |
347 | 347 |
348 if (start.isNotNull() && end.isNotNull()) { | 348 if (start.isNotNull() && end.isNotNull()) { |
349 if (m_selection.isBaseFirst()) | 349 if (m_selection.isBaseFirst()) |
350 m_selection.setWithoutValidation(start, end); | 350 m_selection.setWithoutValidation(start, end); |
351 else | 351 else |
352 m_selection.setWithoutValidation(end, start); | 352 m_selection.setWithoutValidation(end, start); |
353 } else | 353 } else |
354 clearDOMTreeSelection = true; | 354 clearDOMTreeSelection = true; |
355 | 355 |
356 clearRenderTreeSelection = true; | 356 clearRenderTreeSelection = true; |
357 } else if (baseRemoved || extentRemoved) { | 357 } else if (baseRemoved || extentRemoved) { |
358 // The base and/or extent are about to be removed, but the start and end
aren't. | 358 // The base and/or extent are about to be removed, but the start and end
aren't. |
359 // Change the base and extent to the start and end, but don't re-validat
e the | 359 // Change the base and extent to the start and end, but don't re-validat
e the |
360 // selection, since doing so could move the start and end into the node | 360 // selection, since doing so could move the start and end into the node |
361 // that is about to be removed. | 361 // that is about to be removed. |
362 if (m_selection.isBaseFirst()) | 362 if (m_selection.isBaseFirst()) |
363 m_selection.setWithoutValidation(m_selection.start(), m_selection.en
d()); | 363 m_selection.setWithoutValidation(m_selection.start(), m_selection.en
d()); |
364 else | 364 else |
365 m_selection.setWithoutValidation(m_selection.end(), m_selection.star
t()); | 365 m_selection.setWithoutValidation(m_selection.end(), m_selection.star
t()); |
366 } else if (RefPtr<Range> range = m_selection.firstRange()) { | 366 } else if (RefPtr<Range> range = m_selection.firstRange()) { |
367 TrackExceptionState es; | 367 TrackExceptionState es; |
368 Range::CompareResults compareResult = range->compareNode(node, es); | 368 Range::CompareResults compareResult = range->compareNode(&node, es); |
369 if (!es.hadException() && (compareResult == Range::NODE_BEFORE_AND_AFTER
|| compareResult == Range::NODE_INSIDE)) { | 369 if (!es.hadException() && (compareResult == Range::NODE_BEFORE_AND_AFTER
|| compareResult == Range::NODE_INSIDE)) { |
370 // If we did nothing here, when this node's renderer was destroyed,
the rect that it | 370 // If we did nothing here, when this node's renderer was destroyed,
the rect that it |
371 // occupied would be invalidated, but, selection gaps that change as
a result of | 371 // occupied would be invalidated, but, selection gaps that change as
a result of |
372 // the removal wouldn't be invalidated. | 372 // the removal wouldn't be invalidated. |
373 // FIXME: Don't do so much unnecessary invalidation. | 373 // FIXME: Don't do so much unnecessary invalidation. |
374 clearRenderTreeSelection = true; | 374 clearRenderTreeSelection = true; |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 if (clearRenderTreeSelection) | 378 if (clearRenderTreeSelection) |
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 sel.showTreeForThis(); | 1867 sel.showTreeForThis(); |
1868 } | 1868 } |
1869 | 1869 |
1870 void showTree(const WebCore::FrameSelection* sel) | 1870 void showTree(const WebCore::FrameSelection* sel) |
1871 { | 1871 { |
1872 if (sel) | 1872 if (sel) |
1873 sel->showTreeForThis(); | 1873 sel->showTreeForThis(); |
1874 } | 1874 } |
1875 | 1875 |
1876 #endif | 1876 #endif |
OLD | NEW |