Reviewed by Darin.
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2005 20:41:58 +0000 (20:41 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2005 20:41:58 +0000 (20:41 +0000)
        - fixed <rdar://problem/4002164> maps that include start and end
        location don't print right from maps.google.com

I thought I checked this in yesterday but a ChangeLog conflict aborted my checkin
without me noticing.

        * khtml/rendering/render_style.cpp:
        (RenderStyle::diff):
        flag name changed from _should_correct_text_color to _force_backgrounds_to_white

        * khtml/rendering/render_style.h:
        (khtml::RenderStyle::InheritedFlags::operator==):
        flag name changed from _should_correct_text_color to _force_backgrounds_to_white
        (khtml::RenderStyle::setBitDefaults):
        ditto
        (khtml::RenderStyle::forceBackgroundsToWhite):
        ditto, and method name changed too
        (khtml::RenderStyle::setForceBackgroundsToWhite):
        ditto

        * khtml/rendering/render_text.cpp:
        (InlineTextBox::paint):
        updated for name change; also, compare text against white instead of current bg color
        because we no longer actually modify the bg color (previously we would always set
        the bg color to white, so the result is the same)

        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::recalcStyle):
        updated for name change

        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge styleSheetForPrinting]):
        removed this method
        (-[WebCoreBridge reapplyStylesForDeviceType:]):
        removed the code that called styleSheetForPrinting; we no longer use a stylesheet
        for this behavior.

        * khtml/rendering/render_box.cpp:
        (RenderBox::paintBackgroundExtended):
        If forceBackgroundsToWhite flag is set, convert background images and
        background colors to white background color with no background image.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8921 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/render_box.cpp
WebCore/khtml/rendering/render_style.cpp
WebCore/khtml/rendering/render_style.h
WebCore/khtml/rendering/render_text.cpp
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/kwq/WebCoreBridge.mm

index 4ce8e11cb940467a19c0d5caf034059823187fd5..b811b7d1d88ec1052f726de7679597ff95aec66e 100644 (file)
@@ -1,3 +1,49 @@
+2005-03-18  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Darin.
+        
+        - fixed <rdar://problem/4002164> maps that include start and end 
+        location don't print right from maps.google.com
+
+       I thought I checked this in yesterday but a ChangeLog conflict aborted my checkin
+       without me noticing.
+
+        * khtml/rendering/render_style.cpp:
+        (RenderStyle::diff):
+        flag name changed from _should_correct_text_color to _force_backgrounds_to_white
+        
+        * khtml/rendering/render_style.h:
+        (khtml::RenderStyle::InheritedFlags::operator==):
+        flag name changed from _should_correct_text_color to _force_backgrounds_to_white
+        (khtml::RenderStyle::setBitDefaults):
+        ditto
+        (khtml::RenderStyle::forceBackgroundsToWhite):
+        ditto, and method name changed too
+        (khtml::RenderStyle::setForceBackgroundsToWhite):
+        ditto
+        
+        * khtml/rendering/render_text.cpp:
+        (InlineTextBox::paint):
+        updated for name change; also, compare text against white instead of current bg color
+        because we no longer actually modify the bg color (previously we would always set
+        the bg color to white, so the result is the same)
+        
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::recalcStyle):
+        updated for name change
+        
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge styleSheetForPrinting]):
+        removed this method
+        (-[WebCoreBridge reapplyStylesForDeviceType:]):
+        removed the code that called styleSheetForPrinting; we no longer use a stylesheet
+        for this behavior.
+
+        * khtml/rendering/render_box.cpp:
+        (RenderBox::paintBackgroundExtended):
+        If forceBackgroundsToWhite flag is set, convert background images and
+        background colors to white background color with no background image.
+        
 2005-03-18  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by John
index a5dac995bc4e61b119896b80fa0d27f5e310ca3d..51b2d3c49d22ae668eb938395f66a5baa4915e64 100644 (file)
@@ -346,7 +346,23 @@ void RenderBox::paintBackgroundExtended(QPainter *p, const QColor& c, const Back
                                         int bleft, int bright)
 {
     CachedImage* bg = bgLayer->backgroundImage();
+    bool shouldPaintBackgroundImage = bg && bg->pixmap_size() == bg->valid_rect().size() && !bg->isTransparent() && !bg->isErrorImage();
     QColor bgColor = c;
+    
+    // When this style flag is set, change existing background colors and images to a solid white background.
+    // If there's no bg color or image, leave it untouched to avoid affecting transparency.
+    // We don't try to avoid loading the background images, because this style flag is only set
+    // when printing, and at that point we've already loaded the background images anyway. (To avoid
+    // loading the background images we'd have to do this check when applying styles rather than
+    // while rendering.)
+    if (style()->forceBackgroundsToWhite()) {
+        // Note that we can't reuse this variable below because the bgColor might be changed
+        bool shouldPaintBackgroundColor = !bgLayer->next() && bgColor.isValid() && qAlpha(bgColor.rgb()) > 0;
+        if (shouldPaintBackgroundImage || shouldPaintBackgroundColor) {
+            bgColor = Qt::white;
+            shouldPaintBackgroundImage = false;
+        }
+    }
 
     // Only fill with a base color (e.g., white) if we're the root document, since iframes/frames with
     // no background in the child document should show the parent's background.
@@ -383,7 +399,7 @@ void RenderBox::paintBackgroundExtended(QPainter *p, const QColor& c, const Back
     }
     
     // no progressive loading of the background image
-    if (bg && bg->pixmap_size() == bg->valid_rect().size() && !bg->isTransparent() && !bg->isErrorImage()) {
+    if (shouldPaintBackgroundImage) {
         int sx = 0;
         int sy = 0;
         int cw,ch;
index a5ba86f604a0f8466af8730f15444b7c61749f3a..43e85db78ecba395f8e3e70df63bcd91d778f153 100644 (file)
@@ -801,7 +801,7 @@ RenderStyle::Diff RenderStyle::diff( const RenderStyle *other ) const
         !(inherited_flags._visibility == other->inherited_flags._visibility) ||
         !(noninherited_flags._overflow == other->noninherited_flags._overflow) ||
         !(inherited_flags._text_decorations == other->inherited_flags._text_decorations) ||
-        !(inherited_flags._should_correct_text_color == other->inherited_flags._should_correct_text_color) ||
+        !(inherited_flags._force_backgrounds_to_white == other->inherited_flags._force_backgrounds_to_white) ||
         !(surround->border == other->surround->border) ||
         *background.get() != *other->background.get() ||
         visual->textDecoration != other->visual->textDecoration ||
index f968c35df4c1fb2d6c332538f3e0e8c6e9037254..1f5220fb55e10d206afbc64030161aa560d56740 100644 (file)
@@ -905,7 +905,7 @@ protected:
                    (_box_direction == other._box_direction) &&
                    (_visuallyOrdered == other._visuallyOrdered) &&
                    (_htmlHacks == other._htmlHacks) &&
-                   (_should_correct_text_color == other._should_correct_text_color);
+                   (_force_backgrounds_to_white == other._force_backgrounds_to_white);
        }
         
        bool operator!=( const InheritedFlags &other ) const {
@@ -928,7 +928,7 @@ protected:
               // non CSS2 inherited
               bool _visuallyOrdered : 1;
               bool _htmlHacks :1;
-              bool _should_correct_text_color : 1;
+              bool _force_backgrounds_to_white : 1;
     } inherited_flags;
 
 // don't inherit
@@ -1024,7 +1024,7 @@ protected:
        inherited_flags._visuallyOrdered = false;
        inherited_flags._htmlHacks=false;
         inherited_flags._box_direction = initialBoxDirection();
-        inherited_flags._should_correct_text_color = false;
+        inherited_flags._force_backgrounds_to_white = false;
         
        noninherited_flags._effectiveDisplay = noninherited_flags._originalDisplay = initialDisplay();
        noninherited_flags._overflow = initialOverflow();
@@ -1400,8 +1400,8 @@ public:
     void setCursor( ECursor c ) { inherited_flags._cursor_style = c; }
     void setCursorImage( CachedImage *v ) { SET_VAR(inherited,cursor_image,v) }
 
-    bool shouldCorrectTextColor() const { return inherited_flags._should_correct_text_color; }
-    void setShouldCorrectTextColor(bool b=true) { inherited_flags._should_correct_text_color = b; }
+    bool forceBackgroundsToWhite() const { return inherited_flags._force_backgrounds_to_white; }
+    void setForceBackgroundsToWhite(bool b=true) { inherited_flags._force_backgrounds_to_white = b; }
 
     bool htmlHacks() const { return inherited_flags._htmlHacks; }
     void setHtmlHacks(bool b=true) { inherited_flags._htmlHacks = b; }
index 3b6af0dc406e39d21da4c525f88bd5516fd2d5f5..25f489aa313591f2fbb550c10c1c5e2b102cdbca 100644 (file)
@@ -343,8 +343,10 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
     QValueListIterator<KWQKHTMLPart::MarkedTextUnderline> underlineIt = underlines.begin();
 
     QColor textColor = styleToUse->color();
-    if (styleToUse->shouldCorrectTextColor())
-        textColor = correctedTextColor(textColor, styleToUse->backgroundColor());
+    
+    // Make the text color legible against a white background
+    if (styleToUse->forceBackgroundsToWhite())
+        textColor = correctedTextColor(textColor, Qt::white);
 
     if (textColor != i.p->pen().color())
         i.p->setPen(textColor);
index 222aadd564e90ba5439b1d56953d627d439ac121..f94c004efb24b94d8d6b0ea851cd33f8b246a175 100644 (file)
@@ -1036,7 +1036,7 @@ void DocumentImpl::recalcStyle( StyleChange change )
             const KHTMLSettings *settings = m_view->part()->settings();
 #if APPLE_CHANGES
             if (printing && !settings->shouldPrintBackgrounds()) {
-                _style->setShouldCorrectTextColor(true);
+                _style->setForceBackgroundsToWhite(true);
             }
 #endif
             QString stdfont = settings->stdFontName();
index 8464bfc638e0305d9fa3984401c60b663a9071ed..08bf82addb6f23d2716e9e0668b0cf64c838d3ab 100644 (file)
@@ -641,14 +641,6 @@ static bool initializedKJS = FALSE;
     return _part->isFrameSet();
 }
 
-- (NSString *)styleSheetForPrinting
-{
-    if (!_part->settings()->shouldPrintBackgrounds()) {
-        return @"* { background-image: none !important; background-color: white !important;}";
-    }
-    return nil;
-}
-
 - (void)reapplyStylesForDeviceType:(WebCoreDeviceType)deviceType
 {
     _part->setMediaType(deviceType == WebCoreDeviceScreen ? "screen" : "print");
@@ -657,9 +649,6 @@ static bool initializedKJS = FALSE;
         static QPaintDevice screen;
         static QPrinter printer;
        doc->setPaintDevice(deviceType == WebCoreDeviceScreen ? &screen : &printer);
-        if (deviceType != WebCoreDeviceScreen) {
-            doc->setPrintStyleSheet(QString::fromNSString([self styleSheetForPrinting]));
-        }
     }
     return _part->reparseConfiguration();
 }