/src/3rdparty/webkit/Source/WebCore/html/HTMLCanvasElement.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 169 lines · 99 code · 41 blank · 29 comment · 3 complexity · 407e76dd19c0da3d4bcf4725787f6cdf MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2007 Alp Toker <alp@atoker.com>
  4. * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  16. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  19. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  23. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef HTMLCanvasElement_h
  28. #define HTMLCanvasElement_h
  29. #include "FloatRect.h"
  30. #include "HTMLElement.h"
  31. #include "IntSize.h"
  32. #if PLATFORM(CHROMIUM) || PLATFORM(QT)
  33. #define DefaultInterpolationQuality InterpolationMedium
  34. #elif USE(CG)
  35. #define DefaultInterpolationQuality InterpolationLow
  36. #else
  37. #define DefaultInterpolationQuality InterpolationDefault
  38. #endif
  39. namespace WebCore {
  40. class CanvasContextAttributes;
  41. class CanvasRenderingContext;
  42. class GraphicsContext;
  43. class HTMLCanvasElement;
  44. class Image;
  45. class ImageData;
  46. class ImageBuffer;
  47. class IntSize;
  48. class CanvasObserver {
  49. public:
  50. virtual ~CanvasObserver() { }
  51. virtual void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect) = 0;
  52. virtual void canvasResized(HTMLCanvasElement*) = 0;
  53. virtual void canvasDestroyed(HTMLCanvasElement*) = 0;
  54. };
  55. class HTMLCanvasElement : public HTMLElement {
  56. public:
  57. static PassRefPtr<HTMLCanvasElement> create(Document*);
  58. static PassRefPtr<HTMLCanvasElement> create(const QualifiedName&, Document*);
  59. virtual ~HTMLCanvasElement();
  60. void addObserver(CanvasObserver*);
  61. void removeObserver(CanvasObserver*);
  62. // Attributes and functions exposed to script
  63. int width() const { return size().width(); }
  64. int height() const { return size().height(); }
  65. const IntSize& size() const { return m_size; }
  66. void setWidth(int);
  67. void setHeight(int);
  68. void setSize(const IntSize& newSize)
  69. {
  70. if (newSize == size())
  71. return;
  72. m_ignoreReset = true;
  73. setWidth(newSize.width());
  74. setHeight(newSize.height());
  75. m_ignoreReset = false;
  76. reset();
  77. }
  78. CanvasRenderingContext* getContext(const String&, CanvasContextAttributes* attributes = 0);
  79. String toDataURL(const String& mimeType, const double* quality, ExceptionCode&);
  80. String toDataURL(const String& mimeType, ExceptionCode& ec) { return toDataURL(mimeType, 0, ec); }
  81. // Used for rendering
  82. void didDraw(const FloatRect&);
  83. void paint(GraphicsContext*, const IntRect&);
  84. GraphicsContext* drawingContext() const;
  85. GraphicsContext* existingDrawingContext() const;
  86. CanvasRenderingContext* renderingContext() const { return m_context.get(); }
  87. ImageBuffer* buffer() const;
  88. Image* copiedImage() const;
  89. void clearCopiedImage();
  90. PassRefPtr<ImageData> getImageData();
  91. void makePresentationCopy();
  92. void clearPresentationCopy();
  93. IntRect convertLogicalToDevice(const FloatRect&) const;
  94. IntSize convertLogicalToDevice(const FloatSize&) const;
  95. IntSize convertToValidDeviceSize(float width, float height) const;
  96. const SecurityOrigin& securityOrigin() const;
  97. void setOriginTainted() { m_originClean = false; }
  98. bool originClean() const { return m_originClean; }
  99. CSSStyleSelector* styleSelector();
  100. AffineTransform baseTransform() const;
  101. #if ENABLE(WEBGL)
  102. bool is3D() const;
  103. #endif
  104. void makeRenderingResultsAvailable();
  105. private:
  106. HTMLCanvasElement(const QualifiedName&, Document*);
  107. virtual void parseMappedAttribute(Attribute*);
  108. virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
  109. void reset();
  110. void createImageBuffer() const;
  111. void setSurfaceSize(const IntSize&);
  112. bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
  113. HashSet<CanvasObserver*> m_observers;
  114. IntSize m_size;
  115. OwnPtr<CanvasRenderingContext> m_context;
  116. bool m_rendererIsCanvas;
  117. bool m_ignoreReset;
  118. FloatRect m_dirtyRect;
  119. float m_pageScaleFactor;
  120. bool m_originClean;
  121. // m_createdImageBuffer means we tried to malloc the buffer. We didn't necessarily get it.
  122. mutable bool m_hasCreatedImageBuffer;
  123. mutable OwnPtr<ImageBuffer> m_imageBuffer;
  124. mutable RefPtr<Image> m_presentedImage;
  125. mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platforms that have to copy the image buffer to render (and for CSSCanvasValue).
  126. };
  127. } //namespace
  128. #endif