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: third_party/WebKit/Source/core/paint/EmbeddedObjectPainter.cpp

Issue 2416033003: Remove unsafe getFontMetrics methods (Closed)
Patch Set: Address wkroman suggestions Created 4 years, 2 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
OLDNEW
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 "core/paint/EmbeddedObjectPainter.h" 5 #include "core/paint/EmbeddedObjectPainter.h"
6 6
7 #include "core/frame/Settings.h" 7 #include "core/frame/Settings.h"
8 #include "core/layout/LayoutEmbeddedObject.h" 8 #include "core/layout/LayoutEmbeddedObject.h"
9 #include "core/layout/LayoutTheme.h" 9 #include "core/layout/LayoutTheme.h"
10 #include "core/paint/LayoutObjectDrawingRecorder.h" 10 #include "core/paint/LayoutObjectDrawingRecorder.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return; 47 return;
48 48
49 LayoutRect contentRect(m_layoutEmbeddedObject.contentBoxRect()); 49 LayoutRect contentRect(m_layoutEmbeddedObject.contentBoxRect());
50 contentRect.moveBy(paintOffset); 50 contentRect.moveBy(paintOffset);
51 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutEmbeddedObject, 51 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutEmbeddedObject,
52 paintInfo.phase, contentRect); 52 paintInfo.phase, contentRect);
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 const SimpleFontData* fontData = font.primaryFont();
58 // With last resort font, how could this ever be null? 58 DCHECK(fontData);
59 ASSERT(font.primaryFont()); 59 if (!fontData)
60 if (!font.primaryFont())
61 return; 60 return;
61
62 TextRun textRun(m_layoutEmbeddedObject.unavailablePluginReplacementText()); 62 TextRun textRun(m_layoutEmbeddedObject.unavailablePluginReplacementText());
63 FloatSize textGeometry(font.width(textRun), font.getFontMetrics().height()); 63 FloatSize textGeometry(font.width(textRun),
64 fontData->getFontMetrics().height());
64 65
65 LayoutRect backgroundRect( 66 LayoutRect backgroundRect(
66 0, 0, 67 0, 0,
67 textGeometry.width() + 2 * replacementTextRoundedRectLeftRightTextMargin, 68 textGeometry.width() + 2 * replacementTextRoundedRectLeftRightTextMargin,
68 replacementTextRoundedRectHeight); 69 replacementTextRoundedRectHeight);
69 backgroundRect.move(contentRect.center() - backgroundRect.center()); 70 backgroundRect.move(contentRect.center() - backgroundRect.center());
70 backgroundRect = LayoutRect(pixelSnappedIntRect(backgroundRect)); 71 backgroundRect = LayoutRect(pixelSnappedIntRect(backgroundRect));
71 Path roundedBackgroundRect; 72 Path roundedBackgroundRect;
72 FloatRect floatBackgroundRect(backgroundRect); 73 FloatRect floatBackgroundRect(backgroundRect);
73 roundedBackgroundRect.addRoundedRect( 74 roundedBackgroundRect.addRoundedRect(
74 floatBackgroundRect, FloatSize(replacementTextRoundedRectRadius, 75 floatBackgroundRect, FloatSize(replacementTextRoundedRectRadius,
75 replacementTextRoundedRectRadius)); 76 replacementTextRoundedRectRadius));
76 context.setFillColor( 77 context.setFillColor(
77 scaleAlpha(Color::white, replacementTextRoundedRectOpacity)); 78 scaleAlpha(Color::white, replacementTextRoundedRectOpacity));
78 context.fillPath(roundedBackgroundRect); 79 context.fillPath(roundedBackgroundRect);
79 80
80 FloatRect textRect(FloatPoint(), textGeometry); 81 FloatRect textRect(FloatPoint(), textGeometry);
81 textRect.move(FloatPoint(contentRect.center()) - textRect.center()); 82 textRect.move(FloatPoint(contentRect.center()) - textRect.center());
82 TextRunPaintInfo runInfo(textRun); 83 TextRunPaintInfo runInfo(textRun);
83 runInfo.bounds = floatBackgroundRect; 84 runInfo.bounds = floatBackgroundRect;
84 context.setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); 85 context.setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity));
85 context.drawBidiText( 86 context.drawBidiText(
86 font, runInfo, 87 font, runInfo,
87 textRect.location() + FloatSize(0, font.getFontMetrics().ascent())); 88 textRect.location() + FloatSize(0, fontData->getFontMetrics().ascent()));
88 } 89 }
89 90
90 } // namespace blink 91 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698