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 isCaretAtTopOfWrappedLine(FrameSelection& selection) { | |
205 if (!selection.isCaret()) | |
206 return false; | |
207 if (selection.affinity() != TextAffinity::Downstream) | |
208 return false; | |
209 // Enable this operation for plaintext only for now. | |
210 if (selection.isContentRichlyEditable()) | |
211 return false; | |
212 // TODO(kojii): how to know if a Position is at the top of wrapped line? | |
yosin_UTC9
2017/01/05 08:36:50
I think "start" is better than "top".
We can chec
| |
213 return true; | |
214 } | |
215 | |
204 bool Editor::handleTextEvent(TextEvent* event) { | 216 bool Editor::handleTextEvent(TextEvent* event) { |
205 // Default event handling for Drag and Drop will be handled by DragController | 217 // Default event handling for Drag and Drop will be handled by DragController |
206 // so we leave the event for it. | 218 // so we leave the event for it. |
207 if (event->isDrop()) | 219 if (event->isDrop()) |
208 return false; | 220 return false; |
209 | 221 |
210 // Default event handling for IncrementalInsertion will be handled by | 222 // Default event handling for IncrementalInsertion will be handled by |
211 // TypingCommand::insertText(), so we leave the event for it. | 223 // TypingCommand::insertText(), so we leave the event for it. |
212 if (event->isIncrementalInsertion()) | 224 if (event->isIncrementalInsertion()) |
213 return false; | 225 return false; |
(...skipping 16 matching lines...) Expand all Loading... | |
230 return true; | 242 return true; |
231 } | 243 } |
232 | 244 |
233 String data = event->data(); | 245 String data = event->data(); |
234 if (data == "\n") { | 246 if (data == "\n") { |
235 if (event->isLineBreak()) | 247 if (event->isLineBreak()) |
236 return insertLineBreak(); | 248 return insertLineBreak(); |
237 return insertParagraphSeparator(); | 249 return insertParagraphSeparator(); |
238 } | 250 } |
239 | 251 |
252 if (data == " " && isCaretAtTopOfWrappedLine(frame().selection())) | |
253 insertLineBreak(); | |
254 | |
240 return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding, | 255 return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding, |
241 data, false, event); | 256 data, false, event); |
242 } | 257 } |
243 | 258 |
244 bool Editor::canEdit() const { | 259 bool Editor::canEdit() const { |
245 return frame().selection().rootEditableElement(); | 260 return frame().selection().rootEditableElement(); |
246 } | 261 } |
247 | 262 |
248 bool Editor::canEditRichly() const { | 263 bool Editor::canEditRichly() const { |
249 return frame().selection().isContentRichlyEditable(); | 264 return frame().selection().isContentRichlyEditable(); |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1707 } | 1722 } |
1708 | 1723 |
1709 DEFINE_TRACE(Editor) { | 1724 DEFINE_TRACE(Editor) { |
1710 visitor->trace(m_frame); | 1725 visitor->trace(m_frame); |
1711 visitor->trace(m_lastEditCommand); | 1726 visitor->trace(m_lastEditCommand); |
1712 visitor->trace(m_undoStack); | 1727 visitor->trace(m_undoStack); |
1713 visitor->trace(m_mark); | 1728 visitor->trace(m_mark); |
1714 } | 1729 } |
1715 | 1730 |
1716 } // namespace blink | 1731 } // namespace blink |
OLD | NEW |