WebCore:
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Aug 2006 23:09:34 +0000 (23:09 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Aug 2006 23:09:34 +0000 (23:09 +0000)
        Reviewed by Hyatt.

        Allow changing the background color WebCore draws under transparent page backgrounds.
        No automated way to test. All tests pass, no performance regression.

        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge setBaseBackgroundColor:]):
        * page/FrameView.cpp:
        (WebCore::FrameViewPrivate::FrameViewPrivate):
        (WebCore::FrameView::baseBackgroundColor):
        (WebCore::FrameView::setBaseBackgroundColor):
        * page/FrameView.h:
        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::paintBackgroundExtended):
        * rendering/RenderView.cpp:
        (WebCore::RenderView::paintBoxDecorations):

WebKit:

        Reviewed by Hyatt.

        WebView API to allow changing the background color that draws under transparent page backgrounds.

        * WebView/WebFrame.m:
        (-[WebFrame _makeDocumentView]):
        (-[WebFrame _updateBackground]):
        * WebView/WebFrameInternal.h:
        * WebView/WebFrameView.m:
        (-[WebFrameView drawRect:]):
        * WebView/WebView.m:
        (-[WebView setBackgroundColor:]):
        (-[WebView backgroundColor]):
        (-[WebView _commonInitializationWithFrameName:groupName:]):
        (-[WebView setDrawsBackground:]):
        * WebView/WebViewPrivate.h:

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

13 files changed:
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/page/FrameView.cpp
WebCore/page/FrameView.h
WebCore/rendering/RenderBox.cpp
WebCore/rendering/RenderView.cpp
WebKit/ChangeLog
WebKit/WebView/WebFrame.m
WebKit/WebView/WebFrameInternal.h
WebKit/WebView/WebFrameView.m
WebKit/WebView/WebView.m
WebKit/WebView/WebViewPrivate.h

index 3e7cbba67159f2edb9b8efb437adf41283f6ed24..0339d5eb10492d3d1a15e31da66bb86fcc9c179d 100644 (file)
@@ -1,3 +1,23 @@
+2006-08-24  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Hyatt.
+
+        Allow changing the background color WebCore draws under transparent page backgrounds.
+        No automated way to test. All tests pass, no performance regression.
+
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge setBaseBackgroundColor:]):
+        * page/FrameView.cpp:
+        (WebCore::FrameViewPrivate::FrameViewPrivate):
+        (WebCore::FrameView::baseBackgroundColor):
+        (WebCore::FrameView::setBaseBackgroundColor):
+        * page/FrameView.h:
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::paintBackgroundExtended):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::paintBoxDecorations):
+
 2006-08-24  Darin Adler  <darin@apple.com>
 
         Reviewed by Justin.
index faa0543a396f74f222b2cf40b51397ebba472242..49c6e48ef9755c11e11a7e41a80d15e7980f3a01 100644 (file)
@@ -389,6 +389,7 @@ typedef enum {
 - (BOOL)doneProcessingData;
 - (BOOL)shouldClose;
 
+- (void)setBaseBackgroundColor:(NSColor *)backgroundColor;
 - (void)setDrawsBackground:(BOOL)drawsBackround;
 
 - (NSColor *)bodyBackgroundColor;
index cbb41fd43add658a5870557fad7479eb98c40f1c..98eb44684afdc8e69566156f9b5fc2ed2658deda 100644 (file)
@@ -1568,6 +1568,18 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     return m_frame->document()->axObjectCache()->get(root);
 }
 
+- (void)setBaseBackgroundColor:(NSColor *)backgroundColor
+{
+    if (m_frame && m_frame->view()) {
+        NSColor *deviceColor = [backgroundColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
+        Color color = Color(makeRGBA((int)(255 * [deviceColor redComponent]),
+                                     (int)(255 * [deviceColor blueComponent]),
+                                     (int)(255 * [deviceColor greenComponent]),
+                                     (int)(255 * [deviceColor alphaComponent])));
+        m_frame->view()->setBaseBackgroundColor(color);
+    }
+}
+
 - (void)setDrawsBackground:(BOOL)drawsBackground
 {
     if (m_frame && m_frame->view())
index f7d7b16d9131fed72582cdc2beeb2398cbdd956d..9c7fe1bb9433bc3b10775d549402ed97493d954a 100644 (file)
@@ -73,6 +73,7 @@ public:
     {
         repaintRects = 0;
         isTransparent = false;
+        baseBackgroundColor = Color::white;
         vmode = hmode = ScrollBarAuto;
         needToInitScrollBars = true;
         reset();
@@ -147,7 +148,8 @@ public:
     bool needToInitScrollBars;
     bool mousePressed;
     bool isTransparent;
-    
+    Color baseBackgroundColor;
+
     Timer<FrameView> hoverTimer;
     
     RenderLayer* m_resizeLayer;
@@ -1307,6 +1309,18 @@ void FrameView::setTransparent(bool isTransparent)
     d->isTransparent = isTransparent;
 }
 
+Color FrameView::baseBackgroundColor() const
+{
+    return d->baseBackgroundColor;
+}
+
+void FrameView::setBaseBackgroundColor(Color bc)
+{
+    if (!bc.isValid())
+        bc = Color::white;
+    d->baseBackgroundColor = bc;
+}
+
 void FrameView::scheduleHoverStateUpdate()
 {
     if (!d->hoverTimer.isActive())
index e622f253f9913f179c567efcd7044c51c3aca56d..43b84b90de51dd013325555d3cf7273b76ec7141 100644 (file)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class AtomicString;
+class Color;
 class CSSProperty;
 class CSSStyleSelector;
 class Clipboard;
@@ -153,7 +154,10 @@ public:
 
     bool isTransparent() const;
     void setTransparent(bool isTransparent);
-    
+
+    Color baseBackgroundColor() const;
+    void setBaseBackgroundColor(Color);
+
     void scheduleRelayout();
     void scheduleRelayoutOfSubtree(Node*);
     void unscheduleRelayout();
index 057aa3b22fe838df52880205de764203b4ef83cd..948553305e6d492d2724b024f197c37f4c2eb085 100644 (file)
@@ -498,17 +498,25 @@ void RenderBox::paintBackgroundExtended(GraphicsContext* p, const Color& c, cons
         
         if (isTransparent)
             view()->frameView()->setUseSlowRepaints(); // The parent must show behind the child.
-        else
-            bgColor = Color::white;
     }
 
     // Paint the color first underneath all images.
-    if (!bgLayer->next() && bgColor.isValid() && bgColor.alpha() > 0) {
+    if (!bgLayer->next()) {
         IntRect rect(_tx, clipy, w, cliph);
-        // If we have an alpha and we are painting the root element, go ahead and blend with white.
-        if (bgColor.alpha() < 0xFF && isRoot() && !view()->frameView()->isTransparent())
-            p->fillRect(rect, Color(Color::white));
-        p->fillRect(rect, bgColor);
+        // If we have an alpha and we are painting the root element, go ahead and blend with the base background color.
+        if (isRoot() && (!bgColor.isValid() || bgColor.alpha() < 0xFF) && !view()->frameView()->isTransparent()) {
+            Color baseColor = view()->frameView()->baseBackgroundColor();
+            if (baseColor.alpha() > 0) {
+                p->save();
+                p->setCompositeOperation(CompositeCopy);
+                p->fillRect(rect, baseColor);
+                p->restore();
+            } else
+                p->clearRect(rect);
+        }
+
+        if (bgColor.isValid() && bgColor.alpha() > 0)
+            p->fillRect(rect, bgColor);
     }
     
     // no progressive loading of the background image
index ee30d6a8cb824ac320f513561aa61de1072e6a5c..a9ff06cee04520e97fec2442ecbad25e194f58fa 100644 (file)
@@ -199,8 +199,16 @@ void RenderView::paintBoxDecorations(PaintInfo& i, int _tx, int _ty)
     // no background in the child document should show the parent's background.
     if (elt || view()->isTransparent())
         frameView()->setUseSlowRepaints(); // The parent must show behind the child.
-    else
-        i.p->fillRect(i.r, Color(Color::white));
+    else {
+        Color baseColor = frameView()->baseBackgroundColor();
+        if (baseColor.alpha() > 0) {
+            i.p->save();
+            i.p->setCompositeOperation(CompositeCopy);
+            i.p->fillRect(i.r, baseColor);
+            i.p->restore();
+        } else
+            i.p->clearRect(i.r);
+    }
 }
 
 void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
index e1f08f1881516a70c6a70b4b9e80c19f7f607dbb..b52cebf1c6b902ff87e1070970f4e9800137110a 100644 (file)
@@ -1,3 +1,22 @@
+2006-08-24  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Hyatt.
+
+        WebView API to allow changing the background color that draws under transparent page backgrounds.
+
+        * WebView/WebFrame.m:
+        (-[WebFrame _makeDocumentView]):
+        (-[WebFrame _updateBackground]):
+        * WebView/WebFrameInternal.h:
+        * WebView/WebFrameView.m:
+        (-[WebFrameView drawRect:]):
+        * WebView/WebView.m:
+        (-[WebView setBackgroundColor:]):
+        (-[WebView backgroundColor]):
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        (-[WebView setDrawsBackground:]):
+        * WebView/WebViewPrivate.h:
+
 2006-08-24  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Darin.
index ba49ce237aedd902e359fda3457e77d3f989edb7..76bdb0c6486d30f65a315af20d1401d4ecc1a6b8 100644 (file)
@@ -514,7 +514,7 @@ static inline WebFrame *Frame(WebCoreFrameBridge *bridge)
     // FIXME: We could save work and not do this for a top-level view that is not a WebHTMLView.
     WebFrameView *v = _private->webFrameView;
     [_private->bridge createFrameViewWithNSView:documentView marginWidth:[v _marginWidth] marginHeight:[v _marginHeight]];
-    [self _updateDrawsBackground];
+    [self _updateBackground];
     [_private->bridge installInFrame:[v _scrollView]];
 
     // Call setDataSource on the document view after it has been placed in the view hierarchy.
@@ -2236,18 +2236,24 @@ static inline WebFrame *Frame(WebCoreFrameBridge *bridge)
     return result;
 }
 
-- (void)_updateDrawsBackground
+- (void)_updateBackground
 {
     BOOL drawsBackground = [[self webView] drawsBackground];
+    NSColor *backgroundColor = [[self webView] backgroundColor];
 
     for (WebFrame *frame = self; frame; frame = [frame _traverseNextFrameStayWithin:self]) {
-        // FIXME: why not the other way for scroll view?
+        // Never call setDrawsBackground:YES on the scroll view or the background color will
+        // flash between pages loads, very noticeable during the PLT.
         if (!drawsBackground)
             [[[frame frameView] _scrollView] setDrawsBackground:NO];
+        [[[frame frameView] _scrollView] setBackgroundColor:backgroundColor];
         id documentView = [[frame frameView] documentView];
         if ([documentView respondsToSelector:@selector(setDrawsBackground:)])
             [documentView setDrawsBackground:drawsBackground];
+        if ([documentView respondsToSelector:@selector(setBackgroundColor:)])
+            [documentView setBackgroundColor:backgroundColor];
         [[frame _bridge] setDrawsBackground:drawsBackground];
+        [[frame _bridge] setBaseBackgroundColor:backgroundColor];
     }
 }
 
index 356894325a31a05b5acb3913e7f4f4f9f74f2c77..3e1e6ecea69712d69220561761e29da0d36d9ab2 100644 (file)
@@ -35,7 +35,7 @@
 
 @interface WebFrame (WebInternal)
 
-- (void)_updateDrawsBackground;
+- (void)_updateBackground;
 - (void)_setInternalLoadDelegate:(id)internalLoadDelegate;
 - (id)_internalLoadDelegate;
 - (void)_unmarkAllMisspellings;
index e5106b737cc7476e6ccdf20be21971ec8b4050ab..b1c3dad533a11eb9557ea3fe3062824c466bf2c3 100644 (file)
@@ -478,7 +478,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class class,
     if ([self documentView] == nil) {
         // Need to paint ourselves if there's no documentView to do it instead.
         if ([[self _webView] drawsBackground]) {
-            [[NSColor whiteColor] set];
+            [[[self _webView] backgroundColor] set];
             NSRectFill(rect);
         }
     } else {
index d5e6cc61ea3e2421b90a7f5e605ca81afa0c4dd8..ab45fdd12b4dae40b4c1d64f43f761b31b27c903 100644 (file)
@@ -281,6 +281,8 @@ macro(yankAndSelect) \
     BOOL tabKeyCyclesThroughElements;
     BOOL tabKeyCyclesThroughElementsChanged;
 
+    NSColor *backgroundColor;
+
     NSString *mediaStyle;
     
     NSView <WebDocumentDragging> *draggingDocumentView;
@@ -1528,6 +1530,23 @@ static bool debugWidget = true;
     } while (frame);
 }
 
+- (void)setBackgroundColor:(NSColor *)backgroundColor
+{
+    if ([_private->backgroundColor isEqual:backgroundColor])
+        return;
+
+    id old = _private->backgroundColor;
+    _private->backgroundColor = [backgroundColor retain];
+    [old release];
+
+    [[self mainFrame] _updateBackground];
+}
+
+- (NSColor *)backgroundColor
+{
+    return _private->backgroundColor;
+}
+
 @end
 
 
@@ -1717,6 +1736,7 @@ NSMutableDictionary *countInvocations;
     _private->mainFrameDocumentReady = NO;
     _private->drawsBackground = YES;
     _private->smartInsertDeleteEnabled = YES;
+    _private->backgroundColor = [[NSColor whiteColor] retain];
 
     NSRect f = [self frame];
     WebFrameView *frameView = [[WebFrameView alloc] initWithFrame: NSMakeRect(0,0,f.size.width,f.size.height)];
@@ -2600,7 +2620,7 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     if (_private->drawsBackground == drawsBackground)
         return;
     _private->drawsBackground = drawsBackground;
-    [[self mainFrame] _updateDrawsBackground];
+    [[self mainFrame] _updateBackground];
 }
 
 - (BOOL)drawsBackground
index 12a2a79eecdb82c34b923dd116b7069f5558ffdb..d3b6685314fe47cceda6de5ac454dad9c5b73efc 100644 (file)
@@ -116,6 +116,23 @@ typedef enum {
 + (BOOL)_developerExtrasEnabled;
 + (BOOL)_scriptDebuggerEnabled;
 
+/*!
+    @method setBackgroundColor:
+    @param backgroundColor Color to use as the default background.
+    @abstract Sets what color the receiver draws under transparent page background colors and images.
+    This color is also used when no page is loaded. A color with alpha should only be used when the receiver is
+    in a non-opaque window, since the color is drawn using NSCompositeCopy.
+*/
+- (void)setBackgroundColor:(NSColor *)backgroundColor;
+
+/*!
+    @method backgroundColor
+    @result Returns the background color drawn under transparent page background colors and images.
+    This color is also used when no page is loaded. A color with alpha should only be used when the receiver is
+    in a non-opaque window, since the color is drawn using NSCompositeCopy.
+*/
+- (NSColor *)backgroundColor;
+
 /*!
 Could be worth adding to the API.
  @method loadItemsFromOtherView: