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