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.size()); | |
pdr.
2016/04/26 01:29:35
I think this needs to be areaElement.getPath(&m_la
Xianzhu
2016/04/26 17:42:27
Done.
I remember I had changed this before upload
| |
58 if (path.isEmpty()) | |
59 return; | |
60 | |
61 AffineTransform zoomTransform; | |
pdr.
2016/04/26 01:29:35
Why is it correct to zoom here? There are almost n
Xianzhu
2016/04/26 17:42:27
Thanks for the finding. I didn't carefully think a
| |
62 zoomTransform.scale(m_layoutImage.styleRef().effectiveZoom()); | |
63 path.transform(zoomTransform); | |
64 | |
65 LayoutPoint adjustedPaintOffset = paintOffset; | |
66 adjustedPaintOffset.moveBy(m_layoutImage.location()); | |
67 path.translate(FloatSize(adjustedPaintOffset.x(), adjustedPaintOffset.y())); | |
68 | |
63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutImage, DisplayItem::ImageAreaFocusRing)) | 69 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutImage, DisplayItem::ImageAreaFocusRing)) |
64 return; | 70 return; |
65 | 71 |
66 IntRect focusRect = m_layoutImage.absoluteContentBox(); | 72 LayoutRect focusRect = m_layoutImage.contentBoxRect(); |
73 focusRect.moveBy(adjustedPaintOffset); | |
67 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage , DisplayItem::ImageAreaFocusRing, focusRect); | 74 LayoutObjectDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage , DisplayItem::ImageAreaFocusRing, focusRect); |
68 | 75 |
69 // FIXME: Clip path instead of context when Skia pathops is ready. | 76 // FIXME: Clip path instead of context when Skia pathops is ready. |
70 // https://crbug.com/251206 | 77 // https://crbug.com/251206 |
71 | 78 |
72 paintInfo.context.save(); | 79 paintInfo.context.save(); |
73 paintInfo.context.clip(focusRect); | 80 paintInfo.context.clip(pixelSnappedIntRect(focusRect)); |
74 paintInfo.context.drawFocusRing(path, outlineWidth, | 81 paintInfo.context.drawFocusRing(path, outlineWidth, |
75 areaElementStyle.outlineOffset(), | 82 areaElementStyle.outlineOffset(), |
76 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); | 83 m_layoutImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); |
77 paintInfo.context.restore(); | 84 paintInfo.context.restore(); |
78 } | 85 } |
79 | 86 |
80 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) | 87 void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
81 { | 88 { |
82 LayoutUnit cWidth = m_layoutImage.contentWidth(); | 89 LayoutUnit cWidth = m_layoutImage.contentWidth(); |
83 LayoutUnit cHeight = m_layoutImage.contentHeight(); | 90 LayoutUnit cHeight = m_layoutImage.contentHeight(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 143 |
137 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", " data", InspectorPaintImageEvent::data(m_layoutImage)); | 144 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", " data", InspectorPaintImageEvent::data(m_layoutImage)); |
138 | 145 |
139 InterpolationQuality previousInterpolationQuality = context.imageInterpolati onQuality(); | 146 InterpolationQuality previousInterpolationQuality = context.imageInterpolati onQuality(); |
140 context.setImageInterpolationQuality(interpolationQuality); | 147 context.setImageInterpolationQuality(interpolationQuality); |
141 context.drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layou tObject::shouldRespectImageOrientation(&m_layoutImage)); | 148 context.drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, Layou tObject::shouldRespectImageOrientation(&m_layoutImage)); |
142 context.setImageInterpolationQuality(previousInterpolationQuality); | 149 context.setImageInterpolationQuality(previousInterpolationQuality); |
143 } | 150 } |
144 | 151 |
145 } // namespace blink | 152 } // namespace blink |
OLD | NEW |