1 | /* |
2 | * Copyright (C) 2012, 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
14 | * its contributors may be used to endorse or promote products derived |
15 | * from this software without specific prior written permission. |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #pragma once |
30 | |
31 | #include "InspectorWebAgentBase.h" |
32 | #include <JavaScriptCore/InspectorBackendDispatchers.h> |
33 | #include <JavaScriptCore/InspectorFrontendDispatchers.h> |
34 | #include <JavaScriptCore/InspectorProtocolObjects.h> |
35 | #include <wtf/text/WTFString.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | class IntRect; |
40 | class Node; |
41 | class PseudoElement; |
42 | class RenderElement; |
43 | class RenderLayer; |
44 | |
45 | typedef String ErrorString; |
46 | |
47 | class InspectorLayerTreeAgent final : public InspectorAgentBase, public Inspector::LayerTreeBackendDispatcherHandler { |
48 | WTF_MAKE_NONCOPYABLE(InspectorLayerTreeAgent); |
49 | WTF_MAKE_FAST_ALLOCATED; |
50 | public: |
51 | explicit InspectorLayerTreeAgent(WebAgentContext&); |
52 | virtual ~InspectorLayerTreeAgent(); |
53 | |
54 | void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override; |
55 | void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override; |
56 | void reset(); |
57 | |
58 | // InspectorInstrumentation |
59 | void layerTreeDidChange(); |
60 | void renderLayerDestroyed(const RenderLayer&); |
61 | void pseudoElementDestroyed(PseudoElement&); |
62 | |
63 | // Called from the front-end. |
64 | void enable(ErrorString&) override; |
65 | void disable(ErrorString&) override; |
66 | void layersForNode(ErrorString&, int nodeId, RefPtr<JSON::ArrayOf<Inspector::Protocol::LayerTree::Layer>>&) override; |
67 | void reasonsForCompositingLayer(ErrorString&, const String& layerId, RefPtr<Inspector::Protocol::LayerTree::CompositingReasons>&) override; |
68 | |
69 | private: |
70 | // RenderLayer-related methods. |
71 | String bind(const RenderLayer*); |
72 | void unbind(const RenderLayer*); |
73 | |
74 | void gatherLayersUsingRenderObjectHierarchy(ErrorString&, RenderElement&, RefPtr<JSON::ArrayOf<Inspector::Protocol::LayerTree::Layer>>&); |
75 | void gatherLayersUsingRenderLayerHierarchy(ErrorString&, RenderLayer*, RefPtr<JSON::ArrayOf<Inspector::Protocol::LayerTree::Layer>>&); |
76 | |
77 | Ref<Inspector::Protocol::LayerTree::Layer> buildObjectForLayer(ErrorString&, RenderLayer*); |
78 | Ref<Inspector::Protocol::LayerTree::IntRect> buildObjectForIntRect(const IntRect&); |
79 | |
80 | int idForNode(ErrorString&, Node*); |
81 | |
82 | String bindPseudoElement(PseudoElement*); |
83 | void unbindPseudoElement(PseudoElement*); |
84 | |
85 | std::unique_ptr<Inspector::LayerTreeFrontendDispatcher> m_frontendDispatcher; |
86 | RefPtr<Inspector::LayerTreeBackendDispatcher> m_backendDispatcher; |
87 | |
88 | HashMap<const RenderLayer*, String> m_documentLayerToIdMap; |
89 | HashMap<String, const RenderLayer*> m_idToLayer; |
90 | |
91 | HashMap<PseudoElement*, String> m_pseudoElementToIdMap; |
92 | HashMap<String, PseudoElement*> m_idToPseudoElement; |
93 | |
94 | bool m_suppressLayerChangeEvents { false }; |
95 | }; |
96 | |
97 | } // namespace WebCore |
98 | |