Move wheel event dispatch from Node to Element.
[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)
104     : RenderWidget(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     view().frameView().removeEmbeddedObjectToUpdate(*this);
118 }
119
120 RenderEmbeddedObject* RenderEmbeddedObject::createForApplet(HTMLAppletElement& applet)
121 {
122     RenderEmbeddedObject* renderer = new (*applet.document().renderArena()) RenderEmbeddedObject(applet);
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     context->drawImage(image, style()->colorSpace(), alignedRect, CompositeSourceOver, ImageOrientationDescription(shouldRespectImageOrientation()), useLowQualityScaling);
210 }
211
212 void RenderEmbeddedObject::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
213 {
214     if (!frameOwnerElement().isPluginElement())
215         return;
216
217     HTMLPlugInElement& plugInElement = toHTMLPlugInElement(frameOwnerElement());
218
219     if (plugInElement.displayState() > HTMLPlugInElement::DisplayingSnapshot) {
220         RenderWidget::paintContents(paintInfo, paintOffset);
221         if (!plugInElement.isRestartedPlugin())
222             return;
223     }
224
225     if (!plugInElement.isPlugInImageElement())
226         return;
227
228     Image* snapshot = toHTMLPlugInImageElement(plugInElement).snapshotImage();
229     if (snapshot)
230         paintSnapshotImage(paintInfo, paintOffset, snapshot);
231 }
232
233 void RenderEmbeddedObject::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
234 {
235     Page* page = frame().page();
236
237     if (isPluginUnavailable()) {
238         if (page && paintInfo.phase == PaintPhaseForeground)
239             page->addRelevantUnpaintedObject(this, visualOverflowRect());
240         RenderReplaced::paint(paintInfo, paintOffset);
241         return;
242     }
243
244     if (page && paintInfo.phase == PaintPhaseForeground)
245         page->addRelevantRepaintedObject(this, visualOverflowRect());
246
247     RenderWidget::paint(paintInfo, paintOffset);
248 }
249
250 static void drawReplacementArrow(GraphicsContext* context, const FloatRect& insideRect)
251 {
252     GraphicsContextStateSaver stateSaver(*context);
253
254     FloatRect rect(insideRect);
255     rect.inflate(-replacementArrowPadding);
256
257     FloatPoint center(rect.center());
258     FloatPoint arrowTip(rect.maxX(), center.y());
259
260     context->setStrokeThickness(2);
261     context->setLineCap(RoundCap);
262     context->setLineJoin(RoundJoin);
263
264     Path path;
265     path.moveTo(FloatPoint(rect.x(), center.y()));
266     path.addLineTo(arrowTip);
267     path.addLineTo(FloatPoint(center.x(), rect.y()));
268     path.moveTo(arrowTip);
269     path.addLineTo(FloatPoint(center.x(), rect.maxY()));
270     context->strokePath(path);
271 }
272
273 void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
274 {
275     if (!showsUnavailablePluginIndicator())
276         return;
277
278     if (paintInfo.phase == PaintPhaseSelection)
279         return;
280
281     GraphicsContext* context = paintInfo.context;
282     if (context->paintingDisabled())
283         return;
284
285     FloatRect contentRect;
286     FloatRect indicatorRect;
287     FloatRect replacementTextRect;
288     FloatRect arrowRect;
289     Font font;
290     TextRun run("");
291     float textWidth;
292     if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
293         return;
294
295     Path background;
296     background.addRoundedRect(indicatorRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
297
298     GraphicsContextStateSaver stateSaver(*context);
299     context->clip(contentRect);
300     context->setFillColor(m_unavailablePluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : replacementTextRoundedRectColor(), style()->colorSpace());
301     context->fillPath(background);
302
303     Path strokePath;
304     FloatRect strokeRect(indicatorRect);
305     strokeRect.inflate(1);
306     strokePath.addRoundedRect(strokeRect, FloatSize(replacementTextRoundedRectRadius + 1, replacementTextRoundedRectRadius + 1));
307
308     context->setStrokeColor(unavailablePluginBorderColor(), style()->colorSpace());
309     context->setStrokeThickness(2);
310     context->strokePath(strokePath);
311
312     const FontMetrics& fontMetrics = font.fontMetrics();
313     float labelX = roundf(replacementTextRect.location().x() + replacementTextRoundedRectLeftTextMargin);
314     float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent() + replacementTextRoundedRectTopTextMargin);
315     context->setFillColor(replacementTextColor(), style()->colorSpace());
316     context->drawBidiText(font, run, FloatPoint(labelX, labelY));
317
318     if (shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason)) {
319         arrowRect.inflate(-replacementArrowCirclePadding);
320
321         context->beginTransparencyLayer(1.0);
322         context->setFillColor(replacementTextColor(), style()->colorSpace());
323         context->fillEllipse(arrowRect);
324
325         context->setCompositeOperation(CompositeClear);
326         drawReplacementArrow(context, arrowRect);
327         context->endTransparencyLayer();
328     }
329 }
330
331 void RenderEmbeddedObject::setUnavailablePluginIndicatorIsHidden(bool hidden)
332 {
333     m_isUnavailablePluginIndicatorHidden = hidden;
334
335     repaint();
336 }
337
338 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font& font, TextRun& run, float& textWidth) const
339 {
340     bool includesArrow = shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason);
341
342     contentRect = contentBoxRect();
343     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
344
345     FontDescription fontDescription;
346     RenderTheme::defaultTheme()->systemFont(CSSValueWebkitSmallControl, fontDescription);
347     fontDescription.setWeight(FontWeightBold);
348     fontDescription.setRenderingMode(frame().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         opacity *= layer->renderer().style()->opacity();
397         if (opacity < 0.1)
398             return true;
399     }
400
401     // Calculate the absolute rect for the blocked plugin replacement text.
402     IntRect absoluteBoundingBox = absoluteBoundingBoxRect();
403     LayoutPoint absoluteLocation(absoluteBoundingBox.location());
404     LayoutRect rect = unavailablePluginIndicatorBounds(absoluteLocation);
405     if (rect.isEmpty())
406         return true;
407
408     RenderView* rootRenderView = document().topDocument()->renderView();
409     ASSERT(rootRenderView);
410     if (!rootRenderView)
411         return true;
412
413     IntRect rootViewRect = view().frameView().convertToRootView(pixelSnappedIntRect(rect));
414     
415     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::DisallowShadowContent | HitTestRequest::AllowChildFrameContent);
416     HitTestResult result;
417     HitTestLocation location;
418     
419     LayoutUnit x = rootViewRect.x();
420     LayoutUnit y = rootViewRect.y();
421     LayoutUnit width = rootViewRect.width();
422     LayoutUnit height = rootViewRect.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 = rootRenderView->hitTest(request, location, result);
429     if (!hit || result.innerNode() != &frameOwnerElement())
430         return true;
431     
432     location = LayoutPoint(x, y);
433     hit = rootRenderView->hitTest(request, location, result);
434     if (!hit || result.innerNode() != &frameOwnerElement())
435         return true;
436     
437     location = LayoutPoint(x + width, y);
438     hit = rootRenderView->hitTest(request, location, result);
439     if (!hit || result.innerNode() != &frameOwnerElement())
440         return true;
441     
442     location = LayoutPoint(x + width, y + height);
443     hit = rootRenderView->hitTest(request, location, result);
444     if (!hit || result.innerNode() != &frameOwnerElement())
445         return true;
446     
447     location = LayoutPoint(x, y + height);
448     hit = rootRenderView->hitTest(request, location, result);
449     if (!hit || result.innerNode() != &frameOwnerElement())
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     RenderWidget::layout();
466
467     clearOverflow();
468     addVisualEffectOverflow();
469
470     updateLayerTransform();
471
472     bool wasMissingWidget = false;
473     if (!widget() && canHaveWidget()) {
474         wasMissingWidget = true;
475         view().frameView().addEmbeddedObjectToUpdate(*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         HTMLFrameOwnerElement& element = frameOwnerElement();
484         if (element.isPluginElement() && toHTMLPlugInElement(element).isPlugInImageElement()) {
485             HTMLPlugInImageElement& plugInImageElement = toHTMLPlugInImageElement(element);
486             if (plugInImageElement.displayState() > HTMLPlugInElement::DisplayingSnapshot && plugInImageElement.snapshotDecision() == HTMLPlugInImageElement::MaySnapshotWhenResized) {
487                 plugInImageElement.setNeedsCheckForSizeChange();
488                 view().frameView().addEmbeddedObjectToUpdate(*this);
489             }
490         }
491     }
492
493     if (!canHaveChildren())
494         return;
495
496     // This code copied from RenderMedia::layout().
497     RenderObject* child = 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 (widget() && widget()->isFrameView()) {
529         FrameView* view = toFrameView(widget());
530         int marginWidth = -1;
531         int marginHeight = -1;
532         if (isHTMLIFrameElement(frameOwnerElement())) {
533             HTMLIFrameElement& iframe = toHTMLIFrameElement(frameOwnerElement());
534             marginWidth = iframe.marginWidth();
535             marginHeight = iframe.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 (!RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction))
547         return false;
548
549     if (!widget() || !widget()->isPluginViewBase())
550         return true;
551
552     PluginViewBase* view = toPluginViewBase(widget());
553     IntPoint roundedPoint = locationInContainer.roundedPoint();
554
555     if (Scrollbar* horizontalScrollbar = view->horizontalScrollbar()) {
556         if (horizontalScrollbar->shouldParticipateInHitTesting() && horizontalScrollbar->frameRect().contains(roundedPoint)) {
557             result.setScrollbar(horizontalScrollbar);
558             return true;
559         }
560     }
561
562     if (Scrollbar* verticalScrollbar = view->verticalScrollbar()) {
563         if (verticalScrollbar->shouldParticipateInHitTesting() && verticalScrollbar->frameRect().contains(roundedPoint)) {
564             result.setScrollbar(verticalScrollbar);
565             return true;
566         }
567     }
568
569     return true;
570 }
571
572 bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Element**)
573 {
574     if (!widget() || !widget()->isPluginViewBase())
575         return false;
576
577     return toPluginViewBase(widget())->scroll(direction, granularity);
578 }
579
580 bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
581 {
582     // Plugins don't expose a writing direction, so assuming horizontal LTR.
583     return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopElement);
584 }
585
586
587 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const LayoutPoint& point) const
588 {
589     FloatRect contentRect;
590     FloatRect indicatorRect;
591     FloatRect replacementTextRect;
592     FloatRect arrowRect;
593     Font font;
594     TextRun run("");
595     float textWidth;
596     return getReplacementTextGeometry(IntPoint(), contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth)
597         && indicatorRect.contains(point);
598 }
599
600 bool RenderEmbeddedObject::isInUnavailablePluginIndicator(MouseEvent* event) const
601 {
602     return isInUnavailablePluginIndicator(roundedLayoutPoint(absoluteToLocal(event->absoluteLocation(), UseTransforms)));
603 }
604
605 void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
606 {
607     if (!shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason))
608         return;
609
610     if (!event->isMouseEvent())
611         return;
612
613     MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
614     HTMLPlugInElement& element = toHTMLPlugInElement(frameOwnerElement());
615     if (event->type() == eventNames().mousedownEvent && static_cast<MouseEvent*>(event)->button() == LeftButton) {
616         m_mouseDownWasInUnavailablePluginIndicator = isInUnavailablePluginIndicator(mouseEvent);
617         if (m_mouseDownWasInUnavailablePluginIndicator) {
618             frame().eventHandler().setCapturingMouseEventsNode(&element);
619             element.setIsCapturingMouseEvents(true);
620             setUnavailablePluginIndicatorIsPressed(true);
621         }
622         event->setDefaultHandled();
623     }
624     if (event->type() == eventNames().mouseupEvent && static_cast<MouseEvent*>(event)->button() == LeftButton) {
625         if (m_unavailablePluginIndicatorIsPressed) {
626             frame().eventHandler().setCapturingMouseEventsNode(0);
627             element.setIsCapturingMouseEvents(false);
628             setUnavailablePluginIndicatorIsPressed(false);
629         }
630         if (m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent)) {
631             if (Page* page = document().page())
632                 page->chrome().client().unavailablePluginButtonClicked(&element, m_pluginUnavailabilityReason);
633         }
634         m_mouseDownWasInUnavailablePluginIndicator = false;
635         event->setDefaultHandled();
636     }
637     if (event->type() == eventNames().mousemoveEvent) {
638         setUnavailablePluginIndicatorIsPressed(m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent));
639         event->setDefaultHandled();
640     }
641 }
642
643 CursorDirective RenderEmbeddedObject::getCursor(const LayoutPoint& point, Cursor& cursor) const
644 {
645     if (showsUnavailablePluginIndicator() && shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason) && isInUnavailablePluginIndicator(point)) {
646         cursor = handCursor();
647         return SetCursor;
648     }
649     return RenderWidget::getCursor(point, cursor);
650 }
651
652 bool RenderEmbeddedObject::canHaveChildren() const
653 {
654 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
655     if (!node())
656         return false;
657
658     if (toElement(node())->isMediaElement())
659         return true;
660 #endif
661
662     if (isSnapshottedPlugIn())
663         return true;
664
665     return false;
666 }
667
668 }