Commit 06170c05 authored by Kristyn Hamasaki's avatar Kristyn Hamasaki Committed by Commit Bot

Add Debug Bounds Rectangles toggle functionality to UI Devtools

Control + R now allows for toggle of the debug rectangles in UI Devtools.

Bug: 978100
Change-Id: I29f7c4d79b514de88a7594a48fc3cca6526f5346
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1673861Reviewed-by: default avatarWei Li <weili@chromium.org>
Commit-Queue: Kristyn Hamasaki <khamasaki@google.com>
Cr-Commit-Position: refs/heads/master@{#675868}
parent 9e9185ec
......@@ -15,6 +15,8 @@ _protocol_generated = [
"Forward.h",
"Overlay.cpp",
"Overlay.h",
"Page.cpp",
"Page.h",
"Protocol.cpp",
"Protocol.h",
]
......@@ -71,6 +73,8 @@ component("ui_devtools") {
"dom_agent.h",
"overlay_agent.cc",
"overlay_agent.h",
"page_agent.cc",
"page_agent.h",
"root_element.cc",
"root_element.h",
"switches.cc",
......
// Copyright 2019 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.
#include "components/ui_devtools/page_agent.h"
#include "base/command_line.h"
#include "components/ui_devtools/ui_element.h"
namespace ui_devtools {
PageAgent::PageAgent(DOMAgent* dom_agent) : dom_agent_(dom_agent) {}
PageAgent::~PageAgent() {}
void PaintRectVector(std::vector<UIElement*> child_elements) {
for (auto* element : child_elements) {
if (element->type() == UIElementType::VIEW) {
element->PaintRect();
}
PaintRectVector(element->children());
}
}
protocol::Response PageAgent::reload() {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
"draw-view-bounds-rects")) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
"draw-view-bounds-rects");
} else {
base::CommandLine::ForCurrentProcess()->InitFromArgv(
base::CommandLine::ForCurrentProcess()->argv());
}
PaintRectVector(dom_agent_->element_root()->children());
return protocol::Response::OK();
}
} // namespace ui_devtools
// Copyright 2019 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_PAGE_AGENT_H_
#define COMPONENTS_UI_DEVTOOLS_PAGE_AGENT_H_
#include "components/ui_devtools/Page.h"
#include "components/ui_devtools/dom_agent.h"
namespace ui_devtools {
class UI_DEVTOOLS_EXPORT PageAgent
: public UiDevToolsBaseAgent<protocol::Page::Metainfo> {
public:
explicit PageAgent(DOMAgent* dom_agent);
~PageAgent() override;
// Called on Ctrl+R (windows, linux) or Meta+R (mac) from frontend, but used
// in UI Devtools to toggle the bounds debug rectangles for views.
protocol::Response reload() override;
private:
DOMAgent* const dom_agent_;
DISALLOW_COPY_AND_ASSIGN(PageAgent);
};
} // namespace ui_devtools
#endif // COMPONENTS_UI_DEVTOOLS_PAGE_AGENT_H_
......@@ -691,6 +691,27 @@
]
}
]
},
{
"commands" : [
{
"name": "disable",
"description": "Disables domain notifications."
},
{
"name": "enable",
"description": "Enables domain notifications."
},
{
"name": "reload",
"description": "Using frontend reload command to toggle View debug rectangles"
}
],
"description": "Actions and events related to the inspected page belong to the page domain.",
"domain": "Page",
"dependencies": [
"DOM"
]
}
],
"version": {
......
......@@ -97,6 +97,9 @@ class UI_DEVTOOLS_EXPORT UIElement {
return T::From(element);
}
// Called from PageAgent to repaint Views for Debug Bounds Rectangles
virtual void PaintRect() const {}
protected:
UIElement(const UIElementType type,
UIElementDelegate* delegate,
......
......@@ -8,6 +8,7 @@
#include "components/ui_devtools/css_agent.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/ui_devtools/page_agent.h"
#include "components/ui_devtools/switches.h"
#include "components/ui_devtools/views/dom_agent_views.h"
#include "components/ui_devtools/views/overlay_agent_views.h"
......@@ -28,6 +29,7 @@ std::unique_ptr<UiDevToolsServer> CreateUiDevToolsServerForViews(
client->AddAgent(std::move(dom_agent_views));
client->AddAgent(std::make_unique<CSSAgent>(dom_agent_views_ptr));
client->AddAgent(OverlayAgentViews::Create(dom_agent_views_ptr));
client->AddAgent(std::make_unique<PageAgent>(dom_agent_views_ptr));
server->AttachClient(std::move(client));
return server;
}
......
......@@ -168,4 +168,8 @@ int UIElement::FindUIElementIdForBackendElement<views::View>(
return 0;
}
void ViewElement::PaintRect() const {
view()->SchedulePaint();
}
} // namespace ui_devtools
......@@ -42,6 +42,7 @@ class ViewElement : public views::ViewObserver, public UIElement {
std::pair<gfx::NativeWindow, gfx::Rect> GetNodeWindowAndScreenBounds()
const override;
static views::View* From(const UIElement* element);
void PaintRect() const override;
private:
views::View* view_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment