• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5  * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6  * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8  * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9  * Copyright (C) 2012 Intel Corporation. All rights reserved.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26 
27 #include "config.h"
28 #include "core/css/CSSParserMode.h"
29 
30 #include "core/dom/Document.h"
31 #include "core/frame/Settings.h"
32 
33 namespace WebCore {
34 
CSSParserContext(CSSParserMode mode,UseCounter * useCounter)35 CSSParserContext::CSSParserContext(CSSParserMode mode, UseCounter* useCounter)
36     : m_mode(mode)
37     , m_isHTMLDocument(false)
38     , m_useLegacyBackgroundSizeShorthandBehavior(false)
39     , m_useCounter(useCounter)
40 {
41 }
42 
CSSParserContext(const Document & document,UseCounter * useCounter,const KURL & baseURL,const String & charset)43 CSSParserContext::CSSParserContext(const Document& document, UseCounter* useCounter, const KURL& baseURL, const String& charset)
44     : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL)
45     , m_charset(charset)
46     , m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode)
47     , m_referrer(m_baseURL.strippedForUseAsReferrer(), document.referrerPolicy())
48     , m_isHTMLDocument(document.isHTMLDocument())
49     , m_useLegacyBackgroundSizeShorthandBehavior(document.settings() ? document.settings()->useLegacyBackgroundSizeShorthandBehavior() : false)
50     , m_useCounter(useCounter)
51 {
52 }
53 
CSSParserContext(const CSSParserContext & other,UseCounter * useCounter)54 CSSParserContext::CSSParserContext(const CSSParserContext& other, UseCounter* useCounter)
55     : m_baseURL(other.m_baseURL)
56     , m_charset(other.m_charset)
57     , m_mode(other.m_mode)
58     , m_referrer(other.m_referrer)
59     , m_isHTMLDocument(other.m_isHTMLDocument)
60     , m_useLegacyBackgroundSizeShorthandBehavior(other.m_useLegacyBackgroundSizeShorthandBehavior)
61     , m_useCounter(useCounter)
62 {
63 }
64 
operator ==(const CSSParserContext & other) const65 bool CSSParserContext::operator==(const CSSParserContext& other) const
66 {
67     return m_baseURL == other.m_baseURL
68         && m_charset == other.m_charset
69         && m_mode == other.m_mode
70         && m_isHTMLDocument == other.m_isHTMLDocument
71         && m_useLegacyBackgroundSizeShorthandBehavior == other.m_useLegacyBackgroundSizeShorthandBehavior;
72 }
73 
strictCSSParserContext()74 const CSSParserContext& strictCSSParserContext()
75 {
76     DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, (HTMLStandardMode, 0));
77     return strictContext;
78 }
79 
completeURL(const String & url) const80 KURL CSSParserContext::completeURL(const String& url) const
81 {
82     if (url.isNull())
83         return KURL();
84     if (charset().isEmpty())
85         return KURL(baseURL(), url);
86     return KURL(baseURL(), url, charset());
87 }
88 
89 } // namespace WebCore
90