Changeset 243124 in webkit
- Timestamp:
- Mar 18, 2019 6:56:39 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r243109 r243124 1 2019-03-18 Megan Gardner <megan_gardner@apple.com> 2 3 Smart Insert for paragraphs. 4 https://bugs.webkit.org/show_bug.cgi?id=194880 5 6 Reviewed by Ryosuke Niwa. 7 8 List tests are covered by paste-list-00*. 9 Table tests are covered by paste-table-00* and paste-into-table-*. 10 11 * editing/pasteboard/smart-paste-paragraph-001-expected.txt: Added. 12 * editing/pasteboard/smart-paste-paragraph-001.html: Added. 13 * editing/pasteboard/smart-paste-paragraph-002-expected.txt: Added. 14 * editing/pasteboard/smart-paste-paragraph-002.html: Added. 15 * editing/pasteboard/smart-paste-paragraph-003-expected.txt: Added. 16 * editing/pasteboard/smart-paste-paragraph-003.html: Added. 17 * editing/pasteboard/smart-paste-paragraph-004-expected.txt: Added. 18 * editing/pasteboard/smart-paste-paragraph-004.html: Added. 19 * platform/ios-wk2/editing/pasteboard/paste-text-016-expected.txt: 20 This needed to be rebaselined to match the new behaviour. 21 * platform/ios/editing/pasteboard/smart-paste-paragraph-001-expected.txt: Added. 22 * platform/ios/editing/pasteboard/smart-paste-paragraph-002-expected.txt: Added. 23 * platform/ios/editing/pasteboard/smart-paste-paragraph-003-expected.txt: Added. 24 * platform/ios/editing/pasteboard/smart-paste-paragraph-004-expected.txt: Added. 25 1 26 2019-03-18 Jer Noble <jer.noble@apple.com> 2 27 -
trunk/LayoutTests/platform/ios-wk2/editing/pasteboard/paste-text-016-expected.txt
r222051 r243124 39 39 text run at (0,20) width 384: "***TEST*** line should be second, following the first line." 40 40 RenderBlock {DIV} at (0,40) size 784x12 41 RenderBlock {DIV} at (0,52) size 784x2 3842 RenderBlock {DIV} at (0,0) size 784x2 38 [border: (2px solid #FF0000)]41 RenderBlock {DIV} at (0,52) size 784x268 42 RenderBlock {DIV} at (0,0) size 784x268 [border: (2px solid #FF0000)] 43 43 RenderBlock {P} at (14,14) size 756x30 44 44 RenderText {#text} at (0,1) size 316x28 … … 46 46 RenderBR {BR} at (315,23) size 1x0 47 47 RenderBlock {P} at (14,44) size 756x30 48 RenderBR {BR} at (0,1) size 0x28 49 RenderBlock {P} at (14,74) size 756x30 48 50 RenderText {#text} at (0,1) size 130x28 49 51 text run at (0,1) width 130: "***TEST***" 50 RenderBlock {DIV} at (14, 74) size 756x3052 RenderBlock {DIV} at (14,104) size 756x30 51 53 RenderBR {BR} at (0,1) size 0x28 52 RenderBlock {P} at (14,1 04) size 756x3054 RenderBlock {P} at (14,134) size 756x30 53 55 RenderText {#text} at (0,1) size 127x28 54 56 text run at (0,1) width 127: "Another line." 55 RenderBlock {P} at (14,134) size 756x056 RenderBlock (anonymous) at (14,134) size 756x3057 RenderText {#text} at (0,1) size 6x2858 text run at (0,1) width 6: " "59 57 RenderBlock {P} at (14,164) size 756x0 60 58 RenderBlock (anonymous) at (14,164) size 756x30 61 59 RenderText {#text} at (0,1) size 6x28 62 60 text run at (0,1) width 6: " " 63 RenderBlock {P} at (14,194) size 756x30 61 RenderBlock {P} at (14,194) size 756x0 62 RenderBlock (anonymous) at (14,194) size 756x30 63 RenderText {#text} at (0,1) size 6x28 64 text run at (0,1) width 6: " " 65 RenderBlock {P} at (14,224) size 756x30 64 66 RenderBR {BR} at (0,1) size 0x28 65 caret: position 0 of child 0 {BR} of child 2{DIV} of child 1 {DIV} of child 7 {DIV} of body67 caret: position 0 of child 0 {BR} of child 3 {DIV} of child 1 {DIV} of child 7 {DIV} of body -
trunk/Source/WebCore/ChangeLog
r243122 r243124 1 2019-03-18 Megan Gardner <megan_gardner@apple.com> 2 3 Smart Insert for paragraphs. 4 https://bugs.webkit.org/show_bug.cgi?id=194880 5 6 Reviewed by Ryosuke Niwa. 7 8 Add additional newlines to maintain spacing around paragraphs. 9 10 Tests: editing/pasteboard/smart-paste-paragraph-001.html 11 editing/pasteboard/smart-paste-paragraph-002.html 12 editing/pasteboard/smart-paste-paragraph-003.html 13 editing/pasteboard/smart-paste-paragraph-004.html 14 15 * dom/Document.cpp: 16 (WebCore::Document::editingBehavior const): 17 * dom/Document.h: 18 19 Expose editing behaviour through document so that is can be access from the selection commands 20 and allow the editing behaviour to be used. 21 22 * editing/CompositeEditCommand.h: 23 * editing/EditingBehavior.h: 24 (WebCore::EditingBehavior::shouldSmartInsertDeleteParagraphs const): 25 26 Only have editing insert paragraphs on iOS and in editing elements that support multiple lines. 27 28 * editing/ReplaceSelectionCommand.cpp: 29 (WebCore::ReplaceSelectionCommand::doApply): 30 (WebCore::ReplaceSelectionCommand::shouldPerformSmartParagraphReplace const): 31 (WebCore::ReplaceSelectionCommand::addNewLinesForSmartReplace): 32 * editing/ReplaceSelectionCommand.h: 33 34 Add addititional newlines when pasting full paragraphs to maintian two newlines between paragraphs 35 if that is what the original document had. If there are not multiple lines between paragraphs, do not 36 add additional new lines. 37 1 38 2019-03-18 Ryosuke Niwa <rniwa@webkit.org> 2 39 -
trunk/Source/WebCore/dom/Document.cpp
r243122 r243124 7431 7431 return fontSelector().fontFaceSet(); 7432 7432 } 7433 7434 EditingBehavior Document::editingBehavior() const 7435 { 7436 return EditingBehavior { settings().editingBehaviorType() }; 7437 } 7433 7438 7434 7439 float Document::deviceScaleFactor() const -
trunk/Source/WebCore/dom/Document.h
r243122 r243124 117 117 class DocumentTimeline; 118 118 class DocumentType; 119 class EditingBehavior; 119 120 class ExtensionStyleSheets; 120 121 class FloatQuad; … … 563 564 const Settings& settings() const { return m_settings.get(); } 564 565 Settings& mutableSettings() { return m_settings.get(); } 566 EditingBehavior editingBehavior() const; 565 567 566 568 const Quirks& quirks() const { return m_quirks; } -
trunk/Source/WebCore/editing/CompositeEditCommand.h
r240476 r243124 153 153 void insertNodeAtTabSpanPosition(Ref<Node>&&, const Position&); 154 154 void insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); 155 void insertParagraphSeparatorAtPosition(const Position&, bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false); 155 156 void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false); 156 157 void insertLineBreak(); -
trunk/Source/WebCore/editing/EditingBehavior.h
r241719 r243124 99 99 // On iOS, when smart delete is on, it is always on, and should do not additional checks (i.e. WordGranularity). 100 100 bool shouldAlwaysSmartDelete() const { return m_type == EditingIOSBehavior; } 101 102 // On iOS, we should turn on smart insert and delete and newlines around paragraphs to match UIKit behaviour. 103 bool shouldSmartInsertDeleteParagraphs() const { return m_type == EditingIOSBehavior; } 101 104 102 105 private: -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r241932 r243124 778 778 return true; 779 779 } 780 781 static bool isBlankLine(VisiblePosition& position) 782 { 783 return isStartOfLine(position) && startOfLine(position.next()) != startOfLine(position); 784 } 780 785 781 786 // At copy time, WebKit wraps copied content in a span that contains the source document's … … 924 929 m_documentFragmentHTMLMarkup = serializeFragment(*m_documentFragment, SerializedNodes::SubtreeIncludingNode); 925 930 return CompositeEditCommand::willApplyCommand(); 931 } 932 933 static bool hasBlankLineBetweenParagraphs(Position& position) 934 { 935 bool reachedBoundaryStart = false; 936 bool reachedBoundaryEnd = false; 937 VisiblePosition visiblePosition(position); 938 VisiblePosition previousPosition = visiblePosition.previous(CannotCrossEditingBoundary, &reachedBoundaryStart); 939 VisiblePosition nextPosition = visiblePosition.next(CannotCrossEditingBoundary, &reachedBoundaryStart); 940 bool hasLineBeforePosition = isEndOfLine(previousPosition); 941 942 return !reachedBoundaryStart && !reachedBoundaryEnd && isBlankLine(visiblePosition) && hasLineBeforePosition && isStartOfLine(nextPosition); 926 943 } 927 944 … … 1070 1087 insertionPos = positionOutsideTabSpan(insertionPos); 1071 1088 1089 bool hasBlankLinesBetweenParagraphs = hasBlankLineBetweenParagraphs(insertionPos); 1090 1072 1091 bool handledStyleSpans = handleStyleSpansBeforeInsertion(fragment, insertionPos); 1073 1092 … … 1121 1140 1122 1141 Node* blockStart = enclosingBlock(insertionPos.deprecatedNode()); 1123 if ((isListHTMLElement(refNode.get()) || (isLegacyAppleStyleSpan(refNode.get()) && isListHTMLElement(refNode->firstChild()))) 1124 && blockStart && blockStart->renderer()->isListItem()) 1142 bool isInsertingIntoList = (isListHTMLElement(refNode.get()) || (isLegacyAppleStyleSpan(refNode.get()) && isListHTMLElement(refNode->firstChild()))) 1143 && blockStart && blockStart->renderer()->isListItem(); 1144 if (isInsertingIntoList) 1125 1145 refNode = insertAsListItems(downcast<HTMLElement>(*refNode), blockStart, insertionPos, insertedNodes); 1126 1146 else { … … 1271 1291 addSpacesForSmartReplace(); 1272 1292 1293 if (!isInsertingIntoList && hasBlankLinesBetweenParagraphs && shouldPerformSmartParagraphReplace()) 1294 addNewLinesForSmartReplace(); 1295 1273 1296 // If we are dealing with a fragment created from plain text 1274 1297 // no style matching is necessary. … … 1326 1349 return true; 1327 1350 } 1351 1352 bool ReplaceSelectionCommand::shouldPerformSmartParagraphReplace() const 1353 { 1354 if (!m_smartReplace) 1355 return false; 1356 1357 if (!document().editingBehavior().shouldSmartInsertDeleteParagraphs()) 1358 return false; 1359 1360 return true; 1361 } 1328 1362 1329 1363 static bool isCharacterSmartReplaceExemptConsideringNonBreakingSpace(UChar32 character, bool previousCharacter) 1330 1364 { 1331 1365 return isCharacterSmartReplaceExempt(character == noBreakSpace ? ' ' : character, previousCharacter); 1366 } 1367 1368 void ReplaceSelectionCommand::addNewLinesForSmartReplace() 1369 { 1370 VisiblePosition startOfInsertedContent = positionAtStartOfInsertedContent(); 1371 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); 1372 1373 bool isPastedContentEntireParagraphs = isStartOfParagraph(startOfInsertedContent) && isEndOfParagraph(endOfInsertedContent); 1374 1375 // If we aren't pasting a paragraph, no need to attempt to insert newlines. 1376 if (!isPastedContentEntireParagraphs) 1377 return; 1378 1379 bool reachedBoundaryStart = false; 1380 bool reachedBoundaryEnd = false; 1381 VisiblePosition positionBeforeStart = startOfInsertedContent.previous(CannotCrossEditingBoundary, &reachedBoundaryStart); 1382 VisiblePosition positionAfterEnd = endOfInsertedContent.next(CannotCrossEditingBoundary, &reachedBoundaryEnd); 1383 1384 if (!reachedBoundaryStart && !reachedBoundaryEnd) { 1385 if (!isBlankLine(positionBeforeStart) && !isBlankLine(startOfInsertedContent) && isEndOfLine(positionBeforeStart) && !isEndOfEditableOrNonEditableContent(positionAfterEnd) && !isEndOfEditableOrNonEditableContent(endOfInsertedContent)) { 1386 setEndingSelection(startOfInsertedContent); 1387 insertParagraphSeparator(); 1388 auto newStart = endingSelection().visibleStart().previous(CannotCrossEditingBoundary, &reachedBoundaryStart); 1389 if (!reachedBoundaryStart) 1390 m_startOfInsertedContent = newStart.deepEquivalent(); 1391 } 1392 } 1393 1394 reachedBoundaryStart = false; 1395 reachedBoundaryEnd = false; 1396 positionAfterEnd = endOfInsertedContent.next(CannotCrossEditingBoundary, &reachedBoundaryEnd); 1397 positionBeforeStart = startOfInsertedContent.previous(CannotCrossEditingBoundary, &reachedBoundaryStart); 1398 1399 if (!reachedBoundaryEnd && !reachedBoundaryStart) { 1400 if (!isBlankLine(positionAfterEnd) && !isBlankLine(endOfInsertedContent) && isStartOfLine(positionAfterEnd) && !isEndOfLine(positionAfterEnd) && !isEndOfEditableOrNonEditableContent(positionAfterEnd)) { 1401 setEndingSelection(endOfInsertedContent); 1402 insertParagraphSeparator(); 1403 m_endOfInsertedContent = endingSelection().start(); 1404 } 1405 } 1332 1406 } 1333 1407 -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.h
r235775 r243124 109 109 110 110 bool shouldPerformSmartReplace() const; 111 bool shouldPerformSmartParagraphReplace() const; 111 112 void addSpacesForSmartReplace(); 113 void addNewLinesForSmartReplace(); 112 114 void completeHTMLReplacement(const Position& lastPositionToSelect); 113 115 void mergeTextNodesAroundPosition(Position&, Position& positionOnlyToBeUpdated);
Note: See TracChangeset
for help on using the changeset viewer.