summaryrefslogtreecommitdiff
path: root/chromium/components/ui_devtools/css_agent.h
blob: e962f70de9f61a56bbe9374ef48c87b159770860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_
#define COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_

#include "base/macros.h"
#include "components/ui_devtools/CSS.h"
#include "components/ui_devtools/dom_agent.h"

namespace gfx {
class Rect;
}

namespace ui_devtools {

class UIElement;

class UI_DEVTOOLS_EXPORT CSSAgent
    : public UiDevToolsBaseAgent<protocol::CSS::Metainfo>,
      public DOMAgentObserver {
 public:
  explicit CSSAgent(DOMAgent* dom_agent);
  ~CSSAgent() override;

  // CSS::Backend:
  protocol::Response enable() override;
  protocol::Response disable() override;
  protocol::Response getMatchedStylesForNode(
      int node_id,
      protocol::Maybe<protocol::Array<protocol::CSS::RuleMatch>>*
          matched_css_rules) override;
  protocol::Response getStyleSheetText(const protocol::String& style_sheet_id,
                                       protocol::String* text) override;
  protocol::Response setStyleTexts(
      std::unique_ptr<protocol::Array<protocol::CSS::StyleDeclarationEdit>>
          edits,
      std::unique_ptr<protocol::Array<protocol::CSS::CSSStyle>>* result)
      override;

  // DOMAgentObserver:
  void OnElementBoundsChanged(UIElement* ui_element) override;

 private:
  std::unique_ptr<protocol::CSS::CSSStyle> GetStylesForUIElement(
      UIElement* ui_element);
  void InvalidateStyleSheet(UIElement* ui_element);
  bool GetPropertiesForUIElement(UIElement* ui_element,
                                 gfx::Rect* bounds,
                                 bool* visible);
  bool SetPropertiesForUIElement(UIElement* ui_element,
                                 const gfx::Rect& bounds,
                                 bool visible);
  std::unique_ptr<protocol::Array<protocol::CSS::RuleMatch>> BuildMatchedStyles(
      UIElement* ui_element);

  // Sends header to frontend for each section in properties panel.
  void InitStylesheetHeaders(UIElement* ui_element);

  DOMAgent* const dom_agent_;

  DISALLOW_COPY_AND_ASSIGN(CSSAgent);
};

}  // namespace ui_devtools

#endif  // COMPONENTS_UI_DEVTOOLS_CSS_AGENT_H_