[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

cblu cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:23:13 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 760b20f7b565a21354a5e65ef01f8c38805435ad
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jan 23 01:10:02 2004 +0000

    WebCore:
    
    	Fixed: <rdar://problem/3537542>: support for copying HTML
    
            Reviewed by dave.
    
            * khtml/xml/dom2_rangeimpl.cpp:
            (RangeImpl::toHTML): implemented
            * khtml/xml/dom_nodeimpl.cpp:
            (NodeImpl::recursive_toHTMLWithRange): new
            * khtml/xml/dom_nodeimpl.h:
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
            (-[WebCoreBridge selectedHTML]): new
            (-[WebCoreBridge reconstructedSource]): new
    
    WebKit:
    
    	Fixed: <rdar://problem/3537542>: support for copying HTML
    
            Reviewed by dave.
    
            * WebView.subproj/WebHTMLRepresentation.h:
            * WebView.subproj/WebHTMLRepresentation.m:
            (-[WebHTMLRepresentation reconstructedSource]): for BLOT's eventual use
            * WebView.subproj/WebHTMLView.m:
            (+[WebHTMLView _pasteboardTypes]): provide NSHTMLPboardType
            (-[WebHTMLView _writeSelectionToPasteboard:]): add HTML to the pasteboard
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5965 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 4b79943..58f441d 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,19 @@
+2004-01-22  Chris Blumenberg  <cblu at apple.com>
+
+	Fixed: <rdar://problem/3537542>: support for copying HTML
+
+        Reviewed by dave.
+
+        * khtml/xml/dom2_rangeimpl.cpp:
+        (RangeImpl::toHTML): implemented
+        * khtml/xml/dom_nodeimpl.cpp:
+        (NodeImpl::recursive_toHTMLWithRange): new
+        * khtml/xml/dom_nodeimpl.h:
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge selectedHTML]): new
+        (-[WebCoreBridge reconstructedSource]): new
+
 2004-01-21  David Hyatt  <hyatt at apple.com>
 
 	Fix for two margin collapsing edge cases.
diff --git a/WebCore/khtml/xml/dom2_rangeimpl.cpp b/WebCore/khtml/xml/dom2_rangeimpl.cpp
index c63d1b4..081e965 100644
--- a/WebCore/khtml/xml/dom2_rangeimpl.cpp
+++ b/WebCore/khtml/xml/dom2_rangeimpl.cpp
@@ -30,8 +30,10 @@
 #include "dom_xmlimpl.h"
 #include "html/html_elementimpl.h"
 
-using namespace DOM;
+#include "render_block.h"
 
+using namespace DOM;
+using namespace khtml;
 
 RangeImpl::RangeImpl(DocumentPtr *_ownerDocument)
 {
@@ -843,8 +845,29 @@ DOMString RangeImpl::toString( int &exceptioncode )
 
 DOMString RangeImpl::toHTML(  )
 {
-    // ### implement me!!!!
-    return DOMString();
+	// Find the common containing block node of the start and end nodes.
+	RenderBlock *startBlock = m_startContainer->renderer()->containingBlock();
+	RenderBlock *endBlock = m_endContainer->renderer()->containingBlock();
+	NodeImpl *commonBlockNode = 0;
+	while (1) {
+		RenderBlock *newEndBlock = endBlock;
+		while (1) {
+			if (startBlock == newEndBlock) {
+				commonBlockNode = startBlock->element();
+				break;
+			}
+			if (newEndBlock->isRoot()) {
+				break;
+			}
+			newEndBlock = newEndBlock->containingBlock();
+		}
+		if (commonBlockNode) {
+			break;
+		}
+		startBlock = startBlock->containingBlock();
+	}
+	
+    return commonBlockNode->recursive_toHTMLWithRange(true, this);
 }
 
 DocumentFragmentImpl *RangeImpl::createContextualFragment ( DOMString &html, int &exceptioncode )
diff --git a/WebCore/khtml/xml/dom_nodeimpl.cpp b/WebCore/khtml/xml/dom_nodeimpl.cpp
index 0c4a942..17d0bff 100644
--- a/WebCore/khtml/xml/dom_nodeimpl.cpp
+++ b/WebCore/khtml/xml/dom_nodeimpl.cpp
@@ -267,6 +267,118 @@ static QString escapeHTML( const QString& in )
     return s;
 }
 
+QString NodeImpl::recursive_toHTMLWithRange(bool start, const DOM::Range &range) const
+{	
+	QString me = "";
+		
+	NodeImpl *startContainer = range.startContainer().handle();
+	NodeImpl *endContainer = range.endContainer().handle();
+	NodeImpl *n = startContainer;
+	bool isNodeIncluded = false;
+	Id ident = id();
+	
+	if (!start || (start && (ident == ID_TABLE || ident == ID_OL || ident == ID_UL))) {	
+		// Check if this node is in the range or is an ancestor of a node in the range.
+		while (n) {
+			NodeImpl *ancestor = n;
+			while (ancestor) {
+				if (this == ancestor) {
+					isNodeIncluded = true;
+					break;
+				}
+				ancestor = ancestor->parentNode();
+			}
+			if (isNodeIncluded) {
+				break;
+			}
+			if (n == endContainer) {
+				break;
+			}
+			NodeImpl *next = n->firstChild();
+			if (!next) {
+				next = n->nextSibling();
+			}
+			while (!next && n->parentNode()) {
+				n = n->parentNode();
+				next = n->nextSibling();
+			}
+			n = next;
+		}
+	}
+	
+	if (isNodeIncluded) {	
+		// Copy who I am into the htmlText string
+		if (nodeType() == Node::TEXT_NODE) {
+			DOMString str = nodeValue().copy();
+			if (this == endContainer) {
+				str.truncate(range.endOffset());
+			}
+			if (this == startContainer) {
+				str.remove(0, range.startOffset());
+			}
+			me = escapeHTML(str.string());
+		} else {
+			// If I am an element, not a text
+			NodeImpl* temp = previousSibling();
+			if(temp)
+			{
+				if( !start && (temp->nodeType() != Node::TEXT_NODE && nodeType() != Node::TEXT_NODE ) )
+					me = QString("    ") + QChar('<') + nodeName().string();
+				else
+					me = QChar('<') + nodeName().string();
+			}
+			else
+				me = QChar('<') + nodeName().string();
+			// print attributes
+			if( nodeType() == Node::ELEMENT_NODE )
+			{
+				const ElementImpl *el = static_cast<const ElementImpl *>(this);
+				NamedNodeMap attrs = el->attributes();
+				unsigned long lmap = attrs.length();
+				for( unsigned int j=0; j<lmap; j++ )
+					me += " " + attrs.item(j).nodeName().string() + "=\"" + attrs.item(j).nodeValue().string() + "\"";
+			}
+			// print ending bracket of start tag
+			if( firstChild() == 0 ) {    // if element has no endtag
+				if (isHTMLElement()) {
+					me +=">";
+				} else {
+					me +="/>";
+				}
+			} else                        // if element has endtag
+			{
+				NodeImpl* temp = nextSibling();
+				if(temp)
+				{
+					if( (temp->nodeType() != Node::TEXT_NODE) )
+						me += ">\n";
+					else
+						me += ">";
+				}
+				else
+					me += ">";
+			}
+		}
+	}
+	
+    if( (n = firstChild()) )
+    {
+        // print firstChild
+        me += n->recursive_toHTMLWithRange(false, range);
+		
+        // Print my ending tag
+        if (isNodeIncluded && nodeType() != Node::TEXT_NODE) {
+            me += "</" + nodeName().string() + ">\n";
+		}
+    }
+    // print next sibling
+    if( (n = nextSibling()) )
+        me += n->recursive_toHTMLWithRange(false, range);
+	
+    return me;
+}
+
+
 QString NodeImpl::recursive_toHTML(bool start) const
 {
     QString me = "";
diff --git a/WebCore/khtml/xml/dom_nodeimpl.h b/WebCore/khtml/xml/dom_nodeimpl.h
index 670747b..a4475a2 100644
--- a/WebCore/khtml/xml/dom_nodeimpl.h
+++ b/WebCore/khtml/xml/dom_nodeimpl.h
@@ -55,6 +55,7 @@ class NodeListImpl;
 class NamedNodeMapImpl;
 class DocumentImpl;
 class CSSStyleDeclarationImpl;
+class Range;
 class RegisteredEventListener;
 class EventImpl;
 
@@ -209,6 +210,7 @@ public:
     virtual bool isInline() const;
     virtual QString toHTML() const;
     QString recursive_toHTML(bool start = false) const;
+	QString recursive_toHTMLWithRange(bool start, const DOM::Range &range) const;
 
     virtual void getCursor(int offset, int &_x, int &_y, int &height);
     virtual QRect getRect() const;
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index ad5037c..f105718 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -200,6 +200,7 @@ typedef enum {
 
 - (void)setSelectionFrom:(id <WebDOMNode>)start startOffset:(int)startOffset to:(id <WebDOMNode>)end endOffset:(int) endOffset;
 
+- (NSString *)selectedHTML;
 - (NSString *)selectedString;
 - (NSAttributedString *)selectedAttributedString;
 
@@ -236,6 +237,8 @@ typedef enum {
 
 - (id)accessibilityTree;
 
+- (NSString *)reconstructedSource;
+
 @end
 
 // The WebCoreBridge protocol contains methods for use by the WebCore side of the bridge.
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 01a6278..b80bbff 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -356,6 +356,11 @@ static bool initializedKJS = FALSE;
     _part->gotoAnchor(QString::fromNSString(a));
 }
 
+- (NSString *)selectedHTML
+{
+	return _part->selection().toHTML().string().getNSString();
+}
+
 - (NSString *)selectedString
 {
     QString text = _part->selectedText();
@@ -1123,5 +1128,17 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
     return _part->xmlDocImpl()->getOrCreateAccObjectCache()->accObject(root);
 }
 
+- (NSString *)reconstructedSource
+{
+    NSString *string = nil;
+    DOM::DocumentImpl *doc = _part->xmlDocImpl();
+    if (doc) {
+        string = [[doc->recursive_toHTML(1).getNSString() copy] autorelease];
+    }
+    if (string == nil) {
+        string = @"";
+    }
+    return string;
+}
 
 @end
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 87b33ec..7c7121e 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,16 @@
+2004-01-22  Chris Blumenberg  <cblu at apple.com>
+
+	Fixed: <rdar://problem/3537542>: support for copying HTML
+
+        Reviewed by dave.
+
+        * WebView.subproj/WebHTMLRepresentation.h:
+        * WebView.subproj/WebHTMLRepresentation.m:
+        (-[WebHTMLRepresentation reconstructedSource]): for BLOT's eventual use
+        * WebView.subproj/WebHTMLView.m:
+        (+[WebHTMLView _pasteboardTypes]): provide NSHTMLPboardType 
+        (-[WebHTMLView _writeSelectionToPasteboard:]): add HTML to the pasteboard
+
 2004-01-22  John Sullivan  <sullivan at apple.com>
 
         Reviewed by Chris.
diff --git a/WebKit/WebView.subproj/WebHTMLRepresentation.h b/WebKit/WebView.subproj/WebHTMLRepresentation.h
index 2a5e6f7..db1b7d6 100644
--- a/WebKit/WebView.subproj/WebHTMLRepresentation.h
+++ b/WebKit/WebView.subproj/WebHTMLRepresentation.h
@@ -58,4 +58,7 @@
 - (NSArray *)controlsInForm:(id <WebDOMElement>)form;
 - (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element;
 - (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element;
+
+- (NSString *)reconstructedSource;
+
 @end
diff --git a/WebKit/WebView.subproj/WebHTMLRepresentation.m b/WebKit/WebView.subproj/WebHTMLRepresentation.m
index 2d35e42..3cc10b6 100644
--- a/WebKit/WebView.subproj/WebHTMLRepresentation.m
+++ b/WebKit/WebView.subproj/WebHTMLRepresentation.m
@@ -162,4 +162,9 @@
     return [_private->bridge matchLabels:labels againstElement:element];
 }
 
+- (NSString *)reconstructedSource
+{		
+	return [_private->bridge reconstructedSource];
+}
+
 @end
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 35eba4d..8c09a99 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -507,21 +507,15 @@ static WebHTMLView *lastHitView = nil;
 
 + (NSArray *)_pasteboardTypes
 {
-    return [NSArray arrayWithObjects:
-#if SUPPORT_HTML_PBOARD
-        NSHTMLPboardType,
-#endif
-        NSRTFPboardType, NSRTFDPboardType, NSStringPboardType, nil];
+    return [NSArray arrayWithObjects:NSHTMLPboardType, NSRTFPboardType, NSRTFDPboardType, NSStringPboardType, nil];
 }
 
 - (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard
 {
     [pasteboard declareTypes:[[self class] _pasteboardTypes] owner:nil];
 
-#if SUPPORT_HTML_PBOARD
     // Put HTML on the pasteboard.
-    [pasteboard setData:??? forType:NSHTMLPboardType];
-#endif
+    [pasteboard setString:[[self _bridge] selectedHTML] forType:NSHTMLPboardType];
 
     // Put attributed string on the pasteboard (RTF format).
     NSAttributedString *attributedString = [self selectedAttributedString];

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list