Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: Source/core/paint/ImagePainter.cpp

Issue 923953002: Move rendering/RenderImage* to layout/LayoutImage* (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/paint/ImagePainter.h ('k') | Source/core/paint/SVGImagePainter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
12 #include "core/html/HTMLAreaElement.h" 12 #include "core/html/HTMLAreaElement.h"
13 #include "core/html/HTMLImageElement.h" 13 #include "core/html/HTMLImageElement.h"
14 #include "core/layout/LayoutImage.h"
14 #include "core/layout/PaintInfo.h" 15 #include "core/layout/PaintInfo.h"
15 #include "core/layout/TextRunConstructor.h" 16 #include "core/layout/TextRunConstructor.h"
16 #include "core/page/Page.h" 17 #include "core/page/Page.h"
17 #include "core/paint/BoxPainter.h" 18 #include "core/paint/BoxPainter.h"
18 #include "core/paint/RenderDrawingRecorder.h" 19 #include "core/paint/RenderDrawingRecorder.h"
19 #include "core/rendering/RenderImage.h"
20 #include "core/rendering/RenderReplaced.h" 20 #include "core/rendering/RenderReplaced.h"
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_renderImage.RenderReplaced::paint(paintInfo, paintOffset); 28 m_layoutImage.RenderReplaced::paint(paintInfo, paintOffset);
29 29
30 if (paintInfo.phase == PaintPhaseOutline) 30 if (paintInfo.phase == PaintPhaseOutline)
31 paintAreaElementFocusRing(paintInfo); 31 paintAreaElementFocusRing(paintInfo);
32 } 32 }
33 33
34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo) 34 void ImagePainter::paintAreaElementFocusRing(const PaintInfo& paintInfo)
35 { 35 {
36 Document& document = m_renderImage.document(); 36 Document& document = m_layoutImage.document();
37 37
38 if (document.printing() || !document.frame()->selection().isFocusedAndActive ()) 38 if (document.printing() || !document.frame()->selection().isFocusedAndActive ())
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_renderImage.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_renderImage); 52 Path path = areaElement.computePath(&m_layoutImage);
53 if (path.isEmpty()) 53 if (path.isEmpty())
54 return; 54 return;
55 55
56 const LayoutStyle& areaElementStyle = *areaElement.computedStyle(); 56 const LayoutStyle& areaElementStyle = *areaElement.computedStyle();
57 unsigned short outlineWidth = areaElementStyle.outlineWidth(); 57 unsigned short outlineWidth = areaElementStyle.outlineWidth();
58 if (!outlineWidth) 58 if (!outlineWidth)
59 return; 59 return;
60 60
61 IntRect focusRect = m_renderImage.absoluteContentBox(); 61 IntRect focusRect = m_layoutImage.absoluteContentBox();
62 62
63 RenderDrawingRecorder drawingRecorder(paintInfo.context, m_renderImage, pain tInfo.phase, focusRect); 63 RenderDrawingRecorder drawingRecorder(paintInfo.context, m_layoutImage, pain tInfo.phase, focusRect);
64 if (drawingRecorder.canUseCachedDrawing()) 64 if (drawingRecorder.canUseCachedDrawing())
65 return; 65 return;
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_renderImage.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_renderImage.contentWidth(); 80 LayoutUnit cWidth = m_layoutImage.contentWidth();
81 LayoutUnit cHeight = m_renderImage.contentHeight(); 81 LayoutUnit cHeight = m_layoutImage.contentHeight();
82 82
83 GraphicsContext* context = paintInfo.context; 83 GraphicsContext* context = paintInfo.context;
84 84
85 if (!m_renderImage.imageResource()->hasImage()) { 85 if (!m_layoutImage.imageResource()->hasImage()) {
86 if (paintInfo.phase == PaintPhaseSelection) 86 if (paintInfo.phase == PaintPhaseSelection)
87 return; 87 return;
88 88
89 if (cWidth > 2 && cHeight > 2) { 89 if (cWidth > 2 && cHeight > 2) {
90 // Draw an outline rect where the image should be. 90 // Draw an outline rect where the image should be.
91 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_renderImage.borderLeft() + m_renderImage.paddingLeft(), paintOffset.y() + m_r enderImage.borderTop() + m_renderImage.paddingTop(), cWidth, cHeight)); 91 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_layoutImage.borderLeft() + m_layoutImage.paddingLeft(), paintOffset.y() + m_l ayoutImage.borderTop() + m_layoutImage.paddingTop(), cWidth, cHeight));
92 92
93 93
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 LayoutRect contentRect = m_renderImage.contentBoxRect(); 100 LayoutRect contentRect = m_layoutImage.contentBoxRect();
101 contentRect.moveBy(paintOffset); 101 contentRect.moveBy(paintOffset);
102 LayoutRect paintRect = m_renderImage.replacedContentRect(); 102 LayoutRect paintRect = m_layoutImage.replacedContentRect();
103 paintRect.moveBy(paintOffset); 103 paintRect.moveBy(paintOffset);
104 104
105 bool clip = !contentRect.contains(paintRect); 105 bool clip = !contentRect.contains(paintRect);
106 if (clip) { 106 if (clip) {
107 context->save(); 107 context->save();
108 context->clip(contentRect); 108 context->clip(contentRect);
109 } 109 }
110 110
111 paintIntoRect(context, paintRect); 111 paintIntoRect(context, paintRect);
112 112
113 if (clip) 113 if (clip)
114 context->restore(); 114 context->restore();
115 } 115 }
116 } 116 }
117 117
118 void ImagePainter::paintIntoRect(GraphicsContext* context, const LayoutRect& rec t) 118 void ImagePainter::paintIntoRect(GraphicsContext* context, const LayoutRect& rec t)
119 { 119 {
120 if (!m_renderImage.imageResource()->hasImage() || m_renderImage.imageResourc e()->errorOccurred()) 120 if (!m_layoutImage.imageResource()->hasImage() || m_layoutImage.imageResourc e()->errorOccurred())
121 return; // FIXME: should we just ASSERT these conditions? (audit all cal lers). 121 return; // FIXME: should we just ASSERT these conditions? (audit all cal lers).
122 122
123 IntRect alignedRect = pixelSnappedIntRect(rect); 123 IntRect alignedRect = pixelSnappedIntRect(rect);
124 if (alignedRect.width() <= 0 || alignedRect.height() <= 0) 124 if (alignedRect.width() <= 0 || alignedRect.height() <= 0)
125 return; 125 return;
126 126
127 RefPtr<Image> image = m_renderImage.imageResource()->image(alignedRect.width (), alignedRect.height()); 127 RefPtr<Image> image = m_layoutImage.imageResource()->image(alignedRect.width (), alignedRect.height());
128 if (!image || image->isNull()) 128 if (!image || image->isNull())
129 return; 129 return;
130 130
131 // FIXME: why is interpolation quality selection not included in the Instrum entation reported cost of drawing an image? 131 // FIXME: why is interpolation quality selection not included in the Instrum entation reported cost of drawing an image?
132 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ uality(m_renderImage, context, image.get(), image.get(), LayoutSize(alignedRect. size())); 132 InterpolationQuality interpolationQuality = BoxPainter::chooseInterpolationQ uality(m_layoutImage, context, image.get(), image.get(), LayoutSize(alignedRect. size()));
133 133
134 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", " data", InspectorPaintImageEvent::data(m_renderImage)); 134 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", " data", InspectorPaintImageEvent::data(m_layoutImage));
135 135
136 InterpolationQuality previousInterpolationQuality = context->imageInterpolat ionQuality(); 136 InterpolationQuality previousInterpolationQuality = context->imageInterpolat ionQuality();
137 context->setImageInterpolationQuality(interpolationQuality); 137 context->setImageInterpolationQuality(interpolationQuality);
138 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_re nderImage.shouldRespectImageOrientation()); 138 context->drawImage(image.get(), alignedRect, SkXfermode::kSrcOver_Mode, m_la youtImage.shouldRespectImageOrientation());
139 context->setImageInterpolationQuality(previousInterpolationQuality); 139 context->setImageInterpolationQuality(previousInterpolationQuality);
140 } 140 }
141 141
142 } // namespace blink 142 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/ImagePainter.h ('k') | Source/core/paint/SVGImagePainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698