Home | History | Annotate | Download | only in resolver
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
      4  * Copyright (C) 2013 Google Inc. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  *
     21  */
     22 
     23 #include "config.h"
     24 #include "core/css/resolver/ElementStyleResources.h"
     25 
     26 #include "core/css/CSSGradientValue.h"
     27 #include "core/css/CSSSVGDocumentValue.h"
     28 #include "core/rendering/style/StyleGeneratedImage.h"
     29 #include "core/rendering/style/StyleImage.h"
     30 #include "core/rendering/style/StylePendingImage.h"
     31 #include "platform/graphics/filters/FilterOperation.h"
     32 
     33 namespace WebCore {
     34 
     35 ElementStyleResources::ElementStyleResources()
     36     : m_hasNewCustomFilterProgram(false)
     37     , m_deviceScaleFactor(1)
     38 {
     39 }
     40 
     41 PassRefPtr<StyleImage> ElementStyleResources::styleImage(const TextLinkColors& textLinkColors, Color currentColor, CSSPropertyID property, CSSValue* value)
     42 {
     43     if (value->isImageValue())
     44         return cachedOrPendingFromValue(property, toCSSImageValue(value));
     45 
     46     if (value->isImageGeneratorValue()) {
     47         if (value->isGradientValue())
     48             return generatedOrPendingFromValue(property, toCSSGradientValue(value)->gradientWithStylesResolved(textLinkColors, currentColor).get());
     49         return generatedOrPendingFromValue(property, toCSSImageGeneratorValue(value));
     50     }
     51 
     52     if (value->isImageSetValue())
     53         return setOrPendingFromValue(property, toCSSImageSetValue(value));
     54 
     55     if (value->isCursorImageValue())
     56         return cursorOrPendingFromValue(property, toCSSCursorImageValue(value));
     57 
     58     return 0;
     59 }
     60 
     61 PassRefPtr<StyleImage> ElementStyleResources::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
     62 {
     63     if (value->isPending()) {
     64         m_pendingImageProperties.set(property, value);
     65         return StylePendingImage::create(value);
     66     }
     67     return StyleGeneratedImage::create(value);
     68 }
     69 
     70 PassRefPtr<StyleImage> ElementStyleResources::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
     71 {
     72     RefPtr<StyleImage> image = value->cachedOrPendingImageSet(m_deviceScaleFactor);
     73     if (image && image->isPendingImage())
     74         m_pendingImageProperties.set(property, value);
     75     return image.release();
     76 }
     77 
     78 PassRefPtr<StyleImage> ElementStyleResources::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue* value)
     79 {
     80     RefPtr<StyleImage> image = value->cachedOrPendingImage();
     81     if (image && image->isPendingImage())
     82         m_pendingImageProperties.set(property, value);
     83     return image.release();
     84 }
     85 
     86 PassRefPtr<StyleImage> ElementStyleResources::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue* value)
     87 {
     88     RefPtr<StyleImage> image = value->cachedOrPendingImage(m_deviceScaleFactor);
     89     if (image && image->isPendingImage())
     90         m_pendingImageProperties.set(property, value);
     91     return image.release();
     92 }
     93 
     94 void ElementStyleResources::addPendingSVGDocument(FilterOperation* filterOperation, CSSSVGDocumentValue* cssSVGDocumentValue)
     95 {
     96     m_pendingSVGDocuments.set(filterOperation, cssSVGDocumentValue);
     97 }
     98 
     99 }
    100