Commit 5ca176b6 authored by David Black's avatar David Black Committed by Commit Bot

Revert "Synchronize NavigableContentsView's LocalHostView focus w/ window focus."

This reverts commit 22c7b0a0.

Reason for revert: Causing b/140266795.

Original change's description:
> Synchronize NavigableContentsView's LocalHostView focus w/ window focus.
>
> Previously, if the user clicked into the WebContents of an
> AssistantCardElementView, the corresponding RenderWidgetHostViewAura
> would become focused. However, the focused view in the Assistant view
> hierarchy (usually the Textfield in the Assistant Dialog Plate) wouldn't
> receive a blur event. As such, the user would think they could keep
> typing because of the blinking caret in the Textfield. When typing,
> they would find nothing entered and think keyboard was broken.
>
> Now, we synchronize the focus state of NavigableContentsView's
> LocalHostView with the associated native window so that as the native
> window subtree takes focus, so does the LocalHostView.
>
> This fixes AssistantCardElementView further upstream.
>
> Bug: b:134170714
> Change-Id: I03d67a3d9fbc779a87449065c97d7e4a877fe10a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1649084
> Commit-Queue: David Black <dmblack@google.com>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Ken Rockot <rockot@google.com>
> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#668077}

TBR=xiyuan@chromium.org,rockot@google.com,xiaohuic@chromium.org,dmblack@google.com,wutao@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: b:134170714, b:140266795
Change-Id: I4de99b2ef2c18bb503277fc4a528866b2c832764
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778989Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#692866}
parent 307659ac
......@@ -262,10 +262,6 @@ class SearchResultAnswerCardView::AnswerCardResultView
OnVisibilityChanged(true /* is_visible */);
views::View* content_view = contents_->GetView()->view();
if (children().empty()) {
// Focusability is handled on SearchResultAnswerCardView so we explicitly
// disable it on the embedded view (for which it is enabled by default).
content_view->SetFocusBehavior(FocusBehavior::NEVER);
AddChildView(content_view);
ExcludeCardFromEventHandling(contents_->GetView()->native_view());
......
......@@ -22,8 +22,6 @@
#endif // defined(TOOLKIT_VIEWS)
#if defined(USE_AURA)
#include "ui/aura/client/focus_change_observer.h" // nogncheck
#include "ui/aura/client/focus_client.h" // nogncheck
#include "ui/aura/layout_manager.h" // nogncheck
#include "ui/aura/window.h" // nogncheck
#endif
......@@ -77,25 +75,14 @@ class LocalWindowLayoutManager : public aura::LayoutManager {
// Owns an Aura window which parents another Aura window in the same process,
// corresponding to a web contents view hosted in the process.
class LocalViewHost : public views::NativeViewHost,
public aura::WindowObserver,
public aura::client::FocusChangeObserver {
class LocalViewHost : public views::NativeViewHost {
public:
LocalViewHost(aura::Window* window, NavigableContents* contents)
: window_(window), contents_(contents) {
window_->SetLayoutManager(new LocalWindowLayoutManager(window_));
window_->AddObserver(this);
// We set focus behavior to |ALWAYS| to ensure that we receive window focus
// change events when our hosted WebContents takes focus. We utilize this
// change event to keep LocalViewHost and WebContents focus state in sync.
SetFocusBehavior(FocusBehavior::ALWAYS);
}
~LocalViewHost() override {
if (!window_destroyed_)
window_->RemoveObserver(this);
}
~LocalViewHost() override = default;
// views::View:
void AddedToWidget() override {
......@@ -116,54 +103,10 @@ class LocalViewHost : public views::NativeViewHost,
}
}
// aura::WindowObserver:
void OnWindowAddedToRootWindow(aura::Window* window) override {
// Once our |window_| has been added to its root window, we can obtain a
// reference to the root window's focus client which we observe to detect
// window focus changed events.
auto* focus_client = aura::client::GetFocusClient(window_);
if (focus_client)
focus_client->AddObserver(this);
}
void OnWindowRemovingFromRootWindow(aura::Window* window,
aura::Window* root_window) override {
// We need to stop observing the root window's focus client before our
// |window_| is removed. Otherwise, we will leak a pointer to LocalViewHost
// to the focus client that will persist even after LocalViewHost is
// destroyed. This will cause a crash when the focus client attempts to
// notify our destroyed instance of focus changed events.
auto* focus_client = aura::client::GetFocusClient(window_);
if (focus_client)
focus_client->RemoveObserver(this);
}
void OnWindowDestroying(aura::Window* window) override {
window_->RemoveObserver(this);
window_destroyed_ = true;
}
// aura::client::FocusChangeObserver:
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override {
// We need to ensure that LocalViewHost's focus state is synced with that of
// |window_|. This only needs to be done when gaining focus and when
// LocalViewHost doesn't already have focus.
if (!gained_focus || HasFocus())
return;
// When the window gaining focus is contained within |window_|, we need to
// request focus on LocalHostView to remain in sync.
if (window_->Contains(gained_focus))
RequestFocus();
}
private:
aura::Window* const window_;
NavigableContents* const contents_;
bool window_destroyed_ = false;
DISALLOW_COPY_AND_ASSIGN(LocalViewHost);
};
......
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