2 * Copyright (C) 2004, 2006, 2007 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/layout/LayoutHTMLCanvas.h"
29 #include "core/frame/FrameView.h"
30 #include "core/frame/LocalFrame.h"
31 #include "core/html/HTMLCanvasElement.h"
32 #include "core/layout/LayoutView.h"
33 #include "core/page/Page.h"
34 #include "core/paint/HTMLCanvasPainter.h"
38 using namespace HTMLNames
;
40 LayoutHTMLCanvas::LayoutHTMLCanvas(HTMLCanvasElement
* element
)
41 : LayoutReplaced(element
, LayoutSize(element
->size()))
43 view()->frameView()->setIsVisuallyNonEmpty();
46 DeprecatedPaintLayerType
LayoutHTMLCanvas::layerTypeRequired() const
48 return NormalDeprecatedPaintLayer
;
51 void LayoutHTMLCanvas::paintReplaced(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
53 HTMLCanvasPainter(*this).paintReplaced(paintInfo
, paintOffset
);
56 void LayoutHTMLCanvas::canvasSizeChanged()
58 IntSize canvasSize
= toHTMLCanvasElement(node())->size();
59 LayoutSize
zoomedSize(canvasSize
.width() * style()->effectiveZoom(), canvasSize
.height() * style()->effectiveZoom());
61 if (zoomedSize
== intrinsicSize())
64 setIntrinsicSize(zoomedSize
);
69 if (!preferredLogicalWidthsDirty())
70 setPreferredLogicalWidthsDirty();
72 LayoutSize oldSize
= size();
74 updateLogicalHeight();
75 if (oldSize
== size())
78 if (!selfNeedsLayout())
79 setNeedsLayout(LayoutInvalidationReason::SizeChanged
);
82 PaintInvalidationReason
LayoutHTMLCanvas::invalidatePaintIfNeeded(PaintInvalidationState
& paintInvalidationState
, const LayoutBoxModelObject
& paintInvalidationContainer
)
84 PaintInvalidationReason reason
= LayoutBox::invalidatePaintIfNeeded(paintInvalidationState
, paintInvalidationContainer
);
85 HTMLCanvasElement
* element
= toHTMLCanvasElement(node());
86 if (element
->isDirty()) {
87 element
->doDeferredPaintInvalidation();
88 if (reason
< PaintInvalidationRectangle
)
89 reason
= PaintInvalidationRectangle
;
94 CompositingReasons
LayoutHTMLCanvas::additionalCompositingReasons() const
96 if (toHTMLCanvasElement(node())->shouldBeDirectComposited())
97 return CompositingReasonCanvas
;
98 return CompositingReasonNone
;
101 void LayoutHTMLCanvas::styleDidChange(StyleDifference diff
, const ComputedStyle
* oldStyle
)
103 LayoutReplaced::styleDidChange(diff
, oldStyle
);
104 toHTMLCanvasElement(node())->styleDidChange(oldStyle
, styleRef());