From a15d30f54c6edc68da7e82c198b5916dd023ac4d Mon Sep 17 00:00:00 2001 From: Nicolas Roard Date: Fri, 6 Apr 2012 15:16:28 -0700 Subject: CSS Background image implementation bug:1352305 Change-Id: Id9caaae9b9442729110b52c75004f634d8284db4 --- Source/WebKit/android/jni/WebViewCore.cpp | 68 +++++++++++++++++++++++-------- Source/WebKit/android/nav/WebView.cpp | 2 +- 2 files changed, 51 insertions(+), 19 deletions(-) (limited to 'Source/WebKit') diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 7cc427f..726a225 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -88,6 +88,7 @@ #include "NodeList.h" #include "Page.h" #include "PageGroup.h" +#include "PictureLayerContent.h" #include "PictureSetLayerContent.h" #include "PlatformKeyboardEvent.h" #include "PlatformString.h" @@ -872,37 +873,69 @@ void WebViewCore::notifyAnimationStarted() BaseLayerAndroid* WebViewCore::createBaseLayer(SkRegion* region) { - PictureSetLayerContent* content = new PictureSetLayerContent(m_content); - BaseLayerAndroid* base = new BaseLayerAndroid(content); - SkSafeUnref(content); - - m_skipContentDraw = true; - bool layoutSucceeded = layoutIfNeededRecursive(m_mainFrame); - m_skipContentDraw = false; - // Layout only fails if called during a layout. - ALOG_ASSERT(layoutSucceeded, "Can never be called recursively"); - -#if USE(ACCELERATED_COMPOSITING) // We set the background color Color background = Color::white; + + bool bodyHasFixedBackgroundImage = false; + bool bodyHasCSSBackground = false; + if (m_mainFrame && m_mainFrame->document() && m_mainFrame->document()->body()) { - bool hasCSSBackground = false; Document* document = m_mainFrame->document(); RefPtr style = document->styleForElementIgnoringPendingStylesheets(document->body()); if (style->hasBackground()) { background = style->visitedDependentColor(CSSPropertyBackgroundColor); - hasCSSBackground = true; + bodyHasCSSBackground = true; } - WebCore::FrameView* view = m_mainFrame->view(); if (view) { Color viewBackground = view->baseBackgroundColor(); - background = hasCSSBackground ? viewBackground.blend(background) : viewBackground; + background = bodyHasCSSBackground ? viewBackground.blend(background) : viewBackground; } + bodyHasFixedBackgroundImage = style->hasFixedBackgroundImage(); + } + + PictureSetLayerContent* content = new PictureSetLayerContent(m_content); + + BaseLayerAndroid* realBase = 0; + LayerAndroid* base = 0; + + //If we have a fixed background image on the body element, the fixed image + // will be contained in the PictureSet (the content object), and the foreground + //of the body element will be moved to a layer. + //In that case, let's change the hierarchy to obtain: + // + //BaseLayerAndroid + // \- FixedBackgroundBaseLayerAndroid (fixed positioning) + // \- ForegroundBaseLayerAndroid + // \- root layer (webkit composited tree) + + if (bodyHasFixedBackgroundImage) { + base = new ForegroundBaseLayerAndroid(0); + base->setSize(content->width(), content->height()); + FixedBackgroundBaseLayerAndroid* baseBackground = + new FixedBackgroundBaseLayerAndroid(content); + + // TODO -- check we don't have the assumption that baselayer has only one child + realBase = new BaseLayerAndroid(0); + realBase->setSize(content->width(), content->height()); + realBase->addChild(baseBackground); + realBase->addChild(base); + } else { + realBase = new BaseLayerAndroid(content); + base = realBase; } - base->setBackgroundColor(background); + + realBase->setBackgroundColor(background); + + SkSafeUnref(content); + + m_skipContentDraw = true; + bool layoutSucceeded = layoutIfNeededRecursive(m_mainFrame); + m_skipContentDraw = false; + // Layout only fails if called during a layout. + ALOG_ASSERT(layoutSucceeded, "Can never be called recursively"); // We update the layers ChromeClientAndroid* chromeC = static_cast(m_mainFrame->page()->chrome()->client()); @@ -913,9 +946,8 @@ BaseLayerAndroid* WebViewCore::createBaseLayer(SkRegion* region) copyLayer->unref(); root->contentLayer()->clearDirtyRegion(); } -#endif - return base; + return realBase; } BaseLayerAndroid* WebViewCore::recordContent(SkRegion* region, SkIPoint* point) diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index fbd0d94..a852dc7 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -305,7 +305,7 @@ PictureSet* draw(SkCanvas* canvas, SkColor bgColor, DrawExtras extras, bool spli LayerContent* content = m_baseLayer->content(); int sc = canvas->save(SkCanvas::kClip_SaveFlag); canvas->clipRect(SkRect::MakeLTRB(0, 0, content->width(), - content->height()), SkRegion::kDifference_Op); + content->height()), SkRegion::kDifference_Op); Color c = m_baseLayer->getBackgroundColor(); canvas->drawColor(SkColorSetARGBInline(c.alpha(), c.red(), c.green(), c.blue())); canvas->restoreToCount(sc); -- cgit v1.1