Chromium Code Reviews| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 : m_editor(editor) | 95 : m_editor(editor) |
| 96 { | 96 { |
| 97 ++m_editor->m_preventRevealSelection; | 97 ++m_editor->m_preventRevealSelection; |
| 98 } | 98 } |
| 99 | 99 |
| 100 Editor::RevealSelectionScope::~RevealSelectionScope() | 100 Editor::RevealSelectionScope::~RevealSelectionScope() |
| 101 { | 101 { |
| 102 ASSERT(m_editor->m_preventRevealSelection); | 102 ASSERT(m_editor->m_preventRevealSelection); |
| 103 --m_editor->m_preventRevealSelection; | 103 --m_editor->m_preventRevealSelection; |
| 104 if (!m_editor->m_preventRevealSelection) | 104 if (!m_editor->m_preventRevealSelection) |
| 105 m_editor->m_frame.selection().revealSelection(ScrollAlignment::alignToEd geIfNeeded, RevealExtent); | 105 m_editor->m_frame->selection().revealSelection(ScrollAlignment::alignToE dgeIfNeeded, RevealExtent); |
|
haraken
2014/09/08 07:25:57
It looks better to use frame().foo than m_frame->f
sof
2014/09/08 21:17:45
Yes; switched over throughout.
| |
| 106 } | 106 } |
| 107 | 107 |
| 108 // When an event handler has moved the selection outside of a text control | 108 // When an event handler has moved the selection outside of a text control |
| 109 // we should use the target control's selection for this editing operation. | 109 // we should use the target control's selection for this editing operation. |
| 110 VisibleSelection Editor::selectionForCommand(Event* event) | 110 VisibleSelection Editor::selectionForCommand(Event* event) |
| 111 { | 111 { |
| 112 VisibleSelection selection = m_frame.selection().selection(); | 112 VisibleSelection selection = m_frame->selection().selection(); |
| 113 if (!event) | 113 if (!event) |
| 114 return selection; | 114 return selection; |
| 115 // If the target is a text control, and the current selection is outside of its shadow tree, | 115 // If the target is a text control, and the current selection is outside of its shadow tree, |
| 116 // then use the saved selection for that text control. | 116 // then use the saved selection for that text control. |
| 117 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start()); | 117 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start()); |
| 118 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target( )->toNode()) : 0; | 118 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target( )->toNode()) : 0; |
| 119 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro lOfTarget != textFormControlOfSelectionStart)) { | 119 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro lOfTarget != textFormControlOfSelectionStart)) { |
| 120 if (RefPtrWillBeRawPtr<Range> range = textFromControlOfTarget->selection ()) | 120 if (RefPtrWillBeRawPtr<Range> range = textFromControlOfTarget->selection ()) |
| 121 return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirecti onal()); | 121 return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirecti onal()); |
| 122 } | 122 } |
| 123 return selection; | 123 return selection; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Function considers Mac editing behavior a fallback when Page or Settings is n ot available. | 126 // Function considers Mac editing behavior a fallback when Page or Settings is n ot available. |
| 127 EditingBehavior Editor::behavior() const | 127 EditingBehavior Editor::behavior() const |
| 128 { | 128 { |
| 129 if (!m_frame.settings()) | 129 if (!m_frame->settings()) |
| 130 return EditingBehavior(EditingMacBehavior); | 130 return EditingBehavior(EditingMacBehavior); |
| 131 | 131 |
| 132 return EditingBehavior(m_frame.settings()->editingBehaviorType()); | 132 return EditingBehavior(m_frame->settings()->editingBehaviorType()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 static EditorClient& emptyEditorClient() | 135 static EditorClient& emptyEditorClient() |
| 136 { | 136 { |
| 137 DEFINE_STATIC_LOCAL(EmptyEditorClient, client, ()); | 137 DEFINE_STATIC_LOCAL(EmptyEditorClient, client, ()); |
| 138 return client; | 138 return client; |
| 139 } | 139 } |
| 140 | 140 |
| 141 EditorClient& Editor::client() const | 141 EditorClient& Editor::client() const |
| 142 { | 142 { |
| 143 if (Page* page = m_frame.page()) | 143 if (Page* page = m_frame->page()) |
| 144 return page->editorClient(); | 144 return page->editorClient(); |
| 145 return emptyEditorClient(); | 145 return emptyEditorClient(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 UndoStack* Editor::undoStack() const | 148 UndoStack* Editor::undoStack() const |
| 149 { | 149 { |
| 150 if (Page* page = m_frame.page()) | 150 if (Page* page = m_frame->page()) |
| 151 return &page->undoStack(); | 151 return &page->undoStack(); |
| 152 return 0; | 152 return 0; |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool Editor::handleTextEvent(TextEvent* event) | 155 bool Editor::handleTextEvent(TextEvent* event) |
| 156 { | 156 { |
| 157 // Default event handling for Drag and Drop will be handled by DragControlle r | 157 // Default event handling for Drag and Drop will be handled by DragControlle r |
| 158 // so we leave the event for it. | 158 // so we leave the event for it. |
| 159 if (event->isDrop()) | 159 if (event->isDrop()) |
| 160 return false; | 160 return false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 172 if (event->isLineBreak()) | 172 if (event->isLineBreak()) |
| 173 return insertLineBreak(); | 173 return insertLineBreak(); |
| 174 return insertParagraphSeparator(); | 174 return insertParagraphSeparator(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 return insertTextWithoutSendingTextEvent(data, false, event); | 177 return insertTextWithoutSendingTextEvent(data, false, event); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool Editor::canEdit() const | 180 bool Editor::canEdit() const |
| 181 { | 181 { |
| 182 return m_frame.selection().rootEditableElement(); | 182 return m_frame->selection().rootEditableElement(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool Editor::canEditRichly() const | 185 bool Editor::canEditRichly() const |
| 186 { | 186 { |
| 187 return m_frame.selection().isContentRichlyEditable(); | 187 return m_frame->selection().isContentRichlyEditable(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // WinIE uses onbeforecut and onbeforepaste to enables the cut and paste menu it ems. They | 190 // WinIE uses onbeforecut and onbeforepaste to enables the cut and paste menu it ems. They |
| 191 // also send onbeforecopy, apparently for symmetry, but it doesn't affect the me nu items. | 191 // also send onbeforecopy, apparently for symmetry, but it doesn't affect the me nu items. |
| 192 // We need to use onbeforecopy as a real menu enabler because we allow elements that are not | 192 // We need to use onbeforecopy as a real menu enabler because we allow elements that are not |
| 193 // normally selectable to implement copy/paste (like divs, or a document body). | 193 // normally selectable to implement copy/paste (like divs, or a document body). |
| 194 | 194 |
| 195 bool Editor::canDHTMLCut() | 195 bool Editor::canDHTMLCut() |
| 196 { | 196 { |
| 197 return !m_frame.selection().isInPasswordField() && !dispatchCPPEvent(EventTy peNames::beforecut, DataTransferNumb); | 197 return !m_frame->selection().isInPasswordField() && !dispatchCPPEvent(EventT ypeNames::beforecut, DataTransferNumb); |
| 198 } | 198 } |
| 199 | 199 |
| 200 bool Editor::canDHTMLCopy() | 200 bool Editor::canDHTMLCopy() |
| 201 { | 201 { |
| 202 return !m_frame.selection().isInPasswordField() && !dispatchCPPEvent(EventTy peNames::beforecopy, DataTransferNumb); | 202 return !m_frame->selection().isInPasswordField() && !dispatchCPPEvent(EventT ypeNames::beforecopy, DataTransferNumb); |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool Editor::canDHTMLPaste() | 205 bool Editor::canDHTMLPaste() |
| 206 { | 206 { |
| 207 return !dispatchCPPEvent(EventTypeNames::beforepaste, DataTransferNumb); | 207 return !dispatchCPPEvent(EventTypeNames::beforepaste, DataTransferNumb); |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool Editor::canCut() const | 210 bool Editor::canCut() const |
| 211 { | 211 { |
| 212 return canCopy() && canDelete(); | 212 return canCopy() && canDelete(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 224 return 0; | 224 return 0; |
| 225 | 225 |
| 226 Node* node = body->firstChild(); | 226 Node* node = body->firstChild(); |
| 227 if (!isHTMLImageElement(node)) | 227 if (!isHTMLImageElement(node)) |
| 228 return 0; | 228 return 0; |
| 229 return toHTMLImageElement(node); | 229 return toHTMLImageElement(node); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool Editor::canCopy() const | 232 bool Editor::canCopy() const |
| 233 { | 233 { |
| 234 if (imageElementFromImageDocument(m_frame.document())) | 234 if (imageElementFromImageDocument(m_frame->document())) |
| 235 return true; | 235 return true; |
| 236 FrameSelection& selection = m_frame.selection(); | 236 FrameSelection& selection = m_frame->selection(); |
| 237 return selection.isRange() && !selection.isInPasswordField(); | 237 return selection.isRange() && !selection.isInPasswordField(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 bool Editor::canPaste() const | 240 bool Editor::canPaste() const |
| 241 { | 241 { |
| 242 return canEdit(); | 242 return canEdit(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool Editor::canDelete() const | 245 bool Editor::canDelete() const |
| 246 { | 246 { |
| 247 FrameSelection& selection = m_frame.selection(); | 247 FrameSelection& selection = m_frame->selection(); |
| 248 return selection.isRange() && selection.rootEditableElement(); | 248 return selection.isRange() && selection.rootEditableElement(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool Editor::canDeleteRange(Range* range) const | 251 bool Editor::canDeleteRange(Range* range) const |
| 252 { | 252 { |
| 253 Node* startContainer = range->startContainer(); | 253 Node* startContainer = range->startContainer(); |
| 254 Node* endContainer = range->endContainer(); | 254 Node* endContainer = range->endContainer(); |
| 255 if (!startContainer || !endContainer) | 255 if (!startContainer || !endContainer) |
| 256 return false; | 256 return false; |
| 257 | 257 |
| 258 if (!startContainer->hasEditableStyle() || !endContainer->hasEditableStyle() ) | 258 if (!startContainer->hasEditableStyle() || !endContainer->hasEditableStyle() ) |
| 259 return false; | 259 return false; |
| 260 | 260 |
| 261 if (range->collapsed()) { | 261 if (range->collapsed()) { |
| 262 VisiblePosition start(range->startPosition(), DOWNSTREAM); | 262 VisiblePosition start(range->startPosition(), DOWNSTREAM); |
| 263 VisiblePosition previous = start.previous(); | 263 VisiblePosition previous = start.previous(); |
| 264 // FIXME: We sometimes allow deletions at the start of editable roots, l ike when the caret is in an empty list item. | 264 // FIXME: We sometimes allow deletions at the start of editable roots, l ike when the caret is in an empty list item. |
| 265 if (previous.isNull() || previous.deepEquivalent().deprecatedNode()->roo tEditableElement() != startContainer->rootEditableElement()) | 265 if (previous.isNull() || previous.deepEquivalent().deprecatedNode()->roo tEditableElement() != startContainer->rootEditableElement()) |
| 266 return false; | 266 return false; |
| 267 } | 267 } |
| 268 return true; | 268 return true; |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool Editor::smartInsertDeleteEnabled() const | 271 bool Editor::smartInsertDeleteEnabled() const |
| 272 { | 272 { |
| 273 if (Settings* settings = m_frame.settings()) | 273 if (Settings* settings = m_frame->settings()) |
| 274 return settings->smartInsertDeleteEnabled(); | 274 return settings->smartInsertDeleteEnabled(); |
| 275 return false; | 275 return false; |
| 276 } | 276 } |
| 277 | 277 |
| 278 bool Editor::canSmartCopyOrDelete() const | 278 bool Editor::canSmartCopyOrDelete() const |
| 279 { | 279 { |
| 280 return smartInsertDeleteEnabled() && m_frame.selection().granularity() == Wo rdGranularity; | 280 return smartInsertDeleteEnabled() && m_frame->selection().granularity() == W ordGranularity; |
| 281 } | 281 } |
| 282 | 282 |
| 283 bool Editor::isSelectTrailingWhitespaceEnabled() const | 283 bool Editor::isSelectTrailingWhitespaceEnabled() const |
| 284 { | 284 { |
| 285 if (Settings* settings = m_frame.settings()) | 285 if (Settings* settings = m_frame->settings()) |
| 286 return settings->selectTrailingWhitespaceEnabled(); | 286 return settings->selectTrailingWhitespaceEnabled(); |
| 287 return false; | 287 return false; |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g ranularity, bool killRing, bool isTypingAction) | 290 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g ranularity, bool killRing, bool isTypingAction) |
| 291 { | 291 { |
| 292 if (!canEdit()) | 292 if (!canEdit()) |
| 293 return false; | 293 return false; |
| 294 | 294 |
| 295 if (m_frame.selection().isRange()) { | 295 if (m_frame->selection().isRange()) { |
| 296 if (isTypingAction) { | 296 if (isTypingAction) { |
| 297 ASSERT(m_frame.document()); | 297 ASSERT(m_frame->document()); |
| 298 TypingCommand::deleteKeyPressed(*m_frame.document(), canSmartCopyOrD elete() ? TypingCommand::SmartDelete : 0, granularity); | 298 TypingCommand::deleteKeyPressed(*m_frame->document(), canSmartCopyOr Delete() ? TypingCommand::SmartDelete : 0, granularity); |
| 299 revealSelectionAfterEditingOperation(); | 299 revealSelectionAfterEditingOperation(); |
| 300 } else { | 300 } else { |
| 301 if (killRing) | 301 if (killRing) |
| 302 addToKillRing(selectedRange().get(), false); | 302 addToKillRing(selectedRange().get(), false); |
| 303 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); | 303 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); |
| 304 // Implicitly calls revealSelectionAfterEditingOperation(). | 304 // Implicitly calls revealSelectionAfterEditingOperation(). |
| 305 } | 305 } |
| 306 } else { | 306 } else { |
| 307 TypingCommand::Options options = 0; | 307 TypingCommand::Options options = 0; |
| 308 if (canSmartCopyOrDelete()) | 308 if (canSmartCopyOrDelete()) |
| 309 options |= TypingCommand::SmartDelete; | 309 options |= TypingCommand::SmartDelete; |
| 310 if (killRing) | 310 if (killRing) |
| 311 options |= TypingCommand::KillRing; | 311 options |= TypingCommand::KillRing; |
| 312 switch (direction) { | 312 switch (direction) { |
| 313 case DirectionForward: | 313 case DirectionForward: |
| 314 case DirectionRight: | 314 case DirectionRight: |
| 315 ASSERT(m_frame.document()); | 315 ASSERT(m_frame->document()); |
| 316 TypingCommand::forwardDeleteKeyPressed(*m_frame.document(), options, granularity); | 316 TypingCommand::forwardDeleteKeyPressed(*m_frame->document(), options , granularity); |
| 317 break; | 317 break; |
| 318 case DirectionBackward: | 318 case DirectionBackward: |
| 319 case DirectionLeft: | 319 case DirectionLeft: |
| 320 ASSERT(m_frame.document()); | 320 ASSERT(m_frame->document()); |
| 321 TypingCommand::deleteKeyPressed(*m_frame.document(), options, granul arity); | 321 TypingCommand::deleteKeyPressed(*m_frame->document(), options, granu larity); |
| 322 break; | 322 break; |
| 323 } | 323 } |
| 324 revealSelectionAfterEditingOperation(); | 324 revealSelectionAfterEditingOperation(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 // FIXME: We should to move this down into deleteKeyPressed. | 327 // FIXME: We should to move this down into deleteKeyPressed. |
| 328 // clear the "start new kill ring sequence" setting, because it was set to t rue | 328 // clear the "start new kill ring sequence" setting, because it was set to t rue |
| 329 // when the selection was updated by deleting the range | 329 // when the selection was updated by deleting the range |
| 330 if (killRing) | 330 if (killRing) |
| 331 setStartNewKillRingSequence(false); | 331 setStartNewKillRingSequence(false); |
| 332 | 332 |
| 333 return true; | 333 return true; |
| 334 } | 334 } |
| 335 | 335 |
| 336 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) | 336 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) |
| 337 { | 337 { |
| 338 if (m_frame.selection().isNone()) | 338 if (m_frame->selection().isNone()) |
| 339 return; | 339 return; |
| 340 | 340 |
| 341 ASSERT(m_frame.document()); | 341 ASSERT(m_frame->document()); |
| 342 DeleteSelectionCommand::create(*m_frame.document(), smartDelete)->apply(); | 342 DeleteSelectionCommand::create(*m_frame->document(), smartDelete)->apply(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) | 345 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) |
| 346 { | 346 { |
| 347 Element* target = findEventTargetFromSelection(); | 347 Element* target = findEventTargetFromSelection(); |
| 348 if (!target) | 348 if (!target) |
| 349 return; | 349 return; |
| 350 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame.domWindow() , pastingText, smartReplace), IGNORE_EXCEPTION); | 350 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow( ), pastingText, smartReplace), IGNORE_EXCEPTION); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void Editor::pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment> pastingFra gment, bool smartReplace, bool matchStyle) | 353 void Editor::pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment> pastingFra gment, bool smartReplace, bool matchStyle) |
| 354 { | 354 { |
| 355 Element* target = findEventTargetFromSelection(); | 355 Element* target = findEventTargetFromSelection(); |
| 356 if (!target) | 356 if (!target) |
| 357 return; | 357 return; |
| 358 target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame.domWindow(), pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION); | 358 target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame->domWindow() , pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION); |
| 359 } | 359 } |
| 360 | 360 |
| 361 bool Editor::tryDHTMLCopy() | 361 bool Editor::tryDHTMLCopy() |
| 362 { | 362 { |
| 363 if (m_frame.selection().isInPasswordField()) | 363 if (m_frame->selection().isInPasswordField()) |
| 364 return false; | 364 return false; |
| 365 | 365 |
| 366 return !dispatchCPPEvent(EventTypeNames::copy, DataTransferWritable); | 366 return !dispatchCPPEvent(EventTypeNames::copy, DataTransferWritable); |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool Editor::tryDHTMLCut() | 369 bool Editor::tryDHTMLCut() |
| 370 { | 370 { |
| 371 if (m_frame.selection().isInPasswordField()) | 371 if (m_frame->selection().isInPasswordField()) |
| 372 return false; | 372 return false; |
| 373 | 373 |
| 374 return !dispatchCPPEvent(EventTypeNames::cut, DataTransferWritable); | 374 return !dispatchCPPEvent(EventTypeNames::cut, DataTransferWritable); |
| 375 } | 375 } |
| 376 | 376 |
| 377 bool Editor::tryDHTMLPaste(PasteMode pasteMode) | 377 bool Editor::tryDHTMLPaste(PasteMode pasteMode) |
| 378 { | 378 { |
| 379 return !dispatchCPPEvent(EventTypeNames::paste, DataTransferReadable, pasteM ode); | 379 return !dispatchCPPEvent(EventTypeNames::paste, DataTransferReadable, pasteM ode); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard) | 382 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard) |
| 383 { | 383 { |
| 384 String text = pasteboard->plainText(); | 384 String text = pasteboard->plainText(); |
| 385 pasteAsPlainText(text, canSmartReplaceWithPasteboard(pasteboard)); | 385 pasteAsPlainText(text, canSmartReplaceWithPasteboard(pasteboard)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void Editor::pasteWithPasteboard(Pasteboard* pasteboard) | 388 void Editor::pasteWithPasteboard(Pasteboard* pasteboard) |
| 389 { | 389 { |
| 390 RefPtrWillBeRawPtr<Range> range = selectedRange(); | 390 RefPtrWillBeRawPtr<Range> range = selectedRange(); |
| 391 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; | 391 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; |
| 392 bool chosePlainText = false; | 392 bool chosePlainText = false; |
| 393 | 393 |
| 394 if (pasteboard->isHTMLAvailable()) { | 394 if (pasteboard->isHTMLAvailable()) { |
| 395 unsigned fragmentStart = 0; | 395 unsigned fragmentStart = 0; |
| 396 unsigned fragmentEnd = 0; | 396 unsigned fragmentEnd = 0; |
| 397 KURL url; | 397 KURL url; |
| 398 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd); | 398 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd); |
| 399 if (!markup.isEmpty()) { | 399 if (!markup.isEmpty()) { |
| 400 ASSERT(m_frame.document()); | 400 ASSERT(m_frame->document()); |
| 401 fragment = createFragmentFromMarkupWithContext(*m_frame.document(), markup, fragmentStart, fragmentEnd, url, DisallowScriptingAndPluginContent); | 401 fragment = createFragmentFromMarkupWithContext(*m_frame->document(), markup, fragmentStart, fragmentEnd, url, DisallowScriptingAndPluginContent); |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 if (!fragment) { | 405 if (!fragment) { |
| 406 String text = pasteboard->plainText(); | 406 String text = pasteboard->plainText(); |
| 407 if (!text.isEmpty()) { | 407 if (!text.isEmpty()) { |
| 408 chosePlainText = true; | 408 chosePlainText = true; |
| 409 fragment = createFragmentFromText(range.get(), text); | 409 fragment = createFragmentFromText(range.get(), text); |
| 410 } | 410 } |
| 411 } | 411 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 return !noDefaultProcessing; | 496 return !noDefaultProcessing; |
| 497 } | 497 } |
| 498 | 498 |
| 499 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) | 499 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) |
| 500 { | 500 { |
| 501 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); | 501 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); |
| 502 } | 502 } |
| 503 | 503 |
| 504 void Editor::replaceSelectionWithFragment(PassRefPtrWillBeRawPtr<DocumentFragmen t> fragment, bool selectReplacement, bool smartReplace, bool matchStyle) | 504 void Editor::replaceSelectionWithFragment(PassRefPtrWillBeRawPtr<DocumentFragmen t> fragment, bool selectReplacement, bool smartReplace, bool matchStyle) |
| 505 { | 505 { |
| 506 if (m_frame.selection().isNone() || !m_frame.selection().isContentEditable() || !fragment) | 506 if (m_frame->selection().isNone() || !m_frame->selection().isContentEditable () || !fragment) |
| 507 return; | 507 return; |
| 508 | 508 |
| 509 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P reventNesting | ReplaceSelectionCommand::SanitizeFragment; | 509 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P reventNesting | ReplaceSelectionCommand::SanitizeFragment; |
| 510 if (selectReplacement) | 510 if (selectReplacement) |
| 511 options |= ReplaceSelectionCommand::SelectReplacement; | 511 options |= ReplaceSelectionCommand::SelectReplacement; |
| 512 if (smartReplace) | 512 if (smartReplace) |
| 513 options |= ReplaceSelectionCommand::SmartReplace; | 513 options |= ReplaceSelectionCommand::SmartReplace; |
| 514 if (matchStyle) | 514 if (matchStyle) |
| 515 options |= ReplaceSelectionCommand::MatchStyle; | 515 options |= ReplaceSelectionCommand::MatchStyle; |
| 516 ASSERT(m_frame.document()); | 516 ASSERT(m_frame->document()); |
| 517 ReplaceSelectionCommand::create(*m_frame.document(), fragment, options, Edit ActionPaste)->apply(); | 517 ReplaceSelectionCommand::create(*m_frame->document(), fragment, options, Edi tActionPaste)->apply(); |
| 518 revealSelectionAfterEditingOperation(); | 518 revealSelectionAfterEditingOperation(); |
| 519 | 519 |
| 520 if (m_frame.selection().isInPasswordField() || !spellChecker().isContinuousS pellCheckingEnabled()) | 520 if (m_frame->selection().isInPasswordField() || !spellChecker().isContinuous SpellCheckingEnabled()) |
| 521 return; | 521 return; |
| 522 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(m_frame.selection(). rootEditableElement()); | 522 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(m_frame->selection() .rootEditableElement()); |
| 523 } | 523 } |
| 524 | 524 |
| 525 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) | 525 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) |
| 526 { | 526 { |
| 527 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true); | 527 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true); |
| 528 } | 528 } |
| 529 | 529 |
| 530 PassRefPtrWillBeRawPtr<Range> Editor::selectedRange() | 530 PassRefPtrWillBeRawPtr<Range> Editor::selectedRange() |
| 531 { | 531 { |
| 532 return m_frame.selection().toNormalizedRange(); | 532 return m_frame->selection().toNormalizedRange(); |
| 533 } | 533 } |
| 534 | 534 |
| 535 bool Editor::shouldDeleteRange(Range* range) const | 535 bool Editor::shouldDeleteRange(Range* range) const |
| 536 { | 536 { |
| 537 if (!range || range->collapsed()) | 537 if (!range || range->collapsed()) |
| 538 return false; | 538 return false; |
| 539 | 539 |
| 540 return canDeleteRange(range); | 540 return canDeleteRange(range); |
| 541 } | 541 } |
| 542 | 542 |
| 543 void Editor::notifyComponentsOnChangedSelection(const VisibleSelection& oldSelec tion, FrameSelection::SetSelectionOptions options) | 543 void Editor::notifyComponentsOnChangedSelection(const VisibleSelection& oldSelec tion, FrameSelection::SetSelectionOptions options) |
| 544 { | 544 { |
| 545 client().respondToChangedSelection(&m_frame, m_frame.selection().selectionTy pe()); | 545 client().respondToChangedSelection(m_frame, m_frame->selection().selectionTy pe()); |
| 546 setStartNewKillRingSequence(true); | 546 setStartNewKillRingSequence(true); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void Editor::respondToChangedContents(const VisibleSelection& endingSelection) | 549 void Editor::respondToChangedContents(const VisibleSelection& endingSelection) |
| 550 { | 550 { |
| 551 if (m_frame.settings() && m_frame.settings()->accessibilityEnabled()) { | 551 if (m_frame->settings() && m_frame->settings()->accessibilityEnabled()) { |
| 552 Node* node = endingSelection.start().deprecatedNode(); | 552 Node* node = endingSelection.start().deprecatedNode(); |
| 553 if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) | 553 if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache()) |
| 554 cache->postNotification(node, AXObjectCache::AXValueChanged, false); | 554 cache->postNotification(node, AXObjectCache::AXValueChanged, false); |
| 555 } | 555 } |
| 556 | 556 |
| 557 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 557 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 558 client().respondToChangedContents(); | 558 client().respondToChangedContents(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void Editor::removeFormattingAndStyle() | 561 void Editor::removeFormattingAndStyle() |
| 562 { | 562 { |
| 563 ASSERT(m_frame.document()); | 563 ASSERT(m_frame->document()); |
| 564 RemoveFormatCommand::create(*m_frame.document())->apply(); | 564 RemoveFormatCommand::create(*m_frame->document())->apply(); |
| 565 } | 565 } |
| 566 | 566 |
| 567 void Editor::clearLastEditCommand() | 567 void Editor::clearLastEditCommand() |
| 568 { | 568 { |
| 569 m_lastEditCommand.clear(); | 569 m_lastEditCommand.clear(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const | 572 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const |
| 573 { | 573 { |
| 574 Element* target = selection.start().element(); | 574 Element* target = selection.start().element(); |
| 575 if (!target) | 575 if (!target) |
| 576 target = m_frame.document()->body(); | 576 target = m_frame->document()->body(); |
| 577 | 577 |
| 578 return target; | 578 return target; |
| 579 } | 579 } |
| 580 | 580 |
| 581 Element* Editor::findEventTargetFromSelection() const | 581 Element* Editor::findEventTargetFromSelection() const |
| 582 { | 582 { |
| 583 return findEventTargetFrom(m_frame.selection().selection()); | 583 return findEventTargetFrom(m_frame->selection().selection()); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void Editor::applyStyle(StylePropertySet* style, EditAction editingAction) | 586 void Editor::applyStyle(StylePropertySet* style, EditAction editingAction) |
| 587 { | 587 { |
| 588 switch (m_frame.selection().selectionType()) { | 588 switch (m_frame->selection().selectionType()) { |
| 589 case NoSelection: | 589 case NoSelection: |
| 590 // do nothing | 590 // do nothing |
| 591 break; | 591 break; |
| 592 case CaretSelection: | 592 case CaretSelection: |
| 593 computeAndSetTypingStyle(style, editingAction); | 593 computeAndSetTypingStyle(style, editingAction); |
| 594 break; | 594 break; |
| 595 case RangeSelection: | 595 case RangeSelection: |
| 596 if (style) { | 596 if (style) { |
| 597 ASSERT(m_frame.document()); | 597 ASSERT(m_frame->document()); |
| 598 ApplyStyleCommand::create(*m_frame.document(), EditingStyle::create( style).get(), editingAction)->apply(); | 598 ApplyStyleCommand::create(*m_frame->document(), EditingStyle::create (style).get(), editingAction)->apply(); |
| 599 } | 599 } |
| 600 break; | 600 break; |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi on) | 604 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi on) |
| 605 { | 605 { |
| 606 if (m_frame.selection().isNone() || !style) | 606 if (m_frame->selection().isNone() || !style) |
| 607 return; | 607 return; |
| 608 ASSERT(m_frame.document()); | 608 ASSERT(m_frame->document()); |
| 609 ApplyStyleCommand::create(*m_frame.document(), EditingStyle::create(style).g et(), editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); | 609 ApplyStyleCommand::create(*m_frame->document(), EditingStyle::create(style). get(), editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc tion) | 612 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc tion) |
| 613 { | 613 { |
| 614 if (!style || style->isEmpty() || !canEditRichly()) | 614 if (!style || style->isEmpty() || !canEditRichly()) |
| 615 return; | 615 return; |
| 616 | 616 |
| 617 applyStyle(style, editingAction); | 617 applyStyle(style, editingAction); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void Editor::applyParagraphStyleToSelection(StylePropertySet* style, EditAction editingAction) | 620 void Editor::applyParagraphStyleToSelection(StylePropertySet* style, EditAction editingAction) |
| 621 { | 621 { |
| 622 if (!style || style->isEmpty() || !canEditRichly()) | 622 if (!style || style->isEmpty() || !canEditRichly()) |
| 623 return; | 623 return; |
| 624 | 624 |
| 625 applyParagraphStyle(style, editingAction); | 625 applyParagraphStyle(style, editingAction); |
| 626 } | 626 } |
| 627 | 627 |
| 628 bool Editor::selectionStartHasStyle(CSSPropertyID propertyID, const String& valu e) const | 628 bool Editor::selectionStartHasStyle(CSSPropertyID propertyID, const String& valu e) const |
| 629 { | 629 { |
| 630 return EditingStyle::create(propertyID, value)->triStateOfStyle( | 630 return EditingStyle::create(propertyID, value)->triStateOfStyle( |
| 631 EditingStyle::styleAtSelectionStart(m_frame.selection().selection(), pro pertyID == CSSPropertyBackgroundColor).get()); | 631 EditingStyle::styleAtSelectionStart(m_frame->selection().selection(), pr opertyID == CSSPropertyBackgroundColor).get()); |
| 632 } | 632 } |
| 633 | 633 |
| 634 TriState Editor::selectionHasStyle(CSSPropertyID propertyID, const String& value ) const | 634 TriState Editor::selectionHasStyle(CSSPropertyID propertyID, const String& value ) const |
| 635 { | 635 { |
| 636 return EditingStyle::create(propertyID, value)->triStateOfStyle(m_frame.sele ction().selection()); | 636 return EditingStyle::create(propertyID, value)->triStateOfStyle(m_frame->sel ection().selection()); |
| 637 } | 637 } |
| 638 | 638 |
| 639 String Editor::selectionStartCSSPropertyValue(CSSPropertyID propertyID) | 639 String Editor::selectionStartCSSPropertyValue(CSSPropertyID propertyID) |
| 640 { | 640 { |
| 641 RefPtrWillBeRawPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelec tionStart(m_frame.selection().selection(), | 641 RefPtrWillBeRawPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelec tionStart(m_frame->selection().selection(), |
| 642 propertyID == CSSPropertyBackgroundColor); | 642 propertyID == CSSPropertyBackgroundColor); |
| 643 if (!selectionStyle || !selectionStyle->style()) | 643 if (!selectionStyle || !selectionStyle->style()) |
| 644 return String(); | 644 return String(); |
| 645 | 645 |
| 646 if (propertyID == CSSPropertyFontSize) | 646 if (propertyID == CSSPropertyFontSize) |
| 647 return String::number(selectionStyle->legacyFontSize(m_frame.document()) ); | 647 return String::number(selectionStyle->legacyFontSize(m_frame->document() )); |
| 648 return selectionStyle->style()->getPropertyValue(propertyID); | 648 return selectionStyle->style()->getPropertyValue(propertyID); |
| 649 } | 649 } |
| 650 | 650 |
| 651 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element> startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) | 651 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element> startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) |
| 652 { | 652 { |
| 653 if (startRoot) | 653 if (startRoot) |
| 654 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon tentChanged), IGNORE_EXCEPTION); | 654 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon tentChanged), IGNORE_EXCEPTION); |
| 655 if (endRoot && endRoot != startRoot) | 655 if (endRoot && endRoot != startRoot) |
| 656 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte ntChanged), IGNORE_EXCEPTION); | 656 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte ntChanged), IGNORE_EXCEPTION); |
| 657 } | 657 } |
| 658 | 658 |
| 659 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) | 659 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) |
| 660 { | 660 { |
| 661 EventQueueScope scope; | 661 EventQueueScope scope; |
| 662 m_frame.document()->updateLayout(); | 662 m_frame->document()->updateLayout(); |
| 663 | 663 |
| 664 EditCommandComposition* composition = cmd->composition(); | 664 EditCommandComposition* composition = cmd->composition(); |
| 665 ASSERT(composition); | 665 ASSERT(composition); |
| 666 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement()); | 666 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement()); |
| 667 VisibleSelection newSelection(cmd->endingSelection()); | 667 VisibleSelection newSelection(cmd->endingSelection()); |
| 668 | 668 |
| 669 // Don't clear the typing style with this selection change. We do those thin gs elsewhere if necessary. | 669 // Don't clear the typing style with this selection change. We do those thin gs elsewhere if necessary. |
| 670 changeSelectionAfterCommand(newSelection, 0); | 670 changeSelectionAfterCommand(newSelection, 0); |
| 671 | 671 |
| 672 if (!cmd->preservesTypingStyle()) | 672 if (!cmd->preservesTypingStyle()) |
| 673 m_frame.selection().clearTypingStyle(); | 673 m_frame->selection().clearTypingStyle(); |
| 674 | 674 |
| 675 // Command will be equal to last edit command only in the case of typing | 675 // Command will be equal to last edit command only in the case of typing |
| 676 if (m_lastEditCommand.get() == cmd) { | 676 if (m_lastEditCommand.get() == cmd) { |
| 677 ASSERT(cmd->isTypingCommand()); | 677 ASSERT(cmd->isTypingCommand()); |
| 678 } else { | 678 } else { |
| 679 // Only register a new undo command if the command passed in is | 679 // Only register a new undo command if the command passed in is |
| 680 // different from the last command | 680 // different from the last command |
| 681 m_lastEditCommand = cmd; | 681 m_lastEditCommand = cmd; |
| 682 if (UndoStack* undoStack = this->undoStack()) | 682 if (UndoStack* undoStack = this->undoStack()) |
| 683 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); | 683 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); |
| 684 } | 684 } |
| 685 | 685 |
| 686 respondToChangedContents(newSelection); | 686 respondToChangedContents(newSelection); |
| 687 } | 687 } |
| 688 | 688 |
| 689 void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) | 689 void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) |
| 690 { | 690 { |
| 691 EventQueueScope scope; | 691 EventQueueScope scope; |
| 692 m_frame.document()->updateLayout(); | 692 m_frame->document()->updateLayout(); |
| 693 | 693 |
| 694 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); | 694 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); |
| 695 | 695 |
| 696 VisibleSelection newSelection(cmd->startingSelection()); | 696 VisibleSelection newSelection(cmd->startingSelection()); |
| 697 newSelection.validatePositionsIfNeeded(); | 697 newSelection.validatePositionsIfNeeded(); |
| 698 if (newSelection.start().document() == m_frame.document() && newSelection.en d().document() == m_frame.document()) | 698 if (newSelection.start().document() == m_frame->document() && newSelection.e nd().document() == m_frame->document()) |
| 699 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); | 699 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
| 700 | 700 |
| 701 m_lastEditCommand = nullptr; | 701 m_lastEditCommand = nullptr; |
| 702 if (UndoStack* undoStack = this->undoStack()) | 702 if (UndoStack* undoStack = this->undoStack()) |
| 703 undoStack->registerRedoStep(cmd); | 703 undoStack->registerRedoStep(cmd); |
| 704 respondToChangedContents(newSelection); | 704 respondToChangedContents(newSelection); |
| 705 } | 705 } |
| 706 | 706 |
| 707 void Editor::reappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) | 707 void Editor::reappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) |
| 708 { | 708 { |
| 709 EventQueueScope scope; | 709 EventQueueScope scope; |
| 710 m_frame.document()->updateLayout(); | 710 m_frame->document()->updateLayout(); |
| 711 | 711 |
| 712 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); | 712 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); |
| 713 | 713 |
| 714 VisibleSelection newSelection(cmd->endingSelection()); | 714 VisibleSelection newSelection(cmd->endingSelection()); |
| 715 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); | 715 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); |
| 716 | 716 |
| 717 m_lastEditCommand = nullptr; | 717 m_lastEditCommand = nullptr; |
| 718 if (UndoStack* undoStack = this->undoStack()) | 718 if (UndoStack* undoStack = this->undoStack()) |
| 719 undoStack->registerUndoStep(cmd); | 719 undoStack->registerUndoStep(cmd); |
| 720 respondToChangedContents(newSelection); | 720 respondToChangedContents(newSelection); |
| 721 } | 721 } |
| 722 | 722 |
| 723 PassOwnPtrWillBeRawPtr<Editor> Editor::create(LocalFrame& frame) | 723 PassOwnPtrWillBeRawPtr<Editor> Editor::create(LocalFrame& frame) |
| 724 { | 724 { |
| 725 return adoptPtrWillBeNoop(new Editor(frame)); | 725 return adoptPtrWillBeNoop(new Editor(frame)); |
| 726 } | 726 } |
| 727 | 727 |
| 728 Editor::Editor(LocalFrame& frame) | 728 Editor::Editor(LocalFrame& frame) |
| 729 : m_frame(frame) | 729 : m_frame(&frame) |
| 730 , m_preventRevealSelection(0) | 730 , m_preventRevealSelection(0) |
| 731 , m_shouldStartNewKillRingSequence(false) | 731 , m_shouldStartNewKillRingSequence(false) |
| 732 // This is off by default, since most editors want this behavior (this match es IE but not FF). | 732 // This is off by default, since most editors want this behavior (this match es IE but not FF). |
| 733 , m_shouldStyleWithCSS(false) | 733 , m_shouldStyleWithCSS(false) |
| 734 , m_killRing(adoptPtr(new KillRing)) | 734 , m_killRing(adoptPtr(new KillRing)) |
| 735 , m_areMarkedTextMatchesHighlighted(false) | 735 , m_areMarkedTextMatchesHighlighted(false) |
| 736 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv) | 736 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv) |
| 737 , m_overwriteModeEnabled(false) | 737 , m_overwriteModeEnabled(false) |
| 738 { | 738 { |
| 739 } | 739 } |
| 740 | 740 |
| 741 Editor::~Editor() | 741 Editor::~Editor() |
| 742 { | 742 { |
| 743 } | 743 } |
| 744 | 744 |
| 745 void Editor::clear() | 745 void Editor::clear() |
| 746 { | 746 { |
| 747 m_frame.inputMethodController().clear(); | 747 m_frame->inputMethodController().clear(); |
| 748 m_shouldStyleWithCSS = false; | 748 m_shouldStyleWithCSS = false; |
| 749 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; | 749 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; |
| 750 } | 750 } |
| 751 | 751 |
| 752 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) | 752 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) |
| 753 { | 753 { |
| 754 return m_frame.eventHandler().handleTextInputEvent(text, triggeringEvent); | 754 return m_frame->eventHandler().handleTextInputEvent(text, triggeringEvent); |
| 755 } | 755 } |
| 756 | 756 |
| 757 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent) | 757 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent) |
| 758 { | 758 { |
| 759 if (text.isEmpty()) | 759 if (text.isEmpty()) |
| 760 return false; | 760 return false; |
| 761 | 761 |
| 762 VisibleSelection selection = selectionForCommand(triggeringEvent); | 762 VisibleSelection selection = selectionForCommand(triggeringEvent); |
| 763 if (!selection.isContentEditable()) | 763 if (!selection.isContentEditable()) |
| 764 return false; | 764 return false; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 788 } | 788 } |
| 789 | 789 |
| 790 return true; | 790 return true; |
| 791 } | 791 } |
| 792 | 792 |
| 793 bool Editor::insertLineBreak() | 793 bool Editor::insertLineBreak() |
| 794 { | 794 { |
| 795 if (!canEdit()) | 795 if (!canEdit()) |
| 796 return false; | 796 return false; |
| 797 | 797 |
| 798 VisiblePosition caret = m_frame.selection().selection().visibleStart(); | 798 VisiblePosition caret = m_frame->selection().selection().visibleStart(); |
| 799 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 799 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
| 800 ASSERT(m_frame.document()); | 800 ASSERT(m_frame->document()); |
| 801 TypingCommand::insertLineBreak(*m_frame.document(), 0); | 801 TypingCommand::insertLineBreak(*m_frame->document(), 0); |
| 802 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 802 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
| 803 | 803 |
| 804 return true; | 804 return true; |
| 805 } | 805 } |
| 806 | 806 |
| 807 bool Editor::insertParagraphSeparator() | 807 bool Editor::insertParagraphSeparator() |
| 808 { | 808 { |
| 809 if (!canEdit()) | 809 if (!canEdit()) |
| 810 return false; | 810 return false; |
| 811 | 811 |
| 812 if (!canEditRichly()) | 812 if (!canEditRichly()) |
| 813 return insertLineBreak(); | 813 return insertLineBreak(); |
| 814 | 814 |
| 815 VisiblePosition caret = m_frame.selection().selection().visibleStart(); | 815 VisiblePosition caret = m_frame->selection().selection().visibleStart(); |
| 816 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 816 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
| 817 ASSERT(m_frame.document()); | 817 ASSERT(m_frame->document()); |
| 818 TypingCommand::insertParagraphSeparator(*m_frame.document(), 0); | 818 TypingCommand::insertParagraphSeparator(*m_frame->document(), 0); |
| 819 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 819 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
| 820 | 820 |
| 821 return true; | 821 return true; |
| 822 } | 822 } |
| 823 | 823 |
| 824 void Editor::cut() | 824 void Editor::cut() |
| 825 { | 825 { |
| 826 if (tryDHTMLCut()) | 826 if (tryDHTMLCut()) |
| 827 return; // DHTML did the whole operation | 827 return; // DHTML did the whole operation |
| 828 if (!canCut()) | 828 if (!canCut()) |
| 829 return; | 829 return; |
| 830 RefPtrWillBeRawPtr<Range> selection = selectedRange(); | 830 RefPtrWillBeRawPtr<Range> selection = selectedRange(); |
| 831 if (shouldDeleteRange(selection.get())) { | 831 if (shouldDeleteRange(selection.get())) { |
| 832 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 832 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 833 String plainText = m_frame.selectedTextForClipboard(); | 833 String plainText = m_frame->selectedTextForClipboard(); |
| 834 if (enclosingTextFormControl(m_frame.selection().start())) { | 834 if (enclosingTextFormControl(m_frame->selection().start())) { |
| 835 Pasteboard::generalPasteboard()->writePlainText(plainText, | 835 Pasteboard::generalPasteboard()->writePlainText(plainText, |
| 836 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); | 836 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); |
| 837 } else { | 837 } else { |
| 838 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText); | 838 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText); |
| 839 } | 839 } |
| 840 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); | 840 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); |
| 841 } | 841 } |
| 842 } | 842 } |
| 843 | 843 |
| 844 void Editor::copy() | 844 void Editor::copy() |
| 845 { | 845 { |
| 846 if (tryDHTMLCopy()) | 846 if (tryDHTMLCopy()) |
| 847 return; // DHTML did the whole operation | 847 return; // DHTML did the whole operation |
| 848 if (!canCopy()) | 848 if (!canCopy()) |
| 849 return; | 849 return; |
| 850 if (enclosingTextFormControl(m_frame.selection().start())) { | 850 if (enclosingTextFormControl(m_frame->selection().start())) { |
| 851 Pasteboard::generalPasteboard()->writePlainText(m_frame.selectedTextForC lipboard(), | 851 Pasteboard::generalPasteboard()->writePlainText(m_frame->selectedTextFor Clipboard(), |
| 852 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace); | 852 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace); |
| 853 } else { | 853 } else { |
| 854 Document* document = m_frame.document(); | 854 Document* document = m_frame->document(); |
| 855 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent)) | 855 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent)) |
| 856 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title()); | 856 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title()); |
| 857 else | 857 else |
| 858 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selected Range().get(), m_frame.selectedTextForClipboard()); | 858 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selected Range().get(), m_frame->selectedTextForClipboard()); |
| 859 } | 859 } |
| 860 } | 860 } |
| 861 | 861 |
| 862 void Editor::paste() | 862 void Editor::paste() |
| 863 { | 863 { |
| 864 ASSERT(m_frame.document()); | 864 ASSERT(m_frame->document()); |
| 865 if (tryDHTMLPaste(AllMimeTypes)) | 865 if (tryDHTMLPaste(AllMimeTypes)) |
| 866 return; // DHTML did the whole operation | 866 return; // DHTML did the whole operation |
| 867 if (!canPaste()) | 867 if (!canPaste()) |
| 868 return; | 868 return; |
| 869 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 869 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
| 870 ResourceFetcher* loader = m_frame.document()->fetcher(); | 870 ResourceFetcher* loader = m_frame->document()->fetcher(); |
| 871 ResourceCacheValidationSuppressor validationSuppressor(loader); | 871 ResourceCacheValidationSuppressor validationSuppressor(loader); |
| 872 if (m_frame.selection().isContentRichlyEditable()) | 872 if (m_frame->selection().isContentRichlyEditable()) |
| 873 pasteWithPasteboard(Pasteboard::generalPasteboard()); | 873 pasteWithPasteboard(Pasteboard::generalPasteboard()); |
| 874 else | 874 else |
| 875 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); | 875 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
| 876 } | 876 } |
| 877 | 877 |
| 878 void Editor::pasteAsPlainText() | 878 void Editor::pasteAsPlainText() |
| 879 { | 879 { |
| 880 if (tryDHTMLPaste(PlainTextOnly)) | 880 if (tryDHTMLPaste(PlainTextOnly)) |
| 881 return; | 881 return; |
| 882 if (!canPaste()) | 882 if (!canPaste()) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet: :create(); | 1008 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet: :create(); |
| 1009 style->setProperty(CSSPropertyDirection, direction == LeftToRightWritingDire ction ? "ltr" : direction == RightToLeftWritingDirection ? "rtl" : "inherit", fa lse); | 1009 style->setProperty(CSSPropertyDirection, direction == LeftToRightWritingDire ction ? "ltr" : direction == RightToLeftWritingDirection ? "rtl" : "inherit", fa lse); |
| 1010 applyParagraphStyleToSelection(style.get(), EditActionSetWritingDirection); | 1010 applyParagraphStyleToSelection(style.get(), EditActionSetWritingDirection); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 void Editor::revealSelectionAfterEditingOperation(const ScrollAlignment& alignme nt, RevealExtentOption revealExtentOption) | 1013 void Editor::revealSelectionAfterEditingOperation(const ScrollAlignment& alignme nt, RevealExtentOption revealExtentOption) |
| 1014 { | 1014 { |
| 1015 if (m_preventRevealSelection) | 1015 if (m_preventRevealSelection) |
| 1016 return; | 1016 return; |
| 1017 | 1017 |
| 1018 m_frame.selection().revealSelection(alignment, revealExtentOption); | 1018 m_frame->selection().revealSelection(alignment, revealExtentOption); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 void Editor::transpose() | 1021 void Editor::transpose() |
| 1022 { | 1022 { |
| 1023 if (!canEdit()) | 1023 if (!canEdit()) |
| 1024 return; | 1024 return; |
| 1025 | 1025 |
| 1026 VisibleSelection selection = m_frame.selection().selection(); | 1026 VisibleSelection selection = m_frame->selection().selection(); |
| 1027 if (!selection.isCaret()) | 1027 if (!selection.isCaret()) |
| 1028 return; | 1028 return; |
| 1029 | 1029 |
| 1030 // Make a selection that goes back one character and forward two characters. | 1030 // Make a selection that goes back one character and forward two characters. |
| 1031 VisiblePosition caret = selection.visibleStart(); | 1031 VisiblePosition caret = selection.visibleStart(); |
| 1032 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); | 1032 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); |
| 1033 VisiblePosition previous = next.previous(); | 1033 VisiblePosition previous = next.previous(); |
| 1034 if (next == previous) | 1034 if (next == previous) |
| 1035 return; | 1035 return; |
| 1036 previous = previous.previous(); | 1036 previous = previous.previous(); |
| 1037 if (!inSameParagraph(next, previous)) | 1037 if (!inSameParagraph(next, previous)) |
| 1038 return; | 1038 return; |
| 1039 RefPtrWillBeRawPtr<Range> range = makeRange(previous, next); | 1039 RefPtrWillBeRawPtr<Range> range = makeRange(previous, next); |
| 1040 if (!range) | 1040 if (!range) |
| 1041 return; | 1041 return; |
| 1042 VisibleSelection newSelection(range.get(), DOWNSTREAM); | 1042 VisibleSelection newSelection(range.get(), DOWNSTREAM); |
| 1043 | 1043 |
| 1044 // Transpose the two characters. | 1044 // Transpose the two characters. |
| 1045 String text = plainText(range.get()); | 1045 String text = plainText(range.get()); |
| 1046 if (text.length() != 2) | 1046 if (text.length() != 2) |
| 1047 return; | 1047 return; |
| 1048 String transposed = text.right(1) + text.left(1); | 1048 String transposed = text.right(1) + text.left(1); |
| 1049 | 1049 |
| 1050 // Select the two characters. | 1050 // Select the two characters. |
| 1051 if (newSelection != m_frame.selection().selection()) | 1051 if (newSelection != m_frame->selection().selection()) |
| 1052 m_frame.selection().setSelection(newSelection); | 1052 m_frame->selection().setSelection(newSelection); |
| 1053 | 1053 |
| 1054 // Insert the transposed characters. | 1054 // Insert the transposed characters. |
| 1055 replaceSelectionWithText(transposed, false, false); | 1055 replaceSelectionWithText(transposed, false, false); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 void Editor::addToKillRing(Range* range, bool prepend) | 1058 void Editor::addToKillRing(Range* range, bool prepend) |
| 1059 { | 1059 { |
| 1060 if (m_shouldStartNewKillRingSequence) | 1060 if (m_shouldStartNewKillRingSequence) |
| 1061 killRing().startNewSequence(); | 1061 killRing().startNewSequence(); |
| 1062 | 1062 |
| 1063 String text = plainText(range); | 1063 String text = plainText(range); |
| 1064 if (prepend) | 1064 if (prepend) |
| 1065 killRing().prepend(text); | 1065 killRing().prepend(text); |
| 1066 else | 1066 else |
| 1067 killRing().append(text); | 1067 killRing().append(text); |
| 1068 m_shouldStartNewKillRingSequence = false; | 1068 m_shouldStartNewKillRingSequence = false; |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions options) | 1071 void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions options) |
| 1072 { | 1072 { |
| 1073 // If the new selection is orphaned, then don't update the selection. | 1073 // If the new selection is orphaned, then don't update the selection. |
| 1074 if (newSelection.start().isOrphan() || newSelection.end().isOrphan()) | 1074 if (newSelection.start().isOrphan() || newSelection.end().isOrphan()) |
| 1075 return; | 1075 return; |
| 1076 | 1076 |
| 1077 // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ra nges for selections that are no longer valid | 1077 // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ra nges for selections that are no longer valid |
| 1078 bool selectionDidNotChangeDOMPosition = newSelection == m_frame.selection(). selection(); | 1078 bool selectionDidNotChangeDOMPosition = newSelection == m_frame->selection() .selection(); |
| 1079 m_frame.selection().setSelection(newSelection, options); | 1079 m_frame->selection().setSelection(newSelection, options); |
| 1080 | 1080 |
| 1081 // Some editing operations change the selection visually without affecting i ts position within the DOM. | 1081 // Some editing operations change the selection visually without affecting i ts position within the DOM. |
| 1082 // For example when you press return in the following (the caret is marked b y ^): | 1082 // For example when you press return in the following (the caret is marked b y ^): |
| 1083 // <div contentEditable="true"><div>^Hello</div></div> | 1083 // <div contentEditable="true"><div>^Hello</div></div> |
| 1084 // WebCore inserts <div><br></div> *before* the current block, which correct ly moves the paragraph down but which doesn't | 1084 // WebCore inserts <div><br></div> *before* the current block, which correct ly moves the paragraph down but which doesn't |
| 1085 // change the caret's DOM position (["hello", 0]). In these situations the a bove FrameSelection::setSelection call | 1085 // change the caret's DOM position (["hello", 0]). In these situations the a bove FrameSelection::setSelection call |
| 1086 // does not call EditorClient::respondToChangedSelection(), which, on the Ma c, sends selection change notifications and | 1086 // does not call EditorClient::respondToChangedSelection(), which, on the Ma c, sends selection change notifications and |
| 1087 // starts a new kill ring sequence, but we want to do these things (matches AppKit). | 1087 // starts a new kill ring sequence, but we want to do these things (matches AppKit). |
| 1088 if (selectionDidNotChangeDOMPosition) | 1088 if (selectionDidNotChangeDOMPosition) |
| 1089 client().respondToChangedSelection(&m_frame, m_frame.selection().selecti onType()); | 1089 client().respondToChangedSelection(m_frame, m_frame->selection().selecti onType()); |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 IntRect Editor::firstRectForRange(Range* range) const | 1092 IntRect Editor::firstRectForRange(Range* range) const |
| 1093 { | 1093 { |
| 1094 LayoutUnit extraWidthToEndOfLine = 0; | 1094 LayoutUnit extraWidthToEndOfLine = 0; |
| 1095 ASSERT(range->startContainer()); | 1095 ASSERT(range->startContainer()); |
| 1096 ASSERT(range->endContainer()); | 1096 ASSERT(range->endContainer()); |
| 1097 | 1097 |
| 1098 IntRect startCaretRect = RenderedPosition(VisiblePosition(range->startPositi on()).deepEquivalent(), DOWNSTREAM).absoluteRect(&extraWidthToEndOfLine); | 1098 IntRect startCaretRect = RenderedPosition(VisiblePosition(range->startPositi on()).deepEquivalent(), DOWNSTREAM).absoluteRect(&extraWidthToEndOfLine); |
| 1099 if (startCaretRect == LayoutRect()) | 1099 if (startCaretRect == LayoutRect()) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1114 // start and end aren't on the same line, so go from start to the end of its line | 1114 // start and end aren't on the same line, so go from start to the end of its line |
| 1115 return IntRect(startCaretRect.x(), | 1115 return IntRect(startCaretRect.x(), |
| 1116 startCaretRect.y(), | 1116 startCaretRect.y(), |
| 1117 startCaretRect.width() + extraWidthToEndOfLine, | 1117 startCaretRect.width() + extraWidthToEndOfLine, |
| 1118 startCaretRect.height()); | 1118 startCaretRect.height()); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin gAction) | 1121 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin gAction) |
| 1122 { | 1122 { |
| 1123 if (!style || style->isEmpty()) { | 1123 if (!style || style->isEmpty()) { |
| 1124 m_frame.selection().clearTypingStyle(); | 1124 m_frame->selection().clearTypingStyle(); |
| 1125 return; | 1125 return; |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 // Calculate the current typing style. | 1128 // Calculate the current typing style. |
| 1129 RefPtrWillBeRawPtr<EditingStyle> typingStyle = nullptr; | 1129 RefPtrWillBeRawPtr<EditingStyle> typingStyle = nullptr; |
| 1130 if (m_frame.selection().typingStyle()) { | 1130 if (m_frame->selection().typingStyle()) { |
| 1131 typingStyle = m_frame.selection().typingStyle()->copy(); | 1131 typingStyle = m_frame->selection().typingStyle()->copy(); |
| 1132 typingStyle->overrideWithStyle(style); | 1132 typingStyle->overrideWithStyle(style); |
| 1133 } else { | 1133 } else { |
| 1134 typingStyle = EditingStyle::create(style); | 1134 typingStyle = EditingStyle::create(style); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 typingStyle->prepareToApplyAt(m_frame.selection().selection().visibleStart() .deepEquivalent(), EditingStyle::PreserveWritingDirection); | 1137 typingStyle->prepareToApplyAt(m_frame->selection().selection().visibleStart( ).deepEquivalent(), EditingStyle::PreserveWritingDirection); |
| 1138 | 1138 |
| 1139 // Handle block styles, substracting these from the typing style. | 1139 // Handle block styles, substracting these from the typing style. |
| 1140 RefPtrWillBeRawPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveB lockProperties(); | 1140 RefPtrWillBeRawPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveB lockProperties(); |
| 1141 if (!blockStyle->isEmpty()) { | 1141 if (!blockStyle->isEmpty()) { |
| 1142 ASSERT(m_frame.document()); | 1142 ASSERT(m_frame->document()); |
| 1143 ApplyStyleCommand::create(*m_frame.document(), blockStyle.get(), editing Action)->apply(); | 1143 ApplyStyleCommand::create(*m_frame->document(), blockStyle.get(), editin gAction)->apply(); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 // Set the remaining style as the typing style. | 1146 // Set the remaining style as the typing style. |
| 1147 m_frame.selection().setTypingStyle(typingStyle); | 1147 m_frame->selection().setTypingStyle(typingStyle); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) | 1150 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) |
| 1151 { | 1151 { |
| 1152 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; | 1152 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; |
| 1153 return findString(target, options); | 1153 return findString(target, options); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 bool Editor::findString(const String& target, FindOptions options) | 1156 bool Editor::findString(const String& target, FindOptions options) |
| 1157 { | 1157 { |
| 1158 VisibleSelection selection = m_frame.selection().selection(); | 1158 VisibleSelection selection = m_frame->selection().selection(); |
| 1159 | 1159 |
| 1160 RefPtrWillBeRawPtr<Range> resultRange = rangeOfString(target, selection.firs tRange().get(), options); | 1160 RefPtrWillBeRawPtr<Range> resultRange = rangeOfString(target, selection.firs tRange().get(), options); |
| 1161 | 1161 |
| 1162 if (!resultRange) | 1162 if (!resultRange) |
| 1163 return false; | 1163 return false; |
| 1164 | 1164 |
| 1165 m_frame.selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR EAM)); | 1165 m_frame->selection().setSelection(VisibleSelection(resultRange.get(), DOWNST REAM)); |
| 1166 m_frame.selection().revealSelection(); | 1166 m_frame->selection().revealSelection(); |
| 1167 return true; | 1167 return true; |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* previousMatch, FindOptions options) | 1170 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* previousMatch, FindOptions options) |
| 1171 { | 1171 { |
| 1172 RefPtrWillBeRawPtr<Range> nextMatch = rangeOfString(target, previousMatch, o ptions); | 1172 RefPtrWillBeRawPtr<Range> nextMatch = rangeOfString(target, previousMatch, o ptions); |
| 1173 if (!nextMatch) | 1173 if (!nextMatch) |
| 1174 return nullptr; | 1174 return nullptr; |
| 1175 | 1175 |
| 1176 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(), | 1176 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 return nullptr; | 1210 return nullptr; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 PassRefPtrWillBeRawPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRange, FindOptions options) | 1213 PassRefPtrWillBeRawPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRange, FindOptions options) |
| 1214 { | 1214 { |
| 1215 if (target.isEmpty()) | 1215 if (target.isEmpty()) |
| 1216 return nullptr; | 1216 return nullptr; |
| 1217 | 1217 |
| 1218 // Start from an edge of the reference range. Which edge is used depends on whether we're searching forward or | 1218 // Start from an edge of the reference range. Which edge is used depends on whether we're searching forward or |
| 1219 // backward, and whether startInSelection is set. | 1219 // backward, and whether startInSelection is set. |
| 1220 Position searchStart = firstPositionInNode(m_frame.document()); | 1220 Position searchStart = firstPositionInNode(m_frame->document()); |
| 1221 Position searchEnd = lastPositionInNode(m_frame.document()); | 1221 Position searchEnd = lastPositionInNode(m_frame->document()); |
| 1222 | 1222 |
| 1223 bool forward = !(options & Backwards); | 1223 bool forward = !(options & Backwards); |
| 1224 bool startInReferenceRange = referenceRange && (options & StartInSelection); | 1224 bool startInReferenceRange = referenceRange && (options & StartInSelection); |
| 1225 if (referenceRange) { | 1225 if (referenceRange) { |
| 1226 if (forward) | 1226 if (forward) |
| 1227 searchStart = startInReferenceRange ? referenceRange->startPosition( ) : referenceRange->endPosition(); | 1227 searchStart = startInReferenceRange ? referenceRange->startPosition( ) : referenceRange->endPosition(); |
| 1228 else | 1228 else |
| 1229 searchEnd = startInReferenceRange ? referenceRange->endPosition() : referenceRange->startPosition(); | 1229 searchEnd = startInReferenceRange ? referenceRange->endPosition() : referenceRange->startPosition(); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 RefPtrWillBeRawPtr<Range> resultRange = findStringBetweenPositions(target, s earchStart, searchEnd, options); | 1232 RefPtrWillBeRawPtr<Range> resultRange = findStringBetweenPositions(target, s earchStart, searchEnd, options); |
| 1233 | 1233 |
| 1234 // If we started in the reference range and the found range exactly matches the reference range, find again. | 1234 // If we started in the reference range and the found range exactly matches the reference range, find again. |
| 1235 // Build a selection with the found range to remove collapsed whitespace. | 1235 // Build a selection with the found range to remove collapsed whitespace. |
| 1236 // Compare ranges instead of selection objects to ignore the way that the cu rrent selection was made. | 1236 // Compare ranges instead of selection objects to ignore the way that the cu rrent selection was made. |
| 1237 if (resultRange && startInReferenceRange && areRangesEqual(VisibleSelection( resultRange.get()).toNormalizedRange().get(), referenceRange)) { | 1237 if (resultRange && startInReferenceRange && areRangesEqual(VisibleSelection( resultRange.get()).toNormalizedRange().get(), referenceRange)) { |
| 1238 if (forward) | 1238 if (forward) |
| 1239 searchStart = resultRange->endPosition(); | 1239 searchStart = resultRange->endPosition(); |
| 1240 else | 1240 else |
| 1241 searchEnd = resultRange->startPosition(); | 1241 searchEnd = resultRange->startPosition(); |
| 1242 resultRange = findStringBetweenPositions(target, searchStart, searchEnd, options); | 1242 resultRange = findStringBetweenPositions(target, searchStart, searchEnd, options); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 if (!resultRange && options & WrapAround) { | 1245 if (!resultRange && options & WrapAround) { |
| 1246 searchStart = firstPositionInNode(m_frame.document()); | 1246 searchStart = firstPositionInNode(m_frame->document()); |
| 1247 searchEnd = lastPositionInNode(m_frame.document()); | 1247 searchEnd = lastPositionInNode(m_frame->document()); |
| 1248 resultRange = findStringBetweenPositions(target, searchStart, searchEnd, options); | 1248 resultRange = findStringBetweenPositions(target, searchStart, searchEnd, options); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 return resultRange.release(); | 1251 return resultRange.release(); |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 void Editor::setMarkedTextMatchesAreHighlighted(bool flag) | 1254 void Editor::setMarkedTextMatchesAreHighlighted(bool flag) |
| 1255 { | 1255 { |
| 1256 if (flag == m_areMarkedTextMatchesHighlighted) | 1256 if (flag == m_areMarkedTextMatchesHighlighted) |
| 1257 return; | 1257 return; |
| 1258 | 1258 |
| 1259 m_areMarkedTextMatchesHighlighted = flag; | 1259 m_areMarkedTextMatchesHighlighted = flag; |
| 1260 m_frame.document()->markers().repaintMarkers(DocumentMarker::TextMatch); | 1260 m_frame->document()->markers().repaintMarkers(DocumentMarker::TextMatch); |
| 1261 } | 1261 } |
| 1262 | 1262 |
| 1263 void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, Fra meSelection::SetSelectionOptions options) | 1263 void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, Fra meSelection::SetSelectionOptions options) |
| 1264 { | 1264 { |
| 1265 spellChecker().respondToChangedSelection(oldSelection, options); | 1265 spellChecker().respondToChangedSelection(oldSelection, options); |
| 1266 m_frame.inputMethodController().cancelCompositionIfSelectionIsInvalid(); | 1266 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); |
| 1267 notifyComponentsOnChangedSelection(oldSelection, options); | 1267 notifyComponentsOnChangedSelection(oldSelection, options); |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 SpellChecker& Editor::spellChecker() const | 1270 SpellChecker& Editor::spellChecker() const |
| 1271 { | 1271 { |
| 1272 return m_frame.spellChecker(); | 1272 return m_frame->spellChecker(); |
| 1273 } | 1273 } |
| 1274 | 1274 |
| 1275 void Editor::toggleOverwriteModeEnabled() | 1275 void Editor::toggleOverwriteModeEnabled() |
| 1276 { | 1276 { |
| 1277 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1277 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 1278 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1278 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 void Editor::trace(Visitor* visitor) | 1281 void Editor::trace(Visitor* visitor) |
| 1282 { | 1282 { |
| 1283 visitor->trace(m_frame); | |
| 1283 visitor->trace(m_lastEditCommand); | 1284 visitor->trace(m_lastEditCommand); |
| 1284 visitor->trace(m_mark); | 1285 visitor->trace(m_mark); |
| 1285 } | 1286 } |
| 1286 | 1287 |
| 1287 } // namespace blink | 1288 } // namespace blink |
| OLD | NEW |