1/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2002, 2005, 2006, 2007, 2012 Apple 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#include "config.h"
23#include "core/css/CSSRule.h"
24
25#include "core/css/CSSStyleSheet.h"
26#include "core/css/StyleRule.h"
27#include "core/css/StyleSheetContents.h"
28#include "platform/NotImplemented.h"
29
30namespace blink {
31
32// VC++ 2013 doesn't support EBCO (Empty Base Class Optimization), and having
33// multiple empty base classes makes the size of CSSRule bloat (Note that both
34// of GarbageCollectedFinalized and ScriptWrappableBase are empty classes).
35// See the following article for details.
36// http://social.msdn.microsoft.com/forums/vstudio/en-US/504c6598-6076-4acf-96b6-e6acb475d302/vc-multiple-inheritance-empty-base-classes-bloats-object-size
37//
38// FIXME: Remove ScriptWrappableBase from the base class list once VC++'s issue
39// gets fixed.
40// Note that we're going to split CSSRule class into two classes; CSSOMRule
41// (assumed name) which derives ScriptWrappable and CSSRule (new one) which
42// doesn't derive ScriptWrappable or ScriptWrappableBase. Then, we can safely
43// remove ScriptWrappableBase from the base class list.
44struct SameSizeAsCSSRule : public RefCountedWillBeGarbageCollectedFinalized<SameSizeAsCSSRule>, public ScriptWrappableBase {
45    virtual ~SameSizeAsCSSRule();
46    unsigned char bitfields;
47    void* pointerUnion;
48};
49
50COMPILE_ASSERT(sizeof(CSSRule) == sizeof(SameSizeAsCSSRule), CSSRule_should_stay_small);
51
52COMPILE_ASSERT(StyleRuleBase::Viewport == static_cast<StyleRuleBase::Type>(CSSRule::VIEWPORT_RULE), enums_should_match);
53
54void CSSRule::setCSSText(const String&)
55{
56    notImplemented();
57}
58
59const CSSParserContext& CSSRule::parserContext() const
60{
61    CSSStyleSheet* styleSheet = parentStyleSheet();
62    return styleSheet ? styleSheet->contents()->parserContext() : strictCSSParserContext();
63}
64
65void CSSRule::trace(Visitor* visitor)
66{
67#if ENABLE(OILPAN)
68    // This makes the parent link strong, which is different from the
69    // pre-oilpan world, where the parent link is mysteriously zeroed under
70    // some circumstances.
71    if (m_parentIsRule)
72        visitor->trace(m_parentRule);
73    else
74        visitor->trace(m_parentStyleSheet);
75#endif
76}
77
78} // namespace blink
79