Fixed: <rdar://problem/
3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
Reviewed by kocienda.
* khtml/editing/htmlediting.cpp:
(khtml::ApplyStyleCommand::addInlineStyleIfNeeded): don't set class on element returned by createStyleSpanElement since that's already done
(khtml::ReplacementFragment::ReplacementFragment): take matchStyle param, don't call computeStylesAndRemoveUnrendered() if !matchStyle
(khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): take matchStyle param
(khtml::ReplaceSelectionCommand::doApply): if m_matchStyle, use selection.start() as the insertion position and don't call applyStyleToInsertedNodes()
* khtml/editing/htmlediting.h:
* kwq/WebCoreBridge.h:
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]): take matchStyle param and pass it
(-[WebCoreBridge replaceSelectionWithNode:selectReplacement:smartReplace:]): pass NO for matchStyle
(-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:smartReplace:]): pass NO for matchStyle
(-[WebCoreBridge replaceSelectionWithText:selectReplacement:smartReplace:]): pass YES for matchStyle
WebKit:
Fixed: <rdar://problem/
3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
Reviewed by kocienda.
* WebView.subproj/WebDataSource.m:
(-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): pass NO for matchStyle to replaceSelection
* WebView.subproj/WebHTMLView.m:
(-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:chosePlainText:]): return new chosePlainText parameter
(-[WebHTMLView _pasteWithPasteboard:allowPlainText:]): pass chosePlainText for matchStyle to replaceSelection
(-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): ditto
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8632
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2005-02-18 Chris Blumenberg <cblu@apple.com>
+
+ Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
+
+ Reviewed by kocienda.
+
+ * khtml/editing/htmlediting.cpp:
+ (khtml::ApplyStyleCommand::addInlineStyleIfNeeded): don't set class on element returned by createStyleSpanElement since that's already done
+ (khtml::ReplacementFragment::ReplacementFragment): take matchStyle param, don't call computeStylesAndRemoveUnrendered() if !matchStyle
+ (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): take matchStyle param
+ (khtml::ReplaceSelectionCommand::doApply): if m_matchStyle, use selection.start() as the insertion position and don't call applyStyleToInsertedNodes()
+ * khtml/editing/htmlediting.h:
+ * kwq/WebCoreBridge.h:
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]): take matchStyle param and pass it
+ (-[WebCoreBridge replaceSelectionWithNode:selectReplacement:smartReplace:]): pass NO for matchStyle
+ (-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:smartReplace:]): pass NO for matchStyle
+ (-[WebCoreBridge replaceSelectionWithText:selectReplacement:smartReplace:]): pass YES for matchStyle
+
2005-02-18 Ken Kocienda <kocienda@apple.com>
Reviewed by Chris
if (styleChange.cssStyle().length() > 0) {
ElementImpl *styleElement = createStyleSpanElement(document());
styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle());
- styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
insertNodeBefore(styleElement, startNode);
surroundNodeRangeWithElement(startNode, endNode, styleElement);
}
//------------------------------------------------------------------------------------------
// ReplaceSelectionCommand
-ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmentImpl *fragment)
- : m_document(document), m_fragment(fragment), m_hasInterchangeNewline(false), m_hasMoreThanOneBlock(false)
+ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmentImpl *fragment, bool matchStyle)
+ : m_document(document), m_fragment(fragment), m_matchStyle(matchStyle), m_hasInterchangeNewline(false), m_hasMoreThanOneBlock(false)
{
if (!m_document)
return;
removeNode(nodeToDelete);
// Prepare this fragment to merge styles correctly into the destination.
- computeStylesAndRemoveUnrendered();
+ if (!m_matchStyle) {
+ computeStylesAndRemoveUnrendered();
+ }
removeStyleNodes();
int blockCount = realBlockCount;
if (!isProbablyBlock(lastChild) && realBlockCount > 0)
blockCount++;
- if (blockCount > 1)
+ if (blockCount > 1)
m_hasMoreThanOneBlock = true;
}
}
}
-ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, bool selectReplacement, bool smartReplace)
+ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, bool selectReplacement, bool smartReplace, bool matchStyle)
: CompositeEditCommand(document),
- m_fragment(document, fragment),
+ m_fragment(document, fragment, matchStyle),
m_firstNodeInserted(0),
m_lastNodeInserted(0),
m_lastTopNodeInserted(0),
m_selectReplacement(selectReplacement),
- m_smartReplace(smartReplace)
+ m_smartReplace(smartReplace),
+ m_matchStyle(matchStyle)
{
}
// calculate the start and end of the resulting selection
selection = endingSelection();
- if (startAtStartOfBlock && startBlock->inDocument()) {
- startPos = Position(startBlock, 0);
- } else if (startAtEndOfBlock) {
- startPos = selection.start().downstream(StayInBlock);
+ if (m_matchStyle) {
+ startPos = selection.start();
} else {
- startPos = selection.start().upstream(upstreamStayInBlock);
+ if (startAtStartOfBlock && startBlock->inDocument()) {
+ startPos = Position(startBlock, 0);
+ } else if (startAtEndOfBlock) {
+ startPos = selection.start().downstream(StayInBlock);
+ } else {
+ startPos = selection.start().upstream(upstreamStayInBlock);
+ }
}
endPos = selection.end().downstream();
// See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
KHTMLPart *part = document()->part();
part->clearTypingStyle();
- setTypingStyle(0);
-
+ setTypingStyle(0);
+
// done if there is nothing to add
if (!m_fragment.firstChild())
return;
insertParagraphSeparator();
endPos = endingSelection().end().downstream();
}
- applyStyleToInsertedNodes();
+ if (!m_matchStyle) {
+ applyStyleToInsertedNodes();
+ }
completeHTMLReplacement(startPos, endPos);
} else {
if (m_lastNodeInserted && m_lastNodeInserted->id() == ID_BR && !document()->inStrictMode()) {
}
}
- applyStyleToInsertedNodes();
-
+ if (!m_matchStyle) {
+ applyStyleToInsertedNodes();
+ }
+
completeHTMLReplacement();
}
class ReplacementFragment
{
public:
- ReplacementFragment(DOM::DocumentImpl *, DOM::DocumentFragmentImpl *);
+ ReplacementFragment(DOM::DocumentImpl *, DOM::DocumentFragmentImpl *, bool matchStyle);
~ReplacementFragment();
enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
// no copy construction or assignment
ReplacementFragment(const ReplacementFragment &);
ReplacementFragment &operator=(const ReplacementFragment &);
-
+
static bool isInterchangeNewlineNode(const DOM::NodeImpl *);
static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);
DOM::DocumentImpl *m_document;
DOM::DocumentFragmentImpl *m_fragment;
QMap<DOM::NodeImpl *, DOM::CSSMutableStyleDeclarationImpl *> m_styles;
+ bool m_matchStyle;
bool m_hasInterchangeNewline;
bool m_hasMoreThanOneBlock;
};
class ReplaceSelectionCommand : public CompositeEditCommand
{
public:
- ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false);
+ ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false, bool matchStyle=false);
virtual ~ReplaceSelectionCommand();
virtual void doApply();
DOM::NodeImpl *m_lastTopNodeInserted;
bool m_selectReplacement;
bool m_smartReplace;
+ bool m_matchStyle;
};
//------------------------------------------------------------------------------------------
- (DOMDocumentFragment *)documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
- (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text;
-- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle;
- (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
- (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText(_part->xmlDocImpl(), QString::fromNSString(text))];
}
-- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
{
if (!partHasSelection(self) || !fragment)
return;
- EditCommandPtr(new ReplaceSelectionCommand(_part->xmlDocImpl(), [fragment _fragmentImpl], selectReplacement, smartReplace)).apply();
+ EditCommandPtr(new ReplaceSelectionCommand(_part->xmlDocImpl(), [fragment _fragmentImpl], selectReplacement, smartReplace, matchStyle)).apply();
[self ensureSelectionVisible];
}
{
DOMDocumentFragment *fragment = [[self DOMDocument] createDocumentFragment];
[fragment appendChild:node];
- [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace];
+ [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
}
- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
{
DOMDocumentFragment *fragment = [self documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
- [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace];
+ [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
}
- (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
{
- [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement smartReplace:smartReplace];
+ [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
}
- (void)insertLineBreak
+2005-02-18 Chris Blumenberg <cblu@apple.com>
+
+ Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
+
+ Reviewed by kocienda.
+
+ * WebView.subproj/WebDataSource.m:
+ (-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): pass NO for matchStyle to replaceSelection
+ * WebView.subproj/WebHTMLView.m:
+ (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:chosePlainText:]): return new chosePlainText parameter
+ (-[WebHTMLView _pasteWithPasteboard:allowPlainText:]): pass chosePlainText for matchStyle to replaceSelection
+ (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): ditto
+
2005-02-17 Richard Williamson <rjw@apple.com>
Removed code that should not have been checked in from
{
DOMDocumentFragment *fragment = [self _documentFragmentWithArchive:archive];
if (fragment) {
- [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:NO];
+ [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:NO matchStyle:NO];
}
}
@interface WebHTMLView (WebHTMLViewFileInternal)
- (BOOL)_imageExistsAtPaths:(NSArray *)paths;
-- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText;
- (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
- (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;
return elements;
}
-- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText
{
NSArray *types = [pasteboard types];
+ *chosePlainText = NO;
if ([types containsObject:WebArchivePboardType]) {
WebArchive *archive = [[WebArchive alloc] initWithData:[pasteboard dataForType:WebArchivePboardType]];
}
if (allowPlainText && [types containsObject:NSStringPboardType]) {
+ *chosePlainText = YES;
return [[self _bridge] documentFragmentWithText:[pasteboard stringForType:NSStringPboardType]];
}
- (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
{
- DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:allowPlainText];
+ BOOL chosePlainText;
+ DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:allowPlainText chosePlainText:&chosePlainText];
WebBridge *bridge = [self _bridge];
if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[self _selectedRange] givenAction:WebViewInsertActionPasted]) {
- [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+ [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
}
}
BOOL didInsert = NO;
if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
- DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES];
+ BOOL chosePlainText;
+ DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
[[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
if ([self _isMoveDrag]) {
[bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
} else {
[bridge setSelectionToDragCaret];
- [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+ [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
}
didInsert = YES;
}