Commit 46b3d05d authored by Wei Li's avatar Wei Li Committed by Chromium LUCI CQ

Add general widget deactivation blocking for UI DevTools

Bubble locking was used to prevent bubbles from being dismissed after
deactivation. This CL adds general widget blocking by preventing
widgets from being dismissed after deactivation. The impl extends the
ways of disabling widget activation changes to achieve that.

Bug: 1167285
Change-Id: I8b67a7d00e1f1fb9f598d51460e162d111b3110b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638000
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845374}
parent c79ccfac
......@@ -63,8 +63,9 @@ PageAgentViews::PageAgentViews(DOMAgent* dom_agent) : PageAgent(dom_agent) {}
PageAgentViews::~PageAgentViews() {}
protocol::Response PageAgentViews::disable() {
// Set bubble lock flag back to false.
views::BubbleDialogDelegateView::devtools_dismiss_override_ = false;
// Don't disable widget activation handling any more.
views::Widget::SetDisableActivationChangeHandling(
views::Widget::DisableActivationChangeHandlingType::kNone);
// Remove debug bounds rects if enabled.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -82,10 +83,14 @@ protocol::Response PageAgentViews::reload(protocol::Maybe<bool> bypass_cache) {
bool shift_pressed = bypass_cache.fromMaybe(false);
// Ctrl+Shift+R called to toggle bubble lock.
// Ctrl+Shift+R called to toggle widget lock.
if (shift_pressed) {
views::BubbleDialogDelegateView::devtools_dismiss_override_ =
!views::BubbleDialogDelegateView::devtools_dismiss_override_;
views::Widget::SetDisableActivationChangeHandling(
views::Widget::GetDisableActivationChangeHandling() ==
views::Widget::DisableActivationChangeHandlingType::kNone
? views::Widget::DisableActivationChangeHandlingType::
kIgnoreDeactivationOnly
: views::Widget::DisableActivationChangeHandlingType::kNone);
} else {
// Ctrl+R called to toggle debug bounds rectangles.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -152,8 +157,10 @@ protocol::Response PageAgentViews::getResourceContent(
return protocol::Response::ServerError("Could not read source file");
}
bool PageAgentViews::devtools_dismiss_override() {
return views::BubbleDialogDelegateView::devtools_dismiss_override_;
bool PageAgentViews::GetDevtoolsDismissOverrideForTesting() const {
return views::Widget::GetDisableActivationChangeHandling() ==
views::Widget::DisableActivationChangeHandlingType::
kIgnoreDeactivationOnly;
}
} // namespace ui_devtools
......@@ -12,6 +12,8 @@ namespace ui_devtools {
class PageAgentViews : public PageAgent {
public:
explicit PageAgentViews(DOMAgent* dom_agent);
PageAgentViews(const PageAgentViews&) = delete;
PageAgentViews& operator=(const PageAgentViews&) = delete;
~PageAgentViews() override;
// PageAgent:
......@@ -24,11 +26,7 @@ class PageAgentViews : public PageAgent {
protocol::String* out_content,
bool* out_base64Encoded) override;
private:
friend class PageAgentViewsTest;
bool devtools_dismiss_override();
DISALLOW_COPY_AND_ASSIGN(PageAgentViews);
bool GetDevtoolsDismissOverrideForTesting() const;
};
} // namespace ui_devtools
......
......@@ -80,8 +80,8 @@ class PageAgentViewsTest : public views::ViewsTestBase {
protected:
PageAgentViews* page_agent() { return page_agent_.get(); }
DOMAgentViews* dom_agent() { return dom_agent_.get(); }
bool devtools_dismiss_override() {
return page_agent()->devtools_dismiss_override();
bool devtools_dismiss_override() const {
return page_agent_->GetDevtoolsDismissOverrideForTesting();
}
private:
......
......@@ -44,9 +44,6 @@
namespace views {
// static
bool BubbleDialogDelegate::devtools_dismiss_override_ = false;
namespace {
// A BubbleFrameView will apply a masking path to its ClientView to ensure
......@@ -454,9 +451,6 @@ void BubbleDialogDelegate::OnAnchorWidgetDestroying() {
}
void BubbleDialogDelegate::OnBubbleWidgetActivationChanged(bool active) {
if (devtools_dismiss_override_)
return;
#if defined(OS_APPLE)
// Install |mac_bubble_closer_| the first time the widget becomes active.
if (active && !mac_bubble_closer_) {
......
......@@ -29,10 +29,6 @@ namespace gfx {
class Rect;
}
namespace ui_devtools {
class PageAgentViews;
}
namespace views {
class Button;
......@@ -311,7 +307,6 @@ class VIEWS_EXPORT BubbleDialogDelegate : public DialogDelegate,
friend class BubbleBorderDelegate;
friend class BubbleWindowTargeter;
friend class ui_devtools::PageAgentViews;
// Notify the BubbleDialogDelegate about changes in the anchor Widget. You do
// not need to call these yourself.
......@@ -327,10 +322,6 @@ class VIEWS_EXPORT BubbleDialogDelegate : public DialogDelegate,
void OnDeactivate();
// Set from UI DevTools to prevent bubbles from closing in
// OnWidgetActivationChanged().
static bool devtools_dismiss_override_;
gfx::Insets title_margins_;
BubbleBorder::Arrow arrow_ = BubbleBorder::NONE;
BubbleBorder::Shadow shadow_;
......
......@@ -9,7 +9,8 @@
namespace views {
void DisableActivationChangeHandlingForTests() {
Widget::g_disable_activation_change_handling_ = true;
Widget::SetDisableActivationChangeHandling(
Widget::DisableActivationChangeHandlingType::kIgnore);
}
} // namespace views
......@@ -87,7 +87,9 @@ void NotifyCaretBoundsChanged(ui::InputMethod* input_method) {
} // namespace
// static
bool Widget::g_disable_activation_change_handling_ = false;
Widget::DisableActivationChangeHandlingType
Widget::g_disable_activation_change_handling_ =
Widget::DisableActivationChangeHandlingType::kNone;
// A default implementation of WidgetDelegate, used by Widget when no
// WidgetDelegate is supplied.
......@@ -1101,7 +1103,11 @@ bool Widget::IsNativeWidgetInitialized() const {
}
bool Widget::OnNativeWidgetActivationChanged(bool active) {
if (g_disable_activation_change_handling_)
if (g_disable_activation_change_handling_ ==
DisableActivationChangeHandlingType::kIgnore ||
(g_disable_activation_change_handling_ ==
DisableActivationChangeHandlingType::kIgnoreDeactivationOnly &&
!active))
return false;
// On windows we may end up here before we've completed initialization (from
......
......@@ -47,6 +47,10 @@ class OSExchangeData;
class ThemeProvider;
} // namespace ui
namespace ui_devtools {
class PageAgentViews;
}
namespace views {
class DesktopWindowTreeHost;
......@@ -1018,6 +1022,13 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
virtual void OnDragComplete();
private:
// Type of ways to ignore activation changes.
enum class DisableActivationChangeHandlingType {
kNone = 0, // Don't ignore any activation changes.
kIgnore, // Ignore both activation and deactivation changes.
kIgnoreDeactivationOnly, // Ignore only deactivation changes.
};
class PaintAsActiveLockImpl;
friend class ButtonTest;
......@@ -1025,8 +1036,19 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
friend class PaintAsActiveLockImpl;
friend class TextfieldTest;
friend class ViewAuraTest;
friend class ui_devtools::PageAgentViews;
friend void DisableActivationChangeHandlingForTests();
// Sets/gets the type of disabling widget activation change handling.
static void SetDisableActivationChangeHandling(
DisableActivationChangeHandlingType new_type) {
g_disable_activation_change_handling_ = new_type;
}
static DisableActivationChangeHandlingType
GetDisableActivationChangeHandling() {
return g_disable_activation_change_handling_;
}
// Persists the window's restored position and "show" state using the
// window delegate.
void SaveWindowPlacement();
......@@ -1057,7 +1079,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// If a descendent of |root_view_| is focused, then clear the focus.
void ClearFocusFromWidget();
static bool g_disable_activation_change_handling_;
static DisableActivationChangeHandlingType
g_disable_activation_change_handling_;
internal::NativeWidgetPrivate* native_widget_ = nullptr;
......
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