2
* Copyright (C) 2011 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#include "NonCompositedContentHost.h"
30
#include "FloatPoint.h"
31
#include "FloatRect.h"
32
#include "GraphicsLayer.h"
33
#include "GraphicsLayerChromium.h"
34
#include "PlatformContextSkia.h"
36
#include "WebViewImpl.h"
37
#include <public/WebContentLayer.h>
38
#include <public/WebFloatPoint.h>
42
NonCompositedContentHost::NonCompositedContentHost(WebViewImpl* webView)
44
, m_showDebugBorders(false)
46
m_graphicsLayer = WebCore::GraphicsLayer::create(0, this);
48
m_graphicsLayer->setName("non-composited content");
50
m_graphicsLayer->setDrawsContent(true);
51
m_graphicsLayer->setAppliesPageScale(!m_webView->page()->settings()->applyPageScaleFactorInCompositor());
52
m_graphicsLayer->setContentsOpaque(true);
53
// FIXME: Remove LCD text setting after it is implemented in chromium.
54
WebContentLayer* layer = static_cast<WebCore::GraphicsLayerChromium*>(m_graphicsLayer.get())->contentLayer();
55
layer->setUseLCDText(true);
57
layer->setDrawCheckerboardForMissingTiles(true);
61
NonCompositedContentHost::~NonCompositedContentHost()
65
void NonCompositedContentHost::setBackgroundColor(const WebCore::Color& color)
67
m_graphicsLayer->platformLayer()->setBackgroundColor(color.rgb());
70
void NonCompositedContentHost::setOpaque(bool opaque)
72
m_graphicsLayer->setContentsOpaque(opaque);
75
void NonCompositedContentHost::setScrollLayer(WebCore::GraphicsLayer* layer)
77
m_graphicsLayer->setNeedsDisplay();
80
m_graphicsLayer->removeFromParent();
84
if (layer->platformLayer() == scrollLayer())
87
layer->addChildAtIndex(m_graphicsLayer.get(), 0);
88
ASSERT(haveScrollLayer());
91
static void setScrollbarBoundsContainPageScale(WebCore::GraphicsLayer* layer, WebCore::GraphicsLayer* clipLayer)
93
// Scrollbars are attached outside the root clip rect, so skip the
95
if (layer == clipLayer)
98
for (size_t i = 0; i < layer->children().size(); ++i)
99
setScrollbarBoundsContainPageScale(layer->children()[i], clipLayer);
101
if (layer->children().isEmpty())
102
layer->setAppliesPageScale(true);
105
void NonCompositedContentHost::setViewport(const WebCore::IntSize& viewportSize, const WebCore::IntSize& contentsSize, const WebCore::IntPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin)
107
if (!haveScrollLayer())
110
bool visibleRectChanged = m_viewportSize != viewportSize;
112
m_viewportSize = viewportSize;
113
WebLayer* layer = scrollLayer();
114
layer->setScrollPosition(scrollPosition + scrollOrigin);
115
layer->setPosition(WebFloatPoint(-scrollPosition));
116
// Due to the possibility of pinch zoom, the noncomposited layer is always
117
// assumed to be scrollable.
118
layer->setScrollable(true);
119
m_graphicsLayer->setSize(contentsSize);
121
// In RTL-style pages, the origin of the initial containing block for the
122
// root layer may be positive; translate the layer to avoid negative
124
m_layerAdjust = -toSize(scrollOrigin);
125
if (m_graphicsLayer->transform().m41() != m_layerAdjust.width() || m_graphicsLayer->transform().m42() != m_layerAdjust.height()) {
126
WebCore::TransformationMatrix transform = m_graphicsLayer->transform();
127
transform.setM41(m_layerAdjust.width());
128
transform.setM42(m_layerAdjust.height());
129
m_graphicsLayer->setTransform(transform);
131
// If a tiled layer is shifted left or right, the content that goes into
132
// each tile will change. Invalidate the entire layer when this happens.
133
m_graphicsLayer->setNeedsDisplay();
134
} else if (visibleRectChanged)
135
m_graphicsLayer->setNeedsDisplay();
137
WebCore::GraphicsLayer* clipLayer = m_graphicsLayer->parent()->parent();
138
WebCore::GraphicsLayer* rootLayer = clipLayer;
139
while (rootLayer->parent())
140
rootLayer = rootLayer->parent();
141
setScrollbarBoundsContainPageScale(rootLayer, clipLayer);
144
bool NonCompositedContentHost::haveScrollLayer()
146
return m_graphicsLayer->parent();
149
WebLayer* NonCompositedContentHost::scrollLayer()
151
if (!m_graphicsLayer->parent())
153
return m_graphicsLayer->parent()->platformLayer();
156
void NonCompositedContentHost::invalidateRect(const WebCore::IntRect& rect)
158
WebCore::IntRect layerRect = rect;
159
layerRect.move(-m_layerAdjust);
160
m_graphicsLayer->setNeedsDisplayInRect(WebCore::FloatRect(layerRect));
163
void NonCompositedContentHost::notifyAnimationStarted(const WebCore::GraphicsLayer*, double /* time */)
165
// Intentionally left empty since we don't support animations on the non-composited content.
168
void NonCompositedContentHost::notifyFlushRequired(const WebCore::GraphicsLayer*)
170
m_webView->scheduleCompositingLayerSync();
173
void NonCompositedContentHost::paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext& context, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect)
175
// FIXME: Remove LCD text setting after it is implemented in chromium.
176
// On non-android platforms, we want to render text with subpixel antialiasing on the root layer
177
// so long as the root is opaque. On android all text is grayscale.
179
if (m_graphicsLayer->contentsOpaque())
180
context.platformContext()->setDrawingToImageBuffer(false);
182
context.translate(-m_layerAdjust);
183
WebCore::IntRect adjustedClipRect = clipRect;
184
adjustedClipRect.move(m_layerAdjust);
185
m_webView->paintRootLayer(context, adjustedClipRect);
188
void NonCompositedContentHost::setShowDebugBorders(bool showDebugBorders)
190
m_showDebugBorders = showDebugBorders;
191
m_graphicsLayer->updateDebugIndicators();
194
bool NonCompositedContentHost::isTrackingRepaints() const
196
return m_webView->isTrackingRepaints();
199
} // namespace WebKit