Use is<>() / downcast<>() for RenderBox
[WebKit-https.git] / Source / WebCore / rendering / RenderEmbeddedObject.cpp
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 reserved.
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 "RenderEmbeddedObject.h"
26
27 #include "CSSValueKeywords.h"
28 #include "Chrome.h"
29 #include "ChromeClient.h"
30 #include "Cursor.h"
31 #include "EventHandler.h"
32 #include "Font.h"
33 #include "FontSelector.h"
34 #include "Frame.h"
35 #include "FrameLoaderClient.h"
36 #include "GraphicsContext.h"
37 #include "HTMLAppletElement.h"
38 #include "HTMLEmbedElement.h"
39 #include "HTMLIFrameElement.h"
40 #include "HTMLNames.h"
41 #include "HTMLObjectElement.h"
42 #include "HTMLParamElement.h"
43 #include "HTMLPlugInElement.h"
44 #include "HitTestResult.h"
45 #include "LocalizedStrings.h"
46 #include "MIMETypeRegistry.h"
47 #include "MouseEvent.h"
48 #include "Page.h"
49 #include "PaintInfo.h"
50 #include "Path.h"
51 #include "PlatformMouseEvent.h"
52 #include "PluginViewBase.h"
53 #include "RenderLayer.h"
54 #include "RenderTheme.h"
55 #include "RenderView.h"
56 #include "Settings.h"
57 #include "Text.h"
58 #include "TextRun.h"
59 #include <wtf/StackStats.h>
60
61 namespace WebCore {
62
63 using namespace HTMLNames;
64
65 static const float replacementTextRoundedRectHeight = 22;
66 static const float replacementTextRoundedRectLeftTextMargin = 10;
67 static const float replacementTextRoundedRectRightTextMargin = 10;
68 static const float replacementTextRoundedRectRightTextMarginWithArrow = 5;
69 static const float replacementTextRoundedRectTopTextMargin = -1;
70 static const float replacementTextRoundedRectRadius = 11;
71 static const float replacementArrowLeftMargin = -4;
72 static const float replacementArrowPadding = 4;
73 static const float replacementArrowCirclePadding = 3;
74
75 static const Color& replacementTextRoundedRectPressedColor()
76 {
77     static const Color pressed(105, 105, 105, 242);
78     return pressed;
79 }
80
81 static const Color& replacementTextRoundedRectColor()
82 {
83     static const Color standard(125, 125, 125, 242);
84     return standard;
85 }
86
87 static const Color& replacementTextColor()
88 {
89     static const Color standard(240, 240, 240, 255);
90     return standard;
91 }
92
93 static const Color& unavailablePluginBorderColor()
94 {
95     static const Color standard(255, 255, 255, 216);
96     return standard;
97 }
98
99 RenderEmbeddedObject::RenderEmbeddedObject(HTMLFrameOwnerElement& element, PassRef<RenderStyle> style)
100     : RenderWidget(element, WTF::move(style))
101     , m_isPluginUnavailable(false)
102     , m_isUnavailablePluginIndicatorHidden(false)
103     , m_unavailablePluginIndicatorIsPressed(false)
104     , m_mouseDownWasInUnavailablePluginIndicator(false)
105 {
106     // Actual size is not known yet, report the default intrinsic size.
107     view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
108 }
109
110 RenderEmbeddedObject::~RenderEmbeddedObject()
111 {
112     view().frameView().removeEmbeddedObjectToUpdate(*this);
113 }
114
115 RenderPtr<RenderEmbeddedObject> RenderEmbeddedObject::createForApplet(HTMLAppletElement& applet, PassRef<RenderStyle> style)
116 {
117     auto renderer = createRenderer<RenderEmbeddedObject>(applet, WTF::move(style));
118     renderer->setInline(true);
119     return renderer;
120 }
121
122 bool RenderEmbeddedObject::requiresLayer() const
123 {
124     if (RenderWidget::requiresLayer())
125         return true;
126     
127     return allowsAcceleratedCompositing();
128 }
129
130 bool RenderEmbeddedObject::allowsAcceleratedCompositing() const
131 {
132 #if PLATFORM(IOS)
133     // The timing of layer creation is different on the phone, since the plugin can only be manipulated from the main thread.
134     return is<PluginViewBase>(widget()) && downcast<PluginViewBase>(*widget()).willProvidePluginLayer();
135 #else
136     return is<PluginViewBase>(widget()) && downcast<PluginViewBase>(*widget()).platformLayer();
137 #endif
138 }
139
140 #if !PLATFORM(IOS)
141 static String unavailablePluginReplacementText(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason)
142 {
143     switch (pluginUnavailabilityReason) {
144     case RenderEmbeddedObject::PluginMissing:
145         return missingPluginText();
146     case RenderEmbeddedObject::PluginCrashed:
147         return crashedPluginText();
148     case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
149         return blockedPluginByContentSecurityPolicyText();
150     case RenderEmbeddedObject::InsecurePluginVersion:
151         return insecurePluginVersionText();
152     }
153
154     ASSERT_NOT_REACHED();
155     return String();
156 }
157 #endif
158
159 static bool shouldUnavailablePluginMessageBeButton(Document& document, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason)
160 {
161     Page* page = document.page();
162     return page && page->chrome().client().shouldUnavailablePluginMessageBeButton(pluginUnavailabilityReason);
163 }
164
165 void RenderEmbeddedObject::setPluginUnavailabilityReason(PluginUnavailabilityReason pluginUnavailabilityReason)
166 {
167 #if PLATFORM(IOS)
168     UNUSED_PARAM(pluginUnavailabilityReason);
169 #else
170     setPluginUnavailabilityReasonWithDescription(pluginUnavailabilityReason, unavailablePluginReplacementText(pluginUnavailabilityReason));
171 #endif
172 }
173
174 void RenderEmbeddedObject::setPluginUnavailabilityReasonWithDescription(PluginUnavailabilityReason pluginUnavailabilityReason, const String& description)
175 {
176 #if PLATFORM(IOS)
177     UNUSED_PARAM(pluginUnavailabilityReason);
178     UNUSED_PARAM(description);
179 #else
180     ASSERT(!m_isPluginUnavailable);
181     m_isPluginUnavailable = true;
182     m_pluginUnavailabilityReason = pluginUnavailabilityReason;
183
184     if (description.isEmpty())
185         m_unavailablePluginReplacementText = unavailablePluginReplacementText(pluginUnavailabilityReason);
186     else
187         m_unavailablePluginReplacementText = description;
188 #endif
189 }
190
191 void RenderEmbeddedObject::setUnavailablePluginIndicatorIsPressed(bool pressed)
192 {
193     if (m_unavailablePluginIndicatorIsPressed == pressed)
194         return;
195
196     m_unavailablePluginIndicatorIsPressed = pressed;
197     repaint();
198 }
199
200 void RenderEmbeddedObject::paintSnapshotImage(PaintInfo& paintInfo, const LayoutPoint& paintOffset, Image* image)
201 {
202     LayoutUnit cWidth = contentWidth();
203     LayoutUnit cHeight = contentHeight();
204     if (!cWidth || !cHeight)
205         return;
206
207     GraphicsContext* context = paintInfo.context;
208     LayoutSize contentSize(cWidth, cHeight);
209     LayoutPoint contentLocation = location() + paintOffset;
210     contentLocation.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
211
212     LayoutRect rect(contentLocation, contentSize);
213     IntRect alignedRect = snappedIntRect(rect);
214     if (alignedRect.width() <= 0 || alignedRect.height() <= 0)
215         return;
216
217     bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, alignedRect.size());
218     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
219 #if ENABLE(CSS_IMAGE_ORIENTATION)
220     orientationDescription.setImageOrientationEnum(style().imageOrientation());
221 #endif
222     context->drawImage(image, style().colorSpace(), alignedRect, ImagePaintingOptions(orientationDescription, useLowQualityScaling));
223 }
224
225 void RenderEmbeddedObject::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
226 {
227     if (!is<HTMLPlugInElement>(frameOwnerElement()))
228         return;
229
230     HTMLPlugInElement& plugInElement = downcast<HTMLPlugInElement>(frameOwnerElement());
231
232     if (plugInElement.displayState() > HTMLPlugInElement::DisplayingSnapshot) {
233         RenderWidget::paintContents(paintInfo, paintOffset);
234         if (!plugInElement.isRestartedPlugin())
235             return;
236     }
237
238     if (!is<HTMLPlugInImageElement>(plugInElement))
239         return;
240
241     if (Image* snapshot = downcast<HTMLPlugInImageElement>(plugInElement).snapshotImage())
242         paintSnapshotImage(paintInfo, paintOffset, snapshot);
243 }
244
245 void RenderEmbeddedObject::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
246 {
247     Page* page = frame().page();
248
249     if (isPluginUnavailable()) {
250         if (page && paintInfo.phase == PaintPhaseForeground)
251             page->addRelevantUnpaintedObject(this, visualOverflowRect());
252         RenderReplaced::paint(paintInfo, paintOffset);
253         return;
254     }
255
256     if (page && paintInfo.phase == PaintPhaseForeground)
257         page->addRelevantRepaintedObject(this, visualOverflowRect());
258
259     RenderWidget::paint(paintInfo, paintOffset);
260 }
261
262 static void drawReplacementArrow(GraphicsContext* context, const FloatRect& insideRect)
263 {
264     GraphicsContextStateSaver stateSaver(*context);
265
266     FloatRect rect(insideRect);
267     rect.inflate(-replacementArrowPadding);
268
269     FloatPoint center(rect.center());
270     FloatPoint arrowTip(rect.maxX(), center.y());
271
272     context->setStrokeThickness(2);
273     context->setLineCap(RoundCap);
274     context->setLineJoin(RoundJoin);
275
276     Path path;
277     path.moveTo(FloatPoint(rect.x(), center.y()));
278     path.addLineTo(arrowTip);
279     path.addLineTo(FloatPoint(center.x(), rect.y()));
280     path.moveTo(arrowTip);
281     path.addLineTo(FloatPoint(center.x(), rect.maxY()));
282     context->strokePath(path);
283 }
284
285 void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
286 {
287     if (!showsUnavailablePluginIndicator())
288         return;
289
290     if (paintInfo.phase == PaintPhaseSelection)
291         return;
292
293     GraphicsContext* context = paintInfo.context;
294     if (context->paintingDisabled())
295         return;
296
297     FloatRect contentRect;
298     FloatRect indicatorRect;
299     FloatRect replacementTextRect;
300     FloatRect arrowRect;
301     Font font;
302     TextRun run("");
303     float textWidth;
304     if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
305         return;
306
307     Path background;
308     background.addRoundedRect(indicatorRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
309
310     GraphicsContextStateSaver stateSaver(*context);
311     context->clip(contentRect);
312     context->setFillColor(m_unavailablePluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : replacementTextRoundedRectColor(), style().colorSpace());
313     context->fillPath(background);
314
315     Path strokePath;
316     FloatRect strokeRect(indicatorRect);
317     strokeRect.inflate(1);
318     strokePath.addRoundedRect(strokeRect, FloatSize(replacementTextRoundedRectRadius + 1, replacementTextRoundedRectRadius + 1));
319
320     context->setStrokeColor(unavailablePluginBorderColor(), style().colorSpace());
321     context->setStrokeThickness(2);
322     context->strokePath(strokePath);
323
324     const FontMetrics& fontMetrics = font.fontMetrics();
325     float labelX = roundf(replacementTextRect.location().x() + replacementTextRoundedRectLeftTextMargin);
326     float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent() + replacementTextRoundedRectTopTextMargin);
327     context->setFillColor(replacementTextColor(), style().colorSpace());
328     context->drawBidiText(font, run, FloatPoint(labelX, labelY));
329
330     if (shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason)) {
331         arrowRect.inflate(-replacementArrowCirclePadding);
332
333         context->beginTransparencyLayer(1.0);
334         context->setFillColor(replacementTextColor(), style().colorSpace());
335         context->fillEllipse(arrowRect);
336
337         context->setCompositeOperation(CompositeClear);
338         drawReplacementArrow(context, arrowRect);
339         context->endTransparencyLayer();
340     }
341 }
342
343 void RenderEmbeddedObject::setUnavailablePluginIndicatorIsHidden(bool hidden)
344 {
345     m_isUnavailablePluginIndicatorHidden = hidden;
346
347     repaint();
348 }
349
350 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font& font, TextRun& run, float& textWidth) const
351 {
352     bool includesArrow = shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason);
353
354     contentRect = contentBoxRect();
355     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
356
357     FontDescription fontDescription;
358     RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription);
359     fontDescription.setWeight(FontWeightBold);
360     fontDescription.setRenderingMode(frame().settings().fontRenderingMode());
361     fontDescription.setComputedSize(12);
362     font = Font(fontDescription, 0, 0);
363     font.update(0);
364
365     run = TextRun(m_unavailablePluginReplacementText);
366     textWidth = font.width(run);
367
368     replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRectLeftTextMargin + (includesArrow ? replacementTextRoundedRectRightTextMarginWithArrow : replacementTextRoundedRectRightTextMargin), replacementTextRoundedRectHeight));
369     float x = (contentRect.size().width() / 2 - replacementTextRect.size().width() / 2) + contentRect.location().x();
370     float y = (contentRect.size().height() / 2 - replacementTextRect.size().height() / 2) + contentRect.location().y();
371     replacementTextRect.setLocation(FloatPoint(x, y));
372
373     indicatorRect = replacementTextRect;
374
375     // Expand the background rect to include the arrow, if it will be used.
376     if (includesArrow) {
377         arrowRect = indicatorRect;
378         arrowRect.setX(ceilf(arrowRect.maxX() + replacementArrowLeftMargin));
379         arrowRect.setWidth(arrowRect.height());
380         indicatorRect.unite(arrowRect);
381     }
382
383     return true;
384 }
385
386 LayoutRect RenderEmbeddedObject::unavailablePluginIndicatorBounds(const LayoutPoint& accumulatedOffset) const
387 {
388     FloatRect contentRect;
389     FloatRect indicatorRect;
390     FloatRect replacementTextRect;
391     FloatRect arrowRect;
392     Font font;
393     TextRun run("", 0);
394     float textWidth;
395     if (getReplacementTextGeometry(accumulatedOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
396         return LayoutRect(indicatorRect);
397
398     return LayoutRect();
399 }
400
401 bool RenderEmbeddedObject::isReplacementObscured() const
402 {
403     // Return whether or not the replacement content for blocked plugins is accessible to the user.
404
405     // Check the opacity of each layer containing the element or its ancestors.
406     float opacity = 1.0;
407     for (RenderLayer* layer = enclosingLayer(); layer; layer = layer->parent()) {
408         opacity *= layer->renderer().style().opacity();
409         if (opacity < 0.1)
410             return true;
411     }
412
413     // Calculate the absolute rect for the blocked plugin replacement text.
414     IntRect absoluteBoundingBox = absoluteBoundingBoxRect();
415     LayoutPoint absoluteLocation(absoluteBoundingBox.location());
416     LayoutRect rect = unavailablePluginIndicatorBounds(absoluteLocation);
417     if (rect.isEmpty())
418         return true;
419
420     RenderView* rootRenderView = document().topDocument().renderView();
421     ASSERT(rootRenderView);
422     if (!rootRenderView)
423         return true;
424
425     IntRect rootViewRect = view().frameView().convertToRootView(snappedIntRect(rect));
426     
427     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent | HitTestRequest::AllowChildFrameContent);
428     HitTestResult result;
429     HitTestLocation location;
430     
431     LayoutUnit x = rootViewRect.x();
432     LayoutUnit y = rootViewRect.y();
433     LayoutUnit width = rootViewRect.width();
434     LayoutUnit height = rootViewRect.height();
435     
436     // Hit test the center and near the corners of the replacement text to ensure
437     // it is visible and is not masked by other elements.
438     bool hit = false;
439     location = LayoutPoint(x + width / 2, y + height / 2);
440     hit = rootRenderView->hitTest(request, location, result);
441     if (!hit || result.innerNode() != &frameOwnerElement())
442         return true;
443     
444     location = LayoutPoint(x, y);
445     hit = rootRenderView->hitTest(request, location, result);
446     if (!hit || result.innerNode() != &frameOwnerElement())
447         return true;
448     
449     location = LayoutPoint(x + width, y);
450     hit = rootRenderView->hitTest(request, location, result);
451     if (!hit || result.innerNode() != &frameOwnerElement())
452         return true;
453     
454     location = LayoutPoint(x + width, y + height);
455     hit = rootRenderView->hitTest(request, location, result);
456     if (!hit || result.innerNode() != &frameOwnerElement())
457         return true;
458     
459     location = LayoutPoint(x, y + height);
460     hit = rootRenderView->hitTest(request, location, result);
461     if (!hit || result.innerNode() != &frameOwnerElement())
462         return true;
463
464     return false;
465 }
466
467 void RenderEmbeddedObject::layout()
468 {
469     StackStats::LayoutCheckPoint layoutCheckPoint;
470     ASSERT(needsLayout());
471
472     LayoutSize oldSize = contentBoxRect().size();
473
474     updateLogicalWidth();
475     updateLogicalHeight();
476
477     RenderWidget::layout();
478
479     clearOverflow();
480     addVisualEffectOverflow();
481
482     updateLayerTransform();
483
484     bool wasMissingWidget = false;
485     if (!widget() && canHaveWidget()) {
486         wasMissingWidget = true;
487         view().frameView().addEmbeddedObjectToUpdate(*this);
488     }
489
490     clearNeedsLayout();
491
492     LayoutSize newSize = contentBoxRect().size();
493
494     if (!wasMissingWidget && newSize.width() >= oldSize.width() && newSize.height() >= oldSize.height()) {
495         HTMLFrameOwnerElement& element = frameOwnerElement();
496         if (is<HTMLPlugInImageElement>(element)) {
497             HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(element);
498             if (plugInImageElement.displayState() > HTMLPlugInElement::DisplayingSnapshot && plugInImageElement.snapshotDecision() == HTMLPlugInImageElement::MaySnapshotWhenResized) {
499                 plugInImageElement.setNeedsCheckForSizeChange();
500                 view().frameView().addEmbeddedObjectToUpdate(*this);
501             }
502         }
503     }
504
505     if (!canHaveChildren())
506         return;
507
508     // This code copied from RenderMedia::layout().
509     RenderObject* child = firstChild();
510
511     if (!child)
512         return;
513
514     auto& childBox = downcast<RenderBox>(*child);
515
516     if (newSize == oldSize && !childBox.needsLayout())
517         return;
518     
519     // When calling layout() on a child node, a parent must either push a LayoutStateMaintainter, or
520     // instantiate LayoutStateDisabler. Since using a LayoutStateMaintainer is slightly more efficient,
521     // and this method will be called many times per second during playback, use a LayoutStateMaintainer:
522     LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
523     
524     childBox.setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
525     childBox.style().setHeight(Length(newSize.height(), Fixed));
526     childBox.style().setWidth(Length(newSize.width(), Fixed));
527     childBox.setNeedsLayout(MarkOnlyThis);
528     childBox.layout();
529     clearChildNeedsLayout();
530     
531     statePusher.pop();
532 }
533
534 bool RenderEmbeddedObject::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
535 {
536     if (!RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction))
537         return false;
538
539     if (!is<PluginViewBase>(widget()))
540         return true;
541
542     PluginViewBase& view = downcast<PluginViewBase>(*widget());
543     IntPoint roundedPoint = locationInContainer.roundedPoint();
544
545     if (Scrollbar* horizontalScrollbar = view.horizontalScrollbar()) {
546         if (horizontalScrollbar->shouldParticipateInHitTesting() && horizontalScrollbar->frameRect().contains(roundedPoint)) {
547             result.setScrollbar(horizontalScrollbar);
548             return true;
549         }
550     }
551
552     if (Scrollbar* verticalScrollbar = view.verticalScrollbar()) {
553         if (verticalScrollbar->shouldParticipateInHitTesting() && verticalScrollbar->frameRect().contains(roundedPoint)) {
554             result.setScrollbar(verticalScrollbar);
555             return true;
556         }
557     }
558
559     return true;
560 }
561
562 bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Element**, RenderBox*, const IntPoint&)
563 {
564     if (!is<PluginViewBase>(widget()))
565         return false;
566
567     return downcast<PluginViewBase>(*widget()).scroll(direction, granularity);
568 }
569
570 bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
571 {
572     // Plugins don't expose a writing direction, so assuming horizontal LTR.
573     return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopElement);
574 }
575
576
577 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const FloatPoint& point) const
578 {
579     FloatRect contentRect;
580     FloatRect indicatorRect;
581     FloatRect replacementTextRect;
582     FloatRect arrowRect;
583     Font font;
584     TextRun run("");
585     float textWidth;
586     return getReplacementTextGeometry(IntPoint(), contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth)
587         && indicatorRect.contains(point);
588 }
589
590 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const MouseEvent& event) const
591 {
592     return isInUnavailablePluginIndicator(absoluteToLocal(event.absoluteLocation(), UseTransforms));
593 }
594
595 void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
596 {
597     if (!shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason))
598         return;
599
600     if (!is<MouseEvent>(*event))
601         return;
602
603     MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
604     HTMLPlugInElement& element = downcast<HTMLPlugInElement>(frameOwnerElement());
605     if (mouseEvent.type() == eventNames().mousedownEvent && mouseEvent.button() == LeftButton) {
606         m_mouseDownWasInUnavailablePluginIndicator = isInUnavailablePluginIndicator(mouseEvent);
607         if (m_mouseDownWasInUnavailablePluginIndicator) {
608             frame().eventHandler().setCapturingMouseEventsElement(&element);
609             element.setIsCapturingMouseEvents(true);
610             setUnavailablePluginIndicatorIsPressed(true);
611         }
612         mouseEvent.setDefaultHandled();
613     }
614     if (mouseEvent.type() == eventNames().mouseupEvent && mouseEvent.button() == LeftButton) {
615         if (m_unavailablePluginIndicatorIsPressed) {
616             frame().eventHandler().setCapturingMouseEventsElement(nullptr);
617             element.setIsCapturingMouseEvents(false);
618             setUnavailablePluginIndicatorIsPressed(false);
619         }
620         if (m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent)) {
621             if (Page* page = document().page())
622                 page->chrome().client().unavailablePluginButtonClicked(&element, m_pluginUnavailabilityReason);
623         }
624         m_mouseDownWasInUnavailablePluginIndicator = false;
625         event->setDefaultHandled();
626     }
627     if (mouseEvent.type() == eventNames().mousemoveEvent) {
628         setUnavailablePluginIndicatorIsPressed(m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent));
629         mouseEvent.setDefaultHandled();
630     }
631 }
632
633 CursorDirective RenderEmbeddedObject::getCursor(const LayoutPoint& point, Cursor& cursor) const
634 {
635     if (showsUnavailablePluginIndicator() && shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason) && isInUnavailablePluginIndicator(point)) {
636         cursor = handCursor();
637         return SetCursor;
638     }
639     if (widget() && widget()->isPluginViewBase()) {
640         // A plug-in is responsible for setting the cursor when the pointer is over it.
641         return DoNotSetCursor;
642     }
643     return RenderWidget::getCursor(point, cursor);
644 }
645
646 bool RenderEmbeddedObject::canHaveChildren() const
647 {
648     if (isSnapshottedPlugIn())
649         return true;
650
651     return false;
652 }
653
654 }