1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#define LOG_TAG "FixedPositioning"
#define LOG_NDEBUG 1
#include "config.h"
#include "FixedPositioning.h"
#include "AndroidLog.h"
#include "DumpLayer.h"
#include "IFrameLayerAndroid.h"
#include "TilesManager.h"
#include "SkCanvas.h"
#if USE(ACCELERATED_COMPOSITING)
namespace WebCore {
// Called when copying the layer tree to the UI
FixedPositioning::FixedPositioning(LayerAndroid* layer, const FixedPositioning& position)
: m_layer(layer)
, m_fixedLeft(position.m_fixedLeft)
, m_fixedTop(position.m_fixedTop)
, m_fixedRight(position.m_fixedRight)
, m_fixedBottom(position.m_fixedBottom)
, m_fixedMarginLeft(position.m_fixedMarginLeft)
, m_fixedMarginTop(position.m_fixedMarginTop)
, m_fixedMarginRight(position.m_fixedMarginRight)
, m_fixedMarginBottom(position.m_fixedMarginBottom)
, m_fixedRect(position.m_fixedRect)
, m_renderLayerPos(position.m_renderLayerPos)
{
}
// Executed on the UI
IFrameLayerAndroid* FixedPositioning::updatePosition(SkRect viewport,
IFrameLayerAndroid* parentIframeLayer)
{
// So if this is a fixed layer inside a iframe, use the iframe offset
// and the iframe's size as the viewport and pass to the children
if (parentIframeLayer) {
viewport = SkRect::MakeXYWH(parentIframeLayer->iframeOffset().x(),
parentIframeLayer->iframeOffset().y(),
parentIframeLayer->getSize().width(),
parentIframeLayer->getSize().height());
}
float w = viewport.width();
float h = viewport.height();
float dx = viewport.fLeft;
float dy = viewport.fTop;
float x = dx;
float y = dy;
// It turns out that when it is 'auto', we should use the webkit value
// from the original render layer's X,Y, that will take care of alignment
// with the parent's layer and fix Margin etc.
if (!(m_fixedLeft.defined() || m_fixedRight.defined()))
x += m_renderLayerPos.x();
else if (m_fixedLeft.defined() || !m_fixedRight.defined())
x += m_fixedMarginLeft.calcFloatValue(w) + m_fixedLeft.calcFloatValue(w) - m_fixedRect.fLeft;
else
x += w - m_fixedMarginRight.calcFloatValue(w) - m_fixedRight.calcFloatValue(w) - m_fixedRect.fRight;
if (!(m_fixedTop.defined() || m_fixedBottom.defined()))
y += m_renderLayerPos.y();
else if (m_fixedTop.defined() || !m_fixedBottom.defined())
y += m_fixedMarginTop.calcFloatValue(h) + m_fixedTop.calcFloatValue(h) - m_fixedRect.fTop;
else
y += h - m_fixedMarginBottom.calcFloatValue(h) - m_fixedBottom.calcFloatValue(h) - m_fixedRect.fBottom;
m_layer->setPosition(x, y);
return parentIframeLayer;
}
void FixedPositioning::contentDraw(SkCanvas* canvas, Layer::PaintStyle style)
{
if (TilesManager::instance()->getShowVisualIndicator()) {
SkPaint paint;
paint.setARGB(80, 255, 0, 0);
canvas->drawRect(m_fixedRect, paint);
}
}
void writeLength(FILE* file, int indentLevel, const char* str, SkLength length)
{
if (!length.defined())
return;
writeIndent(file, indentLevel);
fprintf(file, "%s = { type = %d; value = %.2f; };\n", str, length.type, length.value);
}
void FixedPositioning::dumpLayer(FILE* file, int indentLevel) const
{
writeLength(file, indentLevel + 1, "fixedLeft", m_fixedLeft);
writeLength(file, indentLevel + 1, "fixedTop", m_fixedTop);
writeLength(file, indentLevel + 1, "fixedRight", m_fixedRight);
writeLength(file, indentLevel + 1, "fixedBottom", m_fixedBottom);
writeLength(file, indentLevel + 1, "fixedMarginLeft", m_fixedMarginLeft);
writeLength(file, indentLevel + 1, "fixedMarginTop", m_fixedMarginTop);
writeLength(file, indentLevel + 1, "fixedMarginRight", m_fixedMarginRight);
writeLength(file, indentLevel + 1, "fixedMarginBottom", m_fixedMarginBottom);
writeRect(file, indentLevel + 1, "fixedRect", m_fixedRect);
}
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
|