Commit 05af4c5a authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Chromium LUCI CQ

Move Aura deep scan cursor bug fix to ContentAnalysisDialog

This should address the concerns raised in crrev.com/c/2391514 without
regressing crbug.com/1100902.

Bug: 1151724, 1139050, 1100902
Change-Id: I2180278fec307555eb9714aed6f3644520838326
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556587Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avataranthonyvd <anthonyvd@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833765}
parent bbc0b285
......@@ -17,6 +17,7 @@
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_types.h"
......@@ -211,6 +212,20 @@ void ContentAnalysisDialog::CancelButtonCallback() {
delegate_->Cancel(is_warning());
}
void ContentAnalysisDialog::SuccessCallback() {
#if defined(USE_AURA)
if (web_contents_) {
// It's possible focus has been lost and gained back incorrectly if the user
// clicked on the page between the time the scan started and the time the
// dialog closes. This results in the behaviour detailed in
// crbug.com/1139050. The fix is to preemptively take back focus when this
// dialog closes on its own.
web_contents_->SetIgnoreInputEvents(false);
web_contents_->Focus();
}
#endif
}
bool ContentAnalysisDialog::ShouldShowCloseButton() const {
return false;
}
......@@ -460,6 +475,9 @@ void ContentAnalysisDialog::SetupButtons() {
} else {
// Include no buttons otherwise.
DialogDelegate::SetButtons(ui::DIALOG_BUTTON_NONE);
DialogDelegate::SetCancelCallback(
base::BindOnce(&ContentAnalysisDialog::SuccessCallback,
weak_ptr_factory_.GetWeakPtr()));
}
}
......
......@@ -208,6 +208,10 @@ class ContentAnalysisDialog : public views::DialogDelegate,
void AcceptButtonCallback();
void CancelButtonCallback();
// This callback used by DialogDelegate::SetCancelCallback and is used to
// ensure the auto-closing success dialog handles focus correctly.
void SuccessCallback();
std::unique_ptr<ContentAnalysisDelegate> delegate_;
content::WebContents* web_contents_;
......
......@@ -1846,15 +1846,10 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
return;
}
// Only lose focus if the associated tab doesn't want input. This ensures
// focus losses from clicking on a page while it has a modal dialog won't
// break it's text cursor after the dialog goes away.
if (!host()->IsIgnoringInputEvents()) {
host()->SetActive(false);
host()->LostFocus();
host()->SetActive(false);
host()->LostFocus();
DetachFromInputMethod(false);
}
DetachFromInputMethod(false);
// TODO(wjmaclean): Do we need to let TouchSelectionControllerClientAura
// handle this, just in case it stomps on a new highlight in another view
......
......@@ -6470,41 +6470,6 @@ TEST_F(RenderWidgetHostViewAuraInputMethodTest,
input_method->RemoveObserver(this);
}
class RenderWidgetHostViewAuraInputMethodFocusTest
: public RenderWidgetHostViewAuraInputMethodTest,
public testing::WithParamInterface<bool> {
public:
RenderWidgetHostViewAuraInputMethodFocusTest() = default;
~RenderWidgetHostViewAuraInputMethodFocusTest() override = default;
bool ignore_input_events() { return GetParam(); }
};
INSTANTIATE_TEST_SUITE_P(RenderWidgetHostViewAuraInputMethodFocusTest,
RenderWidgetHostViewAuraInputMethodFocusTest,
testing::Bool());
TEST_P(RenderWidgetHostViewAuraInputMethodFocusTest, OnFocusLost) {
render_widget_host_delegate()->set_should_ignore_input_events(
ignore_input_events());
ui::InputMethod* input_method = view_->GetInputMethod();
if (input_method != input_method_) {
// Some platforms doesn't support mocking input method. In that case, ignore this test.
return;
}
EXPECT_EQ(input_method, input_method_);
ActivateViewForTextInputManager(view_, ui::TEXT_INPUT_TYPE_TEXT);
input_method->SetFocusedTextInputClient(view_);
EXPECT_EQ(input_method->GetTextInputClient(), view_);
view_->OnWindowFocused(nullptr, view_->GetNativeView());
if (ignore_input_events())
EXPECT_EQ(input_method->GetTextInputClient(), view_);
else
EXPECT_EQ(input_method->GetTextInputClient(), nullptr);
}
#if defined(OS_WIN)
class MockInputMethodKeyboardController final
: public ui::InputMethodKeyboardController {
......
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