blob: cdf405a1cc0b39082696c57f8f7a220600791d9c [file] [log] [blame]
hyatt@apple.com805aaf42008-04-12 03:24:45 +00001/*
darin@apple.com894e8132008-06-17 19:16:22 +00002 * Copyright (C) 2008 Apple Inc. All rights reserved.
hyatt@apple.com805aaf42008-04-12 03:24:45 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
apavlov@chromium.orgf684aec2011-10-19 13:31:03 +000023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hyatt@apple.com805aaf42008-04-12 03:24:45 +000024 */
25
26#ifndef CSSImageGeneratorValue_h
27#define CSSImageGeneratorValue_h
28
29#include "CSSValue.h"
zimmermann@webkit.org57e4d0f2011-11-08 12:29:38 +000030#include "IntSizeHash.h"
31#include <wtf/HashCountedSet.h>
32#include <wtf/RefPtr.h>
hyatt@apple.com805aaf42008-04-12 03:24:45 +000033
34namespace WebCore {
35
timothy_horton@apple.com37b17642011-11-17 01:28:25 +000036class CachedResourceLoader;
hyatt@apple.com805aaf42008-04-12 03:24:45 +000037class Image;
hyatt@apple.com805aaf42008-04-12 03:24:45 +000038class RenderObject;
commit-queue@webkit.org0cda1fa2012-07-24 05:34:42 +000039class StyleResolver;
hyatt@apple.com805aaf42008-04-12 03:24:45 +000040
zimmermann@webkit.org57e4d0f2011-11-08 12:29:38 +000041struct SizeAndCount {
42 SizeAndCount(IntSize newSize = IntSize(), int newCount = 0)
43 : size(newSize)
44 , count(newCount)
45 {
46 }
47
48 IntSize size;
49 int count;
50};
51
52typedef HashMap<const RenderObject*, SizeAndCount> RenderObjectSizeCountMap;
53
hyatt@apple.com805aaf42008-04-12 03:24:45 +000054class CSSImageGeneratorValue : public CSSValue {
55public:
andreas.kling@nokia.coma5eb3c52011-11-08 18:27:07 +000056 ~CSSImageGeneratorValue();
hyatt@apple.com805aaf42008-04-12 03:24:45 +000057
hyatt@apple.com805aaf42008-04-12 03:24:45 +000058 void addClient(RenderObject*, const IntSize&);
59 void removeClient(RenderObject*);
andreas.kling@nokia.com30778ea2011-11-08 17:33:07 +000060 PassRefPtr<Image> image(RenderObject*, const IntSize&);
hyatt@apple.com18d8fbf2008-04-13 08:16:23 +000061
andreas.kling@nokia.com30778ea2011-11-08 17:33:07 +000062 bool isFixedSize() const;
63 IntSize fixedSize(const RenderObject*);
apavlov@chromium.orgf684aec2011-10-19 13:31:03 +000064
timothy_horton@apple.com37b17642011-11-17 01:28:25 +000065 bool isPending() const;
66
67 void loadSubimages(CachedResourceLoader*);
68
hyatt@apple.com805aaf42008-04-12 03:24:45 +000069protected:
andreas.kling@nokia.com5fd2a712011-11-07 21:19:45 +000070 CSSImageGeneratorValue(ClassType);
apavlov@chromium.orgf684aec2011-10-19 13:31:03 +000071
hyatt@apple.com805aaf42008-04-12 03:24:45 +000072 Image* getImage(RenderObject*, const IntSize&);
eric@webkit.org0f901682008-08-29 21:38:56 +000073 void putImage(const IntSize&, PassRefPtr<Image>);
zimmermann@webkit.org57e4d0f2011-11-08 12:29:38 +000074 const RenderObjectSizeCountMap& clients() const { return m_clients; }
hyatt@apple.com805aaf42008-04-12 03:24:45 +000075
yurys@chromium.org3f4777f2012-08-06 14:09:59 +000076 void reportBaseClassMemoryUsage(MemoryObjectInfo*) const;
77
zimmermann@webkit.org57e4d0f2011-11-08 12:29:38 +000078 HashCountedSet<IntSize> m_sizes; // A count of how many times a given image size is in use.
79 RenderObjectSizeCountMap m_clients; // A map from RenderObjects (with entry count) to image sizes.
80 HashMap<IntSize, RefPtr<Image> > m_images; // A cache of Image objects by image size.
hyatt@apple.com805aaf42008-04-12 03:24:45 +000081};
82
83} // namespace WebCore
84
85#endif // CSSImageGeneratorValue_h