~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/src/NonCompositedContentHost.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 *
 
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.
 
13
 *
 
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.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#include "NonCompositedContentHost.h"
 
29
 
 
30
#include "FloatPoint.h"
 
31
#include "FloatRect.h"
 
32
#include "GraphicsLayer.h"
 
33
#include "GraphicsLayerChromium.h"
 
34
#include "PlatformContextSkia.h"
 
35
#include "Settings.h"
 
36
#include "WebViewImpl.h"
 
37
#include <public/WebContentLayer.h>
 
38
#include <public/WebFloatPoint.h>
 
39
 
 
40
namespace WebKit {
 
41
 
 
42
NonCompositedContentHost::NonCompositedContentHost(WebViewImpl* webView)
 
43
    : m_webView(webView)
 
44
    , m_showDebugBorders(false)
 
45
{
 
46
    m_graphicsLayer = WebCore::GraphicsLayer::create(0, this);
 
47
#ifndef NDEBUG
 
48
    m_graphicsLayer->setName("non-composited content");
 
49
#endif
 
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);
 
56
#if !OS(ANDROID)
 
57
    layer->setDrawCheckerboardForMissingTiles(true);
 
58
#endif
 
59
}
 
60
 
 
61
NonCompositedContentHost::~NonCompositedContentHost()
 
62
{
 
63
}
 
64
 
 
65
void NonCompositedContentHost::setBackgroundColor(const WebCore::Color& color)
 
66
{
 
67
    m_graphicsLayer->platformLayer()->setBackgroundColor(color.rgb());
 
68
}
 
69
 
 
70
void NonCompositedContentHost::setOpaque(bool opaque)
 
71
{
 
72
    m_graphicsLayer->setContentsOpaque(opaque);
 
73
}
 
74
 
 
75
void NonCompositedContentHost::setScrollLayer(WebCore::GraphicsLayer* layer)
 
76
{
 
77
    m_graphicsLayer->setNeedsDisplay();
 
78
 
 
79
    if (!layer) {
 
80
        m_graphicsLayer->removeFromParent();
 
81
        return;
 
82
    }
 
83
 
 
84
    if (layer->platformLayer() == scrollLayer())
 
85
        return;
 
86
 
 
87
    layer->addChildAtIndex(m_graphicsLayer.get(), 0);
 
88
    ASSERT(haveScrollLayer());
 
89
}
 
90
 
 
91
static void setScrollbarBoundsContainPageScale(WebCore::GraphicsLayer* layer, WebCore::GraphicsLayer* clipLayer)
 
92
{
 
93
    // Scrollbars are attached outside the root clip rect, so skip the
 
94
    // clipLayer subtree.
 
95
    if (layer == clipLayer)
 
96
        return;
 
97
 
 
98
    for (size_t i = 0; i < layer->children().size(); ++i)
 
99
        setScrollbarBoundsContainPageScale(layer->children()[i], clipLayer);
 
100
 
 
101
    if (layer->children().isEmpty())
 
102
        layer->setAppliesPageScale(true);
 
103
}
 
104
 
 
105
void NonCompositedContentHost::setViewport(const WebCore::IntSize& viewportSize, const WebCore::IntSize& contentsSize, const WebCore::IntPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin)
 
106
{
 
107
    if (!haveScrollLayer())
 
108
        return;
 
109
 
 
110
    bool visibleRectChanged = m_viewportSize != viewportSize;
 
111
 
 
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);
 
120
 
 
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
 
123
    // coordinates.
 
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);
 
130
 
 
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();
 
136
 
 
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);
 
142
}
 
143
 
 
144
bool NonCompositedContentHost::haveScrollLayer()
 
145
{
 
146
    return m_graphicsLayer->parent();
 
147
}
 
148
 
 
149
WebLayer* NonCompositedContentHost::scrollLayer()
 
150
{
 
151
    if (!m_graphicsLayer->parent())
 
152
        return 0;
 
153
    return m_graphicsLayer->parent()->platformLayer();
 
154
}
 
155
 
 
156
void NonCompositedContentHost::invalidateRect(const WebCore::IntRect& rect)
 
157
{
 
158
    WebCore::IntRect layerRect = rect;
 
159
    layerRect.move(-m_layerAdjust);
 
160
    m_graphicsLayer->setNeedsDisplayInRect(WebCore::FloatRect(layerRect));
 
161
}
 
162
 
 
163
void NonCompositedContentHost::notifyAnimationStarted(const WebCore::GraphicsLayer*, double /* time */)
 
164
{
 
165
    // Intentionally left empty since we don't support animations on the non-composited content.
 
166
}
 
167
 
 
168
void NonCompositedContentHost::notifyFlushRequired(const WebCore::GraphicsLayer*)
 
169
{
 
170
    m_webView->scheduleCompositingLayerSync();
 
171
}
 
172
 
 
173
void NonCompositedContentHost::paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext& context, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect)
 
174
{
 
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.
 
178
#if !OS(ANDROID)
 
179
    if (m_graphicsLayer->contentsOpaque())
 
180
        context.platformContext()->setDrawingToImageBuffer(false);
 
181
#endif
 
182
    context.translate(-m_layerAdjust);
 
183
    WebCore::IntRect adjustedClipRect = clipRect;
 
184
    adjustedClipRect.move(m_layerAdjust);
 
185
    m_webView->paintRootLayer(context, adjustedClipRect);
 
186
}
 
187
 
 
188
void NonCompositedContentHost::setShowDebugBorders(bool showDebugBorders)
 
189
{
 
190
    m_showDebugBorders = showDebugBorders;
 
191
    m_graphicsLayer->updateDebugIndicators();
 
192
}
 
193
 
 
194
bool NonCompositedContentHost::isTrackingRepaints() const
 
195
{
 
196
    return m_webView->isTrackingRepaints();
 
197
}
 
198
 
 
199
} // namespace WebKit