OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 { | 112 { |
113 VisibleSelection selection = frame().selection().selection(); | 113 VisibleSelection selection = frame().selection().selection(); |
114 if (!event) | 114 if (!event) |
115 return selection; | 115 return selection; |
116 // If the target is a text control, and the current selection is outside of
its shadow tree, | 116 // If the target is a text control, and the current selection is outside of
its shadow tree, |
117 // then use the saved selection for that text control. | 117 // then use the saved selection for that text control. |
118 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF
ormControl(selection.start()); | 118 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF
ormControl(selection.start()); |
119 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE
lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target(
)->toNode()) : 0; | 119 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE
lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target(
)->toNode()) : 0; |
120 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro
lOfTarget != textFormControlOfSelectionStart)) { | 120 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro
lOfTarget != textFormControlOfSelectionStart)) { |
121 if (RefPtrWillBeRawPtr<Range> range = textFromControlOfTarget->selection
()) | 121 if (RefPtrWillBeRawPtr<Range> range = textFromControlOfTarget->selection
()) |
122 return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirecti
onal()); | 122 return VisibleSelection(range.get(), TextAffinity::Downstream, selec
tion.isDirectional()); |
123 } | 123 } |
124 return selection; | 124 return selection; |
125 } | 125 } |
126 | 126 |
127 // Function considers Mac editing behavior a fallback when Page or Settings is n
ot available. | 127 // Function considers Mac editing behavior a fallback when Page or Settings is n
ot available. |
128 EditingBehavior Editor::behavior() const | 128 EditingBehavior Editor::behavior() const |
129 { | 129 { |
130 if (!frame().settings()) | 130 if (!frame().settings()) |
131 return EditingBehavior(EditingMacBehavior); | 131 return EditingBehavior(EditingMacBehavior); |
132 | 132 |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); | 1026 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); |
1027 VisiblePosition previous = next.previous(); | 1027 VisiblePosition previous = next.previous(); |
1028 if (next.deepEquivalent() == previous.deepEquivalent()) | 1028 if (next.deepEquivalent() == previous.deepEquivalent()) |
1029 return; | 1029 return; |
1030 previous = previous.previous(); | 1030 previous = previous.previous(); |
1031 if (!inSameParagraph(next, previous)) | 1031 if (!inSameParagraph(next, previous)) |
1032 return; | 1032 return; |
1033 const EphemeralRange range = makeRange(previous, next); | 1033 const EphemeralRange range = makeRange(previous, next); |
1034 if (range.isNull()) | 1034 if (range.isNull()) |
1035 return; | 1035 return; |
1036 VisibleSelection newSelection(range, DOWNSTREAM); | 1036 VisibleSelection newSelection(range); |
1037 | 1037 |
1038 // Transpose the two characters. | 1038 // Transpose the two characters. |
1039 String text = plainText(range); | 1039 String text = plainText(range); |
1040 if (text.length() != 2) | 1040 if (text.length() != 2) |
1041 return; | 1041 return; |
1042 String transposed = text.right(1) + text.left(1); | 1042 String transposed = text.right(1) + text.left(1); |
1043 | 1043 |
1044 // Select the two characters. | 1044 // Select the two characters. |
1045 if (!VisibleSelection::InDOMTree::equalSelections(newSelection, frame().sele
ction().selection())) | 1045 if (!VisibleSelection::InDOMTree::equalSelections(newSelection, frame().sele
ction().selection())) |
1046 frame().selection().setSelection(newSelection); | 1046 frame().selection().setSelection(newSelection); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). | 1078 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). |
1079 if (selectionDidNotChangeDOMPosition) | 1079 if (selectionDidNotChangeDOMPosition) |
1080 client().respondToChangedSelection(m_frame, frame().selection().selectio
nType()); | 1080 client().respondToChangedSelection(m_frame, frame().selection().selectio
nType()); |
1081 } | 1081 } |
1082 | 1082 |
1083 IntRect Editor::firstRectForRange(const EphemeralRange& range) const | 1083 IntRect Editor::firstRectForRange(const EphemeralRange& range) const |
1084 { | 1084 { |
1085 LayoutUnit extraWidthToEndOfLine = 0; | 1085 LayoutUnit extraWidthToEndOfLine = 0; |
1086 ASSERT(range.isNotNull()); | 1086 ASSERT(range.isNotNull()); |
1087 | 1087 |
1088 IntRect startCaretRect = RenderedPosition(VisiblePosition(range.startPositio
n()).deepEquivalent(), DOWNSTREAM).absoluteRect(&extraWidthToEndOfLine); | 1088 IntRect startCaretRect = RenderedPosition(VisiblePosition(range.startPositio
n()).deepEquivalent(), TextAffinity::Downstream).absoluteRect(&extraWidthToEndOf
Line); |
1089 if (startCaretRect == LayoutRect()) | 1089 if (startCaretRect == LayoutRect()) |
1090 return IntRect(); | 1090 return IntRect(); |
1091 | 1091 |
1092 IntRect endCaretRect = RenderedPosition(VisiblePosition(range.endPosition())
.deepEquivalent(), UPSTREAM).absoluteRect(); | 1092 IntRect endCaretRect = RenderedPosition(VisiblePosition(range.endPosition())
.deepEquivalent(), TextAffinity::Upstream).absoluteRect(); |
1093 if (endCaretRect == LayoutRect()) | 1093 if (endCaretRect == LayoutRect()) |
1094 return IntRect(); | 1094 return IntRect(); |
1095 | 1095 |
1096 if (startCaretRect.y() == endCaretRect.y()) { | 1096 if (startCaretRect.y() == endCaretRect.y()) { |
1097 // start and end are on the same line | 1097 // start and end are on the same line |
1098 return IntRect(std::min(startCaretRect.x(), endCaretRect.x()), | 1098 return IntRect(std::min(startCaretRect.x(), endCaretRect.x()), |
1099 startCaretRect.y(), | 1099 startCaretRect.y(), |
1100 abs(endCaretRect.x() - startCaretRect.x()), | 1100 abs(endCaretRect.x() - startCaretRect.x()), |
1101 std::max(startCaretRect.height(), endCaretRect.height())); | 1101 std::max(startCaretRect.height(), endCaretRect.height())); |
1102 } | 1102 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 { | 1147 { |
1148 VisibleSelection selection = frame().selection().selection(); | 1148 VisibleSelection selection = frame().selection().selection(); |
1149 | 1149 |
1150 // TODO(yosin) We should make |findRangeOfString()| to return | 1150 // TODO(yosin) We should make |findRangeOfString()| to return |
1151 // |EphemeralRange| rather than|Range| object. | 1151 // |EphemeralRange| rather than|Range| object. |
1152 RefPtrWillBeRawPtr<Range> resultRange = findRangeOfString(target, EphemeralR
ange(selection.start(), selection.end()), static_cast<FindOptions>(options | Fin
dAPICall)); | 1152 RefPtrWillBeRawPtr<Range> resultRange = findRangeOfString(target, EphemeralR
ange(selection.start(), selection.end()), static_cast<FindOptions>(options | Fin
dAPICall)); |
1153 | 1153 |
1154 if (!resultRange) | 1154 if (!resultRange) |
1155 return false; | 1155 return false; |
1156 | 1156 |
1157 frame().selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR
EAM)); | 1157 frame().selection().setSelection(VisibleSelection(resultRange.get())); |
1158 frame().selection().revealSelection(); | 1158 frame().selection().revealSelection(); |
1159 return true; | 1159 return true; |
1160 } | 1160 } |
1161 | 1161 |
1162 template <typename Strategy> | 1162 template <typename Strategy> |
1163 static PassRefPtrWillBeRawPtr<Range> findStringAndScrollToVisibleAlgorithm(Edito
r& editor, const String& target, const EphemeralRangeTemplate<Strategy>& previou
sMatch, FindOptions options) | 1163 static PassRefPtrWillBeRawPtr<Range> findStringAndScrollToVisibleAlgorithm(Edito
r& editor, const String& target, const EphemeralRangeTemplate<Strategy>& previou
sMatch, FindOptions options) |
1164 { | 1164 { |
1165 RefPtrWillBeRawPtr<Range> nextMatch = editor.findRangeOfString(target, previ
ousMatch, options); | 1165 RefPtrWillBeRawPtr<Range> nextMatch = editor.findRangeOfString(target, previ
ousMatch, options); |
1166 if (!nextMatch) | 1166 if (!nextMatch) |
1167 return nullptr; | 1167 return nullptr; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 } | 1296 } |
1297 | 1297 |
1298 DEFINE_TRACE(Editor) | 1298 DEFINE_TRACE(Editor) |
1299 { | 1299 { |
1300 visitor->trace(m_frame); | 1300 visitor->trace(m_frame); |
1301 visitor->trace(m_lastEditCommand); | 1301 visitor->trace(m_lastEditCommand); |
1302 visitor->trace(m_mark); | 1302 visitor->trace(m_mark); |
1303 } | 1303 } |
1304 | 1304 |
1305 } // namespace blink | 1305 } // namespace blink |
OLD | NEW |