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