| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 m_originalBase = base; | 211 m_originalBase = base; |
| 212 newSelection.setBase(newBase); | 212 newSelection.setBase(newBase); |
| 213 newSelection.setExtent(newExtent); | 213 newSelection.setExtent(newExtent); |
| 214 } else if (m_originalBase.isNotNull()) { | 214 } else if (m_originalBase.isNotNull()) { |
| 215 if (m_selection.base() == newSelection.base()) | 215 if (m_selection.base() == newSelection.base()) |
| 216 newSelection.setBase(m_originalBase); | 216 newSelection.setBase(m_originalBase); |
| 217 m_originalBase.clear(); | 217 m_originalBase.clear(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 newSelection.setIsDirectional(isDirectional); // Adjusting base and extent w
ill make newSelection always directional | 220 newSelection.setIsDirectional(isDirectional); // Adjusting base and extent w
ill make newSelection always directional |
| 221 if (m_selection == newSelection || !shouldChangeSelection(newSelection)) | 221 if (m_selection == newSelection) |
| 222 return; | 222 return; |
| 223 | 223 |
| 224 setSelection(newSelection, granularity); | 224 setSelection(newSelection, granularity); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec
tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) | 227 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec
tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) |
| 228 { | 228 { |
| 229 bool closeTyping = options & CloseTyping; | 229 bool closeTyping = options & CloseTyping; |
| 230 bool shouldClearTypingStyle = options & ClearTypingStyle; | 230 bool shouldClearTypingStyle = options & ClearTypingStyle; |
| 231 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 231 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 return granularity == LineBoundary || granularity == ParagraphBoundary || gr
anularity == DocumentBoundary; | 950 return granularity == LineBoundary || granularity == ParagraphBoundary || gr
anularity == DocumentBoundary; |
| 951 } | 951 } |
| 952 | 952 |
| 953 bool FrameSelection::modify(EAlteration alter, SelectionDirection direction, Tex
tGranularity granularity, EUserTriggered userTriggered) | 953 bool FrameSelection::modify(EAlteration alter, SelectionDirection direction, Tex
tGranularity granularity, EUserTriggered userTriggered) |
| 954 { | 954 { |
| 955 if (userTriggered == UserTriggered) { | 955 if (userTriggered == UserTriggered) { |
| 956 FrameSelection trialFrameSelection; | 956 FrameSelection trialFrameSelection; |
| 957 trialFrameSelection.setSelection(m_selection); | 957 trialFrameSelection.setSelection(m_selection); |
| 958 trialFrameSelection.modify(alter, direction, granularity, NotUserTrigger
ed); | 958 trialFrameSelection.modify(alter, direction, granularity, NotUserTrigger
ed); |
| 959 | 959 |
| 960 bool change = shouldChangeSelection(trialFrameSelection.selection()); | |
| 961 if (!change) | |
| 962 return false; | |
| 963 | |
| 964 if (trialFrameSelection.selection().isRange() && m_selection.isCaret() &
& !dispatchSelectStart()) | 960 if (trialFrameSelection.selection().isRange() && m_selection.isCaret() &
& !dispatchSelectStart()) |
| 965 return false; | 961 return false; |
| 966 } | 962 } |
| 967 | 963 |
| 968 willBeModified(alter, direction); | 964 willBeModified(alter, direction); |
| 969 | 965 |
| 970 bool wasRange = m_selection.isRange(); | 966 bool wasRange = m_selection.isRange(); |
| 971 Position originalStartPosition = m_selection.start(); | 967 Position originalStartPosition = m_selection.start(); |
| 972 VisiblePosition position; | 968 VisiblePosition position; |
| 973 switch (direction) { | 969 switch (direction) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 | 1063 |
| 1068 bool FrameSelection::modify(EAlteration alter, unsigned verticalDistance, Vertic
alDirection direction, EUserTriggered userTriggered, CursorAlignOnScroll align) | 1064 bool FrameSelection::modify(EAlteration alter, unsigned verticalDistance, Vertic
alDirection direction, EUserTriggered userTriggered, CursorAlignOnScroll align) |
| 1069 { | 1065 { |
| 1070 if (!verticalDistance) | 1066 if (!verticalDistance) |
| 1071 return false; | 1067 return false; |
| 1072 | 1068 |
| 1073 if (userTriggered == UserTriggered) { | 1069 if (userTriggered == UserTriggered) { |
| 1074 FrameSelection trialFrameSelection; | 1070 FrameSelection trialFrameSelection; |
| 1075 trialFrameSelection.setSelection(m_selection); | 1071 trialFrameSelection.setSelection(m_selection); |
| 1076 trialFrameSelection.modify(alter, verticalDistance, direction, NotUserTr
iggered); | 1072 trialFrameSelection.modify(alter, verticalDistance, direction, NotUserTr
iggered); |
| 1077 | |
| 1078 bool change = shouldChangeSelection(trialFrameSelection.selection()); | |
| 1079 if (!change) | |
| 1080 return false; | |
| 1081 } | 1073 } |
| 1082 | 1074 |
| 1083 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); | 1075 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); |
| 1084 | 1076 |
| 1085 VisiblePosition pos; | 1077 VisiblePosition pos; |
| 1086 LayoutUnit xPos = 0; | 1078 LayoutUnit xPos = 0; |
| 1087 switch (alter) { | 1079 switch (alter) { |
| 1088 case AlterationMove: | 1080 case AlterationMove: |
| 1089 pos = VisiblePosition(direction == DirectionUp ? m_selection.start() : m
_selection.end(), m_selection.affinity()); | 1081 pos = VisiblePosition(direction == DirectionUp ? m_selection.start() : m
_selection.end(), m_selection.affinity()); |
| 1090 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); | 1082 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 if (!ownerElementParent->rendererIsEditable()) | 1447 if (!ownerElementParent->rendererIsEditable()) |
| 1456 return; | 1448 return; |
| 1457 | 1449 |
| 1458 // Create compute positions before and after the element. | 1450 // Create compute positions before and after the element. |
| 1459 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); | 1451 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); |
| 1460 VisiblePosition beforeOwnerElement(VisiblePosition(Position(ownerElementPare
nt, ownerElementNodeIndex, Position::PositionIsOffsetInAnchor))); | 1452 VisiblePosition beforeOwnerElement(VisiblePosition(Position(ownerElementPare
nt, ownerElementNodeIndex, Position::PositionIsOffsetInAnchor))); |
| 1461 VisiblePosition afterOwnerElement(VisiblePosition(Position(ownerElementParen
t, ownerElementNodeIndex + 1, Position::PositionIsOffsetInAnchor), VP_UPSTREAM_I
F_POSSIBLE)); | 1453 VisiblePosition afterOwnerElement(VisiblePosition(Position(ownerElementParen
t, ownerElementNodeIndex + 1, Position::PositionIsOffsetInAnchor), VP_UPSTREAM_I
F_POSSIBLE)); |
| 1462 | 1454 |
| 1463 // Focus on the parent frame, and then select from before this element to af
ter. | 1455 // Focus on the parent frame, and then select from before this element to af
ter. |
| 1464 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); | 1456 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); |
| 1465 if (parent->selection().shouldChangeSelection(newSelection)) { | 1457 page->focusController().setFocusedFrame(parent); |
| 1466 page->focusController().setFocusedFrame(parent); | 1458 parent->selection().setSelection(newSelection); |
| 1467 parent->selection().setSelection(newSelection); | |
| 1468 } | |
| 1469 } | 1459 } |
| 1470 | 1460 |
| 1471 void FrameSelection::selectAll() | 1461 void FrameSelection::selectAll() |
| 1472 { | 1462 { |
| 1473 Document* document = m_frame->document(); | 1463 Document* document = m_frame->document(); |
| 1474 | 1464 |
| 1475 if (document->focusedElement() && document->focusedElement()->hasTagName(sel
ectTag)) { | 1465 if (document->focusedElement() && document->focusedElement()->hasTagName(sel
ectTag)) { |
| 1476 HTMLSelectElement* selectElement = toHTMLSelectElement(document->focused
Element()); | 1466 HTMLSelectElement* selectElement = toHTMLSelectElement(document->focused
Element()); |
| 1477 if (selectElement->canSelectAll()) { | 1467 if (selectElement->canSelectAll()) { |
| 1478 selectElement->selectAll(); | 1468 selectElement->selectAll(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1497 selectStartTarget = document->body(); | 1487 selectStartTarget = document->body(); |
| 1498 } | 1488 } |
| 1499 } | 1489 } |
| 1500 if (!root) | 1490 if (!root) |
| 1501 return; | 1491 return; |
| 1502 | 1492 |
| 1503 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventNames::selectstart))) | 1493 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventNames::selectstart))) |
| 1504 return; | 1494 return; |
| 1505 | 1495 |
| 1506 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(
root.get())); | 1496 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(
root.get())); |
| 1507 | 1497 setSelection(newSelection); |
| 1508 if (shouldChangeSelection(newSelection)) | |
| 1509 setSelection(newSelection); | |
| 1510 | |
| 1511 selectFrameElementInParentIfFullySelected(); | 1498 selectFrameElementInParentIfFullySelected(); |
| 1512 notifyRendererOfSelectionChange(UserTriggered); | 1499 notifyRendererOfSelectionChange(UserTriggered); |
| 1513 } | 1500 } |
| 1514 | 1501 |
| 1515 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool clo
seTyping) | 1502 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool clo
seTyping) |
| 1516 { | 1503 { |
| 1517 if (!range || !range->startContainer() || !range->endContainer()) | 1504 if (!range || !range->startContainer() || !range->endContainer()) |
| 1518 return false; | 1505 return false; |
| 1519 ASSERT(&range->startContainer()->document() == &range->endContainer()->docum
ent()); | 1506 ASSERT(&range->startContainer()->document() == &range->endContainer()->docum
ent()); |
| 1520 | 1507 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 return extractSelectedText(*this, TextIteratorDefaultBehavior); | 1795 return extractSelectedText(*this, TextIteratorDefaultBehavior); |
| 1809 } | 1796 } |
| 1810 | 1797 |
| 1811 String FrameSelection::selectedTextForClipboard() const | 1798 String FrameSelection::selectedTextForClipboard() const |
| 1812 { | 1799 { |
| 1813 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex
t()) | 1800 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex
t()) |
| 1814 return extractSelectedText(*this, TextIteratorEmitsImageAltText); | 1801 return extractSelectedText(*this, TextIteratorEmitsImageAltText); |
| 1815 return selectedText(); | 1802 return selectedText(); |
| 1816 } | 1803 } |
| 1817 | 1804 |
| 1818 bool FrameSelection::shouldDeleteSelection(const VisibleSelection& selection) co
nst | |
| 1819 { | |
| 1820 return m_frame->editor().client().shouldDeleteRange(selection.toNormalizedRa
nge().get()); | |
| 1821 } | |
| 1822 | |
| 1823 FloatRect FrameSelection::bounds(bool clipToVisibleContent) const | 1805 FloatRect FrameSelection::bounds(bool clipToVisibleContent) const |
| 1824 { | 1806 { |
| 1825 RenderView* root = m_frame->contentRenderer(); | 1807 RenderView* root = m_frame->contentRenderer(); |
| 1826 FrameView* view = m_frame->view(); | 1808 FrameView* view = m_frame->view(); |
| 1827 if (!root || !view) | 1809 if (!root || !view) |
| 1828 return LayoutRect(); | 1810 return LayoutRect(); |
| 1829 | 1811 |
| 1830 LayoutRect selectionRect = root->selectionBounds(clipToVisibleContent); | 1812 LayoutRect selectionRect = root->selectionBounds(clipToVisibleContent); |
| 1831 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte
ntRect()) : selectionRect; | 1813 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte
ntRect()) : selectionRect; |
| 1832 } | 1814 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing)) | 1909 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing)) |
| 1928 return; | 1910 return; |
| 1929 | 1911 |
| 1930 Node* node = document->documentElement(); | 1912 Node* node = document->documentElement(); |
| 1931 while (node && !node->hasTagName(bodyTag)) | 1913 while (node && !node->hasTagName(bodyTag)) |
| 1932 node = NodeTraversal::next(node); | 1914 node = NodeTraversal::next(node); |
| 1933 if (node) | 1915 if (node) |
| 1934 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTR
EAM)); | 1916 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTR
EAM)); |
| 1935 } | 1917 } |
| 1936 | 1918 |
| 1937 bool FrameSelection::shouldChangeSelection(const VisibleSelection& newSelection)
const | |
| 1938 { | |
| 1939 return m_frame->editor().shouldChangeSelection(selection(), newSelection, ne
wSelection.affinity(), false); | |
| 1940 } | |
| 1941 | |
| 1942 bool FrameSelection::dispatchSelectStart() | 1919 bool FrameSelection::dispatchSelectStart() |
| 1943 { | 1920 { |
| 1944 Node* selectStartTarget = m_selection.extent().containerNode(); | 1921 Node* selectStartTarget = m_selection.extent().containerNode(); |
| 1945 if (!selectStartTarget) | 1922 if (!selectStartTarget) |
| 1946 return true; | 1923 return true; |
| 1947 | 1924 |
| 1948 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventN
ames::selectstart)); | 1925 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventN
ames::selectstart)); |
| 1949 } | 1926 } |
| 1950 | 1927 |
| 1951 inline bool FrameSelection::visualWordMovementEnabled() const | 1928 inline bool FrameSelection::visualWordMovementEnabled() const |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 sel.showTreeForThis(); | 1963 sel.showTreeForThis(); |
| 1987 } | 1964 } |
| 1988 | 1965 |
| 1989 void showTree(const WebCore::FrameSelection* sel) | 1966 void showTree(const WebCore::FrameSelection* sel) |
| 1990 { | 1967 { |
| 1991 if (sel) | 1968 if (sel) |
| 1992 sel->showTreeForThis(); | 1969 sel->showTreeForThis(); |
| 1993 } | 1970 } |
| 1994 | 1971 |
| 1995 #endif | 1972 #endif |
| OLD | NEW |