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 enum class ColorFormat { RGB, HEX, HSL }; 21 22 struct CORE_EXPORT LineStyle { 23 USING_FAST_MALLOC(LineStyle); 24 25 public: 26 LineStyle(); 27 28 Color color; 29 String pattern; 30 }; 31 32 struct CORE_EXPORT InspectorSourceOrderConfig { 33 USING_FAST_MALLOC(InspectorSourceOrderConfig); 34 35 public: 36 InspectorSourceOrderConfig(); 37 38 Color parent_outline_color; 39 Color child_outline_color; 40 }; 41 42 struct CORE_EXPORT InspectorGridHighlightConfig { 43 USING_FAST_MALLOC(InspectorGridHighlightConfig); 44 45 public: 46 InspectorGridHighlightConfig(); 47 48 Color grid_color; 49 Color row_line_color; 50 Color column_line_color; 51 Color row_gap_color; 52 Color column_gap_color; 53 Color row_hatch_color; 54 Color column_hatch_color; 55 Color area_border_color; 56 Color grid_background_color; 57 58 bool show_grid_extension_lines; 59 bool grid_border_dash; 60 bool row_line_dash; 61 bool column_line_dash; 62 bool show_positive_line_numbers; 63 bool show_negative_line_numbers; 64 bool show_area_names; 65 bool show_line_names; 66 bool show_track_sizes; 67 }; 68 69 struct CORE_EXPORT InspectorFlexContainerHighlightConfig { 70 USING_FAST_MALLOC(InspectorFlexContainerHighlightConfig); 71 72 public: 73 InspectorFlexContainerHighlightConfig(); 74 75 std::unique_ptr<LineStyle> container_border; 76 std::unique_ptr<LineStyle> line_separator; 77 std::unique_ptr<LineStyle> item_separator; 78 }; 79 80 struct CORE_EXPORT InspectorHighlightConfig { 81 USING_FAST_MALLOC(InspectorHighlightConfig); 82 83 public: 84 InspectorHighlightConfig(); 85 86 Color content; 87 Color content_outline; 88 Color padding; 89 Color border; 90 Color margin; 91 Color event_target; 92 Color shape; 93 Color shape_margin; 94 Color css_grid; 95 96 bool show_info; 97 bool show_styles; 98 bool show_rulers; 99 bool show_extension_lines; 100 bool show_accessibility_info; 101 102 String selector_list; 103 ColorFormat color_format; 104 105 std::unique_ptr<InspectorGridHighlightConfig> grid_highlight_config; 106 std::unique_ptr<InspectorFlexContainerHighlightConfig> 107 flex_container_highlight_config; 108 }; 109 110 struct InspectorHighlightContrastInfo { 111 Color background_color; 112 String font_size; 113 String font_weight; 114 }; 115 116 class InspectorHighlightBase { 117 public: 118 explicit InspectorHighlightBase(float scale); 119 explicit InspectorHighlightBase(Node*); 120 void AppendPath(std::unique_ptr<protocol::ListValue> path, 121 const Color& fill_color, 122 const Color& outline_color, 123 const String& name = String()); 124 void AppendQuad(const FloatQuad&, 125 const Color& fill_color, 126 const Color& outline_color = Color::kTransparent, 127 const String& name = String()); 128 virtual std::unique_ptr<protocol::DictionaryValue> AsProtocolValue() 129 const = 0; 130 131 protected: 132 static bool BuildNodeQuads(Node*, 133 FloatQuad* content, 134 FloatQuad* padding, 135 FloatQuad* border, 136 FloatQuad* margin); 137 std::unique_ptr<protocol::ListValue> highlight_paths_; 138 float scale_; 139 }; 140 141 class CORE_EXPORT InspectorSourceOrderHighlight 142 : public InspectorHighlightBase { 143 STACK_ALLOCATED(); 144 145 public: 146 InspectorSourceOrderHighlight(Node*, Color, int source_order_position); 147 static InspectorSourceOrderConfig DefaultConfig(); 148 std::unique_ptr<protocol::DictionaryValue> AsProtocolValue() const override; 149 150 private: 151 int source_order_position_; 152 }; 153 154 class CORE_EXPORT InspectorHighlight : public InspectorHighlightBase { 155 STACK_ALLOCATED(); 156 157 public: 158 InspectorHighlight(Node*, 159 const InspectorHighlightConfig&, 160 const InspectorHighlightContrastInfo&, 161 bool append_element_info, 162 bool append_distance_info, 163 bool is_locked_ancestor); 164 explicit InspectorHighlight(float scale); 165 ~InspectorHighlight(); 166 167 static bool GetBoxModel(Node*, 168 std::unique_ptr<protocol::DOM::BoxModel>*, 169 bool use_absolute_zoom); 170 static bool GetContentQuads( 171 Node*, 172 std::unique_ptr<protocol::Array<protocol::Array<double>>>*); 173 static InspectorHighlightConfig DefaultConfig(); 174 static InspectorGridHighlightConfig DefaultGridConfig(); 175 static InspectorFlexContainerHighlightConfig DefaultFlexContainerConfig(); 176 void AppendEventTargetQuads(Node* event_target_node, 177 const InspectorHighlightConfig&); 178 std::unique_ptr<protocol::DictionaryValue> AsProtocolValue() const override; 179 180 private: 181 static bool BuildSVGQuads(Node*, Vector<FloatQuad>& quads); 182 void AppendNodeHighlight(Node*, const InspectorHighlightConfig&); 183 void AppendPathsForShapeOutside(Node*, const InspectorHighlightConfig&); 184 185 void AppendDistanceInfo(Node* node); 186 void VisitAndCollectDistanceInfo(Node* node); 187 void VisitAndCollectDistanceInfo(PseudoId pseudo_id, 188 LayoutObject* layout_object); 189 void AddLayoutBoxToDistanceInfo(LayoutObject* layout_object); 190 191 static LineStyle DefaultLineStyle(); 192 193 std::unique_ptr<protocol::Array<protocol::Array<double>>> boxes_; 194 std::unique_ptr<protocol::DictionaryValue> computed_style_; 195 std::unique_ptr<protocol::DOM::BoxModel> model_; 196 std::unique_ptr<protocol::DictionaryValue> distance_info_; 197 std::unique_ptr<protocol::DictionaryValue> element_info_; 198 std::unique_ptr<protocol::ListValue> grid_info_; 199 std::unique_ptr<protocol::ListValue> flex_info_; 200 bool show_rulers_; 201 bool show_extension_lines_; 202 bool show_accessibility_info_; 203 ColorFormat color_format_; 204 }; 205 206 std::unique_ptr<protocol::DictionaryValue> InspectorGridHighlight( 207 Node*, 208 const InspectorGridHighlightConfig& config); 209 210 } // namespace blink 211 212 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_HIGHLIGHT_H_ 213