OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | |
3 * (C) 2000 Simon Hausmann <hausmann@kde.org> | |
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) | |
5 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | |
6 * | |
7 * This library is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Library General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2 of the License, or (at your option) any later version. | |
11 * | |
12 * This library is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Library General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Library General Public License | |
18 * along with this library; see the file COPYING.LIB. If not, write to | |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 * Boston, MA 02110-1301, USA. | |
21 * | |
22 */ | |
23 | |
24 #include "config.h" | |
25 #include "core/rendering/RenderEmbeddedObject.h" | |
26 | |
27 #include "core/CSSValueKeywords.h" | |
28 #include "core/HTMLNames.h" | |
29 #include "core/frame/LocalFrame.h" | |
30 #include "core/frame/Settings.h" | |
31 #include "core/html/HTMLIFrameElement.h" | |
32 #include "core/html/HTMLPlugInElement.h" | |
33 #include "core/layout/LayoutTheme.h" | |
34 #include "core/layout/PaintInfo.h" | |
35 #include "core/page/Page.h" | |
36 #include "core/plugins/PluginView.h" | |
37 #include "core/rendering/RenderView.h" | |
38 #include "platform/fonts/Font.h" | |
39 #include "platform/fonts/FontSelector.h" | |
40 #include "platform/graphics/GraphicsContextStateSaver.h" | |
41 #include "platform/graphics/Path.h" | |
42 #include "platform/text/PlatformLocale.h" | |
43 #include "platform/text/TextRun.h" | |
44 | |
45 namespace blink { | |
46 | |
47 using namespace HTMLNames; | |
48 | |
49 static const float replacementTextRoundedRectHeight = 18; | |
50 static const float replacementTextRoundedRectLeftRightTextMargin = 6; | |
51 static const float replacementTextRoundedRectOpacity = 0.20f; | |
52 static const float replacementTextRoundedRectRadius = 5; | |
53 static const float replacementTextTextOpacity = 0.55f; | |
54 | |
55 RenderEmbeddedObject::RenderEmbeddedObject(Element* element) | |
56 : LayoutPart(element) | |
57 , m_showsUnavailablePluginIndicator(false) | |
58 { | |
59 view()->frameView()->setIsVisuallyNonEmpty(); | |
60 } | |
61 | |
62 RenderEmbeddedObject::~RenderEmbeddedObject() | |
63 { | |
64 } | |
65 | |
66 LayerType RenderEmbeddedObject::layerTypeRequired() const | |
67 { | |
68 // This can't just use LayoutPart::layerTypeRequired, because LayerComposito
r | |
69 // doesn't loop through RenderEmbeddedObjects the way it does frames in orde
r | |
70 // to update the self painting bit on their Layer. | |
71 // Also, unlike iframes, embeds don't used the usesCompositing bit on Render
View | |
72 // in requiresAcceleratedCompositing. | |
73 if (requiresAcceleratedCompositing()) | |
74 return NormalLayer; | |
75 return LayoutPart::layerTypeRequired(); | |
76 } | |
77 | |
78 static String unavailablePluginReplacementText(Node* node, RenderEmbeddedObject:
:PluginUnavailabilityReason pluginUnavailabilityReason) | |
79 { | |
80 Locale& locale = node ? toElement(node)->locale() : Locale::defaultLocale(); | |
81 switch (pluginUnavailabilityReason) { | |
82 case RenderEmbeddedObject::PluginMissing: | |
83 return locale.queryString(WebLocalizedString::MissingPluginText); | |
84 case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy: | |
85 return locale.queryString(WebLocalizedString::BlockedPluginText); | |
86 } | |
87 | |
88 ASSERT_NOT_REACHED(); | |
89 return String(); | |
90 } | |
91 | |
92 void RenderEmbeddedObject::setPluginUnavailabilityReason(PluginUnavailabilityRea
son pluginUnavailabilityReason) | |
93 { | |
94 ASSERT(!m_showsUnavailablePluginIndicator); | |
95 m_showsUnavailablePluginIndicator = true; | |
96 m_pluginUnavailabilityReason = pluginUnavailabilityReason; | |
97 | |
98 m_unavailablePluginReplacementText = unavailablePluginReplacementText(node()
, pluginUnavailabilityReason); | |
99 } | |
100 | |
101 bool RenderEmbeddedObject::showsUnavailablePluginIndicator() const | |
102 { | |
103 return m_showsUnavailablePluginIndicator; | |
104 } | |
105 | |
106 void RenderEmbeddedObject::paintContents(const PaintInfo& paintInfo, const Layou
tPoint& paintOffset) | |
107 { | |
108 Element* element = toElement(node()); | |
109 if (!isHTMLPlugInElement(element)) | |
110 return; | |
111 | |
112 LayoutPart::paintContents(paintInfo, paintOffset); | |
113 } | |
114 | |
115 void RenderEmbeddedObject::paint(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | |
116 { | |
117 if (showsUnavailablePluginIndicator()) { | |
118 LayoutReplaced::paint(paintInfo, paintOffset); | |
119 return; | |
120 } | |
121 | |
122 LayoutPart::paint(paintInfo, paintOffset); | |
123 } | |
124 | |
125 void RenderEmbeddedObject::paintReplaced(const PaintInfo& paintInfo, const Layou
tPoint& paintOffset) | |
126 { | |
127 if (!showsUnavailablePluginIndicator()) | |
128 return; | |
129 | |
130 if (paintInfo.phase == PaintPhaseSelection) | |
131 return; | |
132 | |
133 FloatRect contentRect; | |
134 Path path; | |
135 FloatRect replacementTextRect; | |
136 Font font; | |
137 TextRun run(""); | |
138 float textWidth; | |
139 if (!getReplacementTextGeometry(paintOffset, contentRect, path, replacementT
extRect, font, run, textWidth)) | |
140 return; | |
141 | |
142 GraphicsContext* context = paintInfo.context; | |
143 GraphicsContextStateSaver stateSaver(*context); | |
144 context->clip(contentRect); | |
145 context->setFillColor(scaleAlpha(Color::white, replacementTextRoundedRectOpa
city)); | |
146 context->fillPath(path); | |
147 | |
148 const FontMetrics& fontMetrics = font.fontMetrics(); | |
149 float labelX = roundf(replacementTextRect.location().x() + (replacementTextR
ect.size().width() - textWidth) / 2); | |
150 float labelY = roundf(replacementTextRect.location().y() + (replacementTextR
ect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent()); | |
151 TextRunPaintInfo runInfo(run); | |
152 runInfo.bounds = replacementTextRect; | |
153 context->setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); | |
154 context->drawBidiText(font, runInfo, FloatPoint(labelX, labelY)); | |
155 } | |
156 | |
157 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumul
atedOffset, FloatRect& contentRect, Path& path, FloatRect& replacementTextRect,
Font& font, TextRun& run, float& textWidth) const | |
158 { | |
159 contentRect = contentBoxRect(); | |
160 contentRect.moveBy(roundedIntPoint(accumulatedOffset)); | |
161 | |
162 FontDescription fontDescription; | |
163 LayoutTheme::theme().systemFont(CSSValueWebkitSmallControl, fontDescription)
; | |
164 fontDescription.setWeight(FontWeightBold); | |
165 Settings* settings = document().settings(); | |
166 ASSERT(settings); | |
167 if (!settings) | |
168 return false; | |
169 fontDescription.setComputedSize(fontDescription.specifiedSize()); | |
170 font = Font(fontDescription); | |
171 font.update(nullptr); | |
172 | |
173 run = TextRun(m_unavailablePluginReplacementText); | |
174 textWidth = font.width(run); | |
175 | |
176 replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRect
LeftRightTextMargin * 2, replacementTextRoundedRectHeight)); | |
177 float x = (contentRect.size().width() / 2 - replacementTextRect.size().width
() / 2) + contentRect.location().x(); | |
178 float y = (contentRect.size().height() / 2 - replacementTextRect.size().heig
ht() / 2) + contentRect.location().y(); | |
179 replacementTextRect.setLocation(FloatPoint(x, y)); | |
180 | |
181 path.addRoundedRect(replacementTextRect, FloatSize(replacementTextRoundedRec
tRadius, replacementTextRoundedRectRadius)); | |
182 | |
183 return true; | |
184 } | |
185 | |
186 void RenderEmbeddedObject::layout() | |
187 { | |
188 ASSERT(needsLayout()); | |
189 | |
190 updateLogicalWidth(); | |
191 updateLogicalHeight(); | |
192 | |
193 m_overflow.clear(); | |
194 addVisualEffectOverflow(); | |
195 | |
196 updateLayerTransformAfterLayout(); | |
197 | |
198 if (!widget() && frameView()) | |
199 frameView()->addPartToUpdate(*this); | |
200 | |
201 clearNeedsLayout(); | |
202 } | |
203 | |
204 bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity g
ranularity, float) | |
205 { | |
206 return false; | |
207 } | |
208 | |
209 CompositingReasons RenderEmbeddedObject::additionalCompositingReasons() const | |
210 { | |
211 if (requiresAcceleratedCompositing()) | |
212 return CompositingReasonPlugin; | |
213 return CompositingReasonNone; | |
214 } | |
215 | |
216 RenderBox* RenderEmbeddedObject::embeddedContentBox() const | |
217 { | |
218 if (!node() || !widget() || !widget()->isFrameView()) | |
219 return 0; | |
220 return toFrameView(widget())->embeddedContentBox(); | |
221 } | |
222 | |
223 } // namespace blink | |
OLD | NEW |