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

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:59:45 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 1cd910e9945821dd3b74150cdb91bf395a7d85c1
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 7 00:01:43 2003 +0000

            Reviewed by Ken.
    
            - preparation for the upcoming whitespace patch; refactored some of the code that extracts text
    
            * khtml/khtml_part.h: Added text() member function.
            * khtml/khtml_part.cpp:
            (KHTMLPart::text): Added. Refactored from selectedText; takes a DOM::Range as a parameter.
            Also added code to change newlines to spaces when extracting text from the DOM.
            (KHTMLPart::selectedText): Now calls text().
            (KHTMLPart::selection): Removed stray declaration.
    
            * kwq/KWQAccObject.mm: (-[KWQAccObject value]): Changed to call KHTMLPart::text.
            * kwq/WebCoreBridge.mm: (-[WebCoreBridge elementAtPoint:]): Changed to call KHTMLPart::text
            instead of doing it ourselves.
    
            * kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::attributedString): Added code to change change '\n'
            newlines to spaces when extracting text from the DOM.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5140 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 14bb709..cd4b788 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,23 @@
+2003-10-06  Darin Adler  <darin at apple.com>
+
+        Reviewed by Ken.
+        
+        - preparation for the upcoming whitespace patch; refactored some of the code that extracts text
+
+        * khtml/khtml_part.h: Added text() member function.
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::text): Added. Refactored from selectedText; takes a DOM::Range as a parameter.
+        Also added code to change newlines to spaces when extracting text from the DOM.
+        (KHTMLPart::selectedText): Now calls text().
+        (KHTMLPart::selection): Removed stray declaration.
+
+        * kwq/KWQAccObject.mm: (-[KWQAccObject value]): Changed to call KHTMLPart::text.
+        * kwq/WebCoreBridge.mm: (-[WebCoreBridge elementAtPoint:]): Changed to call KHTMLPart::text
+        instead of doing it ourselves.
+        
+        * kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::attributedString): Added code to change change '\n'
+        newlines to spaces when extracting text from the DOM.
+
 2003-10-05  Maciej Stachowiak  <mjs at apple.com>
 
 	Reviewed by Ken.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 14bb709..cd4b788 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,23 @@
+2003-10-06  Darin Adler  <darin at apple.com>
+
+        Reviewed by Ken.
+        
+        - preparation for the upcoming whitespace patch; refactored some of the code that extracts text
+
+        * khtml/khtml_part.h: Added text() member function.
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::text): Added. Refactored from selectedText; takes a DOM::Range as a parameter.
+        Also added code to change newlines to spaces when extracting text from the DOM.
+        (KHTMLPart::selectedText): Now calls text().
+        (KHTMLPart::selection): Removed stray declaration.
+
+        * kwq/KWQAccObject.mm: (-[KWQAccObject value]): Changed to call KHTMLPart::text.
+        * kwq/WebCoreBridge.mm: (-[WebCoreBridge elementAtPoint:]): Changed to call KHTMLPart::text
+        instead of doing it ourselves.
+        
+        * kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::attributedString): Added code to change change '\n'
+        newlines to spaces when extracting text from the DOM.
+
 2003-10-05  Maciej Stachowiak  <mjs at apple.com>
 
 	Reviewed by Ken.
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 063287b..e922c72 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -2216,7 +2216,7 @@ bool KHTMLPart::findTextNext( const QString &str, bool forward, bool caseSensiti
     }
 }
 
-QString KHTMLPart::selectedText() const
+QString KHTMLPart::text(const DOM::Range &r) const
 {
     // FIXME: This whole function should use the render tree and not the DOM tree, since elements could
     // be hidden using CSS, or additional generated content could be added.  For now, we just make sure
@@ -2225,7 +2225,7 @@ QString KHTMLPart::selectedText() const
   bool hasNewLine = true;
   bool addedSpace = true;
   QString text;
-  DOM::Node n = d->m_selectionStart;
+  DOM::Node n = r.startContainer();
   while(!n.isNull()) {
       if(n.nodeType() == DOM::Node::TEXT_NODE) {
           if (hasNewLine) {
@@ -2233,8 +2233,8 @@ QString KHTMLPart::selectedText() const
               hasNewLine = false;
           }
           QString str = n.nodeValue().string();
-          int start = (n == d->m_selectionStart) ? d->m_startOffset : -1;
-          int end = (n == d->m_selectionEnd) ? d->m_endOffset : -1;
+          int start = (n == r.startContainer()) ? r.startOffset() : -1;
+          int end = (n == r.endContainer()) ? r.endOffset() : -1;
           RenderObject* renderer = n.handle()->renderer();
           if (renderer && renderer->isText()) {
               if (renderer->style()->whiteSpace() == khtml::PRE) {
@@ -2261,7 +2261,9 @@ QString KHTMLPart::selectedText() const
                           bool spaceBetweenRuns = false;
                           if (runStart >= runs[i]->m_start &&
                               runStart < runs[i]->m_start + runs[i]->m_len) {
-                              text += str.mid(runStart, runEnd - runStart);
+                              QString runText = str.mid(runStart, runEnd - runStart);
+                              runText.replace('\n', ' ');
+                              text += runText;
                               start = -1;
                               spaceBetweenRuns = i+1 < runs.count() && runs[i+1]->m_start > runEnd;
                               addedSpace = str[runEnd-1].direction() == QChar::DirWS;
@@ -2318,7 +2320,7 @@ QString KHTMLPart::selectedText() const
             break;
         }
       }
-      if(n == d->m_selectionEnd) break;
+      if(n == r.endContainer()) break;
       DOM::Node next = n.firstChild();
       if(next.isNull()) next = n.nextSibling();
       while( next.isNull() && !n.parentNode().isNull() ) {
@@ -2375,6 +2377,11 @@ QString KHTMLPart::selectedText() const
     return text.mid(start, end-start);
 }
 
+QString KHTMLPart::selectedText() const
+{
+    return text(selection());
+}
+
 bool KHTMLPart::hasSelection() const
 {
   return ( !d->m_selectionStart.isNull() &&
@@ -2383,7 +2390,7 @@ bool KHTMLPart::hasSelection() const
 
 DOM::Range KHTMLPart::selection() const
 {
-    DOM::Range r = document().createRange();DOM::Range();
+    DOM::Range r = document().createRange();
     r.setStart( d->m_selectionStart, d->m_startOffset );
     r.setEnd( d->m_selectionEnd, d->m_endOffset );
     return r;
diff --git a/WebCore/khtml/khtml_part.h b/WebCore/khtml/khtml_part.h
index 845213d..d12f758 100644
--- a/WebCore/khtml/khtml_part.h
+++ b/WebCore/khtml/khtml_part.h
@@ -563,6 +563,11 @@ public:
   void setSelection( const DOM::Range & );
 
   /**
+   * Returns the text for a part of the document.
+   */
+  QString text(const DOM::Range &) const;
+
+  /**
    * Has the user selected anything?
    *
    *  Call @ref selectedText() to
diff --git a/WebCore/kwq/KWQAccObject.mm b/WebCore/kwq/KWQAccObject.mm
index 108708a..ce86223 100644
--- a/WebCore/kwq/KWQAccObject.mm
+++ b/WebCore/kwq/KWQAccObject.mm
@@ -24,26 +24,25 @@
  */
 
 #import "KWQAccObject.h"
+
 #import "KWQAccObjectCache.h"
 #import "KWQWidget.h"
 
 #import "dom_docimpl.h"
 #import "dom_elementimpl.h"
 #import "dom_string.h"
+#import "dom2_range.h"
 #import "htmlattrs.h"
 #import "khtmlview.h"
+#import "khtml_part.h"
 #import "render_canvas.h"
 #import "render_object.h"
 #import "render_replaced.h"
 #import "render_style.h"
 #import "render_text.h"
 
-using DOM::DOMString;
 using DOM::ElementImpl;
-using khtml::InlineTextBoxArray;
-using khtml::RenderCanvas;
 using khtml::RenderObject;
-using khtml::RenderText;
 using khtml::RenderWidget;
 
 // FIXME: This will eventually need to really localize.
@@ -224,25 +223,22 @@ using khtml::RenderWidget;
 {
     if (!m_renderer)
         return nil;
+
     if (m_renderer->isText()) {
-        RenderText* textObj = static_cast<RenderText*>(m_renderer);
-        QString text;
-        QString str = textObj->data().string();
-        InlineTextBoxArray runs = textObj->inlineTextBoxes();
-        bool addedSpace = true;
-        for (unsigned i = 0; i < runs.count(); i++) {
-            int runStart = runs[i]->m_start;
-            int runEnd =  runs[i]->m_start + runs[i]->m_len;
-            bool spaceBetweenRuns = false;
-            text += str.mid(runStart, runEnd - runStart);
-            spaceBetweenRuns = i+1 < runs.count() && runs[i+1]->m_start > runEnd;
-            addedSpace = str[runEnd-1].direction() == QChar::DirWS;
-            if (spaceBetweenRuns && !addedSpace) {
-                text += " ";
-                addedSpace = true;
+        NodeImpl *e = m_renderer->element();
+        DocumentImpl *d = m_renderer->document();
+        if (e && d) {
+            KHTMLView *v = d->view();
+            if (v) {
+                KHTMLPart *p = v->part();
+                if (p) {
+                    Range r(p->document());
+                    r.setStartBefore(e);
+                    r.setEndAfter(e);
+                    return p->text(r).getNSString();
+                }
             }
         }
-        return text.getNSString();
     }
     
     return UI_STRING("Value not implemented yet.", "not real yet");
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 18b456b..2d4ba2d 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -2010,7 +2010,9 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_startNode, int sta
                                 bool spaceBetweenRuns = false;
                                 if (runStart >= runs[i]->m_start &&
                                     runStart < runs[i]->m_start + runs[i]->m_len) {
-                                    text += str.mid(runStart, runEnd - runStart);
+                                    QString runText = str.mid(runStart, runEnd - runStart);
+                                    runText.replace('\n', ' ');
+                                    text += runText;
                                     start = -1;
                                     spaceBetweenRuns = i+1 < runs.count() && runs[i+1]->m_start > runEnd;
                                     addedSpace = str[runEnd-1].direction() == QChar::DirWS;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 0c14794..785e93a 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -722,20 +722,12 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
         
         DOMString link = e->getAttribute(ATTR_HREF);
         if (!link.isNull()) {
-            // Look for the first #text node to use as a label.
-            NodeImpl *labelParent = e;
-            while (labelParent->hasChildNodes()){
-                NodeImpl *childNode = labelParent->firstChild();
-                unsigned short type = childNode->nodeType();
-                if (type == Node::TEXT_NODE){
-                    DOMStringImpl *dv = childNode->nodeValue().implementation();
-                    if (dv){
-                        NSString *value = [NSString stringWithCharacters: (const unichar *)dv->s length: dv->l];
-                        [element setObject:value forKey:WebCoreElementLinkLabelKey];
-                        break;
-                    }
-                }
-                labelParent = childNode;
+            Range r(_part->document());
+            r.setStartBefore(e->firstChild());
+            r.setEndAfter(e->lastChild());
+            QString t = _part->text(r);
+            if (!t.isEmpty()) {
+                [element setObject:t.getNSString() forKey:WebCoreElementLinkLabelKey];
             }
             [element setObject:_part->xmlDocImpl()->completeURL(link.string()).getNSString() forKey:WebCoreElementLinkURLKey];
         }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list