RenderImage.h 4.25 KB
Newer Older
1
/*
kocienda's avatar
kocienda committed
2
3
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
ggaren's avatar
ggaren committed
4
5
 *           (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) 
 *           (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
darin's avatar
darin committed
6
 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
kocienda's avatar
kocienda committed
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
ddkilzer's avatar
ddkilzer committed
20
21
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
kocienda's avatar
kocienda committed
22
23
 *
 */
darin's avatar
darin committed
24

weinig's avatar
weinig committed
25
26
#ifndef RenderImage_h
#define RenderImage_h
kocienda's avatar
kocienda committed
27

darin's avatar
darin committed
28
#include "CachedImage.h"
29
#include "CachedResourceHandle.h"
30
#include "RenderReplaced.h"
kocienda's avatar
kocienda committed
31

darin's avatar
darin committed
32
namespace WebCore {
kocienda's avatar
kocienda committed
33

darin's avatar
darin committed
34
class HTMLMapElement;
kocienda's avatar
kocienda committed
35

weinig's avatar
weinig committed
36
class RenderImage : public RenderReplaced {
kocienda's avatar
kocienda committed
37
public:
darin's avatar
darin committed
38
    RenderImage(Node*);
kocienda's avatar
kocienda committed
39
40
    virtual ~RenderImage();

darin's avatar
darin committed
41
    virtual const char* renderName() const { return "RenderImage"; }
42

darin's avatar
darin committed
43
    virtual bool isImage() const { return true; }
44
    virtual bool isRenderImage() const { return true; }
45
    
antti@apple.com's avatar
antti@apple.com committed
46
    virtual void paintReplaced(PaintInfo& paintInfo, int tx, int ty);
kocienda's avatar
kocienda committed
47

antti@apple.com's avatar
antti@apple.com committed
48
    virtual int minimumReplacedHeight() const;
kocienda's avatar
kocienda committed
49

50
    virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
51
    virtual void notifyFinished(CachedResource*);
52
53
    
    bool setImageSizeForAltText(CachedImage* newImage = 0);
weinig's avatar
weinig committed
54

hyatt's avatar
hyatt committed
55
    void updateAltText();
weinig's avatar
weinig committed
56

darin's avatar
darin committed
57
    void setCachedImage(CachedImage*);
58
    CachedImage* cachedImage() const { return m_cachedImage.get(); }
weinig's avatar
weinig committed
59

bdakin's avatar
bdakin committed
60
    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
weinig's avatar
weinig committed
61

mitz@apple.com's avatar
mitz@apple.com committed
62
    virtual int calcReplacedWidth(bool includeMaxWidth = true) const;
darin's avatar
darin committed
63
    virtual int calcReplacedHeight() const;
64

darin's avatar
darin committed
65
    virtual void calcPrefWidths();
ggaren's avatar
ggaren committed
66

darin's avatar
darin committed
67
    HTMLMapElement* imageMap();
68

rjw's avatar
rjw committed
69
70
    void resetAnimation();

71
72
    virtual bool hasImage() const { return m_cachedImage; }

73
74
    void highQualityRepaintTimerFired(Timer<RenderImage>*);

darin's avatar
darin committed
75
protected:
76
    virtual Image* image(int /*w*/ = 0, int /*h*/ = 0) { return m_cachedImage ? m_cachedImage->image() : nullImage(); }
77
78
79
80
81
82
    virtual bool errorOccurred() const { return m_cachedImage && m_cachedImage->errorOccurred(); }
    virtual bool usesImageContainerSize() const { return m_cachedImage ? m_cachedImage->usesImageContainerSize() : false; }
    virtual void setImageContainerSize(const IntSize& size) const { if (m_cachedImage) m_cachedImage->setImageContainerSize(size); }
    virtual bool imageHasRelativeWidth() const { return m_cachedImage ? m_cachedImage->imageHasRelativeWidth() : false; }
    virtual bool imageHasRelativeHeight() const { return m_cachedImage ? m_cachedImage->imageHasRelativeHeight() : false; }
    virtual IntSize imageSize(float multiplier) const { return m_cachedImage ? m_cachedImage->imageSize(multiplier) : IntSize(); }
83
    virtual WrappedImagePtr imagePtr() const { return m_cachedImage.get(); }
darin's avatar
darin committed
84

85
    virtual void intrinsicSizeChanged() { imageChanged(imagePtr()); }
86

kocienda's avatar
kocienda committed
87
private:
darin's avatar
darin committed
88
89
90
    int calcAspectRatioWidth() const;
    int calcAspectRatioHeight() const;

darin's avatar
darin committed
91
92
93
    bool isWidthSpecified() const;
    bool isHeightSpecified() const;

94
protected:
hyatt's avatar
hyatt committed
95
    // The image we are rendering.
96
    CachedResourceHandle<CachedImage> m_cachedImage;
kocienda's avatar
kocienda committed
97

darin's avatar
darin committed
98
    // Text to display as long as the image isn't available.
darin's avatar
darin committed
99
    String m_altText;
darin's avatar
darin committed
100

101
    static Image* nullImage();
102
103
    
    friend class RenderImageScaleObserver;
kocienda's avatar
kocienda committed
104
105
};

darin@apple.com's avatar
darin@apple.com committed
106
inline RenderImage* toRenderImage(RenderObject* object)
107
{ 
darin@apple.com's avatar
darin@apple.com committed
108
109
    ASSERT(!object || object->isRenderImage());
    return static_cast<RenderImage*>(object);
110
111
}

darin@apple.com's avatar
darin@apple.com committed
112
inline const RenderImage* toRenderImage(const RenderObject* object)
113
{ 
darin@apple.com's avatar
darin@apple.com committed
114
115
    ASSERT(!object || object->isRenderImage());
    return static_cast<const RenderImage*>(object);
116
117
118
119
120
}

// This will catch anyone doing an unnecessary cast.
void toRenderImage(const RenderImage*);

weinig's avatar
weinig committed
121
} // namespace WebCore
kocienda's avatar
kocienda committed
122

weinig's avatar
weinig committed
123
#endif // RenderImage_h