InspectorCSSOMWrappers.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  3. * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
  4. * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
  5. * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
  6. * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
  7. * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
  8. * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
  9. * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
  10. * Copyright (C) Research In Motion Limited 2011. All rights reserved.
  11. * Copyright (C) 2012 Google Inc. All rights reserved.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Library General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2 of the License, or (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Library General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Library General Public License
  24. * along with this library; see the file COPYING.LIB. If not, write to
  25. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. * Boston, MA 02110-1301, USA.
  27. */
  28. #include "config.h"
  29. #include "InspectorCSSOMWrappers.h"
  30. #include "CSSDefaultStyleSheets.h"
  31. #include "CSSHostRule.h"
  32. #include "CSSImportRule.h"
  33. #include "CSSMediaRule.h"
  34. #include "CSSRule.h"
  35. #include "CSSStyleRule.h"
  36. #include "CSSStyleSheet.h"
  37. #include "CSSSupportsRule.h"
  38. #include "DocumentStyleSheetCollection.h"
  39. #include "StyleSheetContents.h"
  40. #include "WebKitCSSRegionRule.h"
  41. namespace WebCore {
  42. void InspectorCSSOMWrappers::collectFromStyleSheetIfNeeded(CSSStyleSheet* styleSheet)
  43. {
  44. if (!m_styleRuleToCSSOMWrapperMap.isEmpty())
  45. collect(styleSheet);
  46. }
  47. template <class ListType>
  48. void InspectorCSSOMWrappers::collect(ListType* listType)
  49. {
  50. if (!listType)
  51. return;
  52. unsigned size = listType->length();
  53. for (unsigned i = 0; i < size; ++i) {
  54. CSSRule* cssRule = listType->item(i);
  55. switch (cssRule->type()) {
  56. case CSSRule::IMPORT_RULE:
  57. collect(static_cast<CSSImportRule*>(cssRule)->styleSheet());
  58. break;
  59. case CSSRule::MEDIA_RULE:
  60. collect(static_cast<CSSMediaRule*>(cssRule));
  61. break;
  62. #if ENABLE(CSS3_CONDITIONAL_RULES)
  63. case CSSRule::SUPPORTS_RULE:
  64. collect(static_cast<CSSSupportsRule*>(cssRule));
  65. break;
  66. #endif
  67. #if ENABLE(CSS_REGIONS)
  68. case CSSRule::WEBKIT_REGION_RULE:
  69. collect(static_cast<WebKitCSSRegionRule*>(cssRule));
  70. break;
  71. #endif
  72. #if ENABLE(SHADOW_DOM)
  73. case CSSRule::HOST_RULE:
  74. collect(static_cast<CSSHostRule*>(cssRule));
  75. break;
  76. #endif
  77. case CSSRule::STYLE_RULE:
  78. m_styleRuleToCSSOMWrapperMap.add(static_cast<CSSStyleRule*>(cssRule)->styleRule(), static_cast<CSSStyleRule*>(cssRule));
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. }
  85. void InspectorCSSOMWrappers::collectFromStyleSheetContents(HashSet<RefPtr<CSSStyleSheet> >& sheetWrapperSet, StyleSheetContents* styleSheet)
  86. {
  87. if (!styleSheet)
  88. return;
  89. RefPtr<CSSStyleSheet> styleSheetWrapper = CSSStyleSheet::create(styleSheet);
  90. sheetWrapperSet.add(styleSheetWrapper);
  91. collect(styleSheetWrapper.get());
  92. }
  93. void InspectorCSSOMWrappers::collectFromStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& sheets)
  94. {
  95. for (unsigned i = 0; i < sheets.size(); ++i)
  96. collect(sheets[i].get());
  97. }
  98. void InspectorCSSOMWrappers::collectFromDocumentStyleSheetCollection(DocumentStyleSheetCollection* styleSheetCollection)
  99. {
  100. collectFromStyleSheets(styleSheetCollection->activeAuthorStyleSheets());
  101. collect(styleSheetCollection->pageUserSheet());
  102. collectFromStyleSheets(styleSheetCollection->injectedUserStyleSheets());
  103. collectFromStyleSheets(styleSheetCollection->documentUserStyleSheets());
  104. }
  105. CSSStyleRule* InspectorCSSOMWrappers::getWrapperForRuleInSheets(StyleRule* rule, DocumentStyleSheetCollection* styleSheetCollection)
  106. {
  107. if (m_styleRuleToCSSOMWrapperMap.isEmpty()) {
  108. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::simpleDefaultStyleSheet);
  109. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::defaultStyleSheet);
  110. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::quirksStyleSheet);
  111. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::svgStyleSheet);
  112. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::mathMLStyleSheet);
  113. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::mediaControlsStyleSheet);
  114. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::fullscreenStyleSheet);
  115. collectFromStyleSheetContents(m_styleSheetCSSOMWrapperSet, CSSDefaultStyleSheets::plugInsStyleSheet);
  116. collectFromDocumentStyleSheetCollection(styleSheetCollection);
  117. }
  118. return m_styleRuleToCSSOMWrapperMap.get(rule);
  119. }
  120. } // namespace WebCore