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#ifndef RenderEmbeddedObject_h
24#define RenderEmbeddedObject_h
25
26#include "RenderWidget.h"
27
28namespace WebCore {
29
30class HTMLAppletElement;
31class MouseEvent;
32class TextRun;
33
34// Renderer for embeds and objects, often, but not always, rendered via plug-ins.
35// For example, <embed src="foo.html"> does not invoke a plug-in.
36class RenderEmbeddedObject : public RenderWidget {
37public:
38    RenderEmbeddedObject(HTMLFrameOwnerElement&, PassRef<RenderStyle>);
39    virtual ~RenderEmbeddedObject();
40
41    static RenderPtr<RenderEmbeddedObject> createForApplet(HTMLAppletElement&, PassRef<RenderStyle>);
42
43    enum PluginUnavailabilityReason {
44        PluginMissing,
45        PluginCrashed,
46        PluginBlockedByContentSecurityPolicy,
47        InsecurePluginVersion,
48    };
49    void setPluginUnavailabilityReason(PluginUnavailabilityReason);
50    void setPluginUnavailabilityReasonWithDescription(PluginUnavailabilityReason, const String& description);
51
52    bool isPluginUnavailable() const { return m_isPluginUnavailable; }
53    bool showsUnavailablePluginIndicator() const { return isPluginUnavailable() && !m_isUnavailablePluginIndicatorHidden; }
54
55    void setUnavailablePluginIndicatorIsHidden(bool);
56
57    void handleUnavailablePluginIndicatorEvent(Event*);
58
59    bool isReplacementObscured() const;
60
61    bool allowsAcceleratedCompositing() const;
62
63protected:
64    virtual void paintReplaced(PaintInfo&, const LayoutPoint&) override final;
65    virtual void paint(PaintInfo&, const LayoutPoint&) override;
66
67    virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const override;
68
69protected:
70    virtual void layout() override;
71
72private:
73    virtual const char* renderName() const override { return "RenderEmbeddedObject"; }
74    virtual bool isEmbeddedObject() const override final { return true; }
75
76    void paintSnapshotImage(PaintInfo&, const LayoutPoint&, Image*);
77    virtual void paintContents(PaintInfo&, const LayoutPoint&) override final;
78
79    virtual bool requiresLayer() const override final;
80
81    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override final;
82
83    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) override final;
84    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Element** stopElement) override final;
85
86    void setUnavailablePluginIndicatorIsPressed(bool);
87    bool isInUnavailablePluginIndicator(MouseEvent*) const;
88    bool isInUnavailablePluginIndicator(const LayoutPoint&) const;
89    bool getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font&, TextRun&, float& textWidth) const;
90    LayoutRect unavailablePluginIndicatorBounds(const LayoutPoint&) const;
91
92    virtual bool canHaveChildren() const override final;
93    virtual bool canHaveWidget() const { return true; }
94
95    bool m_isPluginUnavailable;
96    bool m_isUnavailablePluginIndicatorHidden;
97    PluginUnavailabilityReason m_pluginUnavailabilityReason;
98    String m_unavailablePluginReplacementText;
99    bool m_unavailablePluginIndicatorIsPressed;
100    bool m_mouseDownWasInUnavailablePluginIndicator;
101    String m_unavailabilityDescription;
102};
103
104RENDER_OBJECT_TYPE_CASTS(RenderEmbeddedObject, isEmbeddedObject())
105
106} // namespace WebCore
107
108#endif // RenderEmbeddedObject_h
109