Issue repaint at setUnavailablePluginIndicatorIsHidden() only when embedded object...
[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     if (m_isUnavailablePluginIndicatorHidden == hidden)
346         return;
347
348     m_isUnavailablePluginIndicatorHidden = hidden;
349     repaint();
350 }
351
352 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font& font, TextRun& run, float& textWidth) const
353 {
354     bool includesArrow = shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason);
355
356     contentRect = contentBoxRect();
357     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
358
359     FontDescription fontDescription;
360     RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription);
361     fontDescription.setWeight(FontWeightBold);
362     fontDescription.setRenderingMode(frame().settings().fontRenderingMode());
363     fontDescription.setComputedSize(12);
364     font = Font(fontDescription, 0, 0);
365     font.update(0);
366
367     run = TextRun(m_unavailablePluginReplacementText);
368     textWidth = font.width(run);
369
370     replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRectLeftTextMargin + (includesArrow ? replacementTextRoundedRectRightTextMarginWithArrow : replacementTextRoundedRectRightTextMargin), replacementTextRoundedRectHeight));
371     float x = (contentRect.size().width() / 2 - replacementTextRect.size().width() / 2) + contentRect.location().x();
372     float y = (contentRect.size().height() / 2 - replacementTextRect.size().height() / 2) + contentRect.location().y();
373     replacementTextRect.setLocation(FloatPoint(x, y));
374
375     indicatorRect = replacementTextRect;
376
377     // Expand the background rect to include the arrow, if it will be used.
378     if (includesArrow) {
379         arrowRect = indicatorRect;
380         arrowRect.setX(ceilf(arrowRect.maxX() + replacementArrowLeftMargin));
381         arrowRect.setWidth(arrowRect.height());
382         indicatorRect.unite(arrowRect);
383     }
384
385     return true;
386 }
387
388 LayoutRect RenderEmbeddedObject::unavailablePluginIndicatorBounds(const LayoutPoint& accumulatedOffset) const
389 {
390     FloatRect contentRect;
391     FloatRect indicatorRect;
392     FloatRect replacementTextRect;
393     FloatRect arrowRect;
394     Font font;
395     TextRun run("", 0);
396     float textWidth;
397     if (getReplacementTextGeometry(accumulatedOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
398         return LayoutRect(indicatorRect);
399
400     return LayoutRect();
401 }
402
403 bool RenderEmbeddedObject::isReplacementObscured() const
404 {
405     // Return whether or not the replacement content for blocked plugins is accessible to the user.
406
407     // Check the opacity of each layer containing the element or its ancestors.
408     float opacity = 1.0;
409     for (RenderLayer* layer = enclosingLayer(); layer; layer = layer->parent()) {
410         opacity *= layer->renderer().style().opacity();
411         if (opacity < 0.1)
412             return true;
413     }
414
415     // Calculate the absolute rect for the blocked plugin replacement text.
416     IntRect absoluteBoundingBox = absoluteBoundingBoxRect();
417     LayoutPoint absoluteLocation(absoluteBoundingBox.location());
418     LayoutRect rect = unavailablePluginIndicatorBounds(absoluteLocation);
419     if (rect.isEmpty())
420         return true;
421
422     RenderView* rootRenderView = document().topDocument().renderView();
423     ASSERT(rootRenderView);
424     if (!rootRenderView)
425         return true;
426
427     IntRect rootViewRect = view().frameView().convertToRootView(snappedIntRect(rect));
428     
429     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent | HitTestRequest::AllowChildFrameContent);
430     HitTestResult result;
431     HitTestLocation location;
432     
433     LayoutUnit x = rootViewRect.x();
434     LayoutUnit y = rootViewRect.y();
435     LayoutUnit width = rootViewRect.width();
436     LayoutUnit height = rootViewRect.height();
437     
438     // Hit test the center and near the corners of the replacement text to ensure
439     // it is visible and is not masked by other elements.
440     bool hit = false;
441     location = LayoutPoint(x + width / 2, y + height / 2);
442     hit = rootRenderView->hitTest(request, location, result);
443     if (!hit || result.innerNode() != &frameOwnerElement())
444         return true;
445     
446     location = LayoutPoint(x, y);
447     hit = rootRenderView->hitTest(request, location, result);
448     if (!hit || result.innerNode() != &frameOwnerElement())
449         return true;
450     
451     location = LayoutPoint(x + width, y);
452     hit = rootRenderView->hitTest(request, location, result);
453     if (!hit || result.innerNode() != &frameOwnerElement())
454         return true;
455     
456     location = LayoutPoint(x + width, y + height);
457     hit = rootRenderView->hitTest(request, location, result);
458     if (!hit || result.innerNode() != &frameOwnerElement())
459         return true;
460     
461     location = LayoutPoint(x, y + height);
462     hit = rootRenderView->hitTest(request, location, result);
463     if (!hit || result.innerNode() != &frameOwnerElement())
464         return true;
465
466     return false;
467 }
468
469 void RenderEmbeddedObject::layout()
470 {
471     StackStats::LayoutCheckPoint layoutCheckPoint;
472     ASSERT(needsLayout());
473
474     LayoutSize oldSize = contentBoxRect().size();
475
476     updateLogicalWidth();
477     updateLogicalHeight();
478
479     RenderWidget::layout();
480
481     clearOverflow();
482     addVisualEffectOverflow();
483
484     updateLayerTransform();
485
486     bool wasMissingWidget = false;
487     if (!widget() && canHaveWidget()) {
488         wasMissingWidget = true;
489         view().frameView().addEmbeddedObjectToUpdate(*this);
490     }
491
492     clearNeedsLayout();
493
494     LayoutSize newSize = contentBoxRect().size();
495
496     if (!wasMissingWidget && newSize.width() >= oldSize.width() && newSize.height() >= oldSize.height()) {
497         HTMLFrameOwnerElement& element = frameOwnerElement();
498         if (is<HTMLPlugInImageElement>(element)) {
499             HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(element);
500             if (plugInImageElement.displayState() > HTMLPlugInElement::DisplayingSnapshot && plugInImageElement.snapshotDecision() == HTMLPlugInImageElement::MaySnapshotWhenResized) {
501                 plugInImageElement.setNeedsCheckForSizeChange();
502                 view().frameView().addEmbeddedObjectToUpdate(*this);
503             }
504         }
505     }
506
507     if (!canHaveChildren())
508         return;
509
510     // This code copied from RenderMedia::layout().
511     RenderObject* child = firstChild();
512
513     if (!child)
514         return;
515
516     auto& childBox = downcast<RenderBox>(*child);
517
518     if (newSize == oldSize && !childBox.needsLayout())
519         return;
520     
521     // When calling layout() on a child node, a parent must either push a LayoutStateMaintainter, or
522     // instantiate LayoutStateDisabler. Since using a LayoutStateMaintainer is slightly more efficient,
523     // and this method will be called many times per second during playback, use a LayoutStateMaintainer:
524     LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
525     
526     childBox.setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
527     childBox.style().setHeight(Length(newSize.height(), Fixed));
528     childBox.style().setWidth(Length(newSize.width(), Fixed));
529     childBox.setNeedsLayout(MarkOnlyThis);
530     childBox.layout();
531     clearChildNeedsLayout();
532     
533     statePusher.pop();
534 }
535
536 bool RenderEmbeddedObject::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
537 {
538     if (!RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction))
539         return false;
540
541     if (!is<PluginViewBase>(widget()))
542         return true;
543
544     PluginViewBase& view = downcast<PluginViewBase>(*widget());
545     IntPoint roundedPoint = locationInContainer.roundedPoint();
546
547     if (Scrollbar* horizontalScrollbar = view.horizontalScrollbar()) {
548         if (horizontalScrollbar->shouldParticipateInHitTesting() && horizontalScrollbar->frameRect().contains(roundedPoint)) {
549             result.setScrollbar(horizontalScrollbar);
550             return true;
551         }
552     }
553
554     if (Scrollbar* verticalScrollbar = view.verticalScrollbar()) {
555         if (verticalScrollbar->shouldParticipateInHitTesting() && verticalScrollbar->frameRect().contains(roundedPoint)) {
556             result.setScrollbar(verticalScrollbar);
557             return true;
558         }
559     }
560
561     return true;
562 }
563
564 bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Element**, RenderBox*, const IntPoint&)
565 {
566     if (!is<PluginViewBase>(widget()))
567         return false;
568
569     return downcast<PluginViewBase>(*widget()).scroll(direction, granularity);
570 }
571
572 bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
573 {
574     // Plugins don't expose a writing direction, so assuming horizontal LTR.
575     return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopElement);
576 }
577
578
579 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const FloatPoint& point) const
580 {
581     FloatRect contentRect;
582     FloatRect indicatorRect;
583     FloatRect replacementTextRect;
584     FloatRect arrowRect;
585     Font font;
586     TextRun run("");
587     float textWidth;
588     return getReplacementTextGeometry(IntPoint(), contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth)
589         && indicatorRect.contains(point);
590 }
591
592 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const MouseEvent& event) const
593 {
594     return isInUnavailablePluginIndicator(absoluteToLocal(event.absoluteLocation(), UseTransforms));
595 }
596
597 void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
598 {
599     if (!shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason))
600         return;
601
602     if (!is<MouseEvent>(*event))
603         return;
604
605     MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
606     HTMLPlugInElement& element = downcast<HTMLPlugInElement>(frameOwnerElement());
607     if (mouseEvent.type() == eventNames().mousedownEvent && mouseEvent.button() == LeftButton) {
608         m_mouseDownWasInUnavailablePluginIndicator = isInUnavailablePluginIndicator(mouseEvent);
609         if (m_mouseDownWasInUnavailablePluginIndicator) {
610             frame().eventHandler().setCapturingMouseEventsElement(&element);
611             element.setIsCapturingMouseEvents(true);
612             setUnavailablePluginIndicatorIsPressed(true);
613         }
614         mouseEvent.setDefaultHandled();
615     }
616     if (mouseEvent.type() == eventNames().mouseupEvent && mouseEvent.button() == LeftButton) {
617         if (m_unavailablePluginIndicatorIsPressed) {
618             frame().eventHandler().setCapturingMouseEventsElement(nullptr);
619             element.setIsCapturingMouseEvents(false);
620             setUnavailablePluginIndicatorIsPressed(false);
621         }
622         if (m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent)) {
623             if (Page* page = document().page())
624                 page->chrome().client().unavailablePluginButtonClicked(&element, m_pluginUnavailabilityReason);
625         }
626         m_mouseDownWasInUnavailablePluginIndicator = false;
627         event->setDefaultHandled();
628     }
629     if (mouseEvent.type() == eventNames().mousemoveEvent) {
630         setUnavailablePluginIndicatorIsPressed(m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent));
631         mouseEvent.setDefaultHandled();
632     }
633 }
634
635 CursorDirective RenderEmbeddedObject::getCursor(const LayoutPoint& point, Cursor& cursor) const
636 {
637     if (showsUnavailablePluginIndicator() && shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason) && isInUnavailablePluginIndicator(point)) {
638         cursor = handCursor();
639         return SetCursor;
640     }
641     if (widget() && widget()->isPluginViewBase()) {
642         // A plug-in is responsible for setting the cursor when the pointer is over it.
643         return DoNotSetCursor;
644     }
645     return RenderWidget::getCursor(point, cursor);
646 }
647
648 bool RenderEmbeddedObject::canHaveChildren() const
649 {
650     if (isSnapshottedPlugIn())
651         return true;
652
653     return false;
654 }
655
656 }