| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/ImagePainter.h" | 6 #include "core/paint/ImagePainter.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "platform/geometry/LayoutPoint.h" | 21 #include "platform/geometry/LayoutPoint.h" |
| 22 #include "platform/graphics/Path.h" | 22 #include "platform/graphics/Path.h" |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 | 25 |
| 26 void ImagePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 26 void ImagePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
| 27 { | 27 { |
| 28 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); | 28 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); |
| 29 | 29 |
| 30 if (paintInfo.phase == PaintPhaseOutline) | 30 if (paintInfo.phase == PaintPhaseOutline) |
| 31 paintAreaElementFocusRing(paintInfo); | 31 paintAreaElementFocusRing(paintInfo, paintOffset); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo) | 34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo, const L
ayoutPoint& paintOffset) |
| 35 { | 35 { |
| 36 Document& document = m_layoutImage.document(); | 36 Document& document = m_layoutImage.document(); |
| 37 | 37 |
| 38 if (paintInfo.isPrinting() || !document.frame()->selection().isFocusedAndAct
ive()) | 38 if (paintInfo.isPrinting() || !document.frame()->selection().isFocusedAndAct
ive()) |
| 39 return; | 39 return; |
| 40 | 40 |
| 41 Element* focusedElement = document.focusedElement(); | 41 Element* focusedElement = document.focusedElement(); |
| 42 if (!isHTMLAreaElement(focusedElement)) | 42 if (!isHTMLAreaElement(focusedElement)) |
| 43 return; | 43 return; |
| 44 | 44 |
| 45 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); | 45 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); |
| 46 if (areaElement.imageElement() != m_layoutImage.node()) | 46 if (areaElement.imageElement() != m_layoutImage.node()) |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 // Even if the theme handles focus ring drawing for entire elements, it won'
t do it for | 49 // Even if the theme handles focus ring drawing for entire elements, it won'
t do it for |
| 50 // an area within an image, so we don't call LayoutTheme::supportsFocusRing
here. | 50 // an area within an image, so we don't call LayoutTheme::supportsFocusRing
here. |
| 51 | 51 |
| 52 Path path = areaElement.computePath(&m_layoutImage); | 52 Path path = areaElement.computePath(&m_layoutImage); |
| 53 if (path.isEmpty()) | 53 if (path.isEmpty()) |
| 54 return; | 54 return; |
| 55 | 55 |
| 56 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); | 56 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); |
| 57 int outlineWidth = areaElementStyle.outlineWidth(); | 57 int outlineWidth = areaElementStyle.outlineWidth(); |
| 58 if (!outlineWidth) | 58 if (!outlineWidth) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutImage, paintInfo.phase)) | 61 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutImage, paintInfo.phase, paintOffset)) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 IntRect focusRect = m_layoutImage.absoluteContentBox(); | 64 IntRect focusRect = m_layoutImage.absoluteContentBox(); |
| 65 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutImag
e, paintInfo.phase, focusRect); | 65 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutImag
e, paintInfo.phase, focusRect, paintOffset); |
| 66 | 66 |
| 67 // FIXME: Clip path instead of context when Skia pathops is ready. | 67 // FIXME: Clip path instead of context when Skia pathops is ready. |
| 68 // https://crbug.com/251206 | 68 // https://crbug.com/251206 |
| 69 | 69 |
| 70 paintInfo.context->save(); | 70 paintInfo.context->save(); |
| 71 paintInfo.context->clip(focusRect); | 71 paintInfo.context->clip(focusRect); |
| 72 paintInfo.context->drawFocusRing(path, outlineWidth, | 72 paintInfo.context->drawFocusRing(path, outlineWidth, |
| 73 areaElementStyle.outlineOffset(), | 73 areaElementStyle.outlineOffset(), |
| 74 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 74 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
| 75 paintInfo.context->restore(); | 75 paintInfo.context->restore(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 78 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
| 79 { | 79 { |
| 80 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 80 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
| 81 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 81 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
| 82 | 82 |
| 83 GraphicsContext* context = paintInfo.context; | 83 GraphicsContext* context = paintInfo.context; |
| 84 | 84 |
| 85 if (!m_layoutImage.imageResource()->hasImage()) { | 85 if (!m_layoutImage.imageResource()->hasImage()) { |
| 86 if (paintInfo.phase == PaintPhaseSelection) | 86 if (paintInfo.phase == PaintPhaseSelection) |
| 87 return; | 87 return; |
| 88 if (cWidth > 2 && cHeight > 2) { | 88 if (cWidth > 2 && cHeight > 2) { |
| 89 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context
, m_layoutImage, paintInfo.phase)) | 89 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context
, m_layoutImage, paintInfo.phase, paintOffset)) |
| 90 return; | 90 return; |
| 91 // Draw an outline rect where the image should be. | 91 // Draw an outline rect where the image should be. |
| 92 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); | 92 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() +
m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l
ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight)); |
| 93 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage,
paintInfo.phase, paintRect); | 93 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage,
paintInfo.phase, paintRect, paintOffset); |
| 94 context->setStrokeStyle(SolidStroke); | 94 context->setStrokeStyle(SolidStroke); |
| 95 context->setStrokeColor(Color::lightGray); | 95 context->setStrokeColor(Color::lightGray); |
| 96 context->setFillColor(Color::transparent); | 96 context->setFillColor(Color::transparent); |
| 97 context->drawRect(paintRect); | 97 context->drawRect(paintRect); |
| 98 } | 98 } |
| 99 } else if (cWidth > 0 && cHeight > 0) { | 99 } else if (cWidth > 0 && cHeight > 0) { |
| 100 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_
layoutImage, paintInfo.phase)) | 100 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_
layoutImage, paintInfo.phase, paintOffset)) |
| 101 return; | 101 return; |
| 102 LayoutRect contentRect = m_layoutImage.contentBoxRect(); | 102 LayoutRect contentRect = m_layoutImage.contentBoxRect(); |
| 103 contentRect.moveBy(paintOffset); | 103 contentRect.moveBy(paintOffset); |
| 104 LayoutRect paintRect = m_layoutImage.replacedContentRect(); | 104 LayoutRect paintRect = m_layoutImage.replacedContentRect(); |
| 105 paintRect.moveBy(paintOffset); | 105 paintRect.moveBy(paintOffset); |
| 106 | 106 |
| 107 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, pai
ntInfo.phase, contentRect); | 107 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutImage, pai
ntInfo.phase, contentRect, paintOffset); |
| 108 bool clip = !contentRect.contains(paintRect); | 108 bool clip = !contentRect.contains(paintRect); |
| 109 if (clip) { | 109 if (clip) { |
| 110 context->save(); | 110 context->save(); |
| 111 // TODO(chrishtr): this should be pixel-snapped. | 111 // TODO(chrishtr): this should be pixel-snapped. |
| 112 context->clip(FloatRect(contentRect)); | 112 context->clip(FloatRect(contentRect)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 paintIntoRect(context, paintRect); | 115 paintIntoRect(context, paintRect); |
| 116 | 116 |
| 117 if (clip) | 117 if (clip) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 137 | 137 |
| 138 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); | 138 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); |
| 139 | 139 |
| 140 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); | 140 InterpolationQuality previousInterpolationQuality = context->imageInterpolat
ionQuality(); |
| 141 context->setImageInterpolationQuality(interpolationQuality); | 141 context->setImageInterpolationQuality(interpolationQuality); |
| 142 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_la
youtImage.shouldRespectImageOrientation()); | 142 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_la
youtImage.shouldRespectImageOrientation()); |
| 143 context->setImageInterpolationQuality(previousInterpolationQuality); | 143 context->setImageInterpolationQuality(previousInterpolationQuality); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace blink | 146 } // namespace blink |
| OLD | NEW |