1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "RenderWidget.h"
26
27namespace WebCore {
28
29class HTMLAppletElement;
30class MouseEvent;
31class TextRun;
32
33// Renderer for embeds and objects, often, but not always, rendered via plug-ins.
34// For example, <embed src="foo.html"> does not invoke a plug-in.
35class RenderEmbeddedObject : public RenderWidget {
36 WTF_MAKE_ISO_ALLOCATED(RenderEmbeddedObject);
37public:
38 RenderEmbeddedObject(HTMLFrameOwnerElement&, RenderStyle&&);
39 virtual ~RenderEmbeddedObject();
40
41 static RenderPtr<RenderEmbeddedObject> createForApplet(HTMLAppletElement&, RenderStyle&&);
42
43 enum PluginUnavailabilityReason {
44 PluginMissing,
45 PluginCrashed,
46 PluginBlockedByContentSecurityPolicy,
47 InsecurePluginVersion,
48 UnsupportedPlugin,
49 PluginTooSmall
50 };
51 PluginUnavailabilityReason pluginUnavailabilityReason() const { return m_pluginUnavailabilityReason; };
52 WEBCORE_EXPORT void setPluginUnavailabilityReason(PluginUnavailabilityReason);
53 WEBCORE_EXPORT void setPluginUnavailabilityReasonWithDescription(PluginUnavailabilityReason, const String& description);
54
55 bool isPluginUnavailable() const { return m_isPluginUnavailable; }
56
57 WEBCORE_EXPORT void setUnavailablePluginIndicatorIsHidden(bool);
58
59 void handleUnavailablePluginIndicatorEvent(Event*);
60
61 bool allowsAcceleratedCompositing() const;
62
63 LayoutRect unavailablePluginIndicatorBounds(const LayoutPoint& accumulatedOffset) const;
64
65 const String& pluginReplacementTextIfUnavailable() const { return m_unavailablePluginReplacementText; }
66
67protected:
68 void paintReplaced(PaintInfo&, const LayoutPoint&) final;
69 void paint(PaintInfo&, const LayoutPoint&) override;
70
71 CursorDirective getCursor(const LayoutPoint&, Cursor&) const override;
72
73protected:
74 void layout() override;
75 void willBeDestroyed() override;
76
77private:
78 const char* renderName() const override { return "RenderEmbeddedObject"; }
79 bool isEmbeddedObject() const final { return true; }
80
81 bool showsUnavailablePluginIndicator() const { return isPluginUnavailable() && m_isUnavailablePluginIndicatorState != UnavailablePluginIndicatorState::Hidden; }
82 void paintSnapshotImage(PaintInfo&, const LayoutPoint&, Image&);
83 void paintContents(PaintInfo&, const LayoutPoint&) final;
84
85 bool requiresLayer() const final;
86
87 bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) final;
88
89 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) final;
90 bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Element** stopElement) final;
91
92 void setUnavailablePluginIndicatorIsPressed(bool);
93 bool isInUnavailablePluginIndicator(const MouseEvent&) const;
94 bool isInUnavailablePluginIndicator(const FloatPoint&) const;
95 void getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, FontCascade&, TextRun&, float& textWidth) const;
96 LayoutRect getReplacementTextGeometry(const LayoutPoint& accumulatedOffset) const;
97
98 bool canHaveChildren() const final;
99 virtual bool canHaveWidget() const { return true; }
100
101 bool m_isPluginUnavailable;
102 enum class UnavailablePluginIndicatorState { Uninitialized, Hidden, Visible };
103 UnavailablePluginIndicatorState m_isUnavailablePluginIndicatorState { UnavailablePluginIndicatorState::Uninitialized };
104 PluginUnavailabilityReason m_pluginUnavailabilityReason;
105 String m_unavailablePluginReplacementText;
106 bool m_unavailablePluginIndicatorIsPressed;
107 bool m_mouseDownWasInUnavailablePluginIndicator;
108 String m_unavailabilityDescription;
109};
110
111} // namespace WebCore
112
113SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderEmbeddedObject, isEmbeddedObject())
114