PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/Doduo1.1.2/WebCore/css/CSSSelector.h

https://github.com/weissms/owb-mirror
C Header | 259 lines | 198 code | 32 blank | 29 comment | 11 complexity | d29aaf9954ee085fb31fc5349bbb87a2 MD5 | raw file
  1. /*
  2. * This file is part of the CSS implementation for KDE.
  3. *
  4. * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
  5. * 1999 Waldo Bastian (bastian@kde.org)
  6. * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this library; see the file COPYING.LIB. If not, write to
  20. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef CSSSelector_h
  24. #define CSSSelector_h
  25. #include "QualifiedName.h"
  26. #include <wtf/Noncopyable.h>
  27. #include <wtf/OwnPtr.h>
  28. namespace WebCore {
  29. // this class represents a selector for a StyleRule
  30. class CSSSelector : Noncopyable {
  31. public:
  32. CSSSelector()
  33. : m_tag(anyQName())
  34. , m_relation(Descendant)
  35. , m_match(None)
  36. , m_pseudoType(PseudoNotParsed)
  37. , m_parsedNth(false)
  38. , m_isLastInSelectorList(false)
  39. , m_hasRareData(false)
  40. {
  41. }
  42. CSSSelector(const QualifiedName& qName)
  43. : m_tag(qName)
  44. , m_relation(Descendant)
  45. , m_match(None)
  46. , m_pseudoType(PseudoNotParsed)
  47. , m_parsedNth(false)
  48. , m_isLastInSelectorList(false)
  49. , m_hasRareData(false)
  50. {
  51. }
  52. ~CSSSelector()
  53. {
  54. if (m_hasRareData)
  55. delete m_data.m_rareData;
  56. else
  57. delete m_data.m_tagHistory;
  58. }
  59. /**
  60. * Re-create selector text from selector's data
  61. */
  62. String selectorText() const;
  63. // checks if the 2 selectors (including sub selectors) agree.
  64. bool operator==(const CSSSelector&);
  65. // tag == -1 means apply to all elements (Selector = *)
  66. unsigned specificity();
  67. /* how the attribute value has to match.... Default is Exact */
  68. enum Match {
  69. None = 0,
  70. Id,
  71. Class,
  72. Exact,
  73. Set,
  74. List,
  75. Hyphen,
  76. PseudoClass,
  77. PseudoElement,
  78. Contain, // css3: E[foo*="bar"]
  79. Begin, // css3: E[foo^="bar"]
  80. End // css3: E[foo$="bar"]
  81. };
  82. enum Relation {
  83. Descendant = 0,
  84. Child,
  85. DirectAdjacent,
  86. IndirectAdjacent,
  87. SubSelector
  88. };
  89. enum PseudoType {
  90. PseudoNotParsed = 0,
  91. PseudoUnknown,
  92. PseudoEmpty,
  93. PseudoFirstChild,
  94. PseudoFirstOfType,
  95. PseudoLastChild,
  96. PseudoLastOfType,
  97. PseudoOnlyChild,
  98. PseudoOnlyOfType,
  99. PseudoFirstLine,
  100. PseudoFirstLetter,
  101. PseudoNthChild,
  102. PseudoNthOfType,
  103. PseudoNthLastChild,
  104. PseudoNthLastOfType,
  105. PseudoLink,
  106. PseudoVisited,
  107. PseudoAnyLink,
  108. PseudoAutofill,
  109. PseudoHover,
  110. PseudoDrag,
  111. PseudoFocus,
  112. PseudoActive,
  113. PseudoChecked,
  114. PseudoEnabled,
  115. PseudoFullPageMedia,
  116. PseudoDisabled,
  117. PseudoInputPlaceholder,
  118. PseudoReadOnly,
  119. PseudoReadWrite,
  120. PseudoIndeterminate,
  121. PseudoTarget,
  122. PseudoBefore,
  123. PseudoAfter,
  124. PseudoLang,
  125. PseudoNot,
  126. PseudoResizer,
  127. PseudoRoot,
  128. PseudoScrollbar,
  129. PseudoScrollbarBack,
  130. PseudoScrollbarButton,
  131. PseudoScrollbarCorner,
  132. PseudoScrollbarForward,
  133. PseudoScrollbarThumb,
  134. PseudoScrollbarTrack,
  135. PseudoScrollbarTrackPiece,
  136. PseudoWindowInactive,
  137. PseudoCornerPresent,
  138. PseudoDecrement,
  139. PseudoIncrement,
  140. PseudoHorizontal,
  141. PseudoVertical,
  142. PseudoStart,
  143. PseudoEnd,
  144. PseudoDoubleButton,
  145. PseudoSingleButton,
  146. PseudoNoButton,
  147. PseudoSelection,
  148. PseudoFileUploadButton,
  149. PseudoSliderThumb,
  150. PseudoSearchCancelButton,
  151. PseudoSearchDecoration,
  152. PseudoSearchResultsDecoration,
  153. PseudoSearchResultsButton,
  154. PseudoMediaControlsPanel,
  155. PseudoMediaControlsMuteButton,
  156. PseudoMediaControlsPlayButton,
  157. PseudoMediaControlsTimeDisplay,
  158. PseudoMediaControlsTimeline,
  159. PseudoMediaControlsSeekBackButton,
  160. PseudoMediaControlsSeekForwardButton,
  161. PseudoMediaControlsFullscreenButton
  162. };
  163. PseudoType pseudoType() const
  164. {
  165. if (m_pseudoType == PseudoNotParsed)
  166. extractPseudoType();
  167. return static_cast<PseudoType>(m_pseudoType);
  168. }
  169. CSSSelector* tagHistory() const { return m_hasRareData ? m_data.m_rareData->m_tagHistory.get() : m_data.m_tagHistory; }
  170. void setTagHistory(CSSSelector* tagHistory);
  171. bool hasTag() const { return m_tag != anyQName(); }
  172. bool hasAttribute() const { return m_match == Id || m_match == Class || (m_hasRareData && m_data.m_rareData->m_attribute != anyQName()); }
  173. const QualifiedName& attribute() const;
  174. const AtomicString& argument() const { return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; }
  175. CSSSelector* simpleSelector() const { return m_hasRareData ? m_data.m_rareData->m_simpleSelector.get() : 0; }
  176. void setAttribute(const QualifiedName& value);
  177. void setArgument(const AtomicString& value);
  178. void setSimpleSelector(CSSSelector* value);
  179. bool parseNth();
  180. bool matchNth(int count);
  181. Relation relation() const { return static_cast<Relation>(m_relation); }
  182. bool isLastInSelectorList() const { return m_isLastInSelectorList; }
  183. void setLastInSelectorList() { m_isLastInSelectorList = true; }
  184. mutable AtomicString m_value;
  185. QualifiedName m_tag;
  186. unsigned m_relation : 3; // enum Relation
  187. mutable unsigned m_match : 4; // enum Match
  188. mutable unsigned m_pseudoType : 8; // PseudoType
  189. private:
  190. bool m_parsedNth : 1; // Used for :nth-*
  191. bool m_isLastInSelectorList : 1;
  192. bool m_hasRareData : 1;
  193. void extractPseudoType() const;
  194. struct RareData {
  195. RareData(CSSSelector* tagHistory)
  196. : m_tagHistory(tagHistory)
  197. , m_simpleSelector(0)
  198. , m_attribute(anyQName())
  199. , m_argument(nullAtom)
  200. , m_a(0)
  201. , m_b(0)
  202. {
  203. }
  204. bool parseNth();
  205. bool matchNth(int count);
  206. OwnPtr<CSSSelector> m_tagHistory;
  207. OwnPtr<CSSSelector> m_simpleSelector; // Used for :not.
  208. QualifiedName m_attribute; // used for attribute selector
  209. AtomicString m_argument; // Used for :contains, :lang and :nth-*
  210. int m_a; // Used for :nth-*
  211. int m_b; // Used for :nth-*
  212. };
  213. void createRareData()
  214. {
  215. if (m_hasRareData)
  216. return;
  217. m_data.m_rareData = new RareData(m_data.m_tagHistory);
  218. m_hasRareData = true;
  219. }
  220. union DataUnion {
  221. DataUnion() : m_tagHistory(0) { }
  222. CSSSelector* m_tagHistory;
  223. RareData* m_rareData;
  224. } m_data;
  225. };
  226. } // namespace WebCore
  227. #endif // CSSSelector_h