/platform/external/webkit/WebCore/css/CSSImageValue.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 92 lines · 58 code · 14 blank · 20 comment · 7 complexity · a9a49bba520ba9728d61ec46f112287f MD5 · raw file

  1. /*
  2. * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "config.h"
  21. #include "CSSImageValue.h"
  22. #include "CSSValueKeywords.h"
  23. #include "Cache.h"
  24. #include "CachedImage.h"
  25. #include "DocLoader.h"
  26. #include "StyleCachedImage.h"
  27. namespace WebCore {
  28. CSSImageValue::CSSImageValue(const String& url)
  29. : CSSPrimitiveValue(url, CSS_URI)
  30. , m_accessedImage(false)
  31. {
  32. }
  33. CSSImageValue::CSSImageValue()
  34. : CSSPrimitiveValue(CSSValueNone)
  35. , m_accessedImage(true)
  36. {
  37. }
  38. CSSImageValue::~CSSImageValue()
  39. {
  40. if (m_image)
  41. m_image->cachedImage()->removeClient(this);
  42. }
  43. StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader)
  44. {
  45. return cachedImage(loader, getStringValue());
  46. }
  47. StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& url)
  48. {
  49. if (!m_accessedImage) {
  50. m_accessedImage = true;
  51. CachedImage* cachedImage = 0;
  52. if (loader)
  53. cachedImage = loader->requestImage(url);
  54. else {
  55. // FIXME: Should find a way to make these images sit in their own memory partition, since they are user agent images.
  56. cachedImage = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(ParsedURLString, url), String()));
  57. }
  58. if (cachedImage) {
  59. cachedImage->addClient(this);
  60. m_image = StyleCachedImage::create(cachedImage);
  61. }
  62. }
  63. return m_image.get();
  64. }
  65. String CSSImageValue::cachedImageURL()
  66. {
  67. if (!m_image)
  68. return String();
  69. return m_image->cachedImage()->url();
  70. }
  71. void CSSImageValue::clearCachedImage()
  72. {
  73. if (m_image)
  74. m_image->cachedImage()->removeClient(this);
  75. m_image = 0;
  76. m_accessedImage = false;
  77. }
  78. } // namespace WebCore