Commit 99622283 authored by Kristyn Hamasaki's avatar Kristyn Hamasaki Committed by Commit Bot

Add bubble locking to UI Devtools

Ctrl+Shift+R locks bubbles from closing and allows bubbles and their
elements to be inspected.

Change-Id: Iba876a5dcc78324be4750823f6f53a307559bdfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1703459
Commit-Queue: Kristyn Hamasaki <khamasaki@google.com>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680118}
parent 30f282ec
...@@ -4,34 +4,14 @@ ...@@ -4,34 +4,14 @@
#include "components/ui_devtools/page_agent.h" #include "components/ui_devtools/page_agent.h"
#include "base/command_line.h"
#include "components/ui_devtools/ui_element.h"
namespace ui_devtools { namespace ui_devtools {
PageAgent::PageAgent(DOMAgent* dom_agent) : dom_agent_(dom_agent) {} PageAgent::PageAgent(DOMAgent* dom_agent) : dom_agent_(dom_agent) {}
PageAgent::~PageAgent() {} PageAgent::~PageAgent() {}
void PaintRectVector(std::vector<UIElement*> child_elements) { protocol::Response PageAgent::reload(protocol::Maybe<bool> bypass_cache) {
for (auto* element : child_elements) { NOTREACHED();
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(); return protocol::Response::OK();
} }
......
...@@ -17,10 +17,12 @@ class UI_DEVTOOLS_EXPORT PageAgent ...@@ -17,10 +17,12 @@ class UI_DEVTOOLS_EXPORT PageAgent
~PageAgent() override; ~PageAgent() override;
// Called on Ctrl+R (windows, linux) or Meta+R (mac) from frontend, but used // 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. // in UI Devtools to toggle the bounds debug rectangles for views. If called
protocol::Response reload() override; // using Ctrl+Shift+R (windows, linux) or Meta+Shift+R (mac), |bypass_cache|
// will be true and will toggle bubble lock.
protocol::Response reload(protocol::Maybe<bool> bypass_cache) override;
private: protected:
DOMAgent* const dom_agent_; DOMAgent* const dom_agent_;
DISALLOW_COPY_AND_ASSIGN(PageAgent); DISALLOW_COPY_AND_ASSIGN(PageAgent);
......
...@@ -707,7 +707,15 @@ ...@@ -707,7 +707,15 @@
}, },
{ {
"name": "reload", "name": "reload",
"description": "Using frontend reload command to toggle View debug rectangles" "parameters": [
{
"name":"ignoreCache",
"type": "boolean",
"optional": true,
"description": "If true, browser cache is ignored (as if the user pressed Shift+refresh)."
}
],
"description": "Called on Ctrl+R with |ignoreCache|=false, which is used to toggle debug bounds rectangles and Ctrl+Shift+R with |ignoreCache|=true, which is used to toggle bubble locking."
} }
], ],
"description": "Actions and events related to the inspected page belong to the page domain.", "description": "Actions and events related to the inspected page belong to the page domain.",
......
...@@ -19,6 +19,8 @@ source_set("views") { ...@@ -19,6 +19,8 @@ source_set("views") {
"element_utility.h", "element_utility.h",
"overlay_agent_views.cc", "overlay_agent_views.cc",
"overlay_agent_views.h", "overlay_agent_views.h",
"page_agent_views.cc",
"page_agent_views.h",
"view_element.cc", "view_element.cc",
"view_element.h", "view_element.h",
"widget_element.cc", "widget_element.cc",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "components/ui_devtools/switches.h" #include "components/ui_devtools/switches.h"
#include "components/ui_devtools/views/dom_agent_views.h" #include "components/ui_devtools/views/dom_agent_views.h"
#include "components/ui_devtools/views/overlay_agent_views.h" #include "components/ui_devtools/views/overlay_agent_views.h"
#include "components/ui_devtools/views/page_agent_views.h"
namespace ui_devtools { namespace ui_devtools {
...@@ -26,10 +27,10 @@ std::unique_ptr<UiDevToolsServer> CreateUiDevToolsServerForViews( ...@@ -26,10 +27,10 @@ std::unique_ptr<UiDevToolsServer> CreateUiDevToolsServerForViews(
std::make_unique<UiDevToolsClient>("UiDevToolsClient", server.get()); std::make_unique<UiDevToolsClient>("UiDevToolsClient", server.get());
auto dom_agent_views = DOMAgentViews::Create(); auto dom_agent_views = DOMAgentViews::Create();
auto* dom_agent_views_ptr = dom_agent_views.get(); auto* dom_agent_views_ptr = dom_agent_views.get();
client->AddAgent(std::make_unique<PageAgentViews>(dom_agent_views_ptr));
client->AddAgent(std::move(dom_agent_views)); client->AddAgent(std::move(dom_agent_views));
client->AddAgent(std::make_unique<CSSAgent>(dom_agent_views_ptr)); client->AddAgent(std::make_unique<CSSAgent>(dom_agent_views_ptr));
client->AddAgent(OverlayAgentViews::Create(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)); server->AttachClient(std::move(client));
return server; return server;
} }
......
// 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/views/page_agent_views.h"
#include "base/command_line.h"
#include "components/ui_devtools/ui_element.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/views_switches.h"
namespace ui_devtools {
PageAgentViews::PageAgentViews(DOMAgent* dom_agent) : PageAgent(dom_agent) {}
PageAgentViews::~PageAgentViews() {}
void PaintRectVector(std::vector<UIElement*> child_elements) {
for (auto* element : child_elements) {
if (element->type() == UIElementType::VIEW) {
element->PaintRect();
}
PaintRectVector(element->children());
}
}
protocol::Response PageAgentViews::disable() {
// Set bubble lock flag back to false.
views::BubbleDialogDelegateView::devtools_dismiss_override_ = false;
// Remove debug bounds rects if enabled.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
views::switches::kDrawViewBoundsRects)) {
base::CommandLine::ForCurrentProcess()->InitFromArgv(
base::CommandLine::ForCurrentProcess()->argv());
PaintRectVector(dom_agent_->element_root()->children());
}
return protocol::Response::OK();
}
protocol::Response PageAgentViews::reload(protocol::Maybe<bool> bypass_cache) {
if (!bypass_cache.isJust())
return protocol::Response::OK();
bool shift_pressed = bypass_cache.fromMaybe(false);
// Ctrl+Shift+R called to toggle bubble lock.
if (shift_pressed) {
views::BubbleDialogDelegateView::devtools_dismiss_override_ =
!views::BubbleDialogDelegateView::devtools_dismiss_override_;
} else {
// Ctrl+R called to toggle debug bounds rectangles.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
views::switches::kDrawViewBoundsRects)) {
base::CommandLine::ForCurrentProcess()->InitFromArgv(
base::CommandLine::ForCurrentProcess()->argv());
} else {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
views::switches::kDrawViewBoundsRects);
}
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_VIEWS_PAGE_AGENT_VIEWS_H_
#define COMPONENTS_UI_DEVTOOLS_VIEWS_PAGE_AGENT_VIEWS_H_
#include "components/ui_devtools/page_agent.h"
namespace ui_devtools {
class PageAgentViews : public PageAgent {
public:
explicit PageAgentViews(DOMAgent* dom_agent);
~PageAgentViews() override;
// PageAgent:
protocol::Response disable() override;
protocol::Response reload(protocol::Maybe<bool> bypass_cache) override;
private:
DISALLOW_COPY_AND_ASSIGN(PageAgentViews);
};
} // namespace ui_devtools
#endif // COMPONENTS_UI_DEVTOOLS_VIEWS_PAGE_AGENT_VIEWS_H_
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
namespace views { namespace views {
// static
bool BubbleDialogDelegateView::devtools_dismiss_override_ = false;
namespace { namespace {
// Override base functionality of Widget to give bubble dialogs access to the // Override base functionality of Widget to give bubble dialogs access to the
...@@ -222,6 +225,9 @@ void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget, ...@@ -222,6 +225,9 @@ void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget,
void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget, void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget,
bool active) { bool active) {
if (devtools_dismiss_override_)
return;
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Install |mac_bubble_closer_| the first time the widget becomes active. // Install |mac_bubble_closer_| the first time the widget becomes active.
if (widget == GetWidget() && active && !mac_bubble_closer_) { if (widget == GetWidget() && active && !mac_bubble_closer_) {
......
...@@ -30,6 +30,10 @@ namespace ui { ...@@ -30,6 +30,10 @@ namespace ui {
class Accelerator; class Accelerator;
} // namespace ui } // namespace ui
namespace ui_devtools {
class PageAgentViews;
}
namespace views { namespace views {
class BubbleFrameView; class BubbleFrameView;
...@@ -192,6 +196,7 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -192,6 +196,7 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
private: private:
friend class BubbleBorderDelegate; friend class BubbleBorderDelegate;
friend class BubbleWindowTargeter; friend class BubbleWindowTargeter;
friend class ui_devtools::PageAgentViews;
FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CreateDelegate); FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CreateDelegate);
FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, NonClientHitTest); FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, NonClientHitTest);
...@@ -210,6 +215,10 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -210,6 +215,10 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
// provide different highlight effects. // provide different highlight effects.
virtual void UpdateHighlightedButton(bool highlighted); virtual void UpdateHighlightedButton(bool highlighted);
// Set from UI DevTools to prevent bubbles from closing in
// OnWidgetActivationChanged().
static bool devtools_dismiss_override_;
// A flag controlling bubble closure on deactivation. // A flag controlling bubble closure on deactivation.
bool close_on_deactivate_; bool close_on_deactivate_;
......
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