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