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

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


The following commit has been merged in the debian/unstable branch:
commit 3a4aebe63c610a1b0ab6be3c977f095a055ebdd8
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 27 22:57:31 2004 +0000

    WebCore:
    
            Reviewed by Hyatt
    
            Make selections draw in a more Cocoa-like way, where
            fully-selected lines draw out to the ends of lines, and
            spaces between lines are drawn with the selection color as well.
    
            * WebCore-combined.exp: Add _WebCoreInitializeEmptyTextGeometry symbol
            * WebCore.exp: Ditto.
            * khtml/khtml_part.cpp:
            (KHTMLPart::isPointInsideSelection): Marginally-related change. Fix up this function
            so that it works right, given my recent changes to positionForCoordinates. This fix
            "really" fixes the problem. Unlike my attempt to fix yesterday.
            * khtml/rendering/font.cpp:
            (Font::drawHighlightForText): New drawHighlightForText interface which includes extra
            information to draw the selection.
            * khtml/rendering/font.h: Ditto.
            * khtml/rendering/render_block.cpp:
            (khtml::RenderBlock::positionForCoordinates): Some minor improvements and cleanups to
            make this code work correctly in more cases.
            * khtml/rendering/render_block.h: Remove spurious semi-colon after namespace block.
            * khtml/rendering/render_container.cpp:
            (RenderContainer::positionForCoordinates): Fix typo in comment. Also, clean up
            one unnecessary call to absolutePosition.
            * khtml/rendering/render_image.cpp:
            (RenderImage::paint): Many changes to add the new selection drawing behavior.
            * khtml/rendering/render_inline.cpp:
            (RenderInline::positionForCoordinates): Added to help make selections work right
            with continuations.
            * khtml/rendering/render_inline.h: Ditto.
            * khtml/rendering/render_object.h: Give zero default argument to inlineBox() helper.
            * khtml/rendering/render_text.cpp:
            (InlineTextBox::paintSelection): Many changes to add the new selection drawing behavior.
            * kwq/KWQListBox.mm:
            (-[KWQTableView drawRow:clipRect:]): Use new WebCoreTextGeometry struct.
            * kwq/KWQPainter.h: New drawHighlightForText interface which includes extra
            information to draw the selection.
            * kwq/KWQPainter.mm:
            (QPainter::drawText): Use new WebCoreInitializeEmptyTextGeometry struct.
            (QPainter::drawHighlightForText): Use new WebCoreTextGeometry struct.
            * kwq/WebCoreTextRenderer.h: Declare new WebCoreTextGeometry struct.
            * kwq/WebCoreTextRendererFactory.m:
            (WebCoreInitializeEmptyTextGeometry): Initializer for WebCoreTextGeometry struct.
    
    WebKit:
    
            Reviewed by Hyatt
    
            Make selections draw in a more Cocoa-like way, where
            fully-selected lines draw out to the ends of lines, and
            spaces between lines are drawn with the selection color as well.
    
            * Misc.subproj/WebKitNSStringExtras.m: Use new WebCoreTextGeometry struct. No change in functionality.
            * WebCoreSupport.subproj/WebTextRenderer.m:
            (-[WebTextRenderer drawRun:style:geometry:]): Use new WebCoreTextGeometry struct. No change in functionality.
            (-[WebTextRenderer drawHighlightForRun:style:geometry:]): Ditto.
            (-[WebTextRenderer _CG_drawHighlightForRun:style:geometry:]): Many changes to add the new selection drawing behavior.
            (-[WebTextRenderer _CG_drawRun:style:geometry:]):  Use new WebCoreTextGeometry struct. No change in functionality.
            (-[WebTextRenderer _ATSU_drawHighlightForRun:style:geometry:]): Many changes to add the new selection drawing behavior.
            (-[WebTextRenderer _ATSU_drawRun:style:geometry:]):  Use new WebCoreTextGeometry struct. No change in functionality.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6496 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 2746063..7d26e7d 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,48 @@
+2004-04-27  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Hyatt
+        
+        Make selections draw in a more Cocoa-like way, where
+        fully-selected lines draw out to the ends of lines, and
+        spaces between lines are drawn with the selection color as well.
+
+        * WebCore-combined.exp: Add _WebCoreInitializeEmptyTextGeometry symbol
+        * WebCore.exp: Ditto.
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::isPointInsideSelection): Marginally-related change. Fix up this function
+        so that it works right, given my recent changes to positionForCoordinates. This fix
+        "really" fixes the problem. Unlike my attempt to fix yesterday.
+        * khtml/rendering/font.cpp:
+        (Font::drawHighlightForText): New drawHighlightForText interface which includes extra
+        information to draw the selection.
+        * khtml/rendering/font.h: Ditto.
+        * khtml/rendering/render_block.cpp:
+        (khtml::RenderBlock::positionForCoordinates): Some minor improvements and cleanups to
+        make this code work correctly in more cases.
+        * khtml/rendering/render_block.h: Remove spurious semi-colon after namespace block.
+        * khtml/rendering/render_container.cpp:
+        (RenderContainer::positionForCoordinates): Fix typo in comment. Also, clean up
+        one unnecessary call to absolutePosition.
+        * khtml/rendering/render_image.cpp:
+        (RenderImage::paint): Many changes to add the new selection drawing behavior.
+        * khtml/rendering/render_inline.cpp:
+        (RenderInline::positionForCoordinates): Added to help make selections work right 
+        with continuations.
+        * khtml/rendering/render_inline.h: Ditto.
+        * khtml/rendering/render_object.h: Give zero default argument to inlineBox() helper.
+        * khtml/rendering/render_text.cpp:
+        (InlineTextBox::paintSelection): Many changes to add the new selection drawing behavior.
+        * kwq/KWQListBox.mm:
+        (-[KWQTableView drawRow:clipRect:]): Use new WebCoreTextGeometry struct.
+        * kwq/KWQPainter.h: New drawHighlightForText interface which includes extra
+        information to draw the selection.
+        * kwq/KWQPainter.mm:
+        (QPainter::drawText): Use new WebCoreInitializeEmptyTextGeometry struct.
+        (QPainter::drawHighlightForText): Use new WebCoreTextGeometry struct.
+        * kwq/WebCoreTextRenderer.h: Declare new WebCoreTextGeometry struct.
+        * kwq/WebCoreTextRendererFactory.m:
+        (WebCoreInitializeEmptyTextGeometry): Initializer for WebCoreTextGeometry struct.
+
 2004-04-27  Richard Williamson   <rjw at apple.com>
 
 	Don't do unnecessary string comparisons when no composite operator is
diff --git a/WebCore/WebCore-combined.exp b/WebCore/WebCore-combined.exp
index c7193ad..e8235e5 100644
--- a/WebCore/WebCore-combined.exp
+++ b/WebCore/WebCore-combined.exp
@@ -98,6 +98,7 @@ _WebCoreElementLinkTargetFrameKey
 _WebCoreElementLinkTitleKey
 _WebCoreElementLinkURLKey
 _WebCoreElementTitleKey
+_WebCoreInitializeEmptyTextGeometry
 _WebCoreInitializeEmptyTextStyle
 _WebCoreInitializeTextRun
 _WebCorePageCacheStateKey
diff --git a/WebCore/WebCore.exp b/WebCore/WebCore.exp
index 5bdd1d8..ec5626f 100644
--- a/WebCore/WebCore.exp
+++ b/WebCore/WebCore.exp
@@ -98,6 +98,7 @@ _WebCoreElementLinkTargetFrameKey
 _WebCoreElementLinkTitleKey
 _WebCoreElementLinkURLKey
 _WebCoreElementTitleKey
+_WebCoreInitializeEmptyTextGeometry
 _WebCoreInitializeEmptyTextStyle
 _WebCoreInitializeTextRun
 _WebCorePageCacheStateKey
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index f81f60b..65c425a 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -43,6 +43,7 @@
 #include "html/html_baseimpl.h"
 #include "html/html_miscimpl.h"
 #include "html/html_imageimpl.h"
+#include "rendering/render_block.h"
 #include "rendering/render_text.h"
 #include "rendering/render_frames.h"
 #include "misc/htmlhashes.h"
@@ -4494,32 +4495,23 @@ void KHTMLPart::customEvent( QCustomEvent *event )
 
 bool KHTMLPart::isPointInsideSelection(int x, int y)
 {
-    // Treat an empty selection like no selection.
+    // Treat a collapsed selection like no selection.
     if (d->m_selection.state() == Selection::CARET)
         return false;
-    if (!xmlDocImpl()->renderer()) {
+    if (!xmlDocImpl()->renderer()) 
         return false;
-    }
     
     RenderObject::NodeInfo nodeInfo(true, true);
     xmlDocImpl()->renderer()->layer()->nodeAtPoint(nodeInfo, x, y);
-    DOM::NodeImpl* innerNode = nodeInfo.innerNode();
-    if (!innerNode || !innerNode->renderer()) {
+    NodeImpl *innerNode = nodeInfo.innerNode();
+    if (!innerNode || !innerNode->renderer())
         return false;
-    }
     
-    // FIXME: Shouldn't be necessary to skip text nodes.
-    if (innerNode->nodeType() == Node::TEXT_NODE) {
-        innerNode = innerNode->parentNode();
-    }
-    int ax, ay;
-    innerNode->renderer()->absolutePosition(ax, ay);
-    Position pos(innerNode->positionForCoordinates(ax + x, ay + y));
-    if (pos.isEmpty()) {
+    Position pos(innerNode->positionForCoordinates(x, y));
+    if (pos.isEmpty())
         return false;
-    }
 
-    DOM::NodeImpl *n = d->m_selection.start().node();
+    NodeImpl *n = d->m_selection.start().node();
     while (n) {
         if (n == pos.node()) {
             if ((n == d->m_selection.start().node() && pos.offset() < d->m_selection.start().offset()) ||
@@ -4528,20 +4520,12 @@ bool KHTMLPart::isPointInsideSelection(int x, int y)
             }
             return true;
         }
-        if (n == d->m_selection.end().node()) {
+        if (n == d->m_selection.end().node())
             break;
-        }
-        DOM::NodeImpl *next = n->firstChild();
-        if (next) {
-            next = n->nextSibling();
-        }
-        while (!next && n->parentNode()) {
-            n = n->parentNode();
-            next = n->nextSibling();
-        }
-        n = next;
+        n = n->traverseNextNode();
     }
-    return false;
+
+   return false;
 }
 
 #if APPLE_CHANGES
diff --git a/WebCore/khtml/rendering/font.cpp b/WebCore/khtml/rendering/font.cpp
index 9dbd0b9..24367b0 100644
--- a/WebCore/khtml/rendering/font.cpp
+++ b/WebCore/khtml/rendering/font.cpp
@@ -40,10 +40,11 @@
 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, bool visuallyOrdered, int from, int to, QColor bg ) const
+void Font::drawHighlightForText( QPainter *p, int x, int minX, int maxX, int y, int h, 
+                     QChar *str, int slen, int pos, int len,
+                     int toAdd, QPainter::TextDirection d, bool visuallyOrdered, int from, int to, QColor bg) const
 {
-    p->drawHighlightForText(x, y, str + pos, std::min(slen - pos, len), from, to, toAdd, bg, d, visuallyOrdered,
+    p->drawHighlightForText(x, minX, maxX, y, h, str + pos, std::min(slen - pos, len), from, to, toAdd, bg, d, visuallyOrdered,
                 letterSpacing, wordSpacing, fontDef.smallCaps);
 }
 #endif
diff --git a/WebCore/khtml/rendering/font.h b/WebCore/khtml/rendering/font.h
index 608c763..2d1220b 100644
--- a/WebCore/khtml/rendering/font.h
+++ b/WebCore/khtml/rendering/font.h
@@ -130,8 +130,9 @@ 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, bool visuallyOrdered = false, int from=-1, int to=-1, QColor bg=QColor() ) const;
+    void drawHighlightForText( QPainter *p, int x, int minX, int maxX, int y, int h, 
+                   QChar *str, int slen, int pos, int len, int width,
+                   QPainter::TextDirection d, bool visuallyOrdered = false, 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_block.cpp b/WebCore/khtml/rendering/render_block.cpp
index 8fe303e..01b5028 100644
--- a/WebCore/khtml/rendering/render_block.cpp
+++ b/WebCore/khtml/rendering/render_block.cpp
@@ -2075,13 +2075,9 @@ Position RenderBlock::positionForCoordinates(int _x, int _y)
             return Position(element(), 0);
             
         if (_y >= top && _y < absy + firstRootBox()->topOverflow())
-            // y coordinates is above first root line box
+            // y coordinate is above first root line box
             return positionForBox(firstRootBox()->firstLeafChild(), true);
         
-        if (_y < bottom && _y >= absy + lastRootBox()->bottomOverflow())
-            // y coordinates is below last root line box
-            return positionForBox(lastRootBox()->lastLeafChild(), false);
-
         // look for the closest line box in the root box which is at the passed-in y coordinate
         for (RootInlineBox *root = firstRootBox(); root; root = root->nextRootBox()) {
             top = absy + root->topOverflow();
@@ -2093,10 +2089,17 @@ Position RenderBlock::positionForCoordinates(int _x, int _y)
             // check if this root line box is located at this y coordinate
             if (_y >= top && _y < bottom && root->firstChild()) {
                 InlineBox *closestBox = root->closestLeafChildForXPos(_x, absx);
-                if (closestBox)
-                    return closestBox->object()->positionForCoordinates(_x, _y);
+                if (closestBox) {
+                    // pass the box a y position that is inside it
+                    return closestBox->object()->positionForCoordinates(_x, absy + closestBox->m_y);
+                }
             }
         }
+
+        if (lastRootBox())
+            // y coordinate is below last root line box
+            return positionForBox(lastRootBox()->lastLeafChild(), false);
+        
         return Position(element(), 0);
     }
     
@@ -2106,9 +2109,8 @@ Position RenderBlock::positionForCoordinates(int _x, int _y)
             continue;
         renderer->absolutePosition(absx, top);
         RenderObject *next = renderer->nextSibling();
-        while (next && next->isFloatingOrPositioned()) {
+        while (next && next->isFloatingOrPositioned())
             next = next->nextSibling();
-        }
         if (next) 
             next->absolutePosition(absx, bottom);
         else
@@ -2122,7 +2124,7 @@ Position RenderBlock::positionForCoordinates(int _x, int _y)
     if (firstChild())
         return firstChild()->positionForCoordinates(_x, _y);
     
-    // still no luck...return this render object's element, if there isn't one, and offset 0
+    // still no luck...return this render object's element and offset 0
     return Position(element(), 0);
 }
 
diff --git a/WebCore/khtml/rendering/render_block.h b/WebCore/khtml/rendering/render_block.h
index 9f68842..19bc9fb 100644
--- a/WebCore/khtml/rendering/render_block.h
+++ b/WebCore/khtml/rendering/render_block.h
@@ -31,7 +31,7 @@
 
 namespace DOM {
     class Position;
-};
+}
 
 namespace khtml {
 
diff --git a/WebCore/khtml/rendering/render_container.cpp b/WebCore/khtml/rendering/render_container.cpp
index f1d6d94..3878cef 100644
--- a/WebCore/khtml/rendering/render_container.cpp
+++ b/WebCore/khtml/rendering/render_container.cpp
@@ -481,13 +481,13 @@ Position RenderContainer::positionForCoordinates(int _x, int _y)
     if (!firstChild())
         return Position(element(), 0);
 
-    // look for the geometically-closest child and pass off to that child
+    // look for the geometrically-closest child and pass off to that child
     int min = INT_MAX;
-    int absx, absy;
-    absolutePosition(absx, absy);
     RenderObject *closestRenderer = firstChild();
     for (RenderObject *renderer = firstChild(); renderer; renderer = renderer->nextSibling()) {
+        int absx, absy;
         renderer->absolutePosition(absx, absy);
+        
         int top = absy + borderTop() + paddingTop();
         int bottom = top + renderer->contentHeight();
         int left = absx + borderLeft() + paddingLeft();
diff --git a/WebCore/khtml/rendering/render_image.cpp b/WebCore/khtml/rendering/render_image.cpp
index bea2ae5..1d6ac30 100644
--- a/WebCore/khtml/rendering/render_image.cpp
+++ b/WebCore/khtml/rendering/render_image.cpp
@@ -323,6 +323,49 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
     }
     else if (image && !image->isTransparent())
     {
+#if APPLE_CHANGES
+        // Do the calculations to draw selections as tall as the line.
+        // Ignore the passed-in value for _ty.
+        // Use the bottom of the line above as the y position (if there is one, 
+        // otherwise use the top of this renderer's line) and the height of the line as the height. 
+        // This mimics Cocoa.
+        int selectionTop = -1;
+        int selectionHeight = -1;
+        int selectionLeft = -1;
+        int selectionRight = -1;
+        bool extendSelectionToLeft = false;
+        bool extendSelectionToRight = false;
+        if (drawSelectionTint) {
+            InlineBox *box = inlineBox();
+            if (box) {
+                // Get a value for selectionTop that is relative to the containing block.
+                // This value is used for determining left and right offset for the selection, if necessary,
+                // and for calculating the selection height.
+                if (box->root()->prevRootBox())
+                    selectionTop = box->root()->prevRootBox()->bottomOverflow();
+                else
+                    selectionTop = box->root()->topOverflow();
+
+                selectionHeight = box->root()->bottomOverflow() - selectionTop;
+
+                int absx, absy;
+                containingBlock()->absolutePosition(absx, absy);
+
+                if (box->root()->firstLeafChild() == box) {
+                    extendSelectionToLeft = true;
+                    selectionLeft = absx + containingBlock()->leftOffset(selectionTop);
+                }
+                if (box->root()->lastLeafChild() == box) {
+                    extendSelectionToRight = true;
+                    selectionRight = absx + containingBlock()->rightOffset(selectionTop);
+                }
+        
+                // Now make the selectionTop an absolute coordinate.
+                selectionTop += absy;
+            }
+        }
+#endif
+
         if ( (cWidth != intrinsicWidth() ||  cHeight != intrinsicHeight()) &&
              pix.width() > 0 && pix.height() > 0 && image->valid_rect().isValid())
         {
@@ -371,7 +414,16 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
             }
 #if APPLE_CHANGES
             if (drawSelectionTint) {
-                p->fillRect(_tx + leftBorder + leftPad, _ty + topBorder + topPad, tintSize.width(), tintSize.height(), QBrush(selectionTintColor(p)));
+                int left = _tx + leftBorder + leftPad;
+                int width = tintSize.width();
+                int top = selectionTop >= 0 ? selectionTop : _ty + topBorder + topPad;
+                int height = selectionHeight >= 0 ? selectionHeight : tintSize.height();
+                QBrush brush(selectionTintColor(p));
+                p->fillRect(left, top, width, height, brush);
+                if (extendSelectionToLeft)
+                    p->fillRect(selectionLeft, selectionTop, left - selectionLeft, selectionHeight, brush);
+                if (extendSelectionToRight)
+                    p->fillRect(left + width, selectionTop, selectionRight - (left + width), selectionHeight, brush);
             }
 #endif
         }
@@ -405,7 +457,16 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
              }
 #if APPLE_CHANGES
              if (drawSelectionTint) {
-                 p->fillRect(offs.x() + rect.x(), offs.y() + rect.y(), rect.width(), rect.height(), QBrush(selectionTintColor(p)));
+                int left = offs.x() + rect.x();
+                int width = rect.width();
+                int top = selectionTop >= 0 ? selectionTop : offs.y() + rect.y();
+                int height = selectionHeight >= 0 ? selectionHeight : rect.height();
+                QBrush brush(selectionTintColor(p));
+                p->fillRect(left, top, width, height, brush);
+                if (extendSelectionToLeft)
+                    p->fillRect(selectionLeft, selectionTop, left - selectionLeft, selectionHeight, brush);
+                if (extendSelectionToRight)
+                    p->fillRect(left + width, selectionTop, selectionRight - (left + width), selectionHeight, brush);
              }
 #endif
         }
diff --git a/WebCore/khtml/rendering/render_inline.cpp b/WebCore/khtml/rendering/render_inline.cpp
index d160a54..e59d93a 100644
--- a/WebCore/khtml/rendering/render_inline.cpp
+++ b/WebCore/khtml/rendering/render_inline.cpp
@@ -27,7 +27,9 @@
 #include "render_inline.h"
 #include "render_block.h"
 #include "xml/dom_docimpl.h"
+#include "xml/dom_position.h"
 
+using DOM::Position;
 using namespace khtml;
 
 RenderInline::RenderInline(DOM::NodeImpl* node)
@@ -555,3 +557,12 @@ bool RenderInline::nodeAtPoint(NodeInfo& info, int _x, int _y, int _tx, int _ty,
     return inside;
 }
 
+Position RenderInline::positionForCoordinates(int x, int y)
+{
+    for (RenderObject *c = continuation(); c; c = c->continuation()) {
+        if (c->isInline() || c->firstChild())
+            return c->positionForCoordinates(x, y);
+    }
+
+    return RenderFlow::positionForCoordinates(x, y);
+}
diff --git a/WebCore/khtml/rendering/render_inline.h b/WebCore/khtml/rendering/render_inline.h
index eeb47bd..7e9310e 100644
--- a/WebCore/khtml/rendering/render_inline.h
+++ b/WebCore/khtml/rendering/render_inline.h
@@ -27,6 +27,10 @@
 
 #include "render_flow.h"
 
+namespace DOM {
+    class Position;
+}
+
 namespace khtml {
 
 class RenderInline : public RenderFlow
@@ -73,6 +77,8 @@ public:
 
     void absoluteRects(QValueList<QRect>& rects, int _tx, int _ty);
 
+    virtual DOM::Position positionForCoordinates(int x, int y);
+
 #ifdef APPLE_CHANGES
     virtual void addFocusRingRects(QPainter *painter, int _tx, int _ty);
     void paintFocusRing(QPainter *p, int tx, int ty);
diff --git a/WebCore/khtml/rendering/render_object.h b/WebCore/khtml/rendering/render_object.h
index 0d10d0d..3c31c0c 100644
--- a/WebCore/khtml/rendering/render_object.h
+++ b/WebCore/khtml/rendering/render_object.h
@@ -341,7 +341,7 @@ public:
     virtual void setInlineBoxWrapper(InlineBox* b);
     void deleteLineBoxWrapper();
 
-    virtual InlineBox *inlineBox(long offset);
+    virtual InlineBox *inlineBox(long offset=0);
     
     // for discussion of lineHeight see CSS2 spec
     virtual short lineHeight( bool firstLine, bool isRootLineBox=false ) const;
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index 9d8fcee..cb6fee0 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -117,12 +117,35 @@ void InlineTextBox::paintSelection(const Font *f, RenderText *text, QPainter *p,
 #else
     QColor c = style->color();
     p->setPen(QColor(0xff-c.red(),0xff-c.green(),0xff-c.blue()));
+    ty + m_baseline;
 #endif
-    ty += m_baseline;
-
+    
 #if APPLE_CHANGES
-    //kdDebug( 6040 ) << "InlineTextBox::painting(" << s.string() << ") at(" << x+_tx << "/" << y+_ty << ")" << endl;
-    f->drawHighlightForText(p, m_x + tx, m_y + ty, text->str->s, text->str->l, m_start, m_len,
+    // Do the calculations to draw selections as tall as the line.
+    // Use the bottom of the line above as the y position (if there is one, 
+    // otherwise use the top of this renderer's line) and the height of the line as the height. 
+    // This mimics Cocoa.
+    RenderBlock *cb = object()->containingBlock();
+
+    if (root()->prevRootBox())
+        ty = root()->prevRootBox()->bottomOverflow();
+    else
+        ty = root()->topOverflow();
+
+    int h = root()->bottomOverflow() - ty;
+
+    int absx, absy;
+    cb->absolutePosition(absx, absy);
+    
+    int x = m_x + tx;
+    int minX = x;
+    int maxX = x;
+    if (startPos == 0 && root()->firstLeafChild() == this)
+        minX = absx + kMax(cb->leftOffset(ty), cb->leftOffset(root()->blockHeight()));
+    if (endPos == m_len && root()->lastLeafChild() == this)
+        maxX = absx + kMin(cb->rightOffset(ty), cb->rightOffset(root()->blockHeight()));
+    
+    f->drawHighlightForText(p, x, minX, maxX, absy + ty, h, text->str->s, text->str->l, m_start, m_len,
 		m_toAdd, m_reversed ? QPainter::RTL : QPainter::LTR, style->visuallyOrdered(), startPos, endPos, c);
 #else
     f->drawHighlightForText(p, m_x + tx, m_y + ty, text->str->s, text->str->l, m_start, m_len,
diff --git a/WebCore/kwq/KWQListBox.mm b/WebCore/kwq/KWQListBox.mm
index 4a8bae4..2bfb542 100644
--- a/WebCore/kwq/KWQListBox.mm
+++ b/WebCore/kwq/KWQListBox.mm
@@ -532,7 +532,11 @@ void QListBox::setWritingDirection(QPainter::TextDirection d)
     }
     point.y = NSMaxY(cellRect) + [itemFont() descender] - bottomMargin;
 
-    [renderer drawRun:&run style:&style atPoint:point];
+    WebCoreTextGeometry geometry;
+    WebCoreInitializeEmptyTextGeometry(&geometry);
+    geometry.point = point;
+    
+    [renderer drawRun:&run style:&style geometry:&geometry];
 }
 
 - (void)_KWQ_setKeyboardFocusRingNeedsDisplay
diff --git a/WebCore/kwq/KWQPainter.h b/WebCore/kwq/KWQPainter.h
index 1e6a213..c99ff81 100644
--- a/WebCore/kwq/KWQPainter.h
+++ b/WebCore/kwq/KWQPainter.h
@@ -95,7 +95,8 @@ 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,
+    void drawHighlightForText(int x, int minX, int maxX, int y, int h, 
+                  const QChar *, int length, int from, int to, int toAdd,
                   const QColor& backgroundColor, QPainter::TextDirection d, bool visuallyOrdered,
                   int letterSpacing, int wordSpacing, bool smallCaps);
     void drawText(int x, int y, const QChar *, int length, int from, int to, int toAdd,
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index 923df6f..50d0ffe 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -549,8 +549,12 @@ void QPainter::drawText(int x, int y, int, int, int alignmentFlags, const QStrin
     
     if (alignmentFlags & Qt::AlignRight)
         x -= ROUND_TO_INT([data->textRenderer floatWidthForRun:&run style:&style widths:0]);
+
+    WebCoreTextGeometry geometry;
+    WebCoreInitializeEmptyTextGeometry(&geometry);
+    geometry.point = NSMakePoint(x, y);
      
-    [data->textRenderer drawRun:&run style:&style atPoint:NSMakePoint(x, y)];
+    [data->textRenderer drawRun:&run style:&style geometry:&geometry];
 }
 
 void QPainter::drawText(int x, int y, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
@@ -582,11 +586,16 @@ void QPainter::drawText(int x, int y, const QChar *str, int len, int from, int t
     style.smallCaps = smallCaps;
     style.families = families;
     style.padding = toAdd;
+    WebCoreTextGeometry geometry;
+    WebCoreInitializeEmptyTextGeometry(&geometry);
+    geometry.point = NSMakePoint(x, y);
     
-    [data->textRenderer drawRun:&run style:&style atPoint:NSMakePoint(x, y)];
+    [data->textRenderer drawRun:&run style:&style geometry:&geometry];
 }
 
-void QPainter::drawHighlightForText(int x, int y, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
+void QPainter::drawHighlightForText(int x, int minX, int maxX, int y, int h, 
+    const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, 
+    QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
 {
     if (data->state.paintingDisabled || len <= 0)
         return;
@@ -615,8 +624,15 @@ void QPainter::drawHighlightForText(int x, int y, const QChar *str, int len, int
     style.smallCaps = smallCaps;
     style.families = families;
     style.padding = toAdd;
-    
-    [data->textRenderer drawHighlightForRun:&run style:&style atPoint:NSMakePoint(x, y)];
+    WebCoreTextGeometry geometry;
+    WebCoreInitializeEmptyTextGeometry(&geometry);
+    geometry.point = NSMakePoint(x, y);
+    geometry.selectionY = y;
+    geometry.selectionHeight = h;
+    geometry.selectionMinX = minX;
+    geometry.selectionMaxX = maxX;
+    geometry.useFontMetricsForSelectionYAndHeight = false;
+    [data->textRenderer drawHighlightForRun:&run style:&style geometry:&geometry];
 }
 
 void QPainter::drawLineForText(int x, int y, int yOffset, int width)
diff --git a/WebCore/kwq/WebCoreTextRenderer.h b/WebCore/kwq/WebCoreTextRenderer.h
index 9b187c4..bf39608 100644
--- a/WebCore/kwq/WebCoreTextRenderer.h
+++ b/WebCore/kwq/WebCoreTextRenderer.h
@@ -53,6 +53,15 @@ struct WebCoreTextRun
     int to;
 };
 
+struct WebCoreTextGeometry
+{
+    NSPoint point;
+    float selectionY;
+    float selectionHeight;
+    float selectionMinX;
+    float selectionMaxX;
+    bool useFontMetricsForSelectionYAndHeight : 1;
+};
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,15 +69,16 @@ extern "C" {
 
 typedef struct WebCoreTextRun WebCoreTextRun;
 typedef struct WebCoreTextStyle WebCoreTextStyle;
+typedef struct WebCoreTextGeometry WebCoreTextGeometry;
 
 extern void WebCoreInitializeTextRun(WebCoreTextRun *run, const UniChar *characters, unsigned int length, int from, int to);
 extern void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style);
+extern void WebCoreInitializeEmptyTextGeometry(WebCoreTextGeometry *geometry);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 @protocol WebCoreTextRenderer <NSObject>
 
 // WebCoreTextRenderer must guarantee that no calls to any of these
@@ -87,8 +97,8 @@ extern void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style);
 - (float)floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)buffer;
 
 // 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)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
+- (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
 - (void)drawLineForCharacters:(NSPoint)point yOffset:(float)yOffset withWidth:(int)width withColor:(NSColor *)color;
 
 // selection point check
diff --git a/WebCore/kwq/WebCoreTextRendererFactory.m b/WebCore/kwq/WebCoreTextRendererFactory.m
index 8d758c3..b4e3a31 100644
--- a/WebCore/kwq/WebCoreTextRendererFactory.m
+++ b/WebCore/kwq/WebCoreTextRendererFactory.m
@@ -52,6 +52,16 @@ void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style)
     style->families = nil;
 }
 
+void WebCoreInitializeEmptyTextGeometry(WebCoreTextGeometry *geometry)
+{
+    geometry->point = NSMakePoint(0,0);
+    geometry->selectionY = 0;
+    geometry->selectionHeight = 0;
+    geometry->selectionMinX = 0;
+    geometry->selectionMaxX = 0;
+    geometry->useFontMetricsForSelectionYAndHeight = true;
+}
+
 @implementation WebCoreTextRendererFactory
 
 static WebCoreTextRendererFactory *sharedFactory;
diff --git a/WebCore/kwq/WebCoreTextRendererFactory.mm b/WebCore/kwq/WebCoreTextRendererFactory.mm
index 8d758c3..b4e3a31 100644
--- a/WebCore/kwq/WebCoreTextRendererFactory.mm
+++ b/WebCore/kwq/WebCoreTextRendererFactory.mm
@@ -52,6 +52,16 @@ void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style)
     style->families = nil;
 }
 
+void WebCoreInitializeEmptyTextGeometry(WebCoreTextGeometry *geometry)
+{
+    geometry->point = NSMakePoint(0,0);
+    geometry->selectionY = 0;
+    geometry->selectionHeight = 0;
+    geometry->selectionMinX = 0;
+    geometry->selectionMaxX = 0;
+    geometry->useFontMetricsForSelectionYAndHeight = true;
+}
+
 @implementation WebCoreTextRendererFactory
 
 static WebCoreTextRendererFactory *sharedFactory;
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index ad1c202..704590f 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,20 @@
+2004-04-27  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Hyatt
+        
+        Make selections draw in a more Cocoa-like way, where
+        fully-selected lines draw out to the ends of lines, and
+        spaces between lines are drawn with the selection color as well.
+
+        * Misc.subproj/WebKitNSStringExtras.m: Use new WebCoreTextGeometry struct. No change in functionality.
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (-[WebTextRenderer drawRun:style:geometry:]): Use new WebCoreTextGeometry struct. No change in functionality.
+        (-[WebTextRenderer drawHighlightForRun:style:geometry:]): Ditto.
+        (-[WebTextRenderer _CG_drawHighlightForRun:style:geometry:]): Many changes to add the new selection drawing behavior.
+        (-[WebTextRenderer _CG_drawRun:style:geometry:]):  Use new WebCoreTextGeometry struct. No change in functionality.
+        (-[WebTextRenderer _ATSU_drawHighlightForRun:style:geometry:]): Many changes to add the new selection drawing behavior.
+        (-[WebTextRenderer _ATSU_drawRun:style:geometry:]):  Use new WebCoreTextGeometry struct. No change in functionality.
+
 2004-04-26  Richard Williamson   <rjw at apple.com>
 
 	Added support for specifying composite operation on an
@@ -9,6 +26,7 @@
 	This feature was requested by the dashboard guys.  They can use it to apply
 	transparency masks to widgies.
 
+
         Reviewed by Ken.
 
         * WebCoreSupport.subproj/WebImageRenderer.h:
diff --git a/WebKit/Misc.subproj/WebKitNSStringExtras.m b/WebKit/Misc.subproj/WebKitNSStringExtras.m
index 7daacdf..7f2a8a4 100644
--- a/WebKit/Misc.subproj/WebKitNSStringExtras.m
+++ b/WebKit/Misc.subproj/WebKitNSStringExtras.m
@@ -43,7 +43,10 @@ static BOOL canUseFastRenderer (const UniChar *buffer, unsigned length)
         style.applyRunRounding = NO;
         style.applyWordRounding = NO;
         style.textColor = textColor;
-        [renderer drawRun:&run style:&style atPoint:point];
+        WebCoreTextGeometry geometry;
+        WebCoreInitializeEmptyTextGeometry(&geometry);
+        geometry.point = point;
+        [renderer drawRun:&run style:&style geometry:&geometry];
     }
     else {
         // WebTextRenderer assumes drawing from baseline.
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
index 2855bbe..fa1c01b 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
@@ -140,16 +140,16 @@ struct CharacterWidthIterator
 - (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;
+- (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
+- (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
 
 // 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;
+- (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
+- (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
 
 - (BOOL)_setupFont;
 
@@ -433,16 +433,16 @@ static BOOL alwaysUseATSU = NO;
     return [font xHeight];
 }
 
-- (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     if (style->smallCaps && !isSmallCapsRenderer) {
-        [[self _smallCapsRenderer] drawRun:run style:style atPoint:point];
+        [[self _smallCapsRenderer] drawRun:run style:style geometry:geometry];
     }
     else {
         if (shouldUseATSU(run))
-            [self _ATSU_drawRun:run style:style atPoint:point];
+            [self _ATSU_drawRun:run style:style geometry:geometry];
         else
-            [self _CG_drawRun:run style:style atPoint:point];
+            [self _CG_drawRun:run style:style geometry:geometry];
     }
 }
 
@@ -489,16 +489,16 @@ static BOOL alwaysUseATSU = NO;
 }
 
 
-- (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     if (style->smallCaps && !isSmallCapsRenderer) {
-        [[self _smallCapsRenderer] drawHighlightForRun:run style:style atPoint:point];
+        [[self _smallCapsRenderer] drawHighlightForRun:run style:style geometry:geometry];
     }
     else {
         if (shouldUseATSU(run))
-            [self _ATSU_drawHighlightForRun:run style:style atPoint:point];
+            [self _ATSU_drawHighlightForRun:run style:style geometry:geometry];
         else
-            [self _CG_drawHighlightForRun:run style:style atPoint:point];
+            [self _CG_drawHighlightForRun:run style:style geometry:geometry];
     }
 }
 
@@ -814,7 +814,7 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
 }
 
 
-- (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     if (run->length == 0)
         return;
@@ -824,43 +824,52 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
     completeRun.from = 0;
     completeRun.to = run->length;
     initializeCharacterWidthIterator(&widthIterator, self, &completeRun, style);
-            
+    
     float startPosition = 0;
+
+    // The starting point needs to be adjusted to account for the width of
+    // the glyphs at the start of the run.
     while (widthIterator.currentCharacter < (unsigned)run->from) {
         startPosition += widthForNextCharacter(&widthIterator, 0, 0);
     }
-
+    float startX = startPosition + geometry->point.x;
+    
     float backgroundWidth = 0.0;
     while (widthIterator.currentCharacter < (unsigned)run->to) {
         backgroundWidth += widthForNextCharacter(&widthIterator, 0, 0);
     }
 
-    // The starting point needs to be adjusted to account for the width of
-    // the glyphs at the start of the run.
-    float startX = startPosition + point.x;
-
     if (style->backgroundColor != nil){
         // Calculate the width of the selection background by adding
         // up the advances of all the glyphs in the selection.
         
         [style->backgroundColor set];
 
-        float yPos = point.y - [self ascent] - (lineGap/2);
+        float yPos = geometry->useFontMetricsForSelectionYAndHeight ? geometry->point.y - [self ascent] - (lineGap/2) : geometry->selectionY;
+        float height = geometry->useFontMetricsForSelectionYAndHeight ? [self lineSpacing] : geometry->selectionHeight;
         if (style->rtl){
             float completeRunWidth = startPosition + backgroundWidth;
             while (widthIterator.currentCharacter < run->length) {
                 completeRunWidth += widthForNextCharacter(&widthIterator, 0, 0);
             }
 
-            [NSBezierPath fillRect:NSMakeRect(point.x + completeRunWidth - startPosition - backgroundWidth, yPos, backgroundWidth, [self lineSpacing])];
+            [NSBezierPath fillRect:NSMakeRect(geometry->point.x + completeRunWidth - startPosition - backgroundWidth, yPos, backgroundWidth, height)];
         }
-        else
-            [NSBezierPath fillRect:NSMakeRect(startX, yPos, backgroundWidth, [self lineSpacing])];
+        else {
+            [NSBezierPath fillRect:NSMakeRect(startX, yPos, backgroundWidth, height)];
+        }
+
+        // Draw the extra rectangles on either side of the selection to mimic Cocoa behavior.
+        if (geometry->selectionMinX != geometry->point.x) {
+            [NSBezierPath fillRect:NSMakeRect(geometry->selectionMinX, yPos, geometry->point.x - geometry->selectionMinX, height)];
+        }
+        if (geometry->selectionMaxX != geometry->point.x)
+            [NSBezierPath fillRect:NSMakeRect(startX + backgroundWidth, yPos, geometry->selectionMaxX - (startX + backgroundWidth), height)];
     }
 }
 
 
-- (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_CG_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     float *widthBuffer, localWidthBuffer[LOCAL_BUFFER_SIZE];
     CGGlyph *glyphBuffer, localGlyphBuffer[LOCAL_BUFFER_SIZE];
@@ -905,10 +914,10 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
 
     // Calculate the starting point of the glyphs to be displayed by adding
     // all the advances up to the first glyph.
-    startX += point.x;
+    startX += geometry->point.x;
 
     if (style->backgroundColor != nil)
-        [self _CG_drawHighlightForRun:run style:style atPoint:point];
+        [self _CG_drawHighlightForRun:run style:style geometry:geometry];
     
     // Finally, draw the glyphs.
     int lastFrom = 0;
@@ -949,7 +958,7 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
 
     while (nextGlyph < numGlyphs){
         if ((fontBuffer[nextGlyph] != 0 && fontBuffer[nextGlyph] != currentFont)){
-            _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, point.y, nextGlyph - lastFrom);
+            _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, geometry->point.y, nextGlyph - lastFrom);
             lastFrom = nextGlyph;
             currentFont = fontBuffer[nextGlyph];
             startX = nextX;
@@ -957,7 +966,7 @@ static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *a
         nextX += advances[nextGlyph].width;
         nextGlyph++;
     }
-    _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, point.y, nextGlyph - lastFrom);
+    _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, geometry->point.y, nextGlyph - lastFrom);
 
     if (advances != localAdvanceBuffer) {
         free(advances);
@@ -1390,7 +1399,7 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     return swappedRun;
 }
 
-- (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     // The only Cocoa calls made here are to NSColor and NSBezierPath,
     // plus the self calls to _createATSUTextLayoutForRun: and
@@ -1431,31 +1440,39 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     // 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];
+    ATSTrapezoid leadingTrapezoid = [self _trapezoidForRun:&leadingRun style:style atPoint:geometry->point];
+    ATSTrapezoid selectedTrapezoid = [self _trapezoidForRun:run style:style atPoint:geometry->point];
 
     float backgroundWidth = 
             MAX(FixedToFloat(selectedTrapezoid.upperRight.x), FixedToFloat(selectedTrapezoid.lowerRight.x)) - 
             MIN(FixedToFloat(selectedTrapezoid.upperLeft.x), FixedToFloat(selectedTrapezoid.lowerLeft.x));
 
     if (run->from == 0)
-        selectedLeftX = point.x;
+        selectedLeftX = geometry->point.x;
     else
         selectedLeftX = MIN(FixedToFloat(leadingTrapezoid.upperRight.x), FixedToFloat(leadingTrapezoid.lowerRight.x));
     
     [style->backgroundColor set];
 
-    float yPos = point.y - [self ascent];
+    float yPos = geometry->useFontMetricsForSelectionYAndHeight ? geometry->point.y - [self ascent] : geometry->selectionY;
+    float height = geometry->useFontMetricsForSelectionYAndHeight ? [self lineSpacing] : geometry->selectionHeight;
     if (style->rtl || style->visuallyOrdered){
         WebCoreTextRun completeRun = *aRun;
         completeRun.from = 0;
         completeRun.to = aRun->length;
         float completeRunWidth = [self floatWidthForRun:&completeRun style:style widths:0];
-        [NSBezierPath fillRect:NSMakeRect(point.x + completeRunWidth - (selectedLeftX-point.x) - backgroundWidth, yPos, backgroundWidth, [self lineSpacing])];
+        [NSBezierPath fillRect:NSMakeRect(geometry->point.x + completeRunWidth - (selectedLeftX-geometry->point.x) - backgroundWidth, yPos, backgroundWidth, height)];
     }
     else {
-        [NSBezierPath fillRect:NSMakeRect(selectedLeftX, yPos, backgroundWidth, [self lineSpacing])];
+        [NSBezierPath fillRect:NSMakeRect(selectedLeftX, yPos, backgroundWidth, height)];
+    }
+
+    // Draw the extra rectangles on either side of the selection to mimic Cocoa behavior.
+    if (geometry->selectionMinX != geometry->point.x) {
+        [NSBezierPath fillRect:NSMakeRect(geometry->selectionMinX, yPos, geometry->point.x - geometry->selectionMinX, height)];
     }
+    if (geometry->selectionMaxX != geometry->point.x)
+        [NSBezierPath fillRect:NSMakeRect(selectedLeftX + backgroundWidth, yPos, geometry->selectionMaxX - (selectedLeftX + backgroundWidth), height)];
 
     ATSUDisposeTextLayout (layout); // Ignore the error.  Nothing we can do anyway.
 
@@ -1464,7 +1481,7 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
 }
 
 
-- (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style atPoint:(NSPoint)point
+- (void)_ATSU_drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
 {
     // The only Cocoa calls made here are to NSColor, plus the self
     // calls to _createATSUTextLayoutForRun: and
@@ -1495,15 +1512,15 @@ static WebCoreTextRun reverseCharactersInRun(const WebCoreTextRun *run)
     layout = [self _createATSUTextLayoutForRun:aRun];
 
     if (style->backgroundColor != nil)
-        [self _ATSU_drawHighlightForRun:run style:style atPoint:point];
+        [self _ATSU_drawHighlightForRun:run style:style geometry:geometry];
 
     [style->textColor set];
 
     status = ATSUDrawText(layout, 
             aRun->from,
             runLength,
-            FloatToFixed(point.x),   // these values are
-            FloatToFixed(point.y));  // also of type Fixed
+            FloatToFixed(geometry->point.x),   // these values are
+            FloatToFixed(geometry->point.y));  // also of type Fixed
     if (status != noErr){
         // Nothing to do but report the error (dev build only).
         ERROR ("ATSUDrawText() failed(%d)", status);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list