| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/rendering/RenderHTMLCanvas.h" | 27 #include "core/rendering/RenderHTMLCanvas.h" |
| 28 | 28 |
| 29 #include "core/html/HTMLCanvasElement.h" | 29 #include "core/html/HTMLCanvasElement.h" |
| 30 #include "core/html/canvas/CanvasRenderingContext.h" | 30 #include "core/html/canvas/CanvasRenderingContext.h" |
| 31 #include "core/frame/FrameView.h" | 31 #include "core/frame/FrameView.h" |
| 32 #include "core/frame/LocalFrame.h" | 32 #include "core/frame/LocalFrame.h" |
| 33 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
| 34 #include "core/paint/HTMLCanvasPainter.h" |
| 34 #include "core/rendering/PaintInfo.h" | 35 #include "core/rendering/PaintInfo.h" |
| 35 #include "core/rendering/RenderView.h" | 36 #include "core/rendering/RenderView.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 using namespace HTMLNames; | 40 using namespace HTMLNames; |
| 40 | 41 |
| 41 RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element) | 42 RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element) |
| 42 : RenderReplaced(element, element->size()) | 43 : RenderReplaced(element, element->size()) |
| 43 { | 44 { |
| 44 view()->frameView()->setIsVisuallyNonEmpty(); | 45 view()->frameView()->setIsVisuallyNonEmpty(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 LayerType RenderHTMLCanvas::layerTypeRequired() const | 48 LayerType RenderHTMLCanvas::layerTypeRequired() const |
| 48 { | 49 { |
| 49 return NormalLayer; | 50 return NormalLayer; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 53 void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
| 53 { | 54 { |
| 54 GraphicsContext* context = paintInfo.context; | 55 HTMLCanvasPainter(*this).paintReplaced(paintInfo, paintOffset); |
| 55 | |
| 56 LayoutRect contentRect = contentBoxRect(); | |
| 57 contentRect.moveBy(paintOffset); | |
| 58 LayoutRect paintRect = replacedContentRect(); | |
| 59 paintRect.moveBy(paintOffset); | |
| 60 | |
| 61 bool clip = !contentRect.contains(paintRect); | |
| 62 if (clip) { | |
| 63 // Not allowed to overflow the content box. | |
| 64 paintInfo.context->save(); | |
| 65 paintInfo.context->clip(pixelSnappedIntRect(contentRect)); | |
| 66 } | |
| 67 | |
| 68 // FIXME: InterpolationNone should be used if ImageRenderingOptimizeContrast
is set. | |
| 69 // See bug for more details: crbug.com/353716. | |
| 70 InterpolationQuality interpolationQuality = style()->imageRendering() == Ima
geRenderingOptimizeContrast ? InterpolationLow : CanvasDefaultInterpolationQuali
ty; | |
| 71 | |
| 72 HTMLCanvasElement* canvas = toHTMLCanvasElement(node()); | |
| 73 LayoutSize layoutSize = contentRect.size(); | |
| 74 if (style()->imageRendering() == ImageRenderingPixelated | |
| 75 && (layoutSize.width() > canvas->width() || layoutSize.height() > canvas
->height() || layoutSize == canvas->size())) { | |
| 76 interpolationQuality = InterpolationNone; | |
| 77 } | |
| 78 | |
| 79 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | |
| 80 context->setImageInterpolationQuality(interpolationQuality); | |
| 81 canvas->paint(context, paintRect); | |
| 82 context->setImageInterpolationQuality(previousInterpolationQuality); | |
| 83 | |
| 84 if (clip) | |
| 85 context->restore(); | |
| 86 } | 56 } |
| 87 | 57 |
| 88 void RenderHTMLCanvas::canvasSizeChanged() | 58 void RenderHTMLCanvas::canvasSizeChanged() |
| 89 { | 59 { |
| 90 IntSize canvasSize = toHTMLCanvasElement(node())->size(); | 60 IntSize canvasSize = toHTMLCanvasElement(node())->size(); |
| 91 LayoutSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasS
ize.height() * style()->effectiveZoom()); | 61 LayoutSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasS
ize.height() * style()->effectiveZoom()); |
| 92 | 62 |
| 93 if (zoomedSize == intrinsicSize()) | 63 if (zoomedSize == intrinsicSize()) |
| 94 return; | 64 return; |
| 95 | 65 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 114 CompositingReasons RenderHTMLCanvas::additionalCompositingReasons() const | 84 CompositingReasons RenderHTMLCanvas::additionalCompositingReasons() const |
| 115 { | 85 { |
| 116 HTMLCanvasElement* canvas = toHTMLCanvasElement(node()); | 86 HTMLCanvasElement* canvas = toHTMLCanvasElement(node()); |
| 117 if (canvas->renderingContext() && canvas->renderingContext()->isAccelerated(
)) | 87 if (canvas->renderingContext() && canvas->renderingContext()->isAccelerated(
)) |
| 118 return CompositingReasonCanvas; | 88 return CompositingReasonCanvas; |
| 119 | 89 |
| 120 return CompositingReasonNone; | 90 return CompositingReasonNone; |
| 121 } | 91 } |
| 122 | 92 |
| 123 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |