1d487c56b47c747d3e331ee1892e4c0473363afd2Chris Craik#define LOG_TAG "FixedPositioning" 2d487c56b47c747d3e331ee1892e4c0473363afd2Chris Craik#define LOG_NDEBUG 1 3d487c56b47c747d3e331ee1892e4c0473363afd2Chris Craik 474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard#include "config.h" 5ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard#include "FixedPositioning.h" 6ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard 7d487c56b47c747d3e331ee1892e4c0473363afd2Chris Craik#include "AndroidLog.h" 874eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard#include "DumpLayer.h" 9ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard#include "IFrameLayerAndroid.h" 1074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard#include "TilesManager.h" 11594c6b805969c2673c84d1d1d1a3556ce376ac7aChris Craik#include "SkCanvas.h" 1274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 1374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard#if USE(ACCELERATED_COMPOSITING) 1474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 1574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roardnamespace WebCore { 1674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 17ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard// Called when copying the layer tree to the UI 18ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas RoardFixedPositioning::FixedPositioning(LayerAndroid* layer, const FixedPositioning& position) 19ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard : m_layer(layer) 20ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedLeft(position.m_fixedLeft) 21ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedTop(position.m_fixedTop) 22ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedRight(position.m_fixedRight) 23ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedBottom(position.m_fixedBottom) 24ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedMarginLeft(position.m_fixedMarginLeft) 25ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedMarginTop(position.m_fixedMarginTop) 26ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedMarginRight(position.m_fixedMarginRight) 27ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedMarginBottom(position.m_fixedMarginBottom) 28ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_fixedRect(position.m_fixedRect) 29ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard , m_renderLayerPos(position.m_renderLayerPos) 3074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard{ 3174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard} 3274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 33576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas RoardSkRect FixedPositioning::getViewport(SkRect aViewport, IFrameLayerAndroid* parentIframeLayer) 3474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard{ 3574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard // So if this is a fixed layer inside a iframe, use the iframe offset 3674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard // and the iframe's size as the viewport and pass to the children 37576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard if (parentIframeLayer) 38576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard return SkRect::MakeXYWH(parentIframeLayer->iframeOffset().x(), 39576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard parentIframeLayer->iframeOffset().y(), 40576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard parentIframeLayer->getSize().width(), 41576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard parentIframeLayer->getSize().height()); 42576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard return aViewport; 43576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard} 44576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 45576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard// Executed on the UI 46576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas RoardIFrameLayerAndroid* FixedPositioning::updatePosition(SkRect aViewport, 47576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard IFrameLayerAndroid* parentIframeLayer) 48576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard{ 49576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard SkRect viewport = getViewport(aViewport, parentIframeLayer); 50576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 5174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float w = viewport.width(); 5274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float h = viewport.height(); 5374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float dx = viewport.fLeft; 5474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float dy = viewport.fTop; 5574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float x = dx; 5674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard float y = dy; 5774eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 5874eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard // It turns out that when it is 'auto', we should use the webkit value 5974eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard // from the original render layer's X,Y, that will take care of alignment 6074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard // with the parent's layer and fix Margin etc. 6174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard if (!(m_fixedLeft.defined() || m_fixedRight.defined())) 6274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard x += m_renderLayerPos.x(); 6374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard else if (m_fixedLeft.defined() || !m_fixedRight.defined()) 6474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard x += m_fixedMarginLeft.calcFloatValue(w) + m_fixedLeft.calcFloatValue(w) - m_fixedRect.fLeft; 6574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard else 6674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard x += w - m_fixedMarginRight.calcFloatValue(w) - m_fixedRight.calcFloatValue(w) - m_fixedRect.fRight; 6774eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 6874eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard if (!(m_fixedTop.defined() || m_fixedBottom.defined())) 6974eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard y += m_renderLayerPos.y(); 7074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard else if (m_fixedTop.defined() || !m_fixedBottom.defined()) 7174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard y += m_fixedMarginTop.calcFloatValue(h) + m_fixedTop.calcFloatValue(h) - m_fixedRect.fTop; 7274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard else 7374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard y += h - m_fixedMarginBottom.calcFloatValue(h) - m_fixedBottom.calcFloatValue(h) - m_fixedRect.fBottom; 7474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 75ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard m_layer->setPosition(x, y); 7674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 77ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roard return parentIframeLayer; 7874eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard} 7974eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 80ce76304e955cb279f6f237a84c0ba4fd40a2b2baNicolas Roardvoid FixedPositioning::contentDraw(SkCanvas* canvas, Layer::PaintStyle style) 8174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard{ 8274eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard if (TilesManager::instance()->getShowVisualIndicator()) { 8374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard SkPaint paint; 8474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard paint.setARGB(80, 255, 0, 0); 8574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard canvas->drawRect(m_fixedRect, paint); 8674eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard } 8774eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard} 8874eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 89cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reckvoid FixedPositioning::dumpLayer(LayerDumper* dumper) const 9074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard{ 91cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedLeft", m_fixedLeft); 92cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedTop", m_fixedTop); 93cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedRight", m_fixedRight); 94cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedBottom", m_fixedBottom); 95cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedMarginLeft", m_fixedMarginLeft); 96cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedMarginTop", m_fixedMarginTop); 97cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedMarginRight", m_fixedMarginRight); 98cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeLength("fixedMarginBottom", m_fixedMarginBottom); 99cc6ffa0710f304fbcaa43953b0dc89e1d9b931a2John Reck dumper->writeRect("fixedRect", m_fixedRect); 10074eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard} 10174eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 102576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas RoardBackgroundImagePositioning::BackgroundImagePositioning(LayerAndroid* layer, const BackgroundImagePositioning& position) 103576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard : FixedPositioning(layer, position) 104576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_repeatX(position.m_repeatX) 105576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_repeatY(position.m_repeatY) 106576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_nbRepeatX(position.m_nbRepeatX) 107576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_nbRepeatY(position.m_nbRepeatY) 108576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_offsetX(position.m_offsetX) 109576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard , m_offsetY(position.m_offsetY) 110576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard{ 111576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard} 112576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 113576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard// Executed on the UI 114576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas RoardIFrameLayerAndroid* BackgroundImagePositioning::updatePosition(SkRect aViewport, 1156c20d86c1e2d94a15a34cb3881f6c29967591f7dChris Craik IFrameLayerAndroid* parentIframeLayer) 116576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard{ 117576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard SkRect viewport = getViewport(aViewport, parentIframeLayer); 118576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 119576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard float w = viewport.width() - m_layer->getWidth(); 120576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard float h = viewport.height() - m_layer->getHeight(); 121576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard float x = 0; 122576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard float y = 0; 123576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 124576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard if (m_fixedLeft.defined()) 125576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard x += m_fixedLeft.calcFloatValue(w); 126576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard if (m_fixedTop.defined()) 127576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard y += m_fixedTop.calcFloatValue(h); 128576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 129576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard m_nbRepeatX = ceilf((viewport.width() / m_layer->getWidth()) + 1); 130576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard m_offsetX = ceilf(x / m_layer->getWidth()); 131576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 132576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard m_nbRepeatY = ceilf((viewport.height() / m_layer->getHeight()) + 1); 133576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard m_offsetY = ceilf(y / m_layer->getHeight()); 134576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 135576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard x += viewport.fLeft; 136576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard y += viewport.fTop; 137576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 138576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard m_layer->setPosition(x, y); 139576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 140576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard return parentIframeLayer; 141576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard} 142576098317db607e1d3b32a0e53d2551ea0e7ef21Nicolas Roard 14374eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard} // namespace WebCore 14474eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard 14574eee052852e8c1761c48ad2a44a4b394714b8cfNicolas Roard#endif // USE(ACCELERATED_COMPOSITING) 146