OLD | NEW |
| (Empty) |
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 "WebViewImpl.h" | |
31 #include "core/page/Settings.h" | |
32 #include "core/platform/graphics/FloatPoint.h" | |
33 #include "core/platform/graphics/FloatRect.h" | |
34 #include "core/platform/graphics/GraphicsLayer.h" | |
35 #include "core/platform/graphics/chromium/GraphicsLayerChromium.h" | |
36 #include <public/WebContentLayer.h> | |
37 #include <public/WebFloatPoint.h> | |
38 | |
39 namespace WebKit { | |
40 | |
41 NonCompositedContentHost::NonCompositedContentHost(WebViewImpl* webView, WebCore
::GraphicsLayerFactory* graphicsLayerFactory) | |
42 : m_webView(webView) | |
43 , m_showDebugBorders(false) | |
44 { | |
45 m_graphicsLayer = WebCore::GraphicsLayer::create(graphicsLayerFactory, this)
; | |
46 #ifndef NDEBUG | |
47 m_graphicsLayer->setName("non-composited content"); | |
48 #endif | |
49 m_graphicsLayer->setDrawsContent(true); | |
50 m_graphicsLayer->setContentsOpaque(true); | |
51 // FIXME: Remove LCD text setting after it is implemented in chromium. | |
52 WebContentLayer* layer = static_cast<WebCore::GraphicsLayerChromium*>(m_grap
hicsLayer.get())->contentLayer(); | |
53 layer->setUseLCDText(true); | |
54 #if !OS(ANDROID) | |
55 layer->setDrawCheckerboardForMissingTiles(true); | |
56 #endif | |
57 } | |
58 | |
59 NonCompositedContentHost::~NonCompositedContentHost() | |
60 { | |
61 } | |
62 | |
63 void NonCompositedContentHost::setBackgroundColor(const WebCore::Color& color) | |
64 { | |
65 m_graphicsLayer->platformLayer()->setBackgroundColor(color.rgb()); | |
66 } | |
67 | |
68 void NonCompositedContentHost::setOpaque(bool opaque) | |
69 { | |
70 m_graphicsLayer->setContentsOpaque(opaque); | |
71 } | |
72 | |
73 void NonCompositedContentHost::setScrollLayer(WebCore::GraphicsLayer* layer) | |
74 { | |
75 m_graphicsLayer->setNeedsDisplay(); | |
76 | |
77 if (!layer) { | |
78 m_graphicsLayer->removeFromParent(); | |
79 return; | |
80 } | |
81 | |
82 if (layer->platformLayer() == scrollLayer()) | |
83 return; | |
84 | |
85 layer->addChildAtIndex(m_graphicsLayer.get(), 0); | |
86 ASSERT(haveScrollLayer()); | |
87 } | |
88 | |
89 void NonCompositedContentHost::setViewport(const WebCore::IntSize& viewportSize,
const WebCore::IntSize& contentsSize, const WebCore::IntPoint& scrollPosition,
const WebCore::IntPoint& scrollOrigin) | |
90 { | |
91 if (!haveScrollLayer()) | |
92 return; | |
93 | |
94 bool visibleRectChanged = m_viewportSize != viewportSize; | |
95 | |
96 m_viewportSize = viewportSize; | |
97 WebLayer* layer = scrollLayer(); | |
98 layer->setScrollPosition(scrollPosition + scrollOrigin); | |
99 layer->setPosition(WebFloatPoint(-scrollPosition)); | |
100 // Due to the possibility of pinch zoom, the noncomposited layer is always | |
101 // assumed to be scrollable. | |
102 layer->setScrollable(true); | |
103 m_graphicsLayer->setSize(contentsSize); | |
104 | |
105 // In RTL-style pages, the origin of the initial containing block for the | |
106 // root layer may be positive; translate the layer to avoid negative | |
107 // coordinates. | |
108 m_layerAdjust = -toIntSize(scrollOrigin); | |
109 if (m_graphicsLayer->transform().m41() != m_layerAdjust.width() || m_graphic
sLayer->transform().m42() != m_layerAdjust.height()) { | |
110 WebCore::TransformationMatrix transform = m_graphicsLayer->transform(); | |
111 transform.setM41(m_layerAdjust.width()); | |
112 transform.setM42(m_layerAdjust.height()); | |
113 m_graphicsLayer->setTransform(transform); | |
114 | |
115 // If a tiled layer is shifted left or right, the content that goes into | |
116 // each tile will change. Invalidate the entire layer when this happens. | |
117 m_graphicsLayer->setNeedsDisplay(); | |
118 } else if (visibleRectChanged) | |
119 m_graphicsLayer->setNeedsDisplay(); | |
120 } | |
121 | |
122 bool NonCompositedContentHost::haveScrollLayer() | |
123 { | |
124 return m_graphicsLayer->parent(); | |
125 } | |
126 | |
127 WebLayer* NonCompositedContentHost::scrollLayer() | |
128 { | |
129 if (!m_graphicsLayer->parent()) | |
130 return 0; | |
131 return m_graphicsLayer->parent()->platformLayer(); | |
132 } | |
133 | |
134 void NonCompositedContentHost::invalidateRect(const WebCore::IntRect& rect) | |
135 { | |
136 WebCore::IntRect layerRect = rect; | |
137 layerRect.move(-m_layerAdjust); | |
138 m_graphicsLayer->setNeedsDisplayInRect(WebCore::FloatRect(layerRect)); | |
139 } | |
140 | |
141 void NonCompositedContentHost::notifyAnimationStarted(const WebCore::GraphicsLay
er*, double /* time */) | |
142 { | |
143 // Intentionally left empty since we don't support animations on the non-com
posited content. | |
144 } | |
145 | |
146 void NonCompositedContentHost::paintContents(const WebCore::GraphicsLayer*, WebC
ore::GraphicsContext& context, WebCore::GraphicsLayerPaintingPhase, const WebCor
e::IntRect& clipRect) | |
147 { | |
148 context.translate(-m_layerAdjust); | |
149 WebCore::IntRect adjustedClipRect = clipRect; | |
150 adjustedClipRect.move(m_layerAdjust); | |
151 m_webView->paintRootLayer(context, adjustedClipRect); | |
152 } | |
153 | |
154 void NonCompositedContentHost::setShowDebugBorders(bool showDebugBorders) | |
155 { | |
156 m_showDebugBorders = showDebugBorders; | |
157 m_graphicsLayer->updateDebugIndicators(); | |
158 } | |
159 | |
160 bool NonCompositedContentHost::isTrackingRepaints() const | |
161 { | |
162 return m_webView->isTrackingRepaints(); | |
163 } | |
164 | |
165 } // namespace WebKit | |
OLD | NEW |