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