| 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 "core/paint/ImagePainter.h" | 5 #include "core/paint/ImagePainter.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/html/HTMLAreaElement.h" | 11 #include "core/html/HTMLAreaElement.h" |
| 12 #include "core/html/HTMLImageElement.h" | 12 #include "core/html/HTMLImageElement.h" |
| 13 #include "core/layout/LayoutImage.h" | 13 #include "core/layout/LayoutImage.h" |
| 14 #include "core/layout/LayoutReplaced.h" | 14 #include "core/layout/LayoutReplaced.h" |
| 15 #include "core/layout/TextRunConstructor.h" | 15 #include "core/layout/TextRunConstructor.h" |
| 16 #include "core/page/Page.h" | 16 #include "core/page/Page.h" |
| 17 #include "core/paint/BoxPainter.h" | 17 #include "core/paint/BoxPainter.h" |
| 18 #include "core/paint/LayoutObjectDrawingRecorder.h" | 18 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 19 #include "core/paint/ObjectPainter.h" |
| 19 #include "core/paint/PaintInfo.h" | 20 #include "core/paint/PaintInfo.h" |
| 20 #include "platform/geometry/LayoutPoint.h" | 21 #include "platform/geometry/LayoutPoint.h" |
| 21 #include "platform/graphics/Path.h" | 22 #include "platform/graphics/Path.h" |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 void ImagePainter::paint(const PaintInfo& paintInfo, | 26 void ImagePainter::paint(const PaintInfo& paintInfo, |
| 26 const LayoutPoint& paintOffset) { | 27 const LayoutPoint& paintOffset) { |
| 27 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); | 28 m_layoutImage.LayoutReplaced::paint(paintInfo, paintOffset); |
| 28 | 29 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); | 46 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); |
| 46 if (areaElement.imageElement() != m_layoutImage.node()) | 47 if (areaElement.imageElement() != m_layoutImage.node()) |
| 47 return; | 48 return; |
| 48 | 49 |
| 49 // Even if the theme handles focus ring drawing for entire elements, it won't | 50 // Even if the theme handles focus ring drawing for entire elements, it won't |
| 50 // do it for an area within an image, so we don't call | 51 // do it for an area within an image, so we don't call |
| 51 // LayoutTheme::themeDrawsFocusRing here. | 52 // LayoutTheme::themeDrawsFocusRing here. |
| 52 | 53 |
| 53 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); | 54 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); |
| 54 int outlineWidth = areaElementStyle.outlineWidth(); | 55 // If the outline width is 0 we want to avoid drawing anything even if we |
| 55 if (!outlineWidth) | 56 // don't use the value directly. |
| 57 if (!areaElementStyle.outlineWidth()) |
| 56 return; | 58 return; |
| 57 | 59 |
| 58 Path path = areaElement.getPath(&m_layoutImage); | 60 Path path = areaElement.getPath(&m_layoutImage); |
| 59 if (path.isEmpty()) | 61 if (path.isEmpty()) |
| 60 return; | 62 return; |
| 61 | 63 |
| 62 LayoutPoint adjustedPaintOffset = paintOffset; | 64 LayoutPoint adjustedPaintOffset = paintOffset; |
| 63 adjustedPaintOffset.moveBy(m_layoutImage.location()); | 65 adjustedPaintOffset.moveBy(m_layoutImage.location()); |
| 64 path.translate(FloatSize(adjustedPaintOffset.x(), adjustedPaintOffset.y())); | 66 path.translate(FloatSize(adjustedPaintOffset.x(), adjustedPaintOffset.y())); |
| 65 | 67 |
| 66 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 68 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( |
| 67 paintInfo.context, m_layoutImage, DisplayItem::kImageAreaFocusRing)) | 69 paintInfo.context, m_layoutImage, DisplayItem::kImageAreaFocusRing)) |
| 68 return; | 70 return; |
| 69 | 71 |
| 70 LayoutRect focusRect = m_layoutImage.contentBoxRect(); | 72 LayoutRect focusRect = m_layoutImage.contentBoxRect(); |
| 71 focusRect.moveBy(adjustedPaintOffset); | 73 focusRect.moveBy(adjustedPaintOffset); |
| 72 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage, | 74 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage, |
| 73 DisplayItem::kImageAreaFocusRing, | 75 DisplayItem::kImageAreaFocusRing, |
| 74 focusRect); | 76 focusRect); |
| 75 | 77 |
| 76 // FIXME: Clip path instead of context when Skia pathops is ready. | 78 // FIXME: Clip path instead of context when Skia pathops is ready. |
| 77 // https://crbug.com/251206 | 79 // https://crbug.com/251206 |
| 78 | 80 |
| 79 paintInfo.context.save(); | 81 paintInfo.context.save(); |
| 80 paintInfo.context.clip(pixelSnappedIntRect(focusRect)); | 82 paintInfo.context.clip(pixelSnappedIntRect(focusRect)); |
| 81 paintInfo.context.drawFocusRing( | 83 paintInfo.context.drawFocusRing( |
| 82 path, outlineWidth, areaElementStyle.outlineOffset(), | 84 path, ObjectPainter::getOutlineStrokeWidth(areaElementStyle), |
| 85 areaElementStyle.outlineOffset(), |
| 83 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 86 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
| 84 paintInfo.context.restore(); | 87 paintInfo.context.restore(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, | 90 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, |
| 88 const LayoutPoint& paintOffset) { | 91 const LayoutPoint& paintOffset) { |
| 89 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 92 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
| 90 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 93 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
| 91 | 94 |
| 92 GraphicsContext& context = paintInfo.context; | 95 GraphicsContext& context = paintInfo.context; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 InterpolationQuality previousInterpolationQuality = | 173 InterpolationQuality previousInterpolationQuality = |
| 171 context.imageInterpolationQuality(); | 174 context.imageInterpolationQuality(); |
| 172 context.setImageInterpolationQuality(interpolationQuality); | 175 context.setImageInterpolationQuality(interpolationQuality); |
| 173 context.drawImage( | 176 context.drawImage( |
| 174 image.get(), pixelSnappedDestRect, &srcRect, SkXfermode::kSrcOver_Mode, | 177 image.get(), pixelSnappedDestRect, &srcRect, SkXfermode::kSrcOver_Mode, |
| 175 LayoutObject::shouldRespectImageOrientation(&m_layoutImage)); | 178 LayoutObject::shouldRespectImageOrientation(&m_layoutImage)); |
| 176 context.setImageInterpolationQuality(previousInterpolationQuality); | 179 context.setImageInterpolationQuality(previousInterpolationQuality); |
| 177 } | 180 } |
| 178 | 181 |
| 179 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |