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

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


The following commit has been merged in the debian/unstable branch:
commit e453da722c2818ef51da5526c1215fbef1bcfa54
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Aug 2 00:54:31 2003 +0000

    WebKit:
    	Fixed 3095376.  Implemented correct selection behavior for rtl scripts.
    	We still use our Arabic and Hebrew layout scheme.
    
    	Fixed 3360487.  Implemented selection of ATSU rendered code.
    
    	Fixed 3360242.	Return nil from _bodyBackgroundColor when no
    	background color specified.  This was requested by Doug D.
    
            Reviewed by Maciej.
    
            * WebCoreSupport.subproj/WebTextRenderer.m:
            (-[WebTextRenderer drawHighlightForRun:style:atPoint:]):
            (-[WebTextRenderer _CG_drawHighlightForRun:style:atPoint:]):
            (-[WebTextRenderer drawRun:style:atPoint:]):
            (-[WebTextRenderer _CG_drawRun:style:atPoint:]):
            (-[WebTextRenderer _CG_floatWidthForRun:style:widths:fonts:glyphs:startGlyph:endGlyph:numGlyphs:]):
            (-[WebTextRenderer _ATSU_drawHighlightForRun:style:atPoint:]):
            (-[WebTextRenderer _ATSU_drawRun:style:atPoint:]):
            (-[WebTextRenderer pointToOffset:style:position:reversed:]):
            (-[WebTextRenderer _ATSU_pointToOffset:style:position:reversed:]):
            (-[WebTextRenderer _CG_pointToOffset:style:position:reversed:]):
    
    WebCore:
    	Fixed 3095376.  Implemented correct selection behavior for rtl scripts.
    	We still use our Arabic and Hebrew layout scheme.
    
    	Fixed 3360487.  Implemented selection of ATSU rendered code.
    
    	Fixed 3360242.	Return nil from _bodyBackgroundColor when no
    	background color specified.  This was requested by Doug D.
    
            Reviewed by Maciej.
    
            * khtml/rendering/font.cpp:
            (Font::drawHighlightForText):
            * khtml/rendering/font.h:
            * khtml/rendering/render_text.cpp:
            (TextRun::paintSelection):
            * kwq/KWQFontMetrics.mm:
            (QFontMetrics::checkSelectionPoint):
            * kwq/KWQKHTMLPart.mm:
            (KWQKHTMLPart::bodyBackgroundColor):
            * kwq/KWQPainter.h:
            * kwq/KWQPainter.mm:
            (QPainter::drawHighlightForText):
            * kwq/WebCoreTextRenderer.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4760 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index dc2fd6b..00ce21a 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,29 @@
+2003-08-01  Richard Williamson   <rjw at apple.com>
+
+	Fixed 3095376.  Implemented correct selection behavior for rtl scripts.
+	We still use our Arabic and Hebrew layout scheme.
+
+	Fixed 3360487.  Implemented selection of ATSU rendered code.
+
+	Fixed 3360242.	Return nil from _bodyBackgroundColor when no 
+	background color specified.  This was requested by Doug D.
+
+        Reviewed by Maciej.
+
+        * khtml/rendering/font.cpp:
+        (Font::drawHighlightForText):
+        * khtml/rendering/font.h:
+        * khtml/rendering/render_text.cpp:
+        (TextRun::paintSelection):
+        * kwq/KWQFontMetrics.mm:
+        (QFontMetrics::checkSelectionPoint):
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::bodyBackgroundColor):
+        * kwq/KWQPainter.h:
+        * kwq/KWQPainter.mm:
+        (QPainter::drawHighlightForText):
+        * kwq/WebCoreTextRenderer.h:
+
 2003-08-01  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by John.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index dc2fd6b..00ce21a 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,29 @@
+2003-08-01  Richard Williamson   <rjw at apple.com>
+
+	Fixed 3095376.  Implemented correct selection behavior for rtl scripts.
+	We still use our Arabic and Hebrew layout scheme.
+
+	Fixed 3360487.  Implemented selection of ATSU rendered code.
+
+	Fixed 3360242.	Return nil from _bodyBackgroundColor when no 
+	background color specified.  This was requested by Doug D.
+
+        Reviewed by Maciej.
+
+        * khtml/rendering/font.cpp:
+        (Font::drawHighlightForText):
+        * khtml/rendering/font.h:
+        * khtml/rendering/render_text.cpp:
+        (TextRun::paintSelection):
+        * kwq/KWQFontMetrics.mm:
+        (QFontMetrics::checkSelectionPoint):
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::bodyBackgroundColor):
+        * kwq/KWQPainter.h:
+        * kwq/KWQPainter.mm:
+        (QPainter::drawHighlightForText):
+        * kwq/WebCoreTextRenderer.h:
+
 2003-08-01  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by John.
diff --git a/WebCore/khtml/rendering/font.cpp b/WebCore/khtml/rendering/font.cpp
index 4fcee6f..443611e 100644
--- a/WebCore/khtml/rendering/font.cpp
+++ b/WebCore/khtml/rendering/font.cpp
@@ -39,6 +39,15 @@
 
 using namespace khtml;
 
+#if APPLE_CHANGES
+void Font::drawHighlightForText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len,
+                     int toAdd, QPainter::TextDirection d, int from, int to, QColor bg ) const
+{
+    p->drawHighlightForText(x, y, str + pos, std::min(slen - pos, len), from, to, toAdd, bg, d,
+                letterSpacing, wordSpacing, fontDef.smallCaps);
+}
+#endif
+                     
 void Font::drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len,
                      int toAdd, QPainter::TextDirection d, int from, int to, QColor bg ) const
 {
diff --git a/WebCore/khtml/rendering/font.h b/WebCore/khtml/rendering/font.h
index e2e351f..1c4f7c8 100644
--- a/WebCore/khtml/rendering/font.h
+++ b/WebCore/khtml/rendering/font.h
@@ -127,6 +127,8 @@ public:
     void floatCharacterWidths( QChar *str, int slen, int pos, int len, int toAdd, float *buffer) const;
     bool isFixedPitch() const;
     int checkSelectionPoint (QChar *s, int slen, int pos, int len, int toAdd, int x, bool reversed) const;
+    void drawHighlightForText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int width,
+                   QPainter::TextDirection d, int from=-1, int to=-1, QColor bg=QColor() ) const;
 #endif
     int width( QChar *str, int slen, int pos, int len ) const;
     int width( QChar *str, int slen, int pos ) const;
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index bc98017..a11504c 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -96,7 +96,7 @@ void TextRun::paintSelection(const Font *f, RenderText *text, QPainter *p, Rende
     ty += m_baseline;
 
     //kdDebug( 6040 ) << "textRun::painting(" << s.string() << ") at(" << x+_tx << "/" << y+_ty << ")" << endl;
-    f->drawText(p, m_x + tx, m_y + ty, text->str->s, text->str->l, m_start, m_len,
+    f->drawHighlightForText(p, m_x + tx, m_y + ty, text->str->s, text->str->l, m_start, m_len,
 		m_toAdd, m_reversed ? QPainter::RTL : QPainter::LTR, startPos, endPos, c);
     p->restore();
 }
diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index 42df213..201911b 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -305,7 +305,7 @@ int QFontMetrics::checkSelectionPoint (QChar *s, int slen, int pos, int len, int
     style.families = families;
     style.padding = toAdd;
 
-    return [data->getRenderer() checkSelectionPoint:&run style:&style position:x reversed:reversed];
+    return [data->getRenderer() pointToOffset:&run style:&style position:x reversed:reversed];
 }
 
 QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 163f532..cba570c 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -2257,7 +2257,7 @@ NSColor *KWQKHTMLPart::bodyBackgroundColor(void) const
         if (bgColor.isValid())
             return bgColor.getNSColor();
     }
-    return [NSColor whiteColor];
+    return nil;
 }
 
 
diff --git a/WebCore/kwq/KWQPainter.h b/WebCore/kwq/KWQPainter.h
index 21a42da..d93cb39 100644
--- a/WebCore/kwq/KWQPainter.h
+++ b/WebCore/kwq/KWQPainter.h
@@ -94,6 +94,9 @@ public:
     void setRasterOp(RasterOp);
 
     void drawText(int x, int y, int, int, int alignmentFlags, const QString &);
+    void drawHighlightForText(int x, int y, const QChar *, int length, int from, int to, int toAdd,
+                  const QColor& backgroundColor, QPainter::TextDirection d,
+                  int letterSpacing, int wordSpacing, bool smallCaps);
     void drawText(int x, int y, const QChar *, int length, int from, int to, int toAdd,
                   const QColor& backgroundColor, QPainter::TextDirection d,
                   int letterSpacing, int wordSpacing, bool smallCaps);
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index c6adc39..f350cd9 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -517,6 +517,38 @@ void QPainter::drawText(int x, int y, const QChar *str, int len, int from, int t
     [data->textRenderer drawRun:&run style:&style atPoint:NSMakePoint(x, y)];
 }
 
+void QPainter::drawHighlightForText(int x, int y, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, int letterSpacing, int wordSpacing, bool smallCaps)
+{
+    if (data->state.paintingDisabled || len <= 0)
+        return;
+
+    // Avoid allocations, use stack array to pass font families.  Normally these
+    // css fallback lists are small <= 3.
+    CREATE_FAMILY_ARRAY(data->state.font, families);
+    
+    _updateRenderer(families);
+
+    if (from < 0)
+        from = 0;
+    if (to < 0)
+        to = len;
+        
+    WebCoreTextRun run;
+    WebCoreInitializeTextRun(&run, (const UniChar *)str, len, from, to);    
+    WebCoreTextStyle style;
+    WebCoreInitializeEmptyTextStyle(&style);
+    style.textColor = data->state.pen.color().getNSColor();
+    style.backgroundColor = backgroundColor.isValid() ? backgroundColor.getNSColor() : nil;
+    style.rtl = d == RTL ? true : false;
+    style.letterSpacing = letterSpacing;
+    style.wordSpacing = wordSpacing;
+    style.smallCaps = smallCaps;
+    style.families = families;
+    style.padding = toAdd;
+    
+    [data->textRenderer drawHighlightForRun:&run style:&style atPoint:NSMakePoint(x, y)];
+}
+
 void QPainter::drawLineForText(int x, int y, int yOffset, int width)
 {
     if (data->state.paintingDisabled)
diff --git a/WebCore/kwq/WebCoreTextRenderer.h b/WebCore/kwq/WebCoreTextRenderer.h
index f478de1..ac01d5c 100644
--- a/WebCore/kwq/WebCoreTextRenderer.h
+++ b/WebCore/kwq/WebCoreTextRenderer.h
@@ -80,8 +80,9 @@ extern void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style);
 
 // drawing
 - (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
+- (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
 - (void)drawLineForCharacters:(NSPoint)point yOffset:(float)yOffset withWidth:(int)width withColor:(NSColor *)color;
 
 // selection point check
-- (int)checkSelectionPoint:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed;
+- (int)pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed;
 @end
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 6c9cc14..a224ec9 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,27 @@
+2003-08-01  Richard Williamson   <rjw at apple.com>
+
+	Fixed 3095376.  Implemented correct selection behavior for rtl scripts.
+	We still use our Arabic and Hebrew layout scheme.
+
+	Fixed 3360487.  Implemented selection of ATSU rendered code.
+
+	Fixed 3360242.	Return nil from _bodyBackgroundColor when no 
+	background color specified.  This was requested by Doug D.
+
+        Reviewed by Maciej.
+
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (-[WebTextRenderer drawHighlightForRun:style:atPoint:]):
+        (-[WebTextRenderer _CG_drawHighlightForRun:style:atPoint:]):
+        (-[WebTextRenderer drawRun:style:atPoint:]):
+        (-[WebTextRenderer _CG_drawRun:style:atPoint:]):
+        (-[WebTextRenderer _CG_floatWidthForRun:style:widths:fonts:glyphs:startGlyph:endGlyph:numGlyphs:]):
+        (-[WebTextRenderer _ATSU_drawHighlightForRun:style:atPoint:]):
+        (-[WebTextRenderer _ATSU_drawRun:style:atPoint:]):
+        (-[WebTextRenderer pointToOffset:style:position:reversed:]):
+        (-[WebTextRenderer _ATSU_pointToOffset:style:position:reversed:]):
+        (-[WebTextRenderer _CG_pointToOffset:style:position:reversed:]):
+
 2003-08-01  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
index 8b8d0c8..b26ae2c 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
@@ -170,13 +170,22 @@ static CFCharacterSetRef nonBaseChars = NULL;
 
 - (float)_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer fonts:(NSFont **)fontBuffer glyphs:(CGGlyph *)glyphBuffer startGlyph:(int *)startGlyph endGlyph:(int *)endGlyph numGlyphs:(int *)_numGlyphs;
 
-
+// Measuring runs.
 - (float)_CG_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths: (float *)widthBuffer fonts: (NSFont **)fontBuffer glyphs: (CGGlyph *)glyphBuffer  startGlyph:(int *)startGlyph endGlyph:(int *)endGlyph numGlyphs: (int *)_numGlyphs;
 - (float)_ATSU_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style;
 
-
+// Drawing runs.
 - (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
 - (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
+
+// Selection point detection in runs.
+- (int)_CG_pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed;
+- (int)_ATSU_pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed;
+
+// Drawing highlight for runs.
+- (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
+- (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point;
+
 @end
 
 
@@ -807,15 +816,15 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
     }
 }
 
-- (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
 {
     if (shouldUseATSU(run))
-        [self _ATSU_drawRun:run style:style atPoint:point];
+        [self _ATSU_drawHighlightForRun:run style:style atPoint:point];
     else
-        [self _CG_drawRun:run style:style atPoint:point];
+        [self _CG_drawHighlightForRun:run style:style atPoint:point];
 }
 
-- (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
 {
     float *widthBuffer, localWidthBuffer[LOCAL_BUFFER_SIZE];
     CGGlyph *glyphBuffer, localGlyphBuffer[LOCAL_BUFFER_SIZE];
@@ -842,9 +851,9 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
 
     [self _floatWidthForRun:run
         style:style
-        widths: widthBuffer 
-        fonts: fontBuffer
-        glyphs: glyphBuffer
+        widths:widthBuffer 
+        fonts:fontBuffer
+        glyphs:glyphBuffer
         startGlyph:&startGlyph
         endGlyph:&endGlyph
         numGlyphs: &numGlyphs];
@@ -874,9 +883,92 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
             backgroundWidth += advances[i].width;
 
         [style->backgroundColor set];
-        [NSBezierPath fillRect:NSMakeRect(startX, point.y - [self ascent], backgroundWidth, [self lineSpacing])];
+        
+        if (style->rtl){
+            WebCoreTextRun completeRun = *run;
+            completeRun.from = 0;
+            completeRun.to = run->length;
+            float completeRunWidth = [self floatWidthForRun:&completeRun style:style widths:widthBuffer];
+            float leftX = 0;
+            for (i = 0; i < startGlyph; i++)
+                leftX += widthBuffer[i];
+
+            [NSBezierPath fillRect:NSMakeRect(point.x + completeRunWidth - leftX - backgroundWidth, point.y - [self ascent], backgroundWidth, [self lineSpacing])];
+        }
+        else
+            [NSBezierPath fillRect:NSMakeRect(startX, point.y - [self ascent], backgroundWidth, [self lineSpacing])];
     }
     
+    if (advances != localAdvanceBuffer) {
+        free(advances);
+        free(widthBuffer);
+        free(glyphBuffer);
+        free(fontBuffer);
+    }
+}
+
+
+- (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+{
+    if (shouldUseATSU(run))
+        [self _ATSU_drawRun:run style:style atPoint:point];
+    else
+        [self _CG_drawRun:run style:style atPoint:point];
+}
+
+- (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+{
+    float *widthBuffer, localWidthBuffer[LOCAL_BUFFER_SIZE];
+    CGGlyph *glyphBuffer, localGlyphBuffer[LOCAL_BUFFER_SIZE];
+    NSFont **fontBuffer, *localFontBuffer[LOCAL_BUFFER_SIZE];
+    CGSize *advances, localAdvanceBuffer[LOCAL_BUFFER_SIZE];
+    int numGlyphs = 0, i, startGlyph = 0, endGlyph = 0;
+    float startX;
+    unsigned int length = run->length;
+    
+    if (run->length == 0)
+        return;
+
+    if (length/2 > LOCAL_BUFFER_SIZE) {
+        advances = (CGSize *)calloc(length*2, sizeof(CGSize));
+        widthBuffer = (float *)calloc(length*2, sizeof(float));
+        glyphBuffer = (CGGlyph *)calloc(length*2, sizeof(ATSGlyphRef));
+        fontBuffer = (NSFont **)calloc(length*2, sizeof(NSFont *));
+    } else {
+        advances = localAdvanceBuffer;
+        widthBuffer = localWidthBuffer;
+        glyphBuffer = localGlyphBuffer;
+        fontBuffer = localFontBuffer;
+    }
+
+    [self _floatWidthForRun:run
+        style:style
+        widths:widthBuffer 
+        fonts:fontBuffer
+        glyphs:glyphBuffer
+        startGlyph:&startGlyph
+        endGlyph:&endGlyph
+        numGlyphs: &numGlyphs];
+        
+    // Eek.  We couldn't generate ANY glyphs for the run.
+    if (numGlyphs <= 0)
+        return;
+        
+    // Fill the advances array.
+    for (i = 0; i <= endGlyph; i++){
+        advances[i].width = widthBuffer[i];
+        advances[i].height = 0;
+    }
+
+    // Calculate the starting point of the glyphs to be displayed by adding
+    // all the advances up to the first glyph.
+    startX = point.x;
+    for (i = 0; i < startGlyph; i++)
+        startX += advances[i].width;
+
+    if (style->backgroundColor != nil)
+        [self _CG_drawHighlightForRun:run style:style atPoint:point];
+    
     // Finally, draw the glyphs.
     int lastFrom = startGlyph;
     int pos = startGlyph;
@@ -1214,7 +1306,7 @@ static const char *joiningNames[] = {
             }
             substituteFont = [self substituteFontForCharacters: _characters length: clusterLength families: style->families];
             if (substituteFont) {
-                int cNumGlyphs;
+                int cNumGlyphs = 0;
                 ATSGlyphRef localGlyphBuffer[clusterLength*4];
                 
                 WebCoreTextRun clusterRun;
@@ -1679,12 +1771,15 @@ static const char *joiningNames[] = {
 }
 
 
-- (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
 {
     ATSUTextLayout layout;
-    OSStatus status;
     int from = run->from;
     int to = run->to;
+    float selectedLeftX;
+
+    if (style->backgroundColor == nil)
+        return;
     
     if (from == -1)
         from = 0;
@@ -1696,23 +1791,68 @@ static const char *joiningNames[] = {
         return;
     }
 
-    if (style->backgroundColor != nil){
-        ATSTrapezoid trapezoid = [self _trapezoidForRun:run style:style atPoint:point];
-
+    layout = [self _createATSUTextLayoutForRun:run];
 
-        float backgroundWidth = 
-                MAX(FixToFloat(trapezoid.upperRight.x), FixToFloat(trapezoid.lowerRight.x)) - 
-                MIN(FixToFloat(trapezoid.upperLeft.x), FixToFloat(trapezoid.lowerLeft.x));
-        float leftX = MIN(FixToFloat(trapezoid.upperLeft.x), FixToFloat(trapezoid.lowerLeft.x));
-        
-        [style->backgroundColor set];
-        [NSBezierPath fillRect:NSMakeRect(leftX, point.y - [self ascent], backgroundWidth, [self lineSpacing])];
+    WebCoreTextRun leadingRun = *run;
+    leadingRun.from = 0;
+    leadingRun.to = run->from;
+    
+    // ATSU provides the bounds of the glyphs for the run with an origin of
+    // (0,0), so we need to find the width of the glyphs immediately before
+    // the actually selected glyphs.
+    ATSTrapezoid leadingTrapezoid = [self _trapezoidForRun:&leadingRun style:style atPoint:point];
+    ATSTrapezoid selectedTrapezoid = [self _trapezoidForRun:run style:style atPoint:point];
+
+    float backgroundWidth = 
+            MAX(FixToFloat(selectedTrapezoid.upperRight.x), FixToFloat(selectedTrapezoid.lowerRight.x)) - 
+            MIN(FixToFloat(selectedTrapezoid.upperLeft.x), FixToFloat(selectedTrapezoid.lowerLeft.x));
+
+    if (run->from == 0)
+        selectedLeftX = point.x;
+    else
+        selectedLeftX = MIN(FixToFloat(leadingTrapezoid.upperRight.x), FixToFloat(leadingTrapezoid.lowerRight.x));
+    
+    [style->backgroundColor set];
+    
+    float yPos = point.y - [self ascent];
+    if (style->rtl){
+        WebCoreTextRun completeRun = *run;
+        completeRun.from = 0;
+        completeRun.to = run->length;
+        float completeRunWidth = [self floatWidthForRun:&completeRun style:style widths:0];
+        [NSBezierPath fillRect:NSMakeRect(point.x + completeRunWidth - (selectedLeftX-point.x) - backgroundWidth, yPos, backgroundWidth, [self lineSpacing])];
+    }
+    else {
+        [NSBezierPath fillRect:NSMakeRect(selectedLeftX, yPos, backgroundWidth, [self lineSpacing])];
     }
-        
-    [style->textColor set];
 
-    layout = [self _createATSUTextLayoutForRun:run];
+    ATSUDisposeTextLayout (layout); // Ignore the error.  Nothing we can do anyway.
+}
+
+
+- (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+{
+    ATSUTextLayout layout;
+    OSStatus status;
+    int from = run->from;
+    int to = run->to;
     
+    if (from == -1)
+        from = 0;
+    if (to == -1)
+        to = run->length;
+   
+    int runLength = to - from;
+    if (runLength <= 0)
+        return;
+
+    layout = [self _createATSUTextLayoutForRun:run];
+
+    if (style->backgroundColor != nil)
+        [self _ATSU_drawHighlightForRun:run style:style atPoint:point];
+
+    [style->textColor set];
+
     status = ATSUDrawText(layout, 
             from,
             runLength,
@@ -1726,60 +1866,83 @@ static const char *joiningNames[] = {
     ATSUDisposeTextLayout (layout); // Ignore the error.  Nothing we can do anyway.
 }
 
+- (int)pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed
+{
+    if (shouldUseATSU(run))
+        return [self _ATSU_pointToOffset:run style:style position:x reversed:reversed];
+    return [self _CG_pointToOffset:run style:style position:x reversed:reversed];
+}
+
+
+- (int)_ATSU_pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed
+{
+    unsigned int offset = 0;
+    ATSUTextLayout layout;
+    UniCharArrayOffset primaryOffset = 0;
+    UniCharArrayOffset secondaryOffset = 0;
+    OSStatus status;
+    Boolean isLeading;
+
+    layout = [self _createATSUTextLayoutForRun:run];
+
+    status = ATSUPositionToOffset (layout, (ATSUTextMeasurement)FloatToFixed(((float)x)), 1, &primaryOffset, &isLeading, &secondaryOffset);
+    if (status == noErr){
+        offset = (unsigned int)primaryOffset;
+    }
+    else {
+        // Failed to find offset!  Return 0 offset.
+    }
+
+    return offset;
+}
+
+
 #define LOCAL_WIDTH_BUF_SIZE 1024
 
-- (int)checkSelectionPoint:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed
+- (int)_CG_pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed
 {
     // FIXME.  This algorimth is the original KTHML algorithm.  We need to update it to
-    // support unicode (i.e. characters don't have a one-to-one mapping to a width) and our
-    // ATSU work (3095376).
+    // be more savvy about unicode.
     float delta = (float)x;
     float _widths[LOCAL_WIDTH_BUF_SIZE]; 
     float *widths = 0, width;
-    float monospaceWidth = 0;
+    unsigned int offset = 0;
 
-    if ([font isFixedPitch] || [font _isFakeFixedPitch]){
-        monospaceWidth = spaceWidth;
-        width = run->length * monospaceWidth;
-    }
-    else {
-        if (run->length > LOCAL_WIDTH_BUF_SIZE)
-            widths = (float *)malloc(run->length * sizeof(float));
-        else
-            widths = &_widths[0];
-        width = [self floatWidthForRun:run style:style widths: widths];
-    }
+    if (run->length > LOCAL_WIDTH_BUF_SIZE)
+        widths = (float *)malloc(run->length * sizeof(float));
+    else
+        widths = &_widths[0];
+    width = [self floatWidthForRun:run style:style widths:widths];
 
-    unsigned int pos = 0;
     if ( reversed ) {
-	delta -= width;
-	while(pos < run->length) {
-	    float w = (monospaceWidth != 0 ? monospaceWidth : widths[pos+run->from]);
-	    float w2 = w/2;
-	    w -= w2;
-	    delta += w2;
-	    if(delta >= 0)
-	        break;
-	    pos++;
-	    delta += w;
-	}
+        delta -= width;
+        while(offset < run->length) {
+            float w = widths[offset+run->from];
+            float w2 = w/2;
+            w -= w2;
+            delta += w2;
+            if(delta >= 0)
+                break;
+            offset++;
+            delta += w;
+        }
     } else {
-	while(pos < run->length) {
-	    float w = (monospaceWidth != 0 ? monospaceWidth : widths[pos+run->from]);
-	    float w2 = w/2;
-	    w -= w2;
-	    delta -= w2;
-	    if(delta <= 0) 
-	        break;
-	    pos++;
-	    delta -= w;
-	}
+        while(offset < run->length) {
+            float w = widths[offset+run->from];
+            float w2 = w/2;
+            w -= w2;
+            delta -= w2;
+            if(delta <= 0) 
+                break;
+            offset++;
+            delta -= w;
+        }
     }
     
     if (widths != _widths)
         free (widths);
         
-    return pos;
+    return offset;
 }
 
 @end

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list