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.
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.
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.
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.
25 #include "core/layout/LayoutEmbeddedObject.h"
27 #include "core/CSSValueKeywords.h"
28 #include "core/HTMLNames.h"
29 #include "core/frame/LocalFrame.h"
30 #include "core/html/HTMLIFrameElement.h"
31 #include "core/html/HTMLPlugInElement.h"
32 #include "core/layout/LayoutAnalyzer.h"
33 #include "core/layout/LayoutView.h"
34 #include "core/page/Page.h"
35 #include "core/paint/EmbeddedObjectPainter.h"
36 #include "core/plugins/PluginView.h"
37 #include "platform/text/PlatformLocale.h"
41 using namespace HTMLNames
;
43 LayoutEmbeddedObject::LayoutEmbeddedObject(Element
* element
)
45 , m_showsUnavailablePluginIndicator(false)
47 view()->frameView()->setIsVisuallyNonEmpty();
50 LayoutEmbeddedObject::~LayoutEmbeddedObject()
54 DeprecatedPaintLayerType
LayoutEmbeddedObject::layerTypeRequired() const
56 // This can't just use LayoutPart::layerTypeRequired, because DeprecatedPaintLayerCompositor
57 // doesn't loop through LayoutEmbeddedObjects the way it does frames in order
58 // to update the self painting bit on their Layer.
59 // Also, unlike iframes, embeds don't used the usesCompositing bit on LayoutView
60 // in requiresAcceleratedCompositing.
61 if (requiresAcceleratedCompositing())
62 return NormalDeprecatedPaintLayer
;
63 return LayoutPart::layerTypeRequired();
66 static String
localizedUnavailablePluginReplacementText(Node
* node
, LayoutEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason
)
68 Locale
& locale
= node
? toElement(node
)->locale() : Locale::defaultLocale();
69 switch (pluginUnavailabilityReason
) {
70 case LayoutEmbeddedObject::PluginMissing
:
71 return locale
.queryString(WebLocalizedString::MissingPluginText
);
72 case LayoutEmbeddedObject::PluginBlockedByContentSecurityPolicy
:
73 return locale
.queryString(WebLocalizedString::BlockedPluginText
);
80 void LayoutEmbeddedObject::setPluginUnavailabilityReason(PluginUnavailabilityReason pluginUnavailabilityReason
)
82 ASSERT(!m_showsUnavailablePluginIndicator
);
83 m_showsUnavailablePluginIndicator
= true;
84 m_pluginUnavailabilityReason
= pluginUnavailabilityReason
;
86 m_unavailablePluginReplacementText
= localizedUnavailablePluginReplacementText(node(), pluginUnavailabilityReason
);
89 bool LayoutEmbeddedObject::showsUnavailablePluginIndicator() const
91 return m_showsUnavailablePluginIndicator
;
94 void LayoutEmbeddedObject::paintContents(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
96 Element
* element
= toElement(node());
97 if (!isHTMLPlugInElement(element
))
100 LayoutPart::paintContents(paintInfo
, paintOffset
);
103 void LayoutEmbeddedObject::paint(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
105 if (showsUnavailablePluginIndicator()) {
106 LayoutReplaced::paint(paintInfo
, paintOffset
);
110 LayoutPart::paint(paintInfo
, paintOffset
);
113 void LayoutEmbeddedObject::paintReplaced(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
115 EmbeddedObjectPainter(*this).paintReplaced(paintInfo
, paintOffset
);
118 void LayoutEmbeddedObject::layout()
120 ASSERT(needsLayout());
121 LayoutAnalyzer::Scope
analyzer(*this);
123 updateLogicalWidth();
124 updateLogicalHeight();
127 addVisualEffectOverflow();
129 updateLayerTransformAfterLayout();
131 Widget
* widget
= this->widget();
133 if (widget
->isPluginView())
134 toPluginView(widget
)->layoutIfNeeded();
135 } else if (frameView()) {
136 frameView()->addPartToUpdate(*this);
142 PaintInvalidationReason
LayoutEmbeddedObject::invalidatePaintIfNeeded(
143 PaintInvalidationState
& paintInvalidationState
, const LayoutBoxModelObject
& newPaintInvalidationContainer
)
145 PaintInvalidationReason reason
=
146 LayoutPart::invalidatePaintIfNeeded(paintInvalidationState
, newPaintInvalidationContainer
);
148 Widget
* widget
= this->widget();
149 if (widget
&& widget
->isPluginView())
150 toPluginView(widget
)->invalidatePaintIfNeeded();
155 ScrollResultOneDimensional
LayoutEmbeddedObject::scroll(ScrollDirectionPhysical direction
, ScrollGranularity granularity
, float)
157 return ScrollResultOneDimensional(false);
160 CompositingReasons
LayoutEmbeddedObject::additionalCompositingReasons() const
162 if (requiresAcceleratedCompositing())
163 return CompositingReasonPlugin
;
164 return CompositingReasonNone
;
167 LayoutBox
* LayoutEmbeddedObject::embeddedContentBox() const
169 if (!node() || !widget() || !widget()->isFrameView())
171 return toFrameView(widget())->embeddedContentBox();