css_agent.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_
  5. #define COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_
  6. #include "components/ui_devtools/css.h"
  7. #include "components/ui_devtools/dom_agent.h"
  8. namespace gfx {
  9. class Rect;
  10. }
  11. namespace ui_devtools {
  12. class UIElement;
  13. class UI_DEVTOOLS_EXPORT CSSAgent
  14. : public UiDevToolsBaseAgent<protocol::CSS::Metainfo>,
  15. public DOMAgentObserver {
  16. public:
  17. explicit CSSAgent(DOMAgent* dom_agent);
  18. CSSAgent(const CSSAgent&) = delete;
  19. CSSAgent& operator=(const CSSAgent&) = delete;
  20. ~CSSAgent() override;
  21. // CSS::Backend:
  22. protocol::Response enable() override;
  23. protocol::Response disable() override;
  24. protocol::Response getMatchedStylesForNode(
  25. int node_id,
  26. protocol::Maybe<protocol::Array<protocol::CSS::RuleMatch>>*
  27. matched_css_rules) override;
  28. protocol::Response getStyleSheetText(const protocol::String& style_sheet_id,
  29. protocol::String* text) override;
  30. protocol::Response setStyleTexts(
  31. std::unique_ptr<protocol::Array<protocol::CSS::StyleDeclarationEdit>>
  32. edits,
  33. std::unique_ptr<protocol::Array<protocol::CSS::CSSStyle>>* result)
  34. override;
  35. // DOMAgentObserver:
  36. void OnElementBoundsChanged(UIElement* ui_element) override;
  37. private:
  38. std::unique_ptr<protocol::CSS::CSSStyle> GetStylesForUIElement(
  39. UIElement* ui_element);
  40. void InvalidateStyleSheet(UIElement* ui_element);
  41. bool GetPropertiesForUIElement(UIElement* ui_element,
  42. gfx::Rect* bounds,
  43. bool* visible);
  44. bool SetPropertiesForUIElement(UIElement* ui_element,
  45. const gfx::Rect& bounds,
  46. bool visible);
  47. std::unique_ptr<protocol::Array<protocol::CSS::RuleMatch>> BuildMatchedStyles(
  48. UIElement* ui_element);
  49. // Sends header to frontend for each section in properties panel.
  50. void InitStylesheetHeaders(UIElement* ui_element);
  51. DOMAgent* const dom_agent_;
  52. };
  53. } // namespace ui_devtools
  54. #endif // COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_