hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 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.org | f684aec | 2011-10-19 13:31:03 +0000 | [diff] [blame] | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "CSSCanvasValue.h" |
| 28 | |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 29 | #include "RenderElement.h" |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | CSSCanvasValue::~CSSCanvasValue() |
| 34 | { |
| 35 | if (m_element) |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 36 | m_element->removeObserver(m_canvasObserver); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 37 | } |
| 38 | |
timothy_horton@apple.com | df4356a | 2013-09-04 20:13:30 +0000 | [diff] [blame] | 39 | String CSSCanvasValue::customCSSText() const |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 40 | { |
commit-queue@webkit.org | f91acdb | 2015-04-20 22:07:31 +0000 | [diff] [blame] | 41 | return makeString("-webkit-canvas(", m_name, ')'); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 42 | } |
| 43 | |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 44 | void CSSCanvasValue::canvasChanged(HTMLCanvasElement&, const FloatRect& changedRect) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 45 | { |
simon.fraser@apple.com | f7d140d | 2009-01-02 21:04:27 +0000 | [diff] [blame] | 46 | IntRect imageChangeRect = enclosingIntRect(changedRect); |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 47 | for (auto it = clients().begin(), end = clients().end(); it != end; ++it) |
| 48 | it->key->imageChanged(static_cast<WrappedImagePtr>(this), &imageChangeRect); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 49 | } |
| 50 | |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 51 | void CSSCanvasValue::canvasResized(HTMLCanvasElement&) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 52 | { |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 53 | for (auto it = clients().begin(), end = clients().end(); it != end; ++it) |
| 54 | it->key->imageChanged(static_cast<WrappedImagePtr>(this)); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 55 | } |
| 56 | |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 57 | void CSSCanvasValue::canvasDestroyed(HTMLCanvasElement& element) |
eric@webkit.org | 22b2c2c | 2009-05-14 01:44:27 +0000 | [diff] [blame] | 58 | { |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 59 | ASSERT_UNUSED(&element, &element == m_element); |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 60 | m_element = nullptr; |
eric@webkit.org | 22b2c2c | 2009-05-14 01:44:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
simon.fraser@apple.com | 81a0d96 | 2019-10-23 20:14:57 +0000 | [diff] [blame] | 63 | FloatSize CSSCanvasValue::fixedSize(const RenderElement& renderer) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 64 | { |
simon.fraser@apple.com | 81a0d96 | 2019-10-23 20:14:57 +0000 | [diff] [blame] | 65 | if (HTMLCanvasElement* elt = element(renderer.document())) |
zalan@apple.com | facdea7 | 2014-04-02 14:18:58 +0000 | [diff] [blame] | 66 | return FloatSize(elt->width(), elt->height()); |
simon.fraser@apple.com | 81a0d96 | 2019-10-23 20:14:57 +0000 | [diff] [blame] | 67 | return { }; |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 68 | } |
| 69 | |
akling@apple.com | 836b22b | 2013-08-25 21:22:06 +0000 | [diff] [blame] | 70 | HTMLCanvasElement* CSSCanvasValue::element(Document& document) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 71 | { |
| 72 | if (!m_element) { |
akling@apple.com | 836b22b | 2013-08-25 21:22:06 +0000 | [diff] [blame] | 73 | m_element = document.getCSSCanvasElement(m_name); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 74 | if (!m_element) |
weinig@apple.com | 6b952d6 | 2013-11-09 00:27:50 +0000 | [diff] [blame] | 75 | return nullptr; |
| 76 | m_element->addObserver(m_canvasObserver); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 77 | } |
mitz@apple.com | 92dc01a | 2008-10-02 18:48:33 +0000 | [diff] [blame] | 78 | return m_element; |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
simon.fraser@apple.com | 81a0d96 | 2019-10-23 20:14:57 +0000 | [diff] [blame] | 81 | RefPtr<Image> CSSCanvasValue::image(RenderElement& renderer, const FloatSize& /*size*/) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 82 | { |
simon.fraser@apple.com | 81a0d96 | 2019-10-23 20:14:57 +0000 | [diff] [blame] | 83 | ASSERT(clients().contains(&renderer)); |
| 84 | HTMLCanvasElement* element = this->element(renderer.document()); |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 85 | if (!element || !element->buffer()) |
gyuyoung.kim@webkit.org | 7e62568 | 2015-08-12 01:12:58 +0000 | [diff] [blame] | 86 | return nullptr; |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 87 | return element->copiedImage(); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 88 | } |
| 89 | |
commit-queue@webkit.org | b4b784a | 2013-02-11 11:00:54 +0000 | [diff] [blame] | 90 | bool CSSCanvasValue::equals(const CSSCanvasValue& other) const |
| 91 | { |
| 92 | return m_name == other.m_name; |
| 93 | } |
| 94 | |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 95 | } // namespace WebCore |