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 26 matching lines...) Expand all Loading... |
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)) |
| 48 return; |
| 49 |
47 FloatRect contentRect = m_layoutEmbeddedObject.contentBoxRect(); | 50 FloatRect contentRect = m_layoutEmbeddedObject.contentBoxRect(); |
48 contentRect.moveBy(roundedIntPoint(paintOffset)); | 51 contentRect.moveBy(roundedIntPoint(paintOffset)); |
49 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutEmbeddedObject
, paintInfo.phase, contentRect); | 52 LayoutObjectDrawingRecorder drawingRecorder(*context, m_layoutEmbeddedObject
, paintInfo.phase, contentRect); |
50 if (drawingRecorder.canUseCachedDrawing()) | |
51 return; | |
52 | |
53 GraphicsContextStateSaver stateSaver(*context); | 53 GraphicsContextStateSaver stateSaver(*context); |
54 context->clip(contentRect); | 54 context->clip(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 FloatRect backgroundRect(0, 0, textGeometry.width() + 2 * replacementTextRou
ndedRectLeftRightTextMargin, replacementTextRoundedRectHeight); | 65 FloatRect backgroundRect(0, 0, textGeometry.width() + 2 * replacementTextRou
ndedRectLeftRightTextMargin, replacementTextRoundedRectHeight); |
66 backgroundRect.move(contentRect.center() - backgroundRect.center()); | 66 backgroundRect.move(contentRect.center() - backgroundRect.center()); |
67 Path roundedBackgroundRect; | 67 Path roundedBackgroundRect; |
68 roundedBackgroundRect.addRoundedRect(backgroundRect, FloatSize(replacementTe
xtRoundedRectRadius, replacementTextRoundedRectRadius)); | 68 roundedBackgroundRect.addRoundedRect(backgroundRect, FloatSize(replacementTe
xtRoundedRectRadius, replacementTextRoundedRectRadius)); |
69 context->setFillColor(scaleAlpha(Color::white, replacementTextRoundedRectOpa
city)); | 69 context->setFillColor(scaleAlpha(Color::white, replacementTextRoundedRectOpa
city)); |
70 context->fillPath(roundedBackgroundRect); | 70 context->fillPath(roundedBackgroundRect); |
71 | 71 |
72 FloatRect textRect(FloatPoint(), textGeometry); | 72 FloatRect textRect(FloatPoint(), textGeometry); |
73 textRect.move(contentRect.center() - textRect.center()); | 73 textRect.move(contentRect.center() - textRect.center()); |
74 TextRunPaintInfo runInfo(textRun); | 74 TextRunPaintInfo runInfo(textRun); |
75 runInfo.bounds = backgroundRect; | 75 runInfo.bounds = backgroundRect; |
76 context->setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); | 76 context->setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); |
77 context->drawBidiText(font, runInfo, textRect.location() + FloatSize(0, font
.fontMetrics().ascent())); | 77 context->drawBidiText(font, runInfo, textRect.location() + FloatSize(0, font
.fontMetrics().ascent())); |
78 } | 78 } |
79 | 79 |
80 } // namespace blink | 80 } // namespace blink |
OLD | NEW |