/src/mozilla-central/layout/style/CSSMozDocumentRule.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/dom/CSSMozDocumentRule.h" |
8 | | #include "mozilla/dom/CSSMozDocumentRuleBinding.h" |
9 | | #include "mozilla/ServoBindings.h" |
10 | | #include "nsContentUtils.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | using namespace mozilla::css; |
16 | | |
17 | | /* virtual */ JSObject* |
18 | | CSSMozDocumentRule::WrapObject(JSContext* aCx, |
19 | | JS::Handle<JSObject*> aGivenProto) |
20 | 0 | { |
21 | 0 | return CSSMozDocumentRule_Binding::Wrap(aCx, this, aGivenProto); |
22 | 0 | } |
23 | | |
24 | | bool |
25 | | CSSMozDocumentRule::Match(nsIDocument* aDoc, |
26 | | nsIURI* aDocURI, |
27 | | const nsACString& aDocURISpec, |
28 | | const nsACString& aPattern, |
29 | | DocumentMatchingFunction aMatchingFunction) |
30 | 0 | { |
31 | 0 | switch (aMatchingFunction) { |
32 | 0 | case DocumentMatchingFunction::MediaDocument: { |
33 | 0 | auto kind = aDoc->MediaDocumentKind(); |
34 | 0 | if (aPattern.EqualsLiteral("all")) { |
35 | 0 | return kind != nsIDocument::MediaDocumentKind::NotMedia; |
36 | 0 | } |
37 | 0 | MOZ_ASSERT(aPattern.EqualsLiteral("plugin") || |
38 | 0 | aPattern.EqualsLiteral("image") || |
39 | 0 | aPattern.EqualsLiteral("video")); |
40 | 0 | switch (kind) { |
41 | 0 | case nsIDocument::MediaDocumentKind::NotMedia: |
42 | 0 | return false; |
43 | 0 | case nsIDocument::MediaDocumentKind::Plugin: |
44 | 0 | return aPattern.EqualsLiteral("plugin"); |
45 | 0 | case nsIDocument::MediaDocumentKind::Image: |
46 | 0 | return aPattern.EqualsLiteral("image"); |
47 | 0 | case nsIDocument::MediaDocumentKind::Video: |
48 | 0 | return aPattern.EqualsLiteral("video"); |
49 | 0 | } |
50 | 0 | MOZ_ASSERT_UNREACHABLE("Unknown media document kind"); |
51 | 0 | return false; |
52 | 0 | } |
53 | 0 | case DocumentMatchingFunction::URL: |
54 | 0 | return aDocURISpec == aPattern; |
55 | 0 | case DocumentMatchingFunction::URLPrefix: |
56 | 0 | return StringBeginsWith(aDocURISpec, aPattern); |
57 | 0 | case DocumentMatchingFunction::Domain: { |
58 | 0 | nsAutoCString host; |
59 | 0 | if (aDocURI) { |
60 | 0 | aDocURI->GetHost(host); |
61 | 0 | } |
62 | 0 | int32_t lenDiff = host.Length() - aPattern.Length(); |
63 | 0 | if (lenDiff == 0) { |
64 | 0 | return host == aPattern; |
65 | 0 | } |
66 | 0 | return StringEndsWith(host, aPattern) && host.CharAt(lenDiff - 1) == '.'; |
67 | 0 | } |
68 | 0 | case DocumentMatchingFunction::RegExp: { |
69 | 0 | NS_ConvertUTF8toUTF16 spec(aDocURISpec); |
70 | 0 | NS_ConvertUTF8toUTF16 regex(aPattern); |
71 | 0 | return nsContentUtils::IsPatternMatching(spec, regex, aDoc); |
72 | 0 | } |
73 | 0 | } |
74 | 0 | MOZ_ASSERT_UNREACHABLE("Unknown matching function"); |
75 | 0 | return false; |
76 | 0 | } |
77 | | |
78 | | CSSMozDocumentRule::CSSMozDocumentRule(RefPtr<RawServoMozDocumentRule> aRawRule, |
79 | | StyleSheet* aSheet, |
80 | | css::Rule* aParentRule, |
81 | | uint32_t aLine, |
82 | | uint32_t aColumn) |
83 | | : css::ConditionRule(Servo_MozDocumentRule_GetRules(aRawRule).Consume(), |
84 | | aSheet, aParentRule, aLine, aColumn) |
85 | | , mRawRule(std::move(aRawRule)) |
86 | 0 | { |
87 | 0 | } |
88 | | |
89 | | NS_IMPL_ADDREF_INHERITED(CSSMozDocumentRule, css::ConditionRule) |
90 | | NS_IMPL_RELEASE_INHERITED(CSSMozDocumentRule, css::ConditionRule) |
91 | | |
92 | | // QueryInterface implementation for MozDocumentRule |
93 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSMozDocumentRule) |
94 | 0 | NS_INTERFACE_MAP_END_INHERITING(css::ConditionRule) |
95 | | |
96 | | #ifdef DEBUG |
97 | | /* virtual */ void |
98 | | CSSMozDocumentRule::List(FILE* out, int32_t aIndent) const |
99 | | { |
100 | | nsAutoCString str; |
101 | | for (int32_t i = 0; i < aIndent; i++) { |
102 | | str.AppendLiteral(" "); |
103 | | } |
104 | | Servo_MozDocumentRule_Debug(mRawRule, &str); |
105 | | fprintf_stderr(out, "%s\n", str.get()); |
106 | | } |
107 | | #endif |
108 | | |
109 | | void |
110 | | CSSMozDocumentRule::GetConditionText(nsAString& aConditionText) |
111 | 0 | { |
112 | 0 | Servo_MozDocumentRule_GetConditionText(mRawRule, &aConditionText); |
113 | 0 | } |
114 | | |
115 | | void |
116 | | CSSMozDocumentRule::SetConditionText(const nsAString& aConditionText, |
117 | | ErrorResult& aRv) |
118 | 0 | { |
119 | 0 | aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); |
120 | 0 | } |
121 | | |
122 | | /* virtual */ void |
123 | | CSSMozDocumentRule::GetCssText(nsAString& aCssText) const |
124 | 0 | { |
125 | 0 | Servo_MozDocumentRule_GetCssText(mRawRule, &aCssText); |
126 | 0 | } |
127 | | |
128 | | /* virtual */ size_t |
129 | | CSSMozDocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const |
130 | 0 | { |
131 | 0 | // TODO Implement this! |
132 | 0 | return aMallocSizeOf(this); |
133 | 0 | } |
134 | | |
135 | | } // namespace dom |
136 | | } // namespace mozilla |