1 // Copyright 2015 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 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_HIGHLIGHT_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_HIGHLIGHT_H_
7 
8 #include "third_party/blink/renderer/core/core_export.h"
9 #include "third_party/blink/renderer/core/dom/pseudo_element.h"
10 #include "third_party/blink/renderer/core/inspector/protocol/DOM.h"
11 #include "third_party/blink/renderer/platform/geometry/float_quad.h"
12 #include "third_party/blink/renderer/platform/geometry/layout_rect.h"
13 #include "third_party/blink/renderer/platform/graphics/color.h"
14 #include "third_party/blink/renderer/platform/heap/handle.h"
15 
16 namespace blink {
17 
18 class Color;
19 
20 struct CORE_EXPORT InspectorHighlightConfig {
21   USING_FAST_MALLOC(InspectorHighlightConfig);
22 
23  public:
24   InspectorHighlightConfig();
25 
26   Color content;
27   Color content_outline;
28   Color padding;
29   Color border;
30   Color margin;
31   Color event_target;
32   Color shape;
33   Color shape_margin;
34   Color css_grid;
35 
36   bool show_info;
37   bool show_styles;
38   bool show_rulers;
39   bool show_extension_lines;
40 
41   String selector_list;
42 };
43 
44 struct InspectorHighlightContrastInfo {
45   Color background_color;
46   String font_size;
47   String font_weight;
48 };
49 
50 class CORE_EXPORT InspectorHighlight {
51   STACK_ALLOCATED();
52 
53  public:
54   InspectorHighlight(Node*,
55                      const InspectorHighlightConfig&,
56                      const InspectorHighlightContrastInfo&,
57                      bool append_element_info,
58                      bool append_distance_info,
59                      bool is_locked_ancestor);
60   explicit InspectorHighlight(float scale);
61   ~InspectorHighlight();
62 
63   static bool GetBoxModel(Node*,
64                           std::unique_ptr<protocol::DOM::BoxModel>*,
65                           bool use_absolute_zoom);
66   static bool GetContentQuads(
67       Node*,
68       std::unique_ptr<protocol::Array<protocol::Array<double>>>*);
69   static InspectorHighlightConfig DefaultConfig();
70 
71   void AppendPath(std::unique_ptr<protocol::ListValue> path,
72                   const Color& fill_color,
73                   const Color& outline_color,
74                   const String& name = String());
75   void AppendQuad(const FloatQuad&,
76                   const Color& fill_color,
77                   const Color& outline_color = Color::kTransparent,
78                   const String& name = String());
79   void AppendEventTargetQuads(Node* event_target_node,
80                               const InspectorHighlightConfig&);
81   std::unique_ptr<protocol::DictionaryValue> AsProtocolValue() const;
82 
83  private:
84   static bool BuildSVGQuads(Node*, Vector<FloatQuad>& quads);
85   static bool BuildNodeQuads(Node*,
86                              FloatQuad* content,
87                              FloatQuad* padding,
88                              FloatQuad* border,
89                              FloatQuad* margin);
90   void AppendNodeHighlight(Node*, const InspectorHighlightConfig&);
91   void AppendPathsForShapeOutside(Node*, const InspectorHighlightConfig&);
92 
93   void AppendDistanceInfo(Node* node);
94   void VisitAndCollectDistanceInfo(Node* node);
95   void VisitAndCollectDistanceInfo(PseudoId pseudo_id,
96                                    LayoutObject* layout_object);
97   void AddLayoutBoxToDistanceInfo(LayoutObject* layout_object);
98 
99   std::unique_ptr<protocol::Array<protocol::Array<double>>> boxes_;
100   std::unique_ptr<protocol::DictionaryValue> computed_style_;
101   std::unique_ptr<protocol::DOM::BoxModel> model_;
102   std::unique_ptr<protocol::DictionaryValue> distance_info_;
103   std::unique_ptr<protocol::DictionaryValue> element_info_;
104   std::unique_ptr<protocol::ListValue> highlight_paths_;
105   std::unique_ptr<protocol::ListValue> grid_info_;
106   bool show_rulers_;
107   bool show_extension_lines_;
108   float scale_;
109 };
110 
111 }  // namespace blink
112 
113 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_HIGHLIGHT_H_
114