<https://webkit.org/b/119866> Frame::eventHandler() should return a reference.
[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 "HTMLEmbedElement.h"
38 #include "HTMLIFrameElement.h"
39 #include "HTMLNames.h"
40 #include "HTMLObjectElement.h"
41 #include "HTMLParamElement.h"
42 #include "HTMLPlugInElement.h"
43 #include "HitTestResult.h"
44 #include "LocalizedStrings.h"
45 #include "MIMETypeRegistry.h"
46 #include "MouseEvent.h"
47 #include "Page.h"
48 #include "PaintInfo.h"
49 #include "Path.h"
50 #include "PlatformMouseEvent.h"
51 #include "PluginViewBase.h"
52 #include "RenderLayer.h"
53 #include "RenderTheme.h"
54 #include "RenderView.h"
55 #include "RenderWidgetProtector.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 replacementTextRoundedRectRadius = 11;
74 static const float replacementArrowLeftMargin = -4;
75 static const float replacementArrowPadding = 4;
76 static const float replacementArrowCirclePadding = 3;
77
78 static const Color& replacementTextRoundedRectPressedColor()
79 {
80     static const Color pressed(105, 105, 105, 242);
81     return pressed;
82 }
83
84 static const Color& replacementTextRoundedRectColor()
85 {
86     static const Color standard(125, 125, 125, 242);
87     return standard;
88 }
89
90 static const Color& replacementTextColor()
91 {
92     static const Color standard(240, 240, 240, 255);
93     return standard;
94 }
95
96 static const Color& unavailablePluginBorderColor()
97 {
98     static const Color standard(255, 255, 255, 216);
99     return standard;
100 }
101
102 RenderEmbeddedObject::RenderEmbeddedObject(Element* element)
103     : RenderPart(element)
104     , m_hasFallbackContent(false)
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     if (frameView())
117         frameView()->removeWidgetToUpdate(this);
118 }
119
120 #if USE(ACCELERATED_COMPOSITING)
121 bool RenderEmbeddedObject::requiresLayer() const
122 {
123     if (RenderPart::requiresLayer())
124         return true;
125     
126     return allowsAcceleratedCompositing();
127 }
128
129 bool RenderEmbeddedObject::allowsAcceleratedCompositing() const
130 {
131     return widget() && widget()->isPluginViewBase() && toPluginViewBase(widget())->platformLayer();
132 }
133 #endif
134
135 static String unavailablePluginReplacementText(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason)
136 {
137     switch (pluginUnavailabilityReason) {
138     case RenderEmbeddedObject::PluginMissing:
139         return missingPluginText();
140     case RenderEmbeddedObject::PluginCrashed:
141         return crashedPluginText();
142     case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
143         return blockedPluginByContentSecurityPolicyText();
144     case RenderEmbeddedObject::InsecurePluginVersion:
145         return insecurePluginVersionText();
146     }
147
148     ASSERT_NOT_REACHED();
149     return String();
150 }
151
152 static bool shouldUnavailablePluginMessageBeButton(Document* document, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason)
153 {
154     Page* page = document->page();
155     return page && page->chrome().client()->shouldUnavailablePluginMessageBeButton(pluginUnavailabilityReason);
156 }
157
158 void RenderEmbeddedObject::setPluginUnavailabilityReason(PluginUnavailabilityReason pluginUnavailabilityReason)
159 {
160     setPluginUnavailabilityReasonWithDescription(pluginUnavailabilityReason, unavailablePluginReplacementText(pluginUnavailabilityReason));
161 }
162
163 void RenderEmbeddedObject::setPluginUnavailabilityReasonWithDescription(PluginUnavailabilityReason pluginUnavailabilityReason, const String& description)
164 {
165     ASSERT(!m_isPluginUnavailable);
166     m_isPluginUnavailable = true;
167     m_pluginUnavailabilityReason = pluginUnavailabilityReason;
168
169     if (description.isEmpty())
170         m_unavailablePluginReplacementText = unavailablePluginReplacementText(pluginUnavailabilityReason);
171     else
172         m_unavailablePluginReplacementText = description;
173 }
174
175 void RenderEmbeddedObject::setUnavailablePluginIndicatorIsPressed(bool pressed)
176 {
177     if (m_unavailablePluginIndicatorIsPressed == pressed)
178         return;
179
180     m_unavailablePluginIndicatorIsPressed = pressed;
181     repaint();
182 }
183
184 void RenderEmbeddedObject::paintSnapshotImage(PaintInfo& paintInfo, const LayoutPoint& paintOffset, Image* image)
185 {
186     LayoutUnit cWidth = contentWidth();
187     LayoutUnit cHeight = contentHeight();
188     if (!cWidth || !cHeight)
189         return;
190
191     GraphicsContext* context = paintInfo.context;
192     LayoutSize contentSize(cWidth, cHeight);
193     LayoutPoint contentLocation = location() + paintOffset;
194     contentLocation.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
195
196     LayoutRect rect(contentLocation, contentSize);
197     IntRect alignedRect = pixelSnappedIntRect(rect);
198     if (alignedRect.width() <= 0 || alignedRect.height() <= 0)
199         return;
200
201     bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, alignedRect.size());
202     context->drawImage(image, style()->colorSpace(), alignedRect, CompositeSourceOver, ImageOrientationDescription(shouldRespectImageOrientation()), useLowQualityScaling);
203 }
204
205 void RenderEmbeddedObject::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
206 {
207     Element* element = toElement(node());
208     if (!element || !element->isPluginElement())
209         return;
210
211     HTMLPlugInElement* plugInElement = toHTMLPlugInElement(element);
212
213     if (plugInElement->displayState() > HTMLPlugInElement::DisplayingSnapshot) {
214         RenderPart::paintContents(paintInfo, paintOffset);
215         if (!plugInElement->isRestartedPlugin())
216             return;
217     }
218
219     if (!plugInElement->isPlugInImageElement())
220         return;
221
222     Image* snapshot = toHTMLPlugInImageElement(plugInElement)->snapshotImage();
223     if (snapshot)
224         paintSnapshotImage(paintInfo, paintOffset, snapshot);
225 }
226
227 void RenderEmbeddedObject::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
228 {
229     Page* page = 0;
230     if (Frame* frame = this->frame())
231         page = frame->page();
232
233     if (isPluginUnavailable()) {
234         if (page && paintInfo.phase == PaintPhaseForeground)
235             page->addRelevantUnpaintedObject(this, visualOverflowRect());
236         RenderReplaced::paint(paintInfo, paintOffset);
237         return;
238     }
239
240     if (page && paintInfo.phase == PaintPhaseForeground)
241         page->addRelevantRepaintedObject(this, visualOverflowRect());
242
243     RenderPart::paint(paintInfo, paintOffset);
244 }
245
246 static void drawReplacementArrow(GraphicsContext* context, const FloatRect& insideRect)
247 {
248     GraphicsContextStateSaver stateSaver(*context);
249
250     FloatRect rect(insideRect);
251     rect.inflate(-replacementArrowPadding);
252
253     FloatPoint center(rect.center());
254     FloatPoint arrowTip(rect.maxX(), center.y());
255
256     context->setStrokeThickness(2);
257     context->setLineCap(RoundCap);
258     context->setLineJoin(RoundJoin);
259
260     Path path;
261     path.moveTo(FloatPoint(rect.x(), center.y()));
262     path.addLineTo(arrowTip);
263     path.addLineTo(FloatPoint(center.x(), rect.y()));
264     path.moveTo(arrowTip);
265     path.addLineTo(FloatPoint(center.x(), rect.maxY()));
266     context->strokePath(path);
267 }
268
269 void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
270 {
271     if (!showsUnavailablePluginIndicator())
272         return;
273
274     if (paintInfo.phase == PaintPhaseSelection)
275         return;
276
277     GraphicsContext* context = paintInfo.context;
278     if (context->paintingDisabled())
279         return;
280
281     FloatRect contentRect;
282     FloatRect indicatorRect;
283     FloatRect replacementTextRect;
284     FloatRect arrowRect;
285     Font font;
286     TextRun run("");
287     float textWidth;
288     if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
289         return;
290
291     Path background;
292     background.addRoundedRect(indicatorRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
293
294     GraphicsContextStateSaver stateSaver(*context);
295     context->clip(contentRect);
296     context->setFillColor(m_unavailablePluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : replacementTextRoundedRectColor(), style()->colorSpace());
297     context->fillPath(background);
298
299     Path strokePath;
300     FloatRect strokeRect(indicatorRect);
301     strokeRect.inflate(1);
302     strokePath.addRoundedRect(strokeRect, FloatSize(replacementTextRoundedRectRadius + 1, replacementTextRoundedRectRadius + 1));
303
304     context->setStrokeColor(unavailablePluginBorderColor(), style()->colorSpace());
305     context->setStrokeThickness(2);
306     context->strokePath(strokePath);
307
308     const FontMetrics& fontMetrics = font.fontMetrics();
309     float labelX = roundf(replacementTextRect.location().x() + replacementTextRoundedRectLeftTextMargin);
310     float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent());
311     context->setFillColor(replacementTextColor(), style()->colorSpace());
312     context->drawBidiText(font, run, FloatPoint(labelX, labelY));
313
314     if (shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason)) {
315         arrowRect.inflate(-replacementArrowCirclePadding);
316
317         context->beginTransparencyLayer(1.0);
318         context->setFillColor(replacementTextColor(), style()->colorSpace());
319         context->fillEllipse(arrowRect);
320
321         context->setCompositeOperation(CompositeClear);
322         drawReplacementArrow(context, arrowRect);
323         context->endTransparencyLayer();
324     }
325 }
326
327 void RenderEmbeddedObject::setUnavailablePluginIndicatorIsHidden(bool hidden)
328 {
329     m_isUnavailablePluginIndicatorHidden = hidden;
330
331     repaint();
332 }
333
334 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font& font, TextRun& run, float& textWidth) const
335 {
336     bool includesArrow = shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason);
337
338     contentRect = contentBoxRect();
339     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
340
341     FontDescription fontDescription;
342     RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription);
343     fontDescription.setWeight(FontWeightBold);
344     Settings* settings = document()->settings();
345     ASSERT(settings);
346     if (!settings)
347         return false;
348     fontDescription.setRenderingMode(settings->fontRenderingMode());
349     fontDescription.setComputedSize(12);
350     font = Font(fontDescription, 0, 0);
351     font.update(0);
352
353     run = TextRun(m_unavailablePluginReplacementText);
354     textWidth = font.width(run);
355
356     replacementTextRect.setSize(FloatSize(textWidth + replacementTextRoundedRectLeftTextMargin + (includesArrow ? replacementTextRoundedRectRightTextMarginWithArrow : replacementTextRoundedRectRightTextMargin), replacementTextRoundedRectHeight));
357     float x = (contentRect.size().width() / 2 - replacementTextRect.size().width() / 2) + contentRect.location().x();
358     float y = (contentRect.size().height() / 2 - replacementTextRect.size().height() / 2) + contentRect.location().y();
359     replacementTextRect.setLocation(FloatPoint(x, y));
360
361     indicatorRect = replacementTextRect;
362
363     // Expand the background rect to include the arrow, if it will be used.
364     if (includesArrow) {
365         arrowRect = indicatorRect;
366         arrowRect.setX(ceilf(arrowRect.maxX() + replacementArrowLeftMargin));
367         arrowRect.setWidth(arrowRect.height());
368         indicatorRect.unite(arrowRect);
369     }
370
371     return true;
372 }
373
374 LayoutRect RenderEmbeddedObject::unavailablePluginIndicatorBounds(const LayoutPoint& accumulatedOffset) const
375 {
376     FloatRect contentRect;
377     FloatRect indicatorRect;
378     FloatRect replacementTextRect;
379     FloatRect arrowRect;
380     Font font;
381     TextRun run("", 0);
382     float textWidth;
383     if (getReplacementTextGeometry(accumulatedOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
384         return LayoutRect(indicatorRect);
385
386     return LayoutRect();
387 }
388
389 bool RenderEmbeddedObject::isReplacementObscured() const
390 {
391     // Return whether or not the replacement content for blocked plugins is accessible to the user.
392
393     // Check the opacity of each layer containing the element or its ancestors.
394     float opacity = 1.0;
395     for (RenderLayer* layer = enclosingLayer(); layer; layer = layer->parent()) {
396         RenderLayerModelObject* renderer = layer->renderer();
397         RenderStyle* style = renderer->style();
398         opacity *= style->opacity();
399         if (opacity < 0.1)
400             return true;
401     }
402
403     // Calculate the absolute rect for the blocked plugin replacement text.
404     IntRect absoluteBoundingBox = absoluteBoundingBoxRect();
405     LayoutPoint absoluteLocation(absoluteBoundingBox.location());
406     LayoutRect rect = unavailablePluginIndicatorBounds(absoluteLocation);
407     if (rect.isEmpty())
408         return true;
409
410     RenderView* docRenderer = document()->renderView();
411     ASSERT(docRenderer);
412     if (!docRenderer)
413         return true;
414     
415     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent);
416     HitTestResult result;
417     HitTestLocation location;
418     
419     LayoutUnit x = rect.x();
420     LayoutUnit y = rect.y();
421     LayoutUnit width = rect.width();
422     LayoutUnit height = rect.height();
423     
424     // Hit test the center and near the corners of the replacement text to ensure
425     // it is visible and is not masked by other elements.
426     bool hit = false;
427     location = LayoutPoint(x + width / 2, y + height / 2);
428     hit = docRenderer->hitTest(request, location, result);
429     if (!hit || result.innerNode() != node())
430         return true;
431     
432     location = LayoutPoint(x, y);
433     hit = docRenderer->hitTest(request, location, result);
434     if (!hit || result.innerNode() != node())
435         return true;
436     
437     location = LayoutPoint(x + width, y);
438     hit = docRenderer->hitTest(request, location, result);
439     if (!hit || result.innerNode() != node())
440         return true;
441     
442     location = LayoutPoint(x + width, y + height);
443     hit = docRenderer->hitTest(request, location, result);
444     if (!hit || result.innerNode() != node())
445         return true;
446     
447     location = LayoutPoint(x, y + height);
448     hit = docRenderer->hitTest(request, location, result);
449     if (!hit || result.innerNode() != node())
450         return true;
451
452     return false;
453 }
454
455 void RenderEmbeddedObject::layout()
456 {
457     StackStats::LayoutCheckPoint layoutCheckPoint;
458     ASSERT(needsLayout());
459
460     LayoutSize oldSize = contentBoxRect().size();
461
462     updateLogicalWidth();
463     updateLogicalHeight();
464
465     RenderPart::layout();
466
467     m_overflow.clear();
468     addVisualEffectOverflow();
469
470     updateLayerTransform();
471
472     bool wasMissingWidget = false;
473     if (!widget() && frameView() && canHaveWidget()) {
474         wasMissingWidget = true;
475         frameView()->addWidgetToUpdate(this);
476     }
477
478     setNeedsLayout(false);
479
480     LayoutSize newSize = contentBoxRect().size();
481
482     if (!wasMissingWidget && newSize.width() >= oldSize.width() && newSize.height() >= oldSize.height()) {
483         Element* element = toElement(node());
484         if (element && element->isPluginElement() && toHTMLPlugInElement(element)->isPlugInImageElement()) {
485             HTMLPlugInImageElement* plugInImageElement = toHTMLPlugInImageElement(element);
486             if (plugInImageElement->displayState() > HTMLPlugInElement::DisplayingSnapshot && plugInImageElement->snapshotDecision() == HTMLPlugInImageElement::MaySnapshotWhenResized && document()->view()) {
487                 plugInImageElement->setNeedsCheckForSizeChange();
488                 document()->view()->addWidgetToUpdate(this);
489             }
490         }
491     }
492
493     if (!canHaveChildren())
494         return;
495
496     // This code copied from RenderMedia::layout().
497     RenderObject* child = m_children.firstChild();
498
499     if (!child)
500         return;
501
502     RenderBox* childBox = toRenderBox(child);
503
504     if (!childBox)
505         return;
506
507     if (newSize == oldSize && !childBox->needsLayout())
508         return;
509     
510     // When calling layout() on a child node, a parent must either push a LayoutStateMaintainter, or
511     // instantiate LayoutStateDisabler. Since using a LayoutStateMaintainer is slightly more efficient,
512     // and this method will be called many times per second during playback, use a LayoutStateMaintainer:
513     LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode());
514     
515     childBox->setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
516     childBox->style()->setHeight(Length(newSize.height(), Fixed));
517     childBox->style()->setWidth(Length(newSize.width(), Fixed));
518     childBox->setNeedsLayout(true, MarkOnlyThis);
519     childBox->layout();
520     setChildNeedsLayout(false);
521     
522     statePusher.pop();
523 }
524
525 void RenderEmbeddedObject::viewCleared()
526 {
527     // This is required for <object> elements whose contents are rendered by WebCore (e.g. src="foo.html").
528     if (node() && widget() && widget()->isFrameView()) {
529         FrameView* view = toFrameView(widget());
530         int marginWidth = -1;
531         int marginHeight = -1;
532         if (node()->hasTagName(iframeTag)) {
533             HTMLIFrameElement* frame = toHTMLIFrameElement(node());
534             marginWidth = frame->marginWidth();
535             marginHeight = frame->marginHeight();
536         }
537         if (marginWidth != -1)
538             view->setMarginWidth(marginWidth);
539         if (marginHeight != -1)
540             view->setMarginHeight(marginHeight);
541     }
542 }
543
544 bool RenderEmbeddedObject::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
545 {
546     if (!RenderPart::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, Node**)
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, Node** stopNode)
581 {
582     // Plugins don't expose a writing direction, so assuming horizontal LTR.
583     return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopNode);
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(node());
615     if (event->type() == eventNames().mousedownEvent && static_cast<MouseEvent*>(event)->button() == LeftButton) {
616         m_mouseDownWasInUnavailablePluginIndicator = isInUnavailablePluginIndicator(mouseEvent);
617         if (m_mouseDownWasInUnavailablePluginIndicator) {
618             if (Frame* frame = document()->frame()) {
619                 frame->eventHandler().setCapturingMouseEventsNode(element);
620                 element->setIsCapturingMouseEvents(true);
621             }
622             setUnavailablePluginIndicatorIsPressed(true);
623         }
624         event->setDefaultHandled();
625     }
626     if (event->type() == eventNames().mouseupEvent && static_cast<MouseEvent*>(event)->button() == LeftButton) {
627         if (m_unavailablePluginIndicatorIsPressed) {
628             if (Frame* frame = document()->frame()) {
629                 frame->eventHandler().setCapturingMouseEventsNode(0);
630                 element->setIsCapturingMouseEvents(false);
631             }
632             setUnavailablePluginIndicatorIsPressed(false);
633         }
634         if (m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent)) {
635             if (Page* page = document()->page())
636                 page->chrome().client()->unavailablePluginButtonClicked(element, m_pluginUnavailabilityReason);
637         }
638         m_mouseDownWasInUnavailablePluginIndicator = false;
639         event->setDefaultHandled();
640     }
641     if (event->type() == eventNames().mousemoveEvent) {
642         setUnavailablePluginIndicatorIsPressed(m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent));
643         event->setDefaultHandled();
644     }
645 }
646
647 CursorDirective RenderEmbeddedObject::getCursor(const LayoutPoint& point, Cursor& cursor) const
648 {
649     if (showsUnavailablePluginIndicator() && shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason) && isInUnavailablePluginIndicator(point)) {
650         cursor = handCursor();
651         return SetCursor;
652     }
653     return RenderPart::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 }