[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 08:20:25 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit a857235831e06ec7fc5523c491ee5bd6f3ae7332
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Dec 22 19:26:16 2003 +0000

            Reviewed by John.
    
            - follow-on to my fix for 3467919: handle collapsed spaces at the starts of runs too, not just at the
              end, and make sure that a space inherits style from the run it was collapsed from rather than always
              from the run it precedes
    
            * khtml/khtml_part.cpp: (KHTMLPart::text): Add code to deal with collapsed spaces at the start of runs.
            * kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::attributedString): Change code to keep the style of a space that
            was collapsed at the end of the run, and use that styled space if necessary. Also add the code to deal
            with collapsed spaces at the start of runs. Also remove comment that refers to long-since-deleted code.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5845 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 07344fe..15122f7 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,16 @@
+2003-12-22  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+        - follow-on to my fix for 3467919: handle collapsed spaces at the starts of runs too, not just at the
+          end, and make sure that a space inherits style from the run it was collapsed from rather than always
+          from the run it precedes
+
+        * khtml/khtml_part.cpp: (KHTMLPart::text): Add code to deal with collapsed spaces at the start of runs.
+        * kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::attributedString): Change code to keep the style of a space that
+        was collapsed at the end of the run, and use that styled space if necessary. Also add the code to deal
+        with collapsed spaces at the start of runs. Also remove comment that refers to long-since-deleted code.
+
 2003-12-21  Darin Adler  <darin at apple.com>
 
         Reviewed by John.
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 8809d54..57591cb 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -2329,13 +2329,15 @@ QString KHTMLPart::text(const DOM::Range &r) const
                           runEnd = QMIN(runEnd, runs[i]->m_start + runs[i]->m_len);
                           if (runStart >= runs[i]->m_start &&
                               runStart < runs[i]->m_start + runs[i]->m_len) {
+                              if (i == 0 && runs[0]->m_start == runStart && runStart > 0)
+                                  needSpace = true; // collapsed space at the start
                               if (needSpace && !addedSpace)
                                   text += ' ';
                               QString runText = str.mid(runStart, runEnd - runStart);
                               runText.replace('\n', ' ');
                               text += runText;
                               int nextRunStart = (i+1 < runs.count()) ? runs[i+1]->m_start : str.length();
-                              needSpace = nextRunStart > runEnd;
+                              needSpace = nextRunStart > runEnd; // collapsed space between runs or at the end
                               addedSpace = str[runEnd-1].direction() == QChar::DirWS;
                               start = -1;
                           }
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index a66d899..acb6aa7 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -2202,6 +2202,8 @@ static NodeImpl* isTextFirstInListItem(NodeImpl *e)
     return 0;
 }
 
+// FIXME: This collosal function needs to be refactored into maintainable smaller bits.
+
 #define BULLET_CHAR 0x2022
 #define SQUARE_CHAR 0x25AA
 #define CIRCLE_CHAR 0x25E6
@@ -2216,13 +2218,11 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
         return nil;
     }
 
-    // This allocation and autorelease won't raise so it's OK to do it
-    // outside the exception block
     NSMutableAttributedString *result = [[[NSMutableAttributedString alloc] init] autorelease];
 
     bool hasNewLine = true;
     bool addedSpace = true;
-    bool needSpace = false;
+    NSAttributedString *pendingStyledSpace = nil;
     bool hasParagraphBreak = true;
     const ElementImpl *linkStartNode = 0;
     unsigned linkStartLocation = 0;
@@ -2247,6 +2247,7 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
         if (renderer) {
             RenderStyle *style = renderer->style();
             NSFont *font = style->font().getNSFont();
+            bool needSpace = pendingStyledSpace != nil;
             if (n.nodeType() == Node::TEXT_NODE) {
                 if (hasNewLine) {
                     addedSpace = true;
@@ -2262,12 +2263,13 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
                             if (text.isEmpty() && linkStartLocation == [result length]) {
                                 ++linkStartLocation;
                             }
-                            text += ' ';
+                            [result appendAttributedString:pendingStyledSpace];
                         }
                         int runStart = (start == -1) ? 0 : start;
                         int runEnd = (end == -1) ? str.length() : end;
                         text += str.mid(runStart, runEnd-runStart);
-                        needSpace = false;
+                        [pendingStyledSpace release];
+                        pendingStyledSpace = nil;
                         addedSpace = str[runEnd-1].direction() == QChar::DirWS;
                     }
                     else {
@@ -2287,17 +2289,26 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
                                 runEnd = QMIN(runEnd, runs[i]->m_start + runs[i]->m_len);
                                 if (runStart >= runs[i]->m_start &&
                                     runStart < runs[i]->m_start + runs[i]->m_len) {
+                                    if (i == 0 && runs[0]->m_start == runStart && runStart > 0) {
+                                        needSpace = true; // collapsed space at the start
+                                    }
                                     if (needSpace && !addedSpace) {
-                                        if (text.isEmpty() && linkStartLocation == [result length]) {
-                                            ++linkStartLocation;
+                                        if (pendingStyledSpace != nil) {
+                                            if (text.isEmpty() && linkStartLocation == [result length]) {
+                                                ++linkStartLocation;
+                                            }
+                                            [result appendAttributedString:pendingStyledSpace];
+                                        } else {
+                                            text += ' ';
                                         }
-                                        text += ' ';
                                     }
                                     QString runText = str.mid(runStart, runEnd - runStart);
                                     runText.replace('\n', ' ');
                                     text += runText;
-                                    int nextRunStart = (i+1 < runs.count()) ? runs[i+1]->m_start : str.length();
+                                    int nextRunStart = (i+1 < runs.count()) ? runs[i+1]->m_start : str.length(); // collapsed space between runs or at the end
                                     needSpace = nextRunStart > runEnd;
+                                    [pendingStyledSpace release];
+                                    pendingStyledSpace = nil;
                                     addedSpace = str[runEnd-1].direction() == QChar::DirWS;
                                     start = -1;
                                 }
@@ -2310,21 +2321,27 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
                 
                 text.replace('\\', renderer->backslashAsCurrencySymbol());
     
-                if (text.length() > 0) {
-                    hasParagraphBreak = false;
-                    NSMutableDictionary *attrs;
-
-                    attrs = [[NSMutableDictionary alloc] init];
+                if (text.length() > 0 || needSpace) {
+                    NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init];
                     [attrs setObject:font forKey:NSFontAttributeName];
                     if (style && style->color().isValid())
                         [attrs setObject:style->color().getNSColor() forKey:NSForegroundColorAttributeName];
                     if (style && style->backgroundColor().isValid())
                         [attrs setObject:style->backgroundColor().getNSColor() forKey:NSBackgroundColorAttributeName];
 
-                    NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString() attributes:attrs];
+                    if (text.length() > 0) {
+                        hasParagraphBreak = false;
+                        NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString() attributes:attrs];
+                        [result appendAttributedString: partialString];                
+                        [partialString release];
+                    }
+
+                    if (needSpace) {
+                        [pendingStyledSpace release];
+                        pendingStyledSpace = [[NSAttributedString alloc] initWithString:@" " attributes:attrs];
+                    }
+
                     [attrs release];
-                    [result appendAttributedString: partialString];                
-                    [partialString release];
                 }
             } else {
                 // This is our simple HTML -> ASCII transformation:
@@ -2361,7 +2378,6 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
                             
                             listText += '\t';
                             if (itemParent){
-                                // Ick!  Avoid use of itemParent->id() which confuses ObjC++.
                                 khtml::RenderListItem *listRenderer = static_cast<khtml::RenderListItem*>(renderer);
 
                                 maxMarkerWidth = MAX([font pointSize], maxMarkerWidth);
@@ -2443,6 +2459,14 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
                         break;
                         
                     case ID_IMG:
+                        if (pendingStyledSpace != nil) {
+                            if (linkStartLocation == [result length]) {
+                                ++linkStartLocation;
+                            }
+                            [result appendAttributedString:pendingStyledSpace];
+                            [pendingStyledSpace release];
+                            pendingStyledSpace = nil;
+                        }
                         NSFileWrapper *fileWrapper = fileWrapperForElement(static_cast<ElementImpl *>(n.handle()));
                         NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
                         NSAttributedString *iString = [NSAttributedString attributedStringWithAttachment:attachment];
@@ -2546,6 +2570,8 @@ NSAttributedString *KWQKHTMLPart::attributedString(NodeImpl *_start, int startOf
         n = next;
     }
     
+    [pendingStyledSpace release];
+    
     // Apply paragraph styles from outside in.  This ensures that nested lists correctly
     // override their parent's paragraph style.
     {

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list