Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: Source/core/dom/StyleSheetCandidate.cpp

Issue 139273002: Refactoring: Extract StyleSheetCandidate from DocumentStyleSheetCollection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated to ToT Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/StyleSheetCandidate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Neither the name of Google Inc. nor the names of its
11 * contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "config.h"
28 #include "core/dom/StyleSheetCandidate.h"
29
30 #include "HTMLNames.h"
31 #include "core/dom/Element.h"
32 #include "core/dom/ProcessingInstruction.h"
33 #include "core/dom/StyleEngine.h"
34 #include "core/html/HTMLLinkElement.h"
35 #include "core/html/HTMLStyleElement.h"
36 #include "core/svg/SVGStyleElement.h"
37
38 namespace WebCore {
39
40 using namespace HTMLNames;
41
42 AtomicString StyleSheetCandidate::title() const
43 {
44 return isElement() ? toElement(m_node).getAttribute(titleAttr) : nullAtom;
45 }
46
47 bool StyleSheetCandidate::isXSL() const
48 {
49 return !m_node.document().isHTMLDocument() && m_type == Pi && toProcessingIn struction(m_node).isXSL();
50 }
51
52 bool StyleSheetCandidate::isAlternate() const
53 {
54 if (!isElement())
55 return false;
56 return toElement(m_node).getAttribute(relAttr).contains("alternate");
57 }
58
59 bool StyleSheetCandidate::isEnabledViaScript() const
60 {
61 return isHTMLLink() && toHTMLLinkElement(m_node).isEnabledViaScript();
62 }
63
64 bool StyleSheetCandidate::isEnabledAndLoading() const
65 {
66 return isHTMLLink() && !toHTMLLinkElement(m_node).isDisabled() && toHTMLLink Element(m_node).styleSheetIsLoading();
67 }
68
69 bool StyleSheetCandidate::hasPreferrableName(const String& currentPreferrableNam e) const
70 {
71 ASSERT(isEnabledAndLoading() || sheet());
72 return !isEnabledViaScript() && !title().isEmpty() && !isAlternate() && curr entPreferrableName.isEmpty();
73 }
74
75 bool StyleSheetCandidate::canBeActivated(const String& currentPreferrableName) c onst
76 {
77 StyleSheet* sheet = this->sheet();
78 if (!sheet || sheet->disabled() || !sheet->isCSSStyleSheet())
79 return false;
80 const AtomicString& title = this->title();
81 if (!isEnabledViaScript() && !title.isEmpty() && title != currentPreferrable Name)
82 return false;
83 if (isAlternate() && title.isEmpty())
84 return false;
85
86 return true;
87 }
88
89 StyleSheetCandidate::Type StyleSheetCandidate::typeOf(Node& node)
90 {
91 if (node.nodeType() == Node::PROCESSING_INSTRUCTION_NODE)
92 return Pi;
93
94 if (node.isHTMLElement()) {
95 if (node.hasTagName(linkTag))
96 return HTMLLink;
97 if (node.hasTagName(styleTag))
98 return HTMLStyle;
99
100 ASSERT_NOT_REACHED();
101 return HTMLStyle;
102 }
103
104 if (node.isSVGElement() && node.hasTagName(SVGNames::styleTag))
105 return SVGStyle;
106
107 ASSERT_NOT_REACHED();
108 return HTMLStyle;
109 }
110
111 StyleSheet* StyleSheetCandidate::sheet() const
112 {
113 switch (m_type) {
114 case HTMLLink:
115 return toHTMLLinkElement(m_node).sheet();
116 case HTMLStyle:
117 return toHTMLStyleElement(m_node).sheet();
118 case SVGStyle:
119 return toSVGStyleElement(m_node).sheet();
120 case Pi:
121 return toProcessingInstruction(m_node).sheet();
122 }
123
124 ASSERT_NOT_REACHED();
125 return 0;
126 }
127
128 }
OLDNEW
« no previous file with comments | « Source/core/dom/StyleSheetCandidate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698