blob: f7fb372ef6b0172be296b9685557599626fab5f2 [file] [log] [blame]
hyatt@apple.com68382152008-04-17 04:13:36 +00001/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
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 *
mjs@apple.com92047332014-03-15 04:08:27 +000013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
hyatt@apple.com68382152008-04-17 04:13:36 +000014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
hyatt@apple.com68382152008-04-17 04:13:36 +000017 * 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.com68382152008-04-17 04:13:36 +000024 */
25
26#include "config.h"
27#include "CSSCanvasValue.h"
28
darin@apple.com8cdf7122013-09-30 02:40:50 +000029#include "RenderElement.h"
hyatt@apple.com68382152008-04-17 04:13:36 +000030
31namespace WebCore {
32
33CSSCanvasValue::~CSSCanvasValue()
34{
35 if (m_element)
weinig@apple.com6b952d62013-11-09 00:27:50 +000036 m_element->removeObserver(m_canvasObserver);
hyatt@apple.com68382152008-04-17 04:13:36 +000037}
38
timothy_horton@apple.comdf4356a2013-09-04 20:13:30 +000039String CSSCanvasValue::customCSSText() const
hyatt@apple.com68382152008-04-17 04:13:36 +000040{
commit-queue@webkit.orgf91acdb2015-04-20 22:07:31 +000041 return makeString("-webkit-canvas(", m_name, ')');
hyatt@apple.com68382152008-04-17 04:13:36 +000042}
43
weinig@apple.com6b952d62013-11-09 00:27:50 +000044void CSSCanvasValue::canvasChanged(HTMLCanvasElement&, const FloatRect& changedRect)
hyatt@apple.com68382152008-04-17 04:13:36 +000045{
simon.fraser@apple.comf7d140d2009-01-02 21:04:27 +000046 IntRect imageChangeRect = enclosingIntRect(changedRect);
darin@apple.com8cdf7122013-09-30 02:40:50 +000047 for (auto it = clients().begin(), end = clients().end(); it != end; ++it)
48 it->key->imageChanged(static_cast<WrappedImagePtr>(this), &imageChangeRect);
hyatt@apple.com68382152008-04-17 04:13:36 +000049}
50
weinig@apple.com6b952d62013-11-09 00:27:50 +000051void CSSCanvasValue::canvasResized(HTMLCanvasElement&)
hyatt@apple.com68382152008-04-17 04:13:36 +000052{
darin@apple.com8cdf7122013-09-30 02:40:50 +000053 for (auto it = clients().begin(), end = clients().end(); it != end; ++it)
54 it->key->imageChanged(static_cast<WrappedImagePtr>(this));
hyatt@apple.com68382152008-04-17 04:13:36 +000055}
56
weinig@apple.com6b952d62013-11-09 00:27:50 +000057void CSSCanvasValue::canvasDestroyed(HTMLCanvasElement& element)
eric@webkit.org22b2c2c2009-05-14 01:44:27 +000058{
weinig@apple.com6b952d62013-11-09 00:27:50 +000059 ASSERT_UNUSED(&element, &element == m_element);
darin@apple.com8cdf7122013-09-30 02:40:50 +000060 m_element = nullptr;
eric@webkit.org22b2c2c2009-05-14 01:44:27 +000061}
62
simon.fraser@apple.com81a0d962019-10-23 20:14:57 +000063FloatSize CSSCanvasValue::fixedSize(const RenderElement& renderer)
hyatt@apple.com68382152008-04-17 04:13:36 +000064{
simon.fraser@apple.com81a0d962019-10-23 20:14:57 +000065 if (HTMLCanvasElement* elt = element(renderer.document()))
zalan@apple.comfacdea72014-04-02 14:18:58 +000066 return FloatSize(elt->width(), elt->height());
simon.fraser@apple.com81a0d962019-10-23 20:14:57 +000067 return { };
hyatt@apple.com68382152008-04-17 04:13:36 +000068}
69
akling@apple.com836b22b2013-08-25 21:22:06 +000070HTMLCanvasElement* CSSCanvasValue::element(Document& document)
hyatt@apple.com68382152008-04-17 04:13:36 +000071{
72 if (!m_element) {
akling@apple.com836b22b2013-08-25 21:22:06 +000073 m_element = document.getCSSCanvasElement(m_name);
hyatt@apple.com68382152008-04-17 04:13:36 +000074 if (!m_element)
weinig@apple.com6b952d62013-11-09 00:27:50 +000075 return nullptr;
76 m_element->addObserver(m_canvasObserver);
hyatt@apple.com68382152008-04-17 04:13:36 +000077 }
mitz@apple.com92dc01a2008-10-02 18:48:33 +000078 return m_element;
hyatt@apple.com68382152008-04-17 04:13:36 +000079}
80
simon.fraser@apple.com81a0d962019-10-23 20:14:57 +000081RefPtr<Image> CSSCanvasValue::image(RenderElement& renderer, const FloatSize& /*size*/)
hyatt@apple.com68382152008-04-17 04:13:36 +000082{
simon.fraser@apple.com81a0d962019-10-23 20:14:57 +000083 ASSERT(clients().contains(&renderer));
84 HTMLCanvasElement* element = this->element(renderer.document());
darin@apple.com8cdf7122013-09-30 02:40:50 +000085 if (!element || !element->buffer())
gyuyoung.kim@webkit.org7e625682015-08-12 01:12:58 +000086 return nullptr;
darin@apple.com8cdf7122013-09-30 02:40:50 +000087 return element->copiedImage();
hyatt@apple.com68382152008-04-17 04:13:36 +000088}
89
commit-queue@webkit.orgb4b784a2013-02-11 11:00:54 +000090bool CSSCanvasValue::equals(const CSSCanvasValue& other) const
91{
92 return m_name == other.m_name;
93}
94
hyatt@apple.com68382152008-04-17 04:13:36 +000095} // namespace WebCore