| OLD | NEW | 
|---|
|  | (Empty) | 
| 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  * |  | 
| 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 |  | 
| 23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |  | 
| 24  */ |  | 
| 25 |  | 
| 26 #include "config.h" |  | 
| 27 #include "core/css/CSSCanvasValue.h" |  | 
| 28 |  | 
| 29 #include "core/frame/UseCounter.h" |  | 
| 30 #include "core/layout/LayoutObject.h" |  | 
| 31 #include "wtf/text/StringBuilder.h" |  | 
| 32 |  | 
| 33 namespace blink { |  | 
| 34 |  | 
| 35 CSSCanvasValue::~CSSCanvasValue() |  | 
| 36 { |  | 
| 37 #if !ENABLE(OILPAN) |  | 
| 38     if (m_element) |  | 
| 39         m_element->removeObserver(m_canvasObserver.get()); |  | 
| 40 #endif |  | 
| 41 } |  | 
| 42 |  | 
| 43 String CSSCanvasValue::customCSSText() const |  | 
| 44 { |  | 
| 45     StringBuilder result; |  | 
| 46     result.appendLiteral("-webkit-canvas("); |  | 
| 47     result.append(m_name); |  | 
| 48     result.append(')'); |  | 
| 49     return result.toString(); |  | 
| 50 } |  | 
| 51 |  | 
| 52 void CSSCanvasValue::canvasChanged(HTMLCanvasElement*, const FloatRect& changedR
     ect) |  | 
| 53 { |  | 
| 54     IntRect imageChangeRect = enclosingIntRect(changedRect); |  | 
| 55     for (const auto& curr : clients()) |  | 
| 56         const_cast<LayoutObject*>(curr.key)->imageChanged(static_cast<WrappedIma
     gePtr>(this), &imageChangeRect); |  | 
| 57 } |  | 
| 58 |  | 
| 59 void CSSCanvasValue::canvasResized(HTMLCanvasElement*) |  | 
| 60 { |  | 
| 61     for (const auto& curr : clients()) |  | 
| 62         const_cast<LayoutObject*>(curr.key)->imageChanged(static_cast<WrappedIma
     gePtr>(this)); |  | 
| 63 } |  | 
| 64 |  | 
| 65 #if !ENABLE(OILPAN) |  | 
| 66 void CSSCanvasValue::canvasDestroyed(HTMLCanvasElement* element) |  | 
| 67 { |  | 
| 68     ASSERT_UNUSED(element, element == m_element); |  | 
| 69     m_element = nullptr; |  | 
| 70 } |  | 
| 71 #endif |  | 
| 72 |  | 
| 73 IntSize CSSCanvasValue::fixedSize(const LayoutObject* layoutObject) |  | 
| 74 { |  | 
| 75     if (HTMLCanvasElement* elt = element(&layoutObject->document())) |  | 
| 76         return IntSize(elt->width(), elt->height()); |  | 
| 77     return IntSize(); |  | 
| 78 } |  | 
| 79 |  | 
| 80 HTMLCanvasElement* CSSCanvasValue::element(Document* document) |  | 
| 81 { |  | 
| 82     if (!m_element) { |  | 
| 83         m_element = &document->getCSSCanvasElement(m_name); |  | 
| 84         m_element->addObserver(m_canvasObserver.get()); |  | 
| 85     } |  | 
| 86     return m_element; |  | 
| 87 } |  | 
| 88 |  | 
| 89 PassRefPtr<Image> CSSCanvasValue::image(const LayoutObject* layoutObject, const 
     IntSize& /*size*/) |  | 
| 90 { |  | 
| 91     ASSERT(clients().contains(layoutObject)); |  | 
| 92     HTMLCanvasElement* elt = element(&layoutObject->document()); |  | 
| 93     if (!elt) |  | 
| 94         return nullptr; |  | 
| 95     UseCounter::count(layoutObject->document(), UseCounter::WebkitCanvas); |  | 
| 96     return elt->copiedImage(FrontBuffer, PreferNoAcceleration); |  | 
| 97 } |  | 
| 98 |  | 
| 99 bool CSSCanvasValue::equals(const CSSCanvasValue& other) const |  | 
| 100 { |  | 
| 101     return m_name == other.m_name; |  | 
| 102 } |  | 
| 103 |  | 
| 104 DEFINE_TRACE_AFTER_DISPATCH(CSSCanvasValue) |  | 
| 105 { |  | 
| 106     visitor->trace(m_canvasObserver); |  | 
| 107     visitor->trace(m_element); |  | 
| 108     CSSImageGeneratorValue::traceAfterDispatch(visitor); |  | 
| 109 } |  | 
| 110 |  | 
| 111 } // namespace blink |  | 
| OLD | NEW | 
|---|