initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderImage.h
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) 
5  *           (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6  * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #ifndef RenderImage_h
26 #define RenderImage_h
27
28 #include "RenderImageResource.h"
29 #include "RenderReplaced.h"
30
31 namespace WebCore {
32
33 class HTMLAreaElement;
34 class HTMLMapElement;
35
36 class RenderImage : public RenderReplaced {
37 public:
38     RenderImage(Node*);
39     virtual ~RenderImage();
40
41     void setImageResource(PassOwnPtr<RenderImageResource>);
42
43     RenderImageResource* imageResource() { return m_imageResource.get(); }
44     const RenderImageResource* imageResource() const { return m_imageResource.get(); }
45     CachedImage* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
46
47     bool setImageSizeForAltText(CachedImage* newImage = 0);
48
49     void updateAltText();
50
51     HTMLMapElement* imageMap() const;
52     void areaElementFocusChanged(HTMLAreaElement*);
53
54     void highQualityRepaintTimerFired(Timer<RenderImage>*);
55
56 protected:
57     virtual void styleDidChange(StyleDifference, const RenderStyle*);
58
59     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
60
61     virtual void paintIntoRect(GraphicsContext*, const IntRect&);
62     virtual void paint(PaintInfo&, const LayoutPoint&);
63
64     bool isLogicalWidthSpecified() const;
65     bool isLogicalHeightSpecified() const;
66
67     virtual void intrinsicSizeChanged()
68     {
69         if (m_imageResource)
70             imageChanged(m_imageResource->imagePtr());
71     }
72
73 private:
74     virtual const char* renderName() const { return "RenderImage"; }
75
76     virtual bool isImage() const { return true; }
77     virtual bool isRenderImage() const { return true; }
78
79     virtual void paintReplaced(PaintInfo&, const IntPoint&);
80
81     virtual bool backgroundIsObscured() const;
82
83     virtual int minimumReplacedHeight() const;
84
85     virtual void notifyFinished(CachedResource*);
86     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
87
88     virtual LayoutUnit computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
89     virtual LayoutUnit computeReplacedLogicalHeight() const;
90
91     IntSize imageSizeForError(CachedImage*) const;
92     void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0);
93
94     int calcAspectRatioLogicalWidth() const;
95     int calcAspectRatioLogicalHeight() const;
96
97     void paintAreaElementFocusRing(PaintInfo&);
98
99     // Text to display as long as the image isn't available.
100     String m_altText;
101     OwnPtr<RenderImageResource> m_imageResource;
102     bool m_needsToSetSizeForAltText;
103     bool m_didIncrementVisuallyNonEmptyPixelCount;
104
105     friend class RenderImageScaleObserver;
106 };
107
108 inline RenderImage* toRenderImage(RenderObject* object)
109 {
110     ASSERT(!object || object->isRenderImage());
111     return static_cast<RenderImage*>(object);
112 }
113
114 inline const RenderImage* toRenderImage(const RenderObject* object)
115 {
116     ASSERT(!object || object->isRenderImage());
117     return static_cast<const RenderImage*>(object);
118 }
119
120 // This will catch anyone doing an unnecessary cast.
121 void toRenderImage(const RenderImage*);
122
123 } // namespace WebCore
124
125 #endif // RenderImage_h