Skip to content

Commit

Permalink
chromeos: converts Window::set_ignore_events() to EventTargetingPolicy
Browse files Browse the repository at this point in the history
And plumbs through to mus.

BUG=746713
TEST=covered by tests

Change-Id: Ic4dc891dd2983f79f13e1c5edc74bbe1c1469acc
Reviewed-on: https://chromium-review.googlesource.com/580501
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488894}
  • Loading branch information
Scott Violet authored and Commit Bot committed Jul 23, 2017
1 parent 0d1d09c commit ca58856
Show file tree
Hide file tree
Showing 24 changed files with 119 additions and 29 deletions.
4 changes: 3 additions & 1 deletion ash/display/cursor_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/env.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
Expand Down Expand Up @@ -214,7 +215,8 @@ void CursorWindowController::SetContainer(aura::Window* container) {
cursor_window_.reset(new aura::Window(delegate_.get()));
cursor_window_->SetTransparent(true);
cursor_window_->Init(ui::LAYER_TEXTURED);
cursor_window_->set_ignore_events(true);
cursor_window_->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::NONE);
cursor_window_->set_owned_by_parent(false);
// Call UpdateCursorImage() to figure out |cursor_window_|'s desired size.
UpdateCursorImage();
Expand Down
3 changes: 1 addition & 2 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/mus/window_mus.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
Expand Down Expand Up @@ -254,7 +253,7 @@ aura::Window* CreateContainer(int window_id,
new aura::Window(nullptr, aura::client::WINDOW_TYPE_UNKNOWN);
window->Init(ui::LAYER_NOT_DRAWN);
if (Shell::GetAshConfig() != Config::CLASSIC) {
aura::WindowPortMus::Get(window)->SetEventTargetingPolicy(
window->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
}
window->set_id(window_id);
Expand Down
1 change: 1 addition & 0 deletions components/exo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ source_set("exo") {
"//device/gamepad/public/cpp:shared_with_blink",
"//gpu",
"//gpu/command_buffer/client:gles2_interface",
"//services/ui/public/interfaces",
"//skia",
"//ui/aura",
"//ui/compositor",
Expand Down
1 change: 1 addition & 0 deletions components/exo/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include_rules = [
"+device/gamepad",
"+gpu",
"+mojo/public/cpp",
"+services/ui/public/interfaces",
"+third_party/khronos",
"+third_party/skia",
"+ui",
Expand Down
4 changes: 3 additions & 1 deletion components/exo/shell_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/exo/surface.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/window.h"
Expand Down Expand Up @@ -1698,7 +1699,8 @@ void ShellSurface::UpdateShadow() {
shadow_overlay_ = base::MakeUnique<aura::Window>(nullptr);
shadow_overlay_->set_owned_by_parent(false);
DCHECK(!shadow_overlay_->owned_by_parent());
shadow_overlay_->set_ignore_events(true);
shadow_overlay_->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::NONE);
shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
shadow_overlay_->layer()->Add(shadow->layer());
window->AddChild(shadow_overlay());
Expand Down
2 changes: 2 additions & 0 deletions ui/aura/local/window_port_local.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void WindowPortLocal::OnWillRemoveWindowFromRootWindow() {
window_->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_);
}

void WindowPortLocal::OnEventTargetingPolicyChanged() {}

void WindowPortLocal::OnSurfaceChanged(const viz::SurfaceId& surface_id,
const gfx::Size& surface_size) {
DCHECK_EQ(surface_id.frame_sink_id(), frame_sink_id_);
Expand Down
1 change: 1 addition & 0 deletions ui/aura/local/window_port_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AURA_EXPORT WindowPortLocal : public WindowPort {
viz::SurfaceId GetSurfaceId() const override;
void OnWindowAddedToRootWindow() override;
void OnWillRemoveWindowFromRootWindow() override;
void OnEventTargetingPolicyChanged() override;

private:
void OnSurfaceChanged(const viz::SurfaceId& surface_id,
Expand Down
8 changes: 8 additions & 0 deletions ui/aura/mus/window_port_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ viz::SurfaceId WindowPortMus::GetSurfaceId() const {
return viz::SurfaceId();
}

void WindowPortMus::OnWindowAddedToRootWindow() {}

void WindowPortMus::OnWillRemoveWindowFromRootWindow() {}

void WindowPortMus::OnEventTargetingPolicyChanged() {
SetEventTargetingPolicy(window_->event_targeting_policy());
}

void WindowPortMus::UpdatePrimarySurfaceInfo() {
if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM &&
window_mus_type() != WindowMusType::EMBED_IN_OWNER &&
Expand Down
5 changes: 3 additions & 2 deletions ui/aura/mus/window_port_mus.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
std::unique_ptr<ui::PropertyData> data) override;
std::unique_ptr<cc::LayerTreeFrameSink> CreateLayerTreeFrameSink() override;
viz::SurfaceId GetSurfaceId() const override;
void OnWindowAddedToRootWindow() override {}
void OnWillRemoveWindowFromRootWindow() override {}
void OnWindowAddedToRootWindow() override;
void OnWillRemoveWindowFromRootWindow() override;
void OnEventTargetingPolicyChanged() override;

void UpdatePrimarySurfaceInfo();
void UpdateClientSurfaceEmbedder();
Expand Down
5 changes: 5 additions & 0 deletions ui/aura/mus/window_tree_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ void WindowTreeClient::OnWindowMusCreated(WindowMus* window) {
base::MakeUnique<CrashInFlightChange>(window, ChangeType::NEW_WINDOW));
tree_->NewWindow(change_id, window->server_id(),
std::move(transport_properties));
if (window->GetWindow()->event_targeting_policy() !=
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS) {
SetEventTargetingPolicy(window,
window->GetWindow()->event_targeting_policy());
}
if (window->window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED) {
WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
std::unique_ptr<DisplayInitParams> display_init_params =
Expand Down
36 changes: 32 additions & 4 deletions ui/aura/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "cc/output/layer_tree_frame_sink.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/cursor_client.h"
Expand Down Expand Up @@ -64,7 +65,8 @@ Window::Window(WindowDelegate* delegate,
visible_(false),
id_(kInitialId),
transparent_(false),
ignore_events_(false),
event_targeting_policy_(
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS),
// Don't notify newly added observers during notification. This causes
// problems for code that adds an observer as part of an observer
// notification (such as the workspace code).
Expand Down Expand Up @@ -482,6 +484,15 @@ bool Window::HasObserver(const WindowObserver* observer) const {
return observers_.HasObserver(observer);
}

void Window::SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy policy) {
if (event_targeting_policy_ == policy)
return;

event_targeting_policy_ = policy;
if (port_)
port_->OnEventTargetingPolicyChanged();
}

bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const {
const Window* root_window = GetRootWindow();
if (!root_window)
Expand Down Expand Up @@ -745,8 +756,10 @@ Window* Window::GetWindowForPoint(const gfx::Point& local_point,
Window* child = *it;

if (for_event_handling) {
if (child->ignore_events_)
if (child->event_targeting_policy_ ==
ui::mojom::EventTargetingPolicy::NONE) {
continue;
}

// The client may not allow events to be processed by certain subtrees.
client::EventClient* client = client::GetEventClient(GetRootWindow());
Expand All @@ -764,8 +777,23 @@ Window* Window::GetWindowForPoint(const gfx::Point& local_point,
Window* match = child->GetWindowForPoint(point_in_child_coords,
return_tightest,
for_event_handling);
if (match)
return match;
if (!match)
continue;

switch (child->event_targeting_policy_) {
case ui::mojom::EventTargetingPolicy::TARGET_ONLY:
if (child->delegate_)
return child;
break;
case ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS:
return match;
case ui::mojom::EventTargetingPolicy::DESCENDANTS_ONLY:
if (match != child)
return match;
break;
case ui::mojom::EventTargetingPolicy::NONE:
NOTREACHED(); // This case is handled early on.
}
}

return delegate_ ? this : nullptr;
Expand Down
11 changes: 8 additions & 3 deletions ui/aura/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Transform;

namespace ui {
class Layer;
namespace mojom {
enum class EventTargetingPolicy;
}
}

namespace aura {
Expand Down Expand Up @@ -241,8 +244,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
void RemoveObserver(WindowObserver* observer);
bool HasObserver(const WindowObserver* observer) const;

void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; }
bool ignore_events() const { return ignore_events_; }
void SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy policy);
ui::mojom::EventTargetingPolicy event_targeting_policy() const {
return event_targeting_policy_;
}

// Returns true if the |point_in_root| in root window's coordinate falls
// within this window's bounds. Returns false if the window is detached
Expand Down Expand Up @@ -480,7 +485,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
std::unique_ptr<ui::EventTargeter> targeter_;

// Makes the window pass all events through to any windows behind it.
bool ignore_events_;
ui::mojom::EventTargetingPolicy event_targeting_policy_;

base::ObserverList<WindowObserver, true> observers_;

Expand Down
4 changes: 3 additions & 1 deletion ui/aura/window_event_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/event_client.h"
Expand Down Expand Up @@ -670,7 +671,8 @@ void WindowEventDispatcher::OnWindowBoundsChanged(Window* window,
synthesize_mouse_move_ = false;
}

if (window->IsVisible() && !window->ignore_events()) {
if (window->IsVisible() && window->event_targeting_policy() !=
ui::mojom::EventTargetingPolicy::NONE) {
gfx::Rect old_bounds_in_root = old_bounds, new_bounds_in_root = new_bounds;
Window::ConvertRectToTarget(window->parent(), host_->window(),
&old_bounds_in_root);
Expand Down
6 changes: 4 additions & 2 deletions ui/aura/window_event_dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/test/histogram_tester.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/event_client.h"
Expand Down Expand Up @@ -1150,7 +1151,7 @@ TEST_P(WindowEventDispatcherTest,
recorder.Reset();

// Set window to ignore events.
window->set_ignore_events(true);
window->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);

// Update the window bounds so that cursor is back inside the window.
// This should not trigger a synthetic event.
Expand All @@ -1161,7 +1162,8 @@ TEST_P(WindowEventDispatcherTest,
recorder.Reset();

// Set window to accept events but invisible.
window->set_ignore_events(false);
window->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
window->Hide();
recorder.Reset();

Expand Down
2 changes: 2 additions & 0 deletions ui/aura/window_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class AURA_EXPORT WindowPort {
virtual void OnWindowAddedToRootWindow() = 0;
virtual void OnWillRemoveWindowFromRootWindow() = 0;

virtual void OnEventTargetingPolicyChanged() = 0;

protected:
// Returns the WindowPort associated with a Window.
static WindowPort* Get(Window* window);
Expand Down
2 changes: 2 additions & 0 deletions ui/aura/window_port_for_shutdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ void WindowPortForShutdown::OnWindowAddedToRootWindow() {}

void WindowPortForShutdown::OnWillRemoveWindowFromRootWindow() {}

void WindowPortForShutdown::OnEventTargetingPolicyChanged() {}

} // namespace aura
1 change: 1 addition & 0 deletions ui/aura/window_port_for_shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WindowPortForShutdown : public WindowPort {
viz::SurfaceId GetSurfaceId() const override;
void OnWindowAddedToRootWindow() override;
void OnWillRemoveWindowFromRootWindow() override;
void OnEventTargetingPolicyChanged() override;

private:
DISALLOW_COPY_AND_ASSIGN(WindowPortForShutdown);
Expand Down
7 changes: 6 additions & 1 deletion ui/aura/window_targeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ui/aura/window_targeter.h"

#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/event_client.h"
#include "ui/aura/client/focus_client.h"
Expand Down Expand Up @@ -116,8 +117,12 @@ bool WindowTargeter::SubtreeCanAcceptEvent(
const ui::LocatedEvent& event) const {
if (!window->IsVisible())
return false;
if (window->ignore_events())
if (window->event_targeting_policy() ==
ui::mojom::EventTargetingPolicy::NONE ||
window->event_targeting_policy() ==
ui::mojom::EventTargetingPolicy::TARGET_ONLY) {
return false;
}
client::EventClient* client = client::GetEventClient(window->GetRootWindow());
if (client && !client->CanProcessEventsWithinSubtree(window))
return false;
Expand Down
27 changes: 21 additions & 6 deletions ui/aura/window_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/focus_change_observer.h"
Expand Down Expand Up @@ -1544,7 +1545,7 @@ TEST_P(WindowTest, Visibility) {
EXPECT_EQ(1, d2.shown());
}

TEST_P(WindowTest, IgnoreEventsTest) {
TEST_P(WindowTest, EventTargetingPolicy) {
TestWindowDelegate d11;
TestWindowDelegate d12;
TestWindowDelegate d111;
Expand All @@ -1560,18 +1561,32 @@ TEST_P(WindowTest, IgnoreEventsTest) {
std::unique_ptr<Window> w121(CreateTestWindowWithDelegate(
&d121, 121, gfx::Rect(150, 150, 50, 50), w12.get()));

EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w12->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::TARGET_ONLY);
EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w12->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);

EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10)));
w12->set_ignore_events(true);
w12->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);
EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10)));
w12->set_ignore_events(false);
w12->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);

EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w121->set_ignore_events(true);
w121->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);
EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w12->set_ignore_events(true);
w12->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);
EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w111->set_ignore_events(true);
w111->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);
EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));

w11->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
EXPECT_EQ(nullptr, w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
w111->SetEventTargetingPolicy(
ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
}

// Tests transformation on the root window.
Expand Down
5 changes: 3 additions & 2 deletions ui/touch_selection/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ component("touch_selection") {

if (use_aura) {
deps += [
"//services/ui/public/interfaces",
"//skia:skia",
"//ui/aura:aura",
"//ui/aura_extra:aura_extra",
"//ui/aura",
"//ui/aura_extra",
"//ui/compositor:compositor",
"//ui/gfx:gfx",
"//ui/resources",
Expand Down
1 change: 1 addition & 0 deletions ui/touch_selection/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+services/ui/public/interfaces",
"+ui/aura",
"+ui/aura_extra",
"+ui/base",
Expand Down
Loading

0 comments on commit ca58856

Please sign in to comment.