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" |
(...skipping 15 matching lines...) Expand all Loading... |
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, paintOffset); | 31 paintAreaElementFocusRing(paintInfo, paintOffset); |
32 } | 32 } |
33 | 33 |
34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo, const L
ayoutPoint& paintOffset) | 34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo, const L
ayoutPoint& paintOffset) |
35 { | 35 { |
36 // TODO(wangxianzhu): In other places, we just paint focus ring if outline s
tyle is auto. | |
37 // We should also do that here to keep consistency. | |
38 Document& document = m_layoutImage.document(); | 36 Document& document = m_layoutImage.document(); |
39 | 37 |
40 if (paintInfo.isPrinting() || !document.frame()->selection().isFocusedAndAct
ive()) | 38 if (paintInfo.isPrinting() || !document.frame()->selection().isFocusedAndAct
ive()) |
41 return; | 39 return; |
42 | 40 |
43 Element* focusedElement = document.focusedElement(); | 41 Element* focusedElement = document.focusedElement(); |
44 if (!isHTMLAreaElement(focusedElement)) | 42 if (!isHTMLAreaElement(focusedElement)) |
45 return; | 43 return; |
46 | 44 |
47 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); | 45 HTMLAreaElement& areaElement = toHTMLAreaElement(*focusedElement); |
48 if (areaElement.imageElement() != m_layoutImage.node()) | 46 if (areaElement.imageElement() != m_layoutImage.node()) |
49 return; | 47 return; |
50 | 48 |
51 // 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 |
52 // an area within an image, so we don't call LayoutTheme::themeDrawsFocusRin
g here. | 50 // an area within an image, so we don't call LayoutTheme::themeDrawsFocusRin
g here. |
53 | 51 |
54 Path path = areaElement.computePath(&m_layoutImage); | |
55 if (path.isEmpty()) | |
56 return; | |
57 | |
58 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); | 52 const ComputedStyle& areaElementStyle = *areaElement.ensureComputedStyle(); |
59 int outlineWidth = areaElementStyle.outlineWidth(); | 53 int outlineWidth = areaElementStyle.outlineWidth(); |
60 if (!outlineWidth) | 54 if (!outlineWidth) |
61 return; | 55 return; |
62 | 56 |
| 57 Path path = areaElement.getPath(&m_layoutImage); |
| 58 if (path.isEmpty()) |
| 59 return; |
| 60 |
| 61 LayoutPoint adjustedPaintOffset = paintOffset; |
| 62 adjustedPaintOffset.moveBy(m_layoutImage.location()); |
| 63 path.translate(FloatSize(adjustedPaintOffset.x(), adjustedPaintOffset.y())); |
| 64 |
63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutImage, DisplayItem::ImageAreaFocusRing)) | 65 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutImage, DisplayItem::ImageAreaFocusRing)) |
64 return; | 66 return; |
65 | 67 |
66 IntRect focusRect = m_layoutImage.absoluteContentBox(); | 68 LayoutRect focusRect = m_layoutImage.contentBoxRect(); |
| 69 focusRect.moveBy(adjustedPaintOffset); |
67 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage
, DisplayItem::ImageAreaFocusRing, focusRect); | 70 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage
, DisplayItem::ImageAreaFocusRing, focusRect); |
68 | 71 |
69 // FIXME: Clip path instead of context when Skia pathops is ready. | 72 // FIXME: Clip path instead of context when Skia pathops is ready. |
70 // https://crbug.com/251206 | 73 // https://crbug.com/251206 |
71 | 74 |
72 paintInfo.context.save(); | 75 paintInfo.context.save(); |
73 paintInfo.context.clip(focusRect); | 76 paintInfo.context.clip(pixelSnappedIntRect(focusRect)); |
74 paintInfo.context.drawFocusRing(path, outlineWidth, | 77 paintInfo.context.drawFocusRing(path, outlineWidth, |
75 areaElementStyle.outlineOffset(), | 78 areaElementStyle.outlineOffset(), |
76 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 79 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
77 paintInfo.context.restore(); | 80 paintInfo.context.restore(); |
78 } | 81 } |
79 | 82 |
80 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 83 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
81 { | 84 { |
82 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 85 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
83 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 86 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 139 |
137 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); | 140 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", "
data", InspectorPaintImageEvent::data(m_layoutImage)); |
138 | 141 |
139 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); | 142 InterpolationQuality previousInterpolationQuality = context.imageInterpolati
onQuality(); |
140 context.setImageInterpolationQuality(interpolationQuality); | 143 context.setImageInterpolationQuality(interpolationQuality); |
141 context.drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layou
tObject::shouldRespectImageOrientation(&m_layoutImage)); | 144 context.drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layou
tObject::shouldRespectImageOrientation(&m_layoutImage)); |
142 context.setImageInterpolationQuality(previousInterpolationQuality); | 145 context.setImageInterpolationQuality(previousInterpolationQuality); |
143 } | 146 } |
144 | 147 |
145 } // namespace blink | 148 } // namespace blink |
OLD | NEW |