[chromecast] Enable element focus for WebContentController
Web page-level focus was absent, which in turn meant that blink-level focus was suppressed. The aura::Window on which focus was attempted did not have an OnWindowFocused observer; this change focuses the Window that does. This is a reland of one piece of the reverted http://crrev.com/c/2274201 Bug: b/156123509 Test: manual on device Change-Id: I0a9ec66de97f346512f9ade01f7ad4821159c527 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348420 Reviewed-by: Daniel Nicoara <dnicoara@chromium.org> Reviewed-by: Kevin Schoedel <kpschoedel@chromium.org> Commit-Queue: Kevin Schoedel <kpschoedel@chromium.org> Cr-Commit-Position: refs/heads/master@{#805908}
This commit is contained in:

committed by
Commit Bot

parent
eeddc5af3b
commit
5be14cd5b2
@ -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"
|
||||
@ -170,14 +171,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) {
|
||||
|
Reference in New Issue
Block a user