Commit 42fef5d1 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[fuchsia] Wire up FocusClient/ActivationClient for Frames.

This plumbing provides activation and focusing of the WindowTreeHost's
child windows, enabling full use of the mouse and keyboard in
content views.

Also fixed some IWYU linter errors.

Bug: 878439
Change-Id: I0fc344b69edf78ca3aff39f615951cfa016718b2
Reviewed-on: https://chromium-review.googlesource.com/1194868
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587686}
parent bcc1fe8c
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "ui/ozone/platform/scenic/scenic_window.h" #include "ui/ozone/platform/scenic/scenic_window.h"
#include <string>
#include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/sys/cpp/fidl.h>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -276,6 +278,11 @@ void ScenicWindow::OnEvent(fuchsia::ui::input::InputEvent event, ...@@ -276,6 +278,11 @@ void ScenicWindow::OnEvent(fuchsia::ui::input::InputEvent event,
break; break;
case fuchsia::ui::input::InputEvent::Tag::kFocus: case fuchsia::ui::input::InputEvent::Tag::kFocus:
// TODO(crbug.com/878439): Implement this once Scenic adds support for
// sending FocusEvents.
NOTIMPLEMENTED();
break;
case fuchsia::ui::input::InputEvent::Tag::Invalid: case fuchsia::ui::input::InputEvent::Tag::Invalid:
break; break;
} }
......
...@@ -81,6 +81,7 @@ component("service_lib") { ...@@ -81,6 +81,7 @@ component("service_lib") {
"//ui/display", "//ui/display",
"//ui/ozone", "//ui/ozone",
"//ui/platform_window", "//ui/platform_window",
"//ui/wm",
] ]
data_deps = [ data_deps = [
......
...@@ -5,4 +5,5 @@ include_rules = [ ...@@ -5,4 +5,5 @@ include_rules = [
"+ui/display", "+ui/display",
"+ui/ozone/public", "+ui/ozone/public",
"+ui/platform_window", "+ui/platform_window",
"+ui/wm/core",
] ]
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -99,6 +100,7 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents, ...@@ -99,6 +100,7 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
ContextImpl* context, ContextImpl* context,
fidl::InterfaceRequest<chromium::web::Frame> frame_request) fidl::InterfaceRequest<chromium::web::Frame> frame_request)
: web_contents_(std::move(web_contents)), : web_contents_(std::move(web_contents)),
focus_controller_(std::make_unique<wm::FocusController>(this)),
context_(context), context_(context),
binding_(this, std::move(frame_request)) { binding_(this, std::move(frame_request)) {
binding_.set_error_handler([this]() { context_->DestroyFrame(this); }); binding_.set_error_handler([this]() { context_->DestroyFrame(this); });
...@@ -106,8 +108,16 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents, ...@@ -106,8 +108,16 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
FrameImpl::~FrameImpl() { FrameImpl::~FrameImpl() {
if (window_tree_host_) { if (window_tree_host_) {
aura::client::SetFocusClient(root_window(), nullptr);
wm::SetActivationClient(root_window(), nullptr);
window_tree_host_->Hide(); window_tree_host_->Hide();
window_tree_host_->compositor()->SetVisible(false); window_tree_host_->compositor()->SetVisible(false);
// Allows posted focus events to process before the FocusController
// is torn down.
content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
focus_controller_.release());
} }
} }
...@@ -124,11 +134,21 @@ void FrameImpl::CreateView( ...@@ -124,11 +134,21 @@ void FrameImpl::CreateView(
window_tree_host_ = window_tree_host_ =
std::make_unique<aura::WindowTreeHostPlatform>(std::move(properties)); std::make_unique<aura::WindowTreeHostPlatform>(std::move(properties));
window_tree_host_->InitHost(); window_tree_host_->InitHost();
window_tree_host_->window()->SetLayoutManager(new LayoutManagerImpl());
window_tree_host_->window()->AddChild(web_contents_->GetNativeView()); aura::client::SetFocusClient(root_window(), focus_controller_.get());
window_tree_host_->window()->Show(); wm::SetActivationClient(root_window(), focus_controller_.get());
window_tree_host_->Show();
// Add hooks which automatically set the focus state when input events are
// received.
root_window()->AddPreTargetHandler(focus_controller_.get());
// Track child windows for enforcement of window management policies and
// propagate window manager events to them (e.g. window resizing).
root_window()->SetLayoutManager(new LayoutManagerImpl());
root_window()->AddChild(web_contents_->GetNativeView());
web_contents_->GetNativeView()->Show(); web_contents_->GetNativeView()->Show();
window_tree_host_->Show();
} }
void FrameImpl::GetNavigationController( void FrameImpl::GetNavigationController(
...@@ -249,4 +269,10 @@ void FrameImpl::MaybeSendNavigationEvent() { ...@@ -249,4 +269,10 @@ void FrameImpl::MaybeSendNavigationEvent() {
} }
} }
bool FrameImpl::SupportsChildActivation(aura::Window*) const {
// TODO(crbug.com/878439): Return a result based on window properties such as
// visibility.
return true;
}
} // namespace webrunner } // namespace webrunner
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/focus_controller.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h" #include "webrunner/fidl/chromium/web/cpp/fidl.h"
...@@ -32,7 +35,8 @@ class ContextImpl; ...@@ -32,7 +35,8 @@ class ContextImpl;
// Implements a Frame service, which is a wrapper for a WebContents instance. // Implements a Frame service, which is a wrapper for a WebContents instance.
class FrameImpl : public chromium::web::Frame, class FrameImpl : public chromium::web::Frame,
public chromium::web::NavigationController, public chromium::web::NavigationController,
public content::WebContentsObserver { public content::WebContentsObserver,
public wm::BaseFocusRules {
public: public:
FrameImpl(std::unique_ptr<content::WebContents> web_contents, FrameImpl(std::unique_ptr<content::WebContents> web_contents,
ContextImpl* context, ContextImpl* context,
...@@ -70,6 +74,9 @@ class FrameImpl : public chromium::web::Frame, ...@@ -70,6 +74,9 @@ class FrameImpl : public chromium::web::Frame,
void DidFinishLoad(content::RenderFrameHost* render_frame_host, void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override; const GURL& validated_url) override;
// wm::BaseFocusRules implementation.
bool SupportsChildActivation(aura::Window*) const override;
private: private:
FRIEND_TEST_ALL_PREFIXES(ContextImplTest, DelayedNavigationEventAck); FRIEND_TEST_ALL_PREFIXES(ContextImplTest, DelayedNavigationEventAck);
FRIEND_TEST_ALL_PREFIXES(ContextImplTest, NavigationObserverDisconnected); FRIEND_TEST_ALL_PREFIXES(ContextImplTest, NavigationObserverDisconnected);
...@@ -77,12 +84,15 @@ class FrameImpl : public chromium::web::Frame, ...@@ -77,12 +84,15 @@ class FrameImpl : public chromium::web::Frame,
FRIEND_TEST_ALL_PREFIXES(ContextImplTest, ReloadFrame); FRIEND_TEST_ALL_PREFIXES(ContextImplTest, ReloadFrame);
FRIEND_TEST_ALL_PREFIXES(ContextImplTest, Stop); FRIEND_TEST_ALL_PREFIXES(ContextImplTest, Stop);
aura::Window* root_window() const { return window_tree_host_->window(); }
// Sends |pending_navigation_event_| to the observer if there are any changes // Sends |pending_navigation_event_| to the observer if there are any changes
// to be reported. // to be reported.
void MaybeSendNavigationEvent(); void MaybeSendNavigationEvent();
std::unique_ptr<aura::WindowTreeHost> window_tree_host_; std::unique_ptr<aura::WindowTreeHost> window_tree_host_;
std::unique_ptr<content::WebContents> web_contents_; std::unique_ptr<content::WebContents> web_contents_;
std::unique_ptr<wm::FocusController> focus_controller_;
chromium::web::NavigationEventObserverPtr navigation_observer_; chromium::web::NavigationEventObserverPtr navigation_observer_;
chromium::web::NavigationEntry cached_navigation_state_; chromium::web::NavigationEntry cached_navigation_state_;
......
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