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 25 matching lines...) Expand all Loading... |
36 #include "core/dom/Element.h" | 36 #include "core/dom/Element.h" |
37 #include "core/dom/ElementTraversal.h" | 37 #include "core/dom/ElementTraversal.h" |
38 #include "core/dom/NodeTraversal.h" | 38 #include "core/dom/NodeTraversal.h" |
39 #include "core/dom/Text.h" | 39 #include "core/dom/Text.h" |
40 #include "core/editing/EditingUtilities.h" | 40 #include "core/editing/EditingUtilities.h" |
41 #include "core/editing/Editor.h" | 41 #include "core/editing/Editor.h" |
42 #include "core/editing/GranularityStrategy.h" | 42 #include "core/editing/GranularityStrategy.h" |
43 #include "core/editing/InputMethodController.h" | 43 #include "core/editing/InputMethodController.h" |
44 #include "core/editing/RenderedPosition.h" | 44 #include "core/editing/RenderedPosition.h" |
45 #include "core/editing/SelectionController.h" | 45 #include "core/editing/SelectionController.h" |
| 46 #include "core/editing/TextAffinity.h" |
46 #include "core/editing/VisibleUnits.h" | 47 #include "core/editing/VisibleUnits.h" |
47 #include "core/editing/commands/TypingCommand.h" | 48 #include "core/editing/commands/TypingCommand.h" |
48 #include "core/editing/iterators/TextIterator.h" | 49 #include "core/editing/iterators/TextIterator.h" |
49 #include "core/editing/serializers/Serialization.h" | 50 #include "core/editing/serializers/Serialization.h" |
50 #include "core/editing/spellcheck/SpellChecker.h" | 51 #include "core/editing/spellcheck/SpellChecker.h" |
51 #include "core/events/Event.h" | 52 #include "core/events/Event.h" |
52 #include "core/frame/FrameView.h" | 53 #include "core/frame/FrameView.h" |
53 #include "core/frame/LocalDOMWindow.h" | 54 #include "core/frame/LocalDOMWindow.h" |
54 #include "core/frame/LocalFrame.h" | 55 #include "core/frame/LocalFrame.h" |
55 #include "core/frame/Settings.h" | 56 #include "core/frame/Settings.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 setSelection(VisibleSelection(pos, pos, m_selection.isDirectional()), option
s, align); | 145 setSelection(VisibleSelection(pos, pos, m_selection.isDirectional()), option
s, align); |
145 } | 146 } |
146 | 147 |
147 void FrameSelection::moveTo(const VisiblePosition &base, const VisiblePosition &
extent, EUserTriggered userTriggered) | 148 void FrameSelection::moveTo(const VisiblePosition &base, const VisiblePosition &
extent, EUserTriggered userTriggered) |
148 { | 149 { |
149 const bool selectionHasDirection = true; | 150 const bool selectionHasDirection = true; |
150 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; | 151 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; |
151 setSelection(VisibleSelection(base, extent, selectionHasDirection), options)
; | 152 setSelection(VisibleSelection(base, extent, selectionHasDirection), options)
; |
152 } | 153 } |
153 | 154 |
154 void FrameSelection::moveTo(const Position &pos, EAffinity affinity, EUserTrigge
red userTriggered) | 155 void FrameSelection::moveTo(const Position &pos, TextAffinity affinity, EUserTri
ggered userTriggered) |
155 { | 156 { |
156 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; | 157 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; |
157 setSelection(VisibleSelection(pos, affinity, m_selection.isDirectional()), o
ptions); | 158 setSelection(VisibleSelection(pos, affinity, m_selection.isDirectional()), o
ptions); |
158 } | 159 } |
159 | 160 |
160 static void adjustEndpointsAtBidiBoundary(VisiblePosition& visibleBase, VisibleP
osition& visibleExtent) | 161 static void adjustEndpointsAtBidiBoundary(VisiblePosition& visibleBase, VisibleP
osition& visibleExtent) |
161 { | 162 { |
162 RenderedPosition base(visibleBase); | 163 RenderedPosition base(visibleBase); |
163 RenderedPosition extent(visibleExtent); | 164 RenderedPosition extent(visibleExtent); |
164 | 165 |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 } | 1103 } |
1103 | 1104 |
1104 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); | 1105 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); |
1105 | 1106 |
1106 VisiblePosition pos; | 1107 VisiblePosition pos; |
1107 LayoutUnit xPos = 0; | 1108 LayoutUnit xPos = 0; |
1108 switch (alter) { | 1109 switch (alter) { |
1109 case AlterationMove: | 1110 case AlterationMove: |
1110 pos = VisiblePosition(direction == DirectionUp ? m_selection.start() : m
_selection.end(), m_selection.affinity()); | 1111 pos = VisiblePosition(direction == DirectionUp ? m_selection.start() : m
_selection.end(), m_selection.affinity()); |
1111 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); | 1112 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); |
1112 m_selection.setAffinity(direction == DirectionUp ? UPSTREAM : DOWNSTREAM
); | 1113 m_selection.setAffinity(direction == DirectionUp ? TextAffinity::Upstrea
m : TextAffinity::Downstream); |
1113 break; | 1114 break; |
1114 case AlterationExtend: | 1115 case AlterationExtend: |
1115 pos = VisiblePosition(m_selection.extent(), m_selection.affinity()); | 1116 pos = VisiblePosition(m_selection.extent(), m_selection.affinity()); |
1116 xPos = lineDirectionPointForBlockDirectionNavigation(EXTENT); | 1117 xPos = lineDirectionPointForBlockDirectionNavigation(EXTENT); |
1117 m_selection.setAffinity(DOWNSTREAM); | 1118 m_selection.setAffinity(TextAffinity::Downstream); |
1118 break; | 1119 break; |
1119 } | 1120 } |
1120 | 1121 |
1121 int startY; | 1122 int startY; |
1122 if (!absoluteCaretY(pos, startY)) | 1123 if (!absoluteCaretY(pos, startY)) |
1123 return false; | 1124 return false; |
1124 if (direction == DirectionUp) | 1125 if (direction == DirectionUp) |
1125 startY = -startY; | 1126 startY = -startY; |
1126 int lastY = startY; | 1127 int lastY = startY; |
1127 | 1128 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 | 1460 |
1460 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventTypeNames::selectstart))) | 1461 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventTypeNames::selectstart))) |
1461 return; | 1462 return; |
1462 | 1463 |
1463 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(
root.get())); | 1464 VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(
root.get())); |
1464 setSelection(newSelection); | 1465 setSelection(newSelection); |
1465 selectFrameElementInParentIfFullySelected(); | 1466 selectFrameElementInParentIfFullySelected(); |
1466 notifyLayoutObjectOfSelectionChange(UserTriggered); | 1467 notifyLayoutObjectOfSelectionChange(UserTriggered); |
1467 } | 1468 } |
1468 | 1469 |
1469 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, Directio
nalOption directional, SetSelectionOptions options) | 1470 bool FrameSelection::setSelectedRange(Range* range, TextAffinity affinity, Direc
tionalOption directional, SetSelectionOptions options) |
1470 { | 1471 { |
1471 if (!range || !range->startContainer() || !range->endContainer()) | 1472 if (!range || !range->startContainer() || !range->endContainer()) |
1472 return false; | 1473 return false; |
1473 ASSERT(range->startContainer()->document() == range->endContainer()->documen
t()); | 1474 ASSERT(range->startContainer()->document() == range->endContainer()->documen
t()); |
1474 return setSelectedRange(EphemeralRange(range), affinity, directional, option
s); | 1475 return setSelectedRange(EphemeralRange(range), affinity, directional, option
s); |
1475 } | 1476 } |
1476 | 1477 |
1477 bool FrameSelection::setSelectedRange(const EphemeralRange& range, EAffinity aff
inity, DirectionalOption directional, SetSelectionOptions options) | 1478 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity
affinity, DirectionalOption directional, SetSelectionOptions options) |
1478 { | 1479 { |
1479 if (range.isNull()) | 1480 if (range.isNull()) |
1480 return false; | 1481 return false; |
1481 | 1482 |
1482 // Non-collapsed ranges are not allowed to start at the end of a line that i
s wrapped, | 1483 // Non-collapsed ranges are not allowed to start at the end of a line that i
s wrapped, |
1483 // they start at the beginning of the next line instead | 1484 // they start at the beginning of the next line instead |
1484 m_logicalRange = nullptr; | 1485 m_logicalRange = nullptr; |
1485 stopObservingVisibleSelectionChangeIfNecessary(); | 1486 stopObservingVisibleSelectionChangeIfNecessary(); |
1486 | 1487 |
1487 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree | 1488 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 | 1873 |
1873 Document* document = m_frame->document(); | 1874 Document* document = m_frame->document(); |
1874 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); | 1875 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); |
1875 if (!isNone() || !(document->hasEditableStyle() || caretBrowsing)) | 1876 if (!isNone() || !(document->hasEditableStyle() || caretBrowsing)) |
1876 return; | 1877 return; |
1877 | 1878 |
1878 Element* documentElement = document->documentElement(); | 1879 Element* documentElement = document->documentElement(); |
1879 if (!documentElement) | 1880 if (!documentElement) |
1880 return; | 1881 return; |
1881 if (HTMLBodyElement* body = Traversal<HTMLBodyElement>::firstChild(*document
Element)) | 1882 if (HTMLBodyElement* body = Traversal<HTMLBodyElement>::firstChild(*document
Element)) |
1882 setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), DOWNSTR
EAM)); | 1883 setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), TextAff
inity::Downstream)); |
1883 } | 1884 } |
1884 | 1885 |
1885 bool FrameSelection::dispatchSelectStart() | 1886 bool FrameSelection::dispatchSelectStart() |
1886 { | 1887 { |
1887 Node* selectStartTarget = m_selection.extent().computeContainerNode(); | 1888 Node* selectStartTarget = m_selection.extent().computeContainerNode(); |
1888 if (!selectStartTarget) | 1889 if (!selectStartTarget) |
1889 return true; | 1890 return true; |
1890 | 1891 |
1891 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventT
ypeNames::selectstart)); | 1892 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventT
ypeNames::selectstart)); |
1892 } | 1893 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 | 2058 |
2058 void showTree(const blink::FrameSelection* sel) | 2059 void showTree(const blink::FrameSelection* sel) |
2059 { | 2060 { |
2060 if (sel) | 2061 if (sel) |
2061 sel->showTreeForThis(); | 2062 sel->showTreeForThis(); |
2062 else | 2063 else |
2063 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); | 2064 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); |
2064 } | 2065 } |
2065 | 2066 |
2066 #endif | 2067 #endif |
OLD | NEW |