Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / InspectorRenderingAgent.cpp
blobb701be64e96621ca984fef67c18ecdc86d0dbf8f
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.
5 #include "config.h"
6 #include "web/InspectorRenderingAgent.h"
8 #include "core/frame/FrameView.h"
9 #include "core/frame/Settings.h"
10 #include "core/inspector/InspectorState.h"
11 #include "core/page/Page.h"
12 #include "web/WebLocalFrameImpl.h"
13 #include "web/WebViewImpl.h"
15 namespace blink {
17 namespace RenderingAgentState {
18 static const char showDebugBorders[] = "showDebugBorders";
19 static const char showFPSCounter[] = "showFPSCounter";
20 static const char showPaintRects[] = "showPaintRects";
21 static const char showScrollBottleneckRects[] = "showScrollBottleneckRects";
24 PassOwnPtrWillBeRawPtr<InspectorRenderingAgent> InspectorRenderingAgent::create(WebViewImpl* webViewImpl)
26 return adoptPtrWillBeNoop(new InspectorRenderingAgent(webViewImpl));
29 InspectorRenderingAgent::InspectorRenderingAgent(WebViewImpl* webViewImpl)
30 : InspectorBaseAgent<InspectorRenderingAgent, InspectorFrontend::Rendering>("Rendering")
31 , m_webViewImpl(webViewImpl)
35 void InspectorRenderingAgent::restore()
37 ErrorString error;
38 setShowDebugBorders(&error, m_state->getBoolean(RenderingAgentState::showDebugBorders));
39 setShowFPSCounter(&error, m_state->getBoolean(RenderingAgentState::showFPSCounter));
40 setShowPaintRects(&error, m_state->getBoolean(RenderingAgentState::showPaintRects));
41 setShowScrollBottleneckRects(&error, m_state->getBoolean(RenderingAgentState::showScrollBottleneckRects));
44 void InspectorRenderingAgent::disable(ErrorString*)
46 ErrorString error;
47 setShowDebugBorders(&error, false);
48 setShowFPSCounter(&error, false);
49 setShowPaintRects(&error, false);
50 setShowScrollBottleneckRects(&error, false);
53 void InspectorRenderingAgent::setShowDebugBorders(ErrorString* errorString, bool show)
55 m_state->setBoolean(RenderingAgentState::showDebugBorders, show);
56 if (show && !compositingEnabled(errorString))
57 return;
58 m_webViewImpl->setShowDebugBorders(show);
61 void InspectorRenderingAgent::setShowFPSCounter(ErrorString* errorString, bool show)
63 m_state->setBoolean(RenderingAgentState::showFPSCounter, show);
64 if (show && !compositingEnabled(errorString))
65 return;
66 m_webViewImpl->setShowFPSCounter(show);
69 void InspectorRenderingAgent::setShowPaintRects(ErrorString*, bool show)
71 m_state->setBoolean(RenderingAgentState::showPaintRects, show);
72 m_webViewImpl->setShowPaintRects(show);
73 if (!show && m_webViewImpl->mainFrameImpl()->frameView())
74 m_webViewImpl->mainFrameImpl()->frameView()->invalidate();
77 void InspectorRenderingAgent::setShowScrollBottleneckRects(ErrorString* errorString, bool show)
79 m_state->setBoolean(RenderingAgentState::showScrollBottleneckRects, show);
80 if (show && !compositingEnabled(errorString))
81 return;
82 m_webViewImpl->setShowScrollBottleneckRects(show);
85 bool InspectorRenderingAgent::compositingEnabled(ErrorString* errorString)
87 if (!m_webViewImpl->page()->settings().acceleratedCompositingEnabled()) {
88 if (errorString)
89 *errorString = "Compositing mode is not supported";
90 return false;
92 return true;
95 DEFINE_TRACE(InspectorRenderingAgent)
97 InspectorBaseAgent::trace(visitor);
100 } // namespace blink