OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/EmbeddedObjectPainter.h" | 6 #include "core/paint/EmbeddedObjectPainter.h" |
7 | 7 |
8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
9 #include "core/layout/LayoutEmbeddedObject.h" | 9 #include "core/layout/LayoutEmbeddedObject.h" |
10 #include "core/layout/LayoutTheme.h" | 10 #include "core/layout/LayoutTheme.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 void EmbeddedObjectPainter::paintReplaced(const PaintInfo& paintInfo, const Layo
utPoint& paintOffset) | 38 void EmbeddedObjectPainter::paintReplaced(const PaintInfo& paintInfo, const Layo
utPoint& paintOffset) |
39 { | 39 { |
40 if (!m_layoutEmbeddedObject.showsUnavailablePluginIndicator()) | 40 if (!m_layoutEmbeddedObject.showsUnavailablePluginIndicator()) |
41 return; | 41 return; |
42 | 42 |
43 if (paintInfo.phase == PaintPhaseSelection) | 43 if (paintInfo.phase == PaintPhaseSelection) |
44 return; | 44 return; |
45 | 45 |
46 GraphicsContext* context = paintInfo.context; | 46 GraphicsContext& context = paintInfo.context; |
47 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, m_layo
utEmbeddedObject, paintInfo.phase, paintOffset)) | 47 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou
tEmbeddedObject, paintInfo.phase, paintOffset)) |
48 return; | 48 return; |
49 | 49 |
50 LayoutRect contentRect(m_layoutEmbeddedObject.contentBoxRect()); | 50 LayoutRect contentRect(m_layoutEmbeddedObject.contentBoxRect()); |
51 contentRect.moveBy(paintOffset); | 51 contentRect.moveBy(paintOffset); |
52 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutEmbeddedObject
, paintInfo.phase, contentRect, paintOffset); | 52 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutEmbeddedObject,
paintInfo.phase, contentRect, paintOffset); |
53 GraphicsContextStateSaver stateSaver(*context); | 53 GraphicsContextStateSaver stateSaver(context); |
54 context->clip(pixelSnappedIntRect(contentRect)); | 54 context.clip(pixelSnappedIntRect(contentRect)); |
55 | 55 |
56 Font font = replacementTextFont(); | 56 Font font = replacementTextFont(); |
57 // TODO(trchen): Speculative fix for crbug.com/481880 | 57 // TODO(trchen): Speculative fix for crbug.com/481880 |
58 // With last resort font, how could this ever be null? | 58 // With last resort font, how could this ever be null? |
59 ASSERT(font.primaryFont()); | 59 ASSERT(font.primaryFont()); |
60 if (!font.primaryFont()) | 60 if (!font.primaryFont()) |
61 return; | 61 return; |
62 TextRun textRun(m_layoutEmbeddedObject.unavailablePluginReplacementText()); | 62 TextRun textRun(m_layoutEmbeddedObject.unavailablePluginReplacementText()); |
63 FloatSize textGeometry(font.width(textRun), font.fontMetrics().height()); | 63 FloatSize textGeometry(font.width(textRun), font.fontMetrics().height()); |
64 | 64 |
65 LayoutRect backgroundRect(0, 0, textGeometry.width() + 2 * replacementTextRo
undedRectLeftRightTextMargin, replacementTextRoundedRectHeight); | 65 LayoutRect backgroundRect(0, 0, textGeometry.width() + 2 * replacementTextRo
undedRectLeftRightTextMargin, replacementTextRoundedRectHeight); |
66 backgroundRect.move(contentRect.center() - backgroundRect.center()); | 66 backgroundRect.move(contentRect.center() - backgroundRect.center()); |
67 backgroundRect = LayoutRect(pixelSnappedIntRect(backgroundRect)); | 67 backgroundRect = LayoutRect(pixelSnappedIntRect(backgroundRect)); |
68 Path roundedBackgroundRect; | 68 Path roundedBackgroundRect; |
69 FloatRect floatBackgroundRect(backgroundRect); | 69 FloatRect floatBackgroundRect(backgroundRect); |
70 roundedBackgroundRect.addRoundedRect(floatBackgroundRect, FloatSize(replacem
entTextRoundedRectRadius, replacementTextRoundedRectRadius)); | 70 roundedBackgroundRect.addRoundedRect(floatBackgroundRect, FloatSize(replacem
entTextRoundedRectRadius, replacementTextRoundedRectRadius)); |
71 context->setFillColor(scaleAlpha(Color::white, replacementTextRoundedRectOpa
city)); | 71 context.setFillColor(scaleAlpha(Color::white, replacementTextRoundedRectOpac
ity)); |
72 context->fillPath(roundedBackgroundRect); | 72 context.fillPath(roundedBackgroundRect); |
73 | 73 |
74 FloatRect textRect(FloatPoint(), textGeometry); | 74 FloatRect textRect(FloatPoint(), textGeometry); |
75 textRect.move(FloatPoint(contentRect.center()) - textRect.center()); | 75 textRect.move(FloatPoint(contentRect.center()) - textRect.center()); |
76 TextRunPaintInfo runInfo(textRun); | 76 TextRunPaintInfo runInfo(textRun); |
77 runInfo.bounds = floatBackgroundRect; | 77 runInfo.bounds = floatBackgroundRect; |
78 context->setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); | 78 context.setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); |
79 context->drawBidiText(font, runInfo, textRect.location() + FloatSize(0, font
.fontMetrics().ascent())); | 79 context.drawBidiText(font, runInfo, textRect.location() + FloatSize(0, font.
fontMetrics().ascent())); |
80 } | 80 } |
81 | 81 |
82 } // namespace blink | 82 } // namespace blink |
OLD | NEW |