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