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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 DEFINE_STATIC_LOCAL(EmptyEditorClient, client, ()); | 194 DEFINE_STATIC_LOCAL(EmptyEditorClient, client, ()); |
195 return client; | 195 return client; |
196 } | 196 } |
197 | 197 |
198 EditorClient& Editor::client() const { | 198 EditorClient& Editor::client() const { |
199 if (Page* page = frame().page()) | 199 if (Page* page = frame().page()) |
200 return page->editorClient(); | 200 return page->editorClient(); |
201 return emptyEditorClient(); | 201 return emptyEditorClient(); |
202 } | 202 } |
203 | 203 |
| 204 static bool isCaretAtStartOfWrappedLine(const FrameSelection& selection) { |
| 205 if (!selection.isCaret()) |
| 206 return false; |
| 207 if (selection.affinity() != TextAffinity::Downstream) |
| 208 return false; |
| 209 const Position& position = selection.start(); |
| 210 return !inSameLine(PositionWithAffinity(position, TextAffinity::Upstream), |
| 211 PositionWithAffinity(position, TextAffinity::Downstream)); |
| 212 } |
| 213 |
204 bool Editor::handleTextEvent(TextEvent* event) { | 214 bool Editor::handleTextEvent(TextEvent* event) { |
205 // Default event handling for Drag and Drop will be handled by DragController | 215 // Default event handling for Drag and Drop will be handled by DragController |
206 // so we leave the event for it. | 216 // so we leave the event for it. |
207 if (event->isDrop()) | 217 if (event->isDrop()) |
208 return false; | 218 return false; |
209 | 219 |
210 // Default event handling for IncrementalInsertion will be handled by | 220 // Default event handling for IncrementalInsertion will be handled by |
211 // TypingCommand::insertText(), so we leave the event for it. | 221 // TypingCommand::insertText(), so we leave the event for it. |
212 if (event->isIncrementalInsertion()) | 222 if (event->isIncrementalInsertion()) |
213 return false; | 223 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
230 return true; | 240 return true; |
231 } | 241 } |
232 | 242 |
233 String data = event->data(); | 243 String data = event->data(); |
234 if (data == "\n") { | 244 if (data == "\n") { |
235 if (event->isLineBreak()) | 245 if (event->isLineBreak()) |
236 return insertLineBreak(); | 246 return insertLineBreak(); |
237 return insertParagraphSeparator(); | 247 return insertParagraphSeparator(); |
238 } | 248 } |
239 | 249 |
| 250 // Typing spaces at the beginning of wrapped line is confusing, because |
| 251 // inserted spaces would appear in the previous line. |
| 252 // Insert a line break automatically so that the spaces appear at the caret. |
| 253 // TODO(kojii): rich editing has the same issue, but has more options and |
| 254 // needs coordination with JS. Enable for plaintext only for now and collect |
| 255 // feedback. |
| 256 if (data == " " && !canEditRichly() && |
| 257 isCaretAtStartOfWrappedLine(frame().selection())) { |
| 258 insertLineBreak(); |
| 259 } |
| 260 |
240 return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding, | 261 return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding, |
241 data, false, event); | 262 data, false, event); |
242 } | 263 } |
243 | 264 |
244 bool Editor::canEdit() const { | 265 bool Editor::canEdit() const { |
245 return frame().selection().rootEditableElement(); | 266 return frame().selection().rootEditableElement(); |
246 } | 267 } |
247 | 268 |
248 bool Editor::canEditRichly() const { | 269 bool Editor::canEditRichly() const { |
249 return frame().selection().isContentRichlyEditable(); | 270 return frame().selection().isContentRichlyEditable(); |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 } | 1728 } |
1708 | 1729 |
1709 DEFINE_TRACE(Editor) { | 1730 DEFINE_TRACE(Editor) { |
1710 visitor->trace(m_frame); | 1731 visitor->trace(m_frame); |
1711 visitor->trace(m_lastEditCommand); | 1732 visitor->trace(m_lastEditCommand); |
1712 visitor->trace(m_undoStack); | 1733 visitor->trace(m_undoStack); |
1713 visitor->trace(m_mark); | 1734 visitor->trace(m_mark); |
1714 } | 1735 } |
1715 | 1736 |
1716 } // namespace blink | 1737 } // namespace blink |
OLD | NEW |