| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 void CompositeEditCommand::applyStyledElement(PassRefPtr<Element> element) | 281 void CompositeEditCommand::applyStyledElement(PassRefPtr<Element> element) |
| 282 { | 282 { |
| 283 applyCommandToComposite(ApplyStyleCommand::create(element, false)); | 283 applyCommandToComposite(ApplyStyleCommand::create(element, false)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void CompositeEditCommand::removeStyledElement(PassRefPtr<Element> element) | 286 void CompositeEditCommand::removeStyledElement(PassRefPtr<Element> element) |
| 287 { | 287 { |
| 288 applyCommandToComposite(ApplyStyleCommand::create(element, true)); | 288 applyCommandToComposite(ApplyStyleCommand::create(element, true)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void CompositeEditCommand::insertParagraphSeparator(bool useDefaultParagraphElem
ent, bool pasteBlockqutoeIntoUnquotedArea) | 291 void CompositeEditCommand::insertParagraphSeparator(bool useDefaultParagraphElem
ent) |
| 292 { | 292 { |
| 293 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(),
useDefaultParagraphElement, pasteBlockqutoeIntoUnquotedArea)); | 293 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(),
useDefaultParagraphElement)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void CompositeEditCommand::insertLineBreak() | 296 void CompositeEditCommand::insertLineBreak() |
| 297 { | 297 { |
| 298 applyCommandToComposite(InsertLineBreakCommand::create(document())); | 298 applyCommandToComposite(InsertLineBreakCommand::create(document())); |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool CompositeEditCommand::isRemovableBlock(const Node* node) | 301 bool CompositeEditCommand::isRemovableBlock(const Node* node) |
| 302 { | 302 { |
| 303 if (!node->hasTagName(divTag)) | 303 if (!node->hasTagName(divTag)) |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 appendBlockPlaceholder(newBlock); | 1314 appendBlockPlaceholder(newBlock); |
| 1315 setEndingSelection(VisibleSelection(firstPositionInNode(newBlock.get()), DOW
NSTREAM, endingSelection().isDirectional())); | 1315 setEndingSelection(VisibleSelection(firstPositionInNode(newBlock.get()), DOW
NSTREAM, endingSelection().isDirectional())); |
| 1316 | 1316 |
| 1317 style->prepareToApplyAt(endingSelection().start()); | 1317 style->prepareToApplyAt(endingSelection().start()); |
| 1318 if (!style->isEmpty()) | 1318 if (!style->isEmpty()) |
| 1319 applyStyle(style.get()); | 1319 applyStyle(style.get()); |
| 1320 | 1320 |
| 1321 return true; | 1321 return true; |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 // If the caret is in an empty quoted paragraph, and either there is nothing bef
ore that | |
| 1325 // paragraph, or what is before is unquoted, and the user presses delete, unquot
e that paragraph. | |
| 1326 bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph() | |
| 1327 { | |
| 1328 if (!endingSelection().isCaret()) | |
| 1329 return false; | |
| 1330 | |
| 1331 VisiblePosition caret(endingSelection().visibleStart()); | |
| 1332 Node* highestBlockquote = highestEnclosingNodeOfType(caret.deepEquivalent(),
&isMailBlockquote); | |
| 1333 if (!highestBlockquote) | |
| 1334 return false; | |
| 1335 | |
| 1336 if (!isStartOfParagraph(caret) || !isEndOfParagraph(caret)) | |
| 1337 return false; | |
| 1338 | |
| 1339 VisiblePosition previous(caret.previous(CannotCrossEditingBoundary)); | |
| 1340 // Only move forward if there's nothing before the caret, or if there's unqu
oted content before it. | |
| 1341 if (enclosingNodeOfType(previous.deepEquivalent(), &isMailBlockquote)) | |
| 1342 return false; | |
| 1343 | |
| 1344 RefPtr<Node> br = createBreakElement(document()); | |
| 1345 // We want to replace this quoted paragraph with an unquoted one, so insert
a br | |
| 1346 // to hold the caret before the highest blockquote. | |
| 1347 insertNodeBefore(br, highestBlockquote); | |
| 1348 VisiblePosition atBR(positionBeforeNode(br.get())); | |
| 1349 // If the br we inserted collapsed, for example foo<br><blockquote>...</bloc
kquote>, insert | |
| 1350 // a second one. | |
| 1351 if (!isStartOfParagraph(atBR)) | |
| 1352 insertNodeBefore(createBreakElement(document()), br); | |
| 1353 setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional())
); | |
| 1354 | |
| 1355 // If this is an empty paragraph there must be a line break here. | |
| 1356 if (!lineBreakExistsAtVisiblePosition(caret)) | |
| 1357 return false; | |
| 1358 | |
| 1359 Position caretPos(caret.deepEquivalent().downstream()); | |
| 1360 // A line break is either a br or a preserved newline. | |
| 1361 ASSERT(caretPos.deprecatedNode()->hasTagName(brTag) || (caretPos.deprecatedN
ode()->isTextNode() && caretPos.deprecatedNode()->renderer()->style()->preserveN
ewline())); | |
| 1362 | |
| 1363 if (caretPos.deprecatedNode()->hasTagName(brTag)) | |
| 1364 removeNodeAndPruneAncestors(caretPos.deprecatedNode()); | |
| 1365 else if (caretPos.deprecatedNode()->isTextNode()) { | |
| 1366 ASSERT(caretPos.deprecatedEditingOffset() == 0); | |
| 1367 Text* textNode = toText(caretPos.deprecatedNode()); | |
| 1368 ContainerNode* parentNode = textNode->parentNode(); | |
| 1369 // The preserved newline must be the first thing in the node, since othe
rwise the previous | |
| 1370 // paragraph would be quoted, and we verified that it wasn't above. | |
| 1371 deleteTextFromNode(textNode, 0, 1); | |
| 1372 prune(parentNode); | |
| 1373 } | |
| 1374 | |
| 1375 return true; | |
| 1376 } | |
| 1377 | |
| 1378 // Operations use this function to avoid inserting content into an anchor when a
t the start or the end of | 1324 // Operations use this function to avoid inserting content into an anchor when a
t the start or the end of |
| 1379 // that anchor, as in NSTextView. | 1325 // that anchor, as in NSTextView. |
| 1380 // FIXME: This is only an approximation of NSTextViews insertion behavior, which
varies depending on how | 1326 // FIXME: This is only an approximation of NSTextViews insertion behavior, which
varies depending on how |
| 1381 // the caret was made. | 1327 // the caret was made. |
| 1382 Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
tion& original) | 1328 Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
tion& original) |
| 1383 { | 1329 { |
| 1384 if (original.isNull()) | 1330 if (original.isNull()) |
| 1385 return original; | 1331 return original; |
| 1386 | 1332 |
| 1387 VisiblePosition visiblePos(original); | 1333 VisiblePosition visiblePos(original); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 return node.release(); | 1408 return node.release(); |
| 1463 } | 1409 } |
| 1464 | 1410 |
| 1465 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) | 1411 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) |
| 1466 { | 1412 { |
| 1467 RefPtr<Element> breakNode = document->createElement(brTag, false); | 1413 RefPtr<Element> breakNode = document->createElement(brTag, false); |
| 1468 return breakNode.release(); | 1414 return breakNode.release(); |
| 1469 } | 1415 } |
| 1470 | 1416 |
| 1471 } // namespace WebCore | 1417 } // namespace WebCore |
| OLD | NEW |