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