Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 22417002: Rename ASSERT_NO_EXCEPTION_STATE and IGNORE_EXCEPTION_STATE (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/EditingStyle.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 bool Editor::canDeleteRange(Range* range) const 247 bool Editor::canDeleteRange(Range* range) const
248 { 248 {
249 Node* startContainer = range->startContainer(); 249 Node* startContainer = range->startContainer();
250 Node* endContainer = range->endContainer(); 250 Node* endContainer = range->endContainer();
251 if (!startContainer || !endContainer) 251 if (!startContainer || !endContainer)
252 return false; 252 return false;
253 253
254 if (!startContainer->rendererIsEditable() || !endContainer->rendererIsEditab le()) 254 if (!startContainer->rendererIsEditable() || !endContainer->rendererIsEditab le())
255 return false; 255 return false;
256 256
257 if (range->collapsed(IGNORE_EXCEPTION_STATE)) { 257 if (range->collapsed(IGNORE_EXCEPTION)) {
258 VisiblePosition start(range->startPosition(), DOWNSTREAM); 258 VisiblePosition start(range->startPosition(), DOWNSTREAM);
259 VisiblePosition previous = start.previous(); 259 VisiblePosition previous = start.previous();
260 // FIXME: We sometimes allow deletions at the start of editable roots, l ike when the caret is in an empty list item. 260 // FIXME: We sometimes allow deletions at the start of editable roots, l ike when the caret is in an empty list item.
261 if (previous.isNull() || previous.deepEquivalent().deprecatedNode()->roo tEditableElement() != startContainer->rootEditableElement()) 261 if (previous.isNull() || previous.deepEquivalent().deprecatedNode()->roo tEditableElement() != startContainer->rootEditableElement())
262 return false; 262 return false;
263 } 263 }
264 return true; 264 return true;
265 } 265 }
266 266
267 bool Editor::smartInsertDeleteEnabled() 267 bool Editor::smartInsertDeleteEnabled()
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return; 328 return;
329 329
330 applyCommand(DeleteSelectionCommand::create(m_frame->document(), smartDelete )); 330 applyCommand(DeleteSelectionCommand::create(m_frame->document(), smartDelete ));
331 } 331 }
332 332
333 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) 333 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
334 { 334 {
335 Node* target = findEventTargetFromSelection(); 335 Node* target = findEventTargetFromSelection();
336 if (!target) 336 if (!target)
337 return; 337 return;
338 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow( ), pastingText, smartReplace), IGNORE_EXCEPTION_STATE); 338 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow( ), pastingText, smartReplace), IGNORE_EXCEPTION);
339 } 339 }
340 340
341 void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle) 341 void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle)
342 { 342 {
343 Node* target = findEventTargetFromSelection(); 343 Node* target = findEventTargetFromSelection();
344 if (!target) 344 if (!target)
345 return; 345 return;
346 target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame->domWindow() , pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION_STATE); 346 target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame->domWindow() , pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION);
347 } 347 }
348 348
349 void Editor::pasteAsPlainTextBypassingDHTML() 349 void Editor::pasteAsPlainTextBypassingDHTML()
350 { 350 {
351 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); 351 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
352 } 352 }
353 353
354 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard) 354 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard)
355 { 355 {
356 String text = pasteboard->plainText(m_frame); 356 String text = pasteboard->plainText(m_frame);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 PassRefPtr<Range> Editor::selectedRange() 419 PassRefPtr<Range> Editor::selectedRange()
420 { 420 {
421 if (!m_frame) 421 if (!m_frame)
422 return 0; 422 return 0;
423 return m_frame->selection()->toNormalizedRange(); 423 return m_frame->selection()->toNormalizedRange();
424 } 424 }
425 425
426 bool Editor::shouldDeleteRange(Range* range) const 426 bool Editor::shouldDeleteRange(Range* range) const
427 { 427 {
428 if (!range || range->collapsed(IGNORE_EXCEPTION_STATE)) 428 if (!range || range->collapsed(IGNORE_EXCEPTION))
429 return false; 429 return false;
430 430
431 if (!canDeleteRange(range)) 431 if (!canDeleteRange(range))
432 return false; 432 return false;
433 433
434 return client() && client()->shouldDeleteRange(range); 434 return client() && client()->shouldDeleteRange(range);
435 } 435 }
436 436
437 bool Editor::tryDHTMLCopy() 437 bool Editor::tryDHTMLCopy()
438 { 438 {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // the event handler NOT setting the return value to false 594 // the event handler NOT setting the return value to false
595 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli cy policy) 595 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli cy policy)
596 { 596 {
597 Node* target = findEventTargetFromSelection(); 597 Node* target = findEventTargetFromSelection();
598 if (!target) 598 if (!target)
599 return true; 599 return true;
600 600
601 RefPtr<Clipboard> clipboard = newGeneralClipboard(policy, m_frame); 601 RefPtr<Clipboard> clipboard = newGeneralClipboard(policy, m_frame);
602 602
603 RefPtr<Event> evt = ClipboardEvent::create(eventType, true, true, clipboard) ; 603 RefPtr<Event> evt = ClipboardEvent::create(eventType, true, true, clipboard) ;
604 target->dispatchEvent(evt, IGNORE_EXCEPTION_STATE); 604 target->dispatchEvent(evt, IGNORE_EXCEPTION);
605 bool noDefaultProcessing = evt->defaultPrevented(); 605 bool noDefaultProcessing = evt->defaultPrevented();
606 if (noDefaultProcessing && policy == ClipboardWritable) { 606 if (noDefaultProcessing && policy == ClipboardWritable) {
607 Pasteboard* pasteboard = Pasteboard::generalPasteboard(); 607 Pasteboard* pasteboard = Pasteboard::generalPasteboard();
608 pasteboard->clear(); 608 pasteboard->clear();
609 pasteboard->writeClipboard(clipboard.get()); 609 pasteboard->writeClipboard(clipboard.get());
610 } 610 }
611 611
612 // invalidate clipboard here for security 612 // invalidate clipboard here for security
613 clipboard->setAccessPolicy(ClipboardNumb); 613 clipboard->setAccessPolicy(ClipboardNumb);
614 614
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 713 }
714 714
715 void Editor::outdent() 715 void Editor::outdent()
716 { 716 {
717 applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdent Command::Outdent)); 717 applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdent Command::Outdent));
718 } 718 }
719 719
720 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot, PassRefPtr<Element> endRoot) 720 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot, PassRefPtr<Element> endRoot)
721 { 721 {
722 if (startRoot) 722 if (startRoot)
723 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten tChangedEvent, false, false), IGNORE_EXCEPTION_STATE); 723 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten tChangedEvent, false, false), IGNORE_EXCEPTION);
724 if (endRoot && endRoot != startRoot) 724 if (endRoot && endRoot != startRoot)
725 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC hangedEvent, false, false), IGNORE_EXCEPTION_STATE); 725 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC hangedEvent, false, false), IGNORE_EXCEPTION);
726 } 726 }
727 727
728 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd) 728 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd)
729 { 729 {
730 m_frame->document()->updateLayout(); 730 m_frame->document()->updateLayout();
731 731
732 EditCommandComposition* composition = cmd->composition(); 732 EditCommandComposition* composition = cmd->composition();
733 ASSERT(composition); 733 ASSERT(composition);
734 VisibleSelection newSelection(cmd->endingSelection()); 734 VisibleSelection newSelection(cmd->endingSelection());
735 735
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 if (m_frame->selection()->isNone()) { 1189 if (m_frame->selection()->isNone()) {
1190 setIgnoreCompositionSelectionChange(false); 1190 setIgnoreCompositionSelectionChange(false);
1191 return; 1191 return;
1192 } 1192 }
1193 1193
1194 // Dispatch a compositionend event to the focused node. 1194 // Dispatch a compositionend event to the focused node.
1195 // We should send this event before sending a TextEvent as written in Sectio n 6.2.2 and 6.2.3 of 1195 // We should send this event before sending a TextEvent as written in Sectio n 6.2.2 and 6.2.3 of
1196 // the DOM Event specification. 1196 // the DOM Event specification.
1197 if (Element* target = m_frame->document()->focusedElement()) { 1197 if (Element* target = m_frame->document()->focusedElement()) {
1198 RefPtr<CompositionEvent> event = CompositionEvent::create(eventNames().c ompositionendEvent, m_frame->domWindow(), text); 1198 RefPtr<CompositionEvent> event = CompositionEvent::create(eventNames().c ompositionendEvent, m_frame->domWindow(), text);
1199 target->dispatchEvent(event, IGNORE_EXCEPTION_STATE); 1199 target->dispatchEvent(event, IGNORE_EXCEPTION);
1200 } 1200 }
1201 1201
1202 // If text is empty, then delete the old composition here. If text is non-e mpty, InsertTextCommand::input 1202 // If text is empty, then delete the old composition here. If text is non-e mpty, InsertTextCommand::input
1203 // will delete the old composition with an optimized replace operation. 1203 // will delete the old composition with an optimized replace operation.
1204 if (text.isEmpty() && mode != CancelComposition) 1204 if (text.isEmpty() && mode != CancelComposition)
1205 TypingCommand::deleteSelection(m_frame->document(), 0); 1205 TypingCommand::deleteSelection(m_frame->document(), 0);
1206 1206
1207 m_compositionNode = 0; 1207 m_compositionNode = 0;
1208 m_customCompositionUnderlines.clear(); 1208 m_customCompositionUnderlines.clear();
1209 1209
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 target->dispatchEvent(CompositionEvent::create(eventNames().comp ositionstartEvent, m_frame->domWindow(), selectedText())); 1259 target->dispatchEvent(CompositionEvent::create(eventNames().comp ositionstartEvent, m_frame->domWindow(), selectedText()));
1260 event = CompositionEvent::create(eventNames().compositionupdateE vent, m_frame->domWindow(), text); 1260 event = CompositionEvent::create(eventNames().compositionupdateE vent, m_frame->domWindow(), text);
1261 } 1261 }
1262 } else { 1262 } else {
1263 if (!text.isEmpty()) 1263 if (!text.isEmpty())
1264 event = CompositionEvent::create(eventNames().compositionupdateE vent, m_frame->domWindow(), text); 1264 event = CompositionEvent::create(eventNames().compositionupdateE vent, m_frame->domWindow(), text);
1265 else 1265 else
1266 event = CompositionEvent::create(eventNames().compositionendEven t, m_frame->domWindow(), text); 1266 event = CompositionEvent::create(eventNames().compositionendEven t, m_frame->domWindow(), text);
1267 } 1267 }
1268 if (event.get()) 1268 if (event.get())
1269 target->dispatchEvent(event, IGNORE_EXCEPTION_STATE); 1269 target->dispatchEvent(event, IGNORE_EXCEPTION);
1270 } 1270 }
1271 1271
1272 // If text is empty, then delete the old composition here. If text is non-e mpty, InsertTextCommand::input 1272 // If text is empty, then delete the old composition here. If text is non-e mpty, InsertTextCommand::input
1273 // will delete the old composition with an optimized replace operation. 1273 // will delete the old composition with an optimized replace operation.
1274 if (text.isEmpty()) 1274 if (text.isEmpty())
1275 TypingCommand::deleteSelection(m_frame->document(), TypingCommand::Preve ntSpellChecking); 1275 TypingCommand::deleteSelection(m_frame->document(), TypingCommand::Preve ntSpellChecking);
1276 1276
1277 m_compositionNode = 0; 1277 m_compositionNode = 0;
1278 m_customCompositionUnderlines.clear(); 1278 m_customCompositionUnderlines.clear();
1279 1279
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 // selection is editable. 1349 // selection is editable.
1350 // This can happen in Mail for a mix of non-editable and editable conten t (like Stationary), 1350 // This can happen in Mail for a mix of non-editable and editable conten t (like Stationary),
1351 // when spell checking the whole document before sending the message. 1351 // when spell checking the whole document before sending the message.
1352 // In that case the document might not be editable, but there are editab le pockets that need to be spell checked. 1352 // In that case the document might not be editable, but there are editab le pockets that need to be spell checked.
1353 1353
1354 position = firstEditablePositionAfterPositionInRoot(position, frame()->d ocument()->documentElement()).deepEquivalent(); 1354 position = firstEditablePositionAfterPositionInRoot(position, frame()->d ocument()->documentElement()).deepEquivalent();
1355 if (position.isNull()) 1355 if (position.isNull())
1356 return; 1356 return;
1357 1357
1358 Position rangeCompliantPosition = position.parentAnchoredEquivalent(); 1358 Position rangeCompliantPosition = position.parentAnchoredEquivalent();
1359 spellingSearchRange->setStart(rangeCompliantPosition.deprecatedNode(), r angeCompliantPosition.deprecatedEditingOffset(), IGNORE_EXCEPTION_STATE); 1359 spellingSearchRange->setStart(rangeCompliantPosition.deprecatedNode(), r angeCompliantPosition.deprecatedEditingOffset(), IGNORE_EXCEPTION);
1360 startedWithSelection = false; // won't need to wrap 1360 startedWithSelection = false; // won't need to wrap
1361 } 1361 }
1362 1362
1363 // topNode defines the whole range we want to operate on 1363 // topNode defines the whole range we want to operate on
1364 Node* topNode = highestEditableRoot(position); 1364 Node* topNode = highestEditableRoot(position);
1365 // FIXME: lastOffsetForEditing() is wrong here if editingIgnoresContent(high estEditableRoot()) returns true (e.g. a <table>) 1365 // FIXME: lastOffsetForEditing() is wrong here if editingIgnoresContent(high estEditableRoot()) returns true (e.g. a <table>)
1366 spellingSearchRange->setEnd(topNode, lastOffsetForEditing(topNode), IGNORE_E XCEPTION_STATE); 1366 spellingSearchRange->setEnd(topNode, lastOffsetForEditing(topNode), IGNORE_E XCEPTION);
1367 1367
1368 // If spellingSearchRange starts in the middle of a word, advance to the nex t word so we start checking 1368 // If spellingSearchRange starts in the middle of a word, advance to the nex t word so we start checking
1369 // at a word boundary. Going back by one char and then forward by a word doe s the trick. 1369 // at a word boundary. Going back by one char and then forward by a word doe s the trick.
1370 if (startedWithSelection) { 1370 if (startedWithSelection) {
1371 VisiblePosition oneBeforeStart = startVisiblePosition(spellingSearchRang e.get(), DOWNSTREAM).previous(); 1371 VisiblePosition oneBeforeStart = startVisiblePosition(spellingSearchRang e.get(), DOWNSTREAM).previous();
1372 if (oneBeforeStart.isNotNull()) 1372 if (oneBeforeStart.isNotNull())
1373 setStart(spellingSearchRange.get(), endOfWord(oneBeforeStart)); 1373 setStart(spellingSearchRange.get(), endOfWord(oneBeforeStart));
1374 // else we were already at the start of the editable node 1374 // else we were already at the start of the editable node
1375 } 1375 }
1376 1376
1377 if (spellingSearchRange->collapsed(IGNORE_EXCEPTION_STATE)) 1377 if (spellingSearchRange->collapsed(IGNORE_EXCEPTION))
1378 return; // nothing to search in 1378 return; // nothing to search in
1379 1379
1380 // Get the spell checker if it is available 1380 // Get the spell checker if it is available
1381 if (!client()) 1381 if (!client())
1382 return; 1382 return;
1383 1383
1384 // We go to the end of our first range instead of the start of it, just to b e sure 1384 // We go to the end of our first range instead of the start of it, just to b e sure
1385 // we don't get foiled by any word boundary problems at the start. It means we might 1385 // we don't get foiled by any word boundary problems at the start. It means we might
1386 // do a tiny bit more searching. 1386 // do a tiny bit more searching.
1387 Node* searchEndNodeAfterWrap = spellingSearchRange->endContainer(); 1387 Node* searchEndNodeAfterWrap = spellingSearchRange->endContainer();
1388 int searchEndOffsetAfterWrap = spellingSearchRange->endOffset(); 1388 int searchEndOffsetAfterWrap = spellingSearchRange->endOffset();
1389 1389
1390 int misspellingOffset = 0; 1390 int misspellingOffset = 0;
1391 GrammarDetail grammarDetail; 1391 GrammarDetail grammarDetail;
1392 int grammarPhraseOffset = 0; 1392 int grammarPhraseOffset = 0;
1393 RefPtr<Range> grammarSearchRange; 1393 RefPtr<Range> grammarSearchRange;
1394 String badGrammarPhrase; 1394 String badGrammarPhrase;
1395 String misspelledWord; 1395 String misspelledWord;
1396 1396
1397 bool isSpelling = true; 1397 bool isSpelling = true;
1398 int foundOffset = 0; 1398 int foundOffset = 0;
1399 String foundItem; 1399 String foundItem;
1400 RefPtr<Range> firstMisspellingRange; 1400 RefPtr<Range> firstMisspellingRange;
1401 if (unifiedTextCheckerEnabled()) { 1401 if (unifiedTextCheckerEnabled()) {
1402 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION_ST ATE); 1402 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION);
1403 foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstM isspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, gram marDetail); 1403 foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstM isspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, gram marDetail);
1404 if (isSpelling) { 1404 if (isSpelling) {
1405 misspelledWord = foundItem; 1405 misspelledWord = foundItem;
1406 misspellingOffset = foundOffset; 1406 misspellingOffset = foundOffset;
1407 } else { 1407 } else {
1408 badGrammarPhrase = foundItem; 1408 badGrammarPhrase = foundItem;
1409 grammarPhraseOffset = foundOffset; 1409 grammarPhraseOffset = foundOffset;
1410 } 1410 }
1411 } else { 1411 } else {
1412 misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findF irstMisspelling(misspellingOffset, false, firstMisspellingRange); 1412 misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findF irstMisspelling(misspellingOffset, false, firstMisspellingRange);
1413 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION_ST ATE); 1413 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION);
1414 if (!misspelledWord.isEmpty()) { 1414 if (!misspelledWord.isEmpty()) {
1415 // Stop looking at start of next misspelled word 1415 // Stop looking at start of next misspelled word
1416 CharacterIterator chars(grammarSearchRange.get()); 1416 CharacterIterator chars(grammarSearchRange.get());
1417 chars.advance(misspellingOffset); 1417 chars.advance(misspellingOffset);
1418 grammarSearchRange->setEnd(chars.range()->startContainer(), chars.ra nge()->startOffset(), IGNORE_EXCEPTION_STATE); 1418 grammarSearchRange->setEnd(chars.range()->startContainer(), chars.ra nge()->startOffset(), IGNORE_EXCEPTION);
1419 } 1419 }
1420 1420
1421 if (isGrammarCheckingEnabled()) 1421 if (isGrammarCheckingEnabled())
1422 badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange). findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 1422 badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange). findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
1423 } 1423 }
1424 1424
1425 // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the 1425 // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
1426 // block rather than at a selection). 1426 // block rather than at a selection).
1427 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) { 1427 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
1428 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION_STATE); 1428 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION);
1429 // going until the end of the very first chunk we tested is far enough 1429 // going until the end of the very first chunk we tested is far enough
1430 spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfter Wrap, IGNORE_EXCEPTION_STATE); 1430 spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfter Wrap, IGNORE_EXCEPTION);
1431 1431
1432 if (unifiedTextCheckerEnabled()) { 1432 if (unifiedTextCheckerEnabled()) {
1433 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N_STATE); 1433 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N);
1434 foundItem = TextCheckingHelper(client(), spellingSearchRange).findFi rstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail); 1434 foundItem = TextCheckingHelper(client(), spellingSearchRange).findFi rstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
1435 if (isSpelling) { 1435 if (isSpelling) {
1436 misspelledWord = foundItem; 1436 misspelledWord = foundItem;
1437 misspellingOffset = foundOffset; 1437 misspellingOffset = foundOffset;
1438 } else { 1438 } else {
1439 badGrammarPhrase = foundItem; 1439 badGrammarPhrase = foundItem;
1440 grammarPhraseOffset = foundOffset; 1440 grammarPhraseOffset = foundOffset;
1441 } 1441 }
1442 } else { 1442 } else {
1443 misspelledWord = TextCheckingHelper(client(), spellingSearchRange).f indFirstMisspelling(misspellingOffset, false, firstMisspellingRange); 1443 misspelledWord = TextCheckingHelper(client(), spellingSearchRange).f indFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
1444 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N_STATE); 1444 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N);
1445 if (!misspelledWord.isEmpty()) { 1445 if (!misspelledWord.isEmpty()) {
1446 // Stop looking at start of next misspelled word 1446 // Stop looking at start of next misspelled word
1447 CharacterIterator chars(grammarSearchRange.get()); 1447 CharacterIterator chars(grammarSearchRange.get());
1448 chars.advance(misspellingOffset); 1448 chars.advance(misspellingOffset);
1449 grammarSearchRange->setEnd(chars.range()->startContainer(), char s.range()->startOffset(), IGNORE_EXCEPTION_STATE); 1449 grammarSearchRange->setEnd(chars.range()->startContainer(), char s.range()->startOffset(), IGNORE_EXCEPTION);
1450 } 1450 }
1451 1451
1452 if (isGrammarCheckingEnabled()) 1452 if (isGrammarCheckingEnabled())
1453 badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRan ge).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 1453 badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRan ge).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
1454 } 1454 }
1455 } 1455 }
1456 1456
1457 if (!badGrammarPhrase.isEmpty()) { 1457 if (!badGrammarPhrase.isEmpty()) {
1458 // We found bad grammar. Since we only searched for bad grammar up to th e first misspelled word, the bad grammar 1458 // We found bad grammar. Since we only searched for bad grammar up to th e first misspelled word, the bad grammar
1459 // takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling 1459 // takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 int selectionOffset = 0; 1717 int selectionOffset = 0;
1718 int ambiguousBoundaryOffset = -1; 1718 int ambiguousBoundaryOffset = -1;
1719 bool selectionChanged = false; 1719 bool selectionChanged = false;
1720 bool restoreSelectionAfterChange = false; 1720 bool restoreSelectionAfterChange = false;
1721 bool adjustSelectionForParagraphBoundaries = false; 1721 bool adjustSelectionForParagraphBoundaries = false;
1722 1722
1723 if (shouldMarkSpelling) { 1723 if (shouldMarkSpelling) {
1724 if (m_frame->selection()->selectionType() == VisibleSelection::CaretSele ction) { 1724 if (m_frame->selection()->selectionType() == VisibleSelection::CaretSele ction) {
1725 // Attempt to save the caret position so we can restore it later if needed 1725 // Attempt to save the caret position so we can restore it later if needed
1726 Position caretPosition = m_frame->selection()->end(); 1726 Position caretPosition = m_frame->selection()->end();
1727 selectionOffset = paragraph.offsetTo(caretPosition, ASSERT_NO_EXCEPT ION_STATE); 1727 selectionOffset = paragraph.offsetTo(caretPosition, ASSERT_NO_EXCEPT ION);
1728 restoreSelectionAfterChange = true; 1728 restoreSelectionAfterChange = true;
1729 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) 1729 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter))
1730 adjustSelectionForParagraphBoundaries = true; 1730 adjustSelectionForParagraphBoundaries = true;
1731 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) 1731 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1)))
1732 ambiguousBoundaryOffset = selectionOffset - 1; 1732 ambiguousBoundaryOffset = selectionOffset - 1;
1733 } 1733 }
1734 } 1734 }
1735 1735
1736 for (unsigned i = 0; i < results.size(); i++) { 1736 for (unsigned i = 0; i < results.size(); i++) {
1737 int spellingRangeEndOffset = paragraph.checkingEnd(); 1737 int spellingRangeEndOffset = paragraph.checkingEnd();
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 void Editor::applyEditingStyleToElement(Element* element) const 2139 void Editor::applyEditingStyleToElement(Element* element) const
2140 { 2140 {
2141 if (!element) 2141 if (!element)
2142 return; 2142 return;
2143 ASSERT(element->isStyledElement()); 2143 ASSERT(element->isStyledElement());
2144 if (!element->isStyledElement()) 2144 if (!element->isStyledElement())
2145 return; 2145 return;
2146 2146
2147 // Mutate using the CSSOM wrapper so we get the same event behavior as a scr ipt. 2147 // Mutate using the CSSOM wrapper so we get the same event behavior as a scr ipt.
2148 CSSStyleDeclaration* style = element->style(); 2148 CSSStyleDeclaration* style = element->style();
2149 style->setPropertyInternal(CSSPropertyWordWrap, "break-word", false, IGNORE_ EXCEPTION_STATE); 2149 style->setPropertyInternal(CSSPropertyWordWrap, "break-word", false, IGNORE_ EXCEPTION);
2150 style->setPropertyInternal(CSSPropertyWebkitLineBreak, "after-white-space", false, IGNORE_EXCEPTION_STATE); 2150 style->setPropertyInternal(CSSPropertyWebkitLineBreak, "after-white-space", false, IGNORE_EXCEPTION);
2151 } 2151 }
2152 2152
2153 // Searches from the beginning of the document if nothing is selected. 2153 // Searches from the beginning of the document if nothing is selected.
2154 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) 2154 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection)
2155 { 2155 {
2156 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; 2156 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ;
2157 return findString(target, options); 2157 return findString(target, options);
2158 } 2158 }
2159 2159
2160 bool Editor::findString(const String& target, FindOptions options) 2160 bool Editor::findString(const String& target, FindOptions options)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 if (forward) 2224 if (forward)
2225 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->childN odeCount()); 2225 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->childN odeCount());
2226 else 2226 else
2227 searchRange->setStart(shadowTreeRoot.get(), 0); 2227 searchRange->setStart(shadowTreeRoot.get(), 0);
2228 } 2228 }
2229 2229
2230 resultRange = findPlainText(searchRange.get(), target, options); 2230 resultRange = findPlainText(searchRange.get(), target, options);
2231 } 2231 }
2232 2232
2233 // If nothing was found in the shadow tree, search in main content following the shadow tree. 2233 // If nothing was found in the shadow tree, search in main content following the shadow tree.
2234 if (resultRange->collapsed(ASSERT_NO_EXCEPTION_STATE) && shadowTreeRoot) { 2234 if (resultRange->collapsed(ASSERT_NO_EXCEPTION) && shadowTreeRoot) {
2235 searchRange = rangeOfContents(m_frame->document()); 2235 searchRange = rangeOfContents(m_frame->document());
2236 if (forward) 2236 if (forward)
2237 searchRange->setStartAfter(shadowTreeRoot->shadowHost()); 2237 searchRange->setStartAfter(shadowTreeRoot->shadowHost());
2238 else 2238 else
2239 searchRange->setEndBefore(shadowTreeRoot->shadowHost()); 2239 searchRange->setEndBefore(shadowTreeRoot->shadowHost());
2240 2240
2241 resultRange = findPlainText(searchRange.get(), target, options); 2241 resultRange = findPlainText(searchRange.get(), target, options);
2242 } 2242 }
2243 2243
2244 // If we didn't find anything and we're wrapping, search again in the entire document (this will 2244 // If we didn't find anything and we're wrapping, search again in the entire document (this will
2245 // redundantly re-search the area already searched in some cases). 2245 // redundantly re-search the area already searched in some cases).
2246 if (resultRange->collapsed(ASSERT_NO_EXCEPTION_STATE) && options & WrapAroun d) { 2246 if (resultRange->collapsed(ASSERT_NO_EXCEPTION) && options & WrapAround) {
2247 searchRange = rangeOfContents(m_frame->document()); 2247 searchRange = rangeOfContents(m_frame->document());
2248 resultRange = findPlainText(searchRange.get(), target, options); 2248 resultRange = findPlainText(searchRange.get(), target, options);
2249 // We used to return false here if we ended up with the same range that we started with 2249 // We used to return false here if we ended up with the same range that we started with
2250 // (e.g., the reference range was already the only instance of this text ). But we decided that 2250 // (e.g., the reference range was already the only instance of this text ). But we decided that
2251 // this should be a success case instead, so we'll just fall through in that case. 2251 // this should be a success case instead, so we'll just fall through in that case.
2252 } 2252 }
2253 2253
2254 return resultRange->collapsed(ASSERT_NO_EXCEPTION_STATE) ? 0 : resultRange.r elease(); 2254 return resultRange->collapsed(ASSERT_NO_EXCEPTION) ? 0 : resultRange.release ();
2255 } 2255 }
2256 2256
2257 void Editor::setMarkedTextMatchesAreHighlighted(bool flag) 2257 void Editor::setMarkedTextMatchesAreHighlighted(bool flag)
2258 { 2258 {
2259 if (flag == m_areMarkedTextMatchesHighlighted) 2259 if (flag == m_areMarkedTextMatchesHighlighted)
2260 return; 2260 return;
2261 2261
2262 m_areMarkedTextMatchesHighlighted = flag; 2262 m_areMarkedTextMatchesHighlighted = flag;
2263 m_frame->document()->markers()->repaintMarkers(DocumentMarker::TextMatch); 2263 m_frame->document()->markers()->repaintMarkers(DocumentMarker::TextMatch);
2264 } 2264 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 return WebCore::unifiedTextCheckerEnabled(m_frame); 2378 return WebCore::unifiedTextCheckerEnabled(m_frame);
2379 } 2379 }
2380 2380
2381 void Editor::toggleOverwriteModeEnabled() 2381 void Editor::toggleOverwriteModeEnabled()
2382 { 2382 {
2383 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2383 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2384 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); 2384 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled);
2385 }; 2385 };
2386 2386
2387 } // namespace WebCore 2387 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/EditingStyle.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698