Commit ffc6f22e authored by Kevin Schoedel's avatar Kevin Schoedel Committed by Commit Bot

[chromecast] Enable element focus for WebContentController

Focus did not work due to two distinct problems, both of which caused
page-level focus to be absent, which in turn meant that blink-level
focus was suppressed.

- The aura::Window on which focus was attempted does not have an
  OnWindowFocused observer. This change focuses the Window that does.

- Wayland app's aura::Windows are not visible. This change adds a check
  for an ancestor that is an exo window.

Bug: b/156123509
Test: manual on device
Change-Id: Ib4e8a5101bbc28d2b7a0448aff8142c8cffa2a76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274201Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarAlbert Chaulk <achaulk@chromium.org>
Commit-Queue: Kevin Schoedel <kpschoedel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786469}
parent debbe86e
......@@ -12,6 +12,7 @@
#include "chromecast/browser/cast_web_contents.h"
#include "chromecast/browser/webview/proto/webview.pb.h"
#include "chromecast/browser/webview/webview_navigation_throttle.h"
#include "chromecast/graphics/cast_focus_client_aura.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/navigation_handle.h"
......@@ -180,14 +181,23 @@ void WebContentController::AttachTo(aura::Window* window, int window_id) {
void WebContentController::ProcessInputEvent(const webview::InputEvent& ev) {
content::WebContents* contents = GetWebContents();
DCHECK(contents);
DCHECK(contents->GetNativeView());
if (!contents->GetNativeView()->CanFocus())
return;
// Ensure this web contents has focus before sending it input.
if (!contents->GetNativeView()->HasFocus())
contents->GetNativeView()->Focus();
// Ensure this web contents has focus before sending it input.
// Focus at this level is necessary, or else Blink will ignore
// attempts to focus any elements in the contents.
//
// Via b/156123509: The aura::Window given by |contents->GetNativeView()|
// is not suitable for this purpose, because it has no OnWindowFocused
// observer. The |window| used here is the same one whose |delegate|
// is the EventHandler for this input event.
content::RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView();
aura::Window* window = rwhv->GetNativeView();
DCHECK(window == contents->GetContentNativeView());
if (!window->CanFocus())
return;
if (!window->HasFocus())
window->Focus();
ui::EventHandler* handler = rwhv->GetNativeView()->delegate();
ui::EventType type = static_cast<ui::EventType>(ev.event_type());
switch (type) {
......
......@@ -105,7 +105,10 @@ cast_source_set("graphics") {
}
if (use_ozone) {
deps += [ "//ui/ozone" ]
deps += [
"//components/exo",
"//ui/ozone",
]
}
}
......
include_rules = [
"+chromecast/ui",
"+components/exo",
"+components/viz/common/frame_sinks",
"+ui/aura",
"+ui/base",
......
......@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "components/exo/surface.h"
#include "ui/aura/window.h"
#define LOG_WINDOW_INFO(top_level, window) \
......@@ -13,6 +14,19 @@
<< "', window: " << (window)->id() << ": '" \
<< (window)->GetName() << "'"
namespace {
bool IsVisibleExoWindow(aura::Window* window) {
for (aura::Window* w = window; w; w = w->parent()) {
if (w->GetProperty(exo::kClientSurfaceIdKey) && w->IsVisible()) {
return true;
}
}
return false;
}
} // namespace
namespace chromecast {
CastFocusClientAura::CastFocusClientAura() : focused_window_(nullptr) {}
......@@ -193,7 +207,10 @@ aura::Window* CastFocusClientAura::GetWindowToFocus() {
aura::Window* next = nullptr;
aura::Window* next_top_level = nullptr;
for (aura::Window* window : focusable_windows_) {
if (!window->CanFocus() || !window->IsVisible()) {
if (!window->CanFocus()) {
continue;
}
if (!window->IsVisible() && !IsVisibleExoWindow(window)) {
continue;
}
......
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