Commit 36529166 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

Reland "aura: makes each Window be associated with an Env"

This reverts commit c179496f.

Reason for revert: The test failure was fixed at https://chromium-review.googlesource.com/c/chromium/src/+/1168466 . The failure was a lingering issue and not caused by patch (but triggered by my patch), so reverting the revert.

Original change's description:
> Revert "aura: makes each Window be associated with an Env"
> 
> This reverts commit 99df3b26.
> 
> Reason for revert: Caused failures on msan bot.
> 
> Original change's description:
> > aura: makes each Window be associated with an Env
> > 
> > This is to avoid using Env::GetInstance(), so that there can be multiple
> > Envs created at once.
> > 
> > BUG=847992
> > TEST=covered by tests
> > 
> > Change-Id: I2e2604c8f8a356ca9cc6771ed050ef8431e7b840
> > Reviewed-on: https://chromium-review.googlesource.com/1165861
> > Commit-Queue: Scott Violet <sky@chromium.org>
> > Reviewed-by: Michael Wasserman <msw@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#581568}
> 
> TBR=sky@chromium.org,msw@chromium.org
> 
> Change-Id: I50fb5f0d27011219ed2569b1035a78e01b9b3de9
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 847992
> Reviewed-on: https://chromium-review.googlesource.com/1168323
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#581718}

TBR=sky@chromium.org,msw@chromium.org

Change-Id: I83e61d6ca9de8dcd023757f03bb18f0abf09790e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 847992
Reviewed-on: https://chromium-review.googlesource.com/1168565Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581796}
parent efca1917
...@@ -187,7 +187,7 @@ bool Env::initial_throttle_input_on_resize_ = true; ...@@ -187,7 +187,7 @@ bool Env::initial_throttle_input_on_resize_ = true;
Env::Env(Mode mode) Env::Env(Mode mode)
: mode_(mode), : mode_(mode),
env_controller_(new EnvInputStateController), env_controller_(std::make_unique<EnvInputStateController>(this)),
mouse_button_flags_(0), mouse_button_flags_(0),
is_touch_down_(false), is_touch_down_(false),
get_last_mouse_location_from_mus_(mode_ == Mode::MUS), get_last_mouse_location_from_mus_(mode_ == Mode::MUS),
......
...@@ -11,16 +11,20 @@ ...@@ -11,16 +11,20 @@
namespace aura { namespace aura {
EnvInputStateController::EnvInputStateController(Env* env) : env_(env) {}
EnvInputStateController::~EnvInputStateController() = default;
void EnvInputStateController::UpdateStateForMouseEvent( void EnvInputStateController::UpdateStateForMouseEvent(
const Window* window, const Window* window,
const ui::MouseEvent& event) { const ui::MouseEvent& event) {
switch (event.type()) { switch (event.type()) {
case ui::ET_MOUSE_PRESSED: case ui::ET_MOUSE_PRESSED:
Env::GetInstance()->set_mouse_button_flags(event.button_flags()); env_->set_mouse_button_flags(event.button_flags());
break; break;
case ui::ET_MOUSE_RELEASED: case ui::ET_MOUSE_RELEASED:
Env::GetInstance()->set_mouse_button_flags( env_->set_mouse_button_flags(event.button_flags() &
event.button_flags() & ~event.changed_button_flags()); ~event.changed_button_flags());
break; break;
default: default:
break; break;
...@@ -40,7 +44,7 @@ void EnvInputStateController::UpdateStateForTouchEvent( ...@@ -40,7 +44,7 @@ void EnvInputStateController::UpdateStateForTouchEvent(
switch (event.type()) { switch (event.type()) {
case ui::ET_TOUCH_PRESSED: case ui::ET_TOUCH_PRESSED:
touch_ids_down_ |= (1 << event.pointer_details().id); touch_ids_down_ |= (1 << event.pointer_details().id);
Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); env_->set_touch_down(touch_ids_down_ != 0);
break; break;
// Handle ET_TOUCH_CANCELLED only if it has a native event. // Handle ET_TOUCH_CANCELLED only if it has a native event.
...@@ -51,7 +55,7 @@ void EnvInputStateController::UpdateStateForTouchEvent( ...@@ -51,7 +55,7 @@ void EnvInputStateController::UpdateStateForTouchEvent(
case ui::ET_TOUCH_RELEASED: case ui::ET_TOUCH_RELEASED:
touch_ids_down_ = (touch_ids_down_ | (1 << event.pointer_details().id)) ^ touch_ids_down_ = (touch_ids_down_ | (1 << event.pointer_details().id)) ^
(1 << event.pointer_details().id); (1 << event.pointer_details().id);
Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); env_->set_touch_down(touch_ids_down_ != 0);
break; break;
case ui::ET_TOUCH_MOVED: case ui::ET_TOUCH_MOVED:
...@@ -68,7 +72,7 @@ void EnvInputStateController::SetLastMouseLocation( ...@@ -68,7 +72,7 @@ void EnvInputStateController::SetLastMouseLocation(
const gfx::Point& location_in_root) const { const gfx::Point& location_in_root) const {
// If |root_window| is null, we are only using the event to update event // If |root_window| is null, we are only using the event to update event
// states, so we shouldn't update mouse location. // states, so we shouldn't update mouse location.
if (!root_window && Env::GetInstance()->mode() == aura::Env::Mode::MUS) if (!root_window && env_->mode() == aura::Env::Mode::MUS)
return; return;
client::ScreenPositionClient* client = client::ScreenPositionClient* client =
...@@ -76,9 +80,9 @@ void EnvInputStateController::SetLastMouseLocation( ...@@ -76,9 +80,9 @@ void EnvInputStateController::SetLastMouseLocation(
if (client) { if (client) {
gfx::Point location_in_screen = location_in_root; gfx::Point location_in_screen = location_in_root;
client->ConvertPointToScreen(root_window, &location_in_screen); client->ConvertPointToScreen(root_window, &location_in_screen);
Env::GetInstance()->SetLastMouseLocation(location_in_screen); env_->SetLastMouseLocation(location_in_screen);
} else { } else {
Env::GetInstance()->SetLastMouseLocation(location_in_root); env_->SetLastMouseLocation(location_in_root);
} }
} }
......
...@@ -24,12 +24,13 @@ namespace test { ...@@ -24,12 +24,13 @@ namespace test {
class EnvTestHelper; class EnvTestHelper;
} }
class Env;
class Window; class Window;
class AURA_EXPORT EnvInputStateController { class AURA_EXPORT EnvInputStateController {
public: public:
EnvInputStateController() : touch_ids_down_(0) {} explicit EnvInputStateController(Env* env);
~EnvInputStateController() {} ~EnvInputStateController();
void UpdateStateForMouseEvent(const Window* window, void UpdateStateForMouseEvent(const Window* window,
const ui::MouseEvent& event); const ui::MouseEvent& event);
...@@ -39,8 +40,10 @@ class AURA_EXPORT EnvInputStateController { ...@@ -39,8 +40,10 @@ class AURA_EXPORT EnvInputStateController {
private: private:
friend class test::EnvTestHelper; friend class test::EnvTestHelper;
Env* env_;
// Touch ids that are currently down. // Touch ids that are currently down.
uint32_t touch_ids_down_; uint32_t touch_ids_down_ = 0;
DISALLOW_COPY_AND_ASSIGN(EnvInputStateController); DISALLOW_COPY_AND_ASSIGN(EnvInputStateController);
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "services/ui/public/interfaces/constants.mojom.h" #include "services/ui/public/interfaces/constants.mojom.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/mus/window_tree_client.h" #include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_sink.h" #include "ui/events/event_sink.h"
...@@ -38,9 +39,9 @@ EventInjector::~EventInjector() {} ...@@ -38,9 +39,9 @@ EventInjector::~EventInjector() {}
ui::EventDispatchDetails EventInjector::Inject(WindowTreeHost* host, ui::EventDispatchDetails EventInjector::Inject(WindowTreeHost* host,
ui::Event* event) { ui::Event* event) {
Env* env = Env::GetInstance();
DCHECK(env);
DCHECK(host); DCHECK(host);
Env* env = host->window()->env();
DCHECK(env);
DCHECK(event); DCHECK(event);
if (env->mode() == Env::Mode::LOCAL) if (env->mode() == Env::Mode::LOCAL)
......
...@@ -28,7 +28,7 @@ class ScopedCursorHider { ...@@ -28,7 +28,7 @@ class ScopedCursorHider {
if (!window_->IsRootWindow()) if (!window_->IsRootWindow())
return; return;
const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains( const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains(
Env::GetInstance()->last_mouse_location()); window->env()->last_mouse_location());
client::CursorClient* cursor_client = client::GetCursorClient(window_); client::CursorClient* cursor_client = client::GetCursorClient(window_);
if (cursor_is_in_bounds && cursor_client && if (cursor_is_in_bounds && cursor_client &&
cursor_client->IsCursorVisible()) { cursor_client->IsCursorVisible()) {
...@@ -133,8 +133,7 @@ void WindowPortLocal::OnPropertyChanged( ...@@ -133,8 +133,7 @@ void WindowPortLocal::OnPropertyChanged(
std::unique_ptr<cc::LayerTreeFrameSink> std::unique_ptr<cc::LayerTreeFrameSink>
WindowPortLocal::CreateLayerTreeFrameSink() { WindowPortLocal::CreateLayerTreeFrameSink() {
DCHECK(!frame_sink_id_.is_valid()); DCHECK(!frame_sink_id_.is_valid());
auto* context_factory_private = auto* context_factory_private = window_->env()->context_factory_private();
aura::Env::GetInstance()->context_factory_private();
auto* host_frame_sink_manager = auto* host_frame_sink_manager =
context_factory_private->GetHostFrameSinkManager(); context_factory_private->GetHostFrameSinkManager();
frame_sink_id_ = context_factory_private->AllocateFrameSinkId(); frame_sink_id_ = context_factory_private->AllocateFrameSinkId();
...@@ -154,7 +153,7 @@ WindowPortLocal::CreateLayerTreeFrameSink() { ...@@ -154,7 +153,7 @@ WindowPortLocal::CreateLayerTreeFrameSink() {
cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams params; cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams params;
params.gpu_memory_buffer_manager = params.gpu_memory_buffer_manager =
aura::Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager(); window_->env()->context_factory()->GetGpuMemoryBufferManager();
params.pipes.compositor_frame_sink_info = std::move(sink_info); params.pipes.compositor_frame_sink_info = std::move(sink_info);
params.pipes.client_request = std::move(client_request); params.pipes.client_request = std::move(client_request);
params.enable_surface_synchronization = true; params.enable_surface_synchronization = true;
......
...@@ -38,13 +38,15 @@ static uint32_t accelerated_widget_count = 1; ...@@ -38,13 +38,15 @@ static uint32_t accelerated_widget_count = 1;
// WindowTreeHostMus, public: // WindowTreeHostMus, public:
WindowTreeHostMus::WindowTreeHostMus(WindowTreeHostMusInitParams init_params) WindowTreeHostMus::WindowTreeHostMus(WindowTreeHostMusInitParams init_params)
: WindowTreeHostPlatform(std::move(init_params.window_port)), : WindowTreeHostPlatform(
std::make_unique<Window>(nullptr,
std::move(init_params.window_port))),
display_id_(init_params.display_id), display_id_(init_params.display_id),
delegate_(init_params.window_tree_client) { delegate_(init_params.window_tree_client) {
gfx::Rect bounds_in_pixels; gfx::Rect bounds_in_pixels;
window()->SetProperty(kWindowTreeHostMusKey, this); window()->SetProperty(kWindowTreeHostMusKey, this);
// TODO(sky): find a cleaner way to set this! Better solution is to likely // TODO(sky): find a cleaner way to set this! Revisit this now that
// have constructor take aura::Window. // constructor takes a Window.
WindowPortMus* window_mus = WindowPortMus::Get(window()); WindowPortMus* window_mus = WindowPortMus::Get(window());
window_mus->window_ = window(); window_mus->window_ = window();
// Apply the properties before initializing the window, that way the server // Apply the properties before initializing the window, that way the server
......
...@@ -66,9 +66,8 @@ const Window* WindowFromTarget(const ui::EventTarget* event_target) { ...@@ -66,9 +66,8 @@ const Window* WindowFromTarget(const ui::EventTarget* event_target) {
} // namespace } // namespace
void InitializeAuraEventGeneratorDelegate() { void InitializeAuraEventGeneratorDelegate() {
if (!ui::test::EventGenerator::default_delegate) { if (!ui::test::EventGenerator::default_delegate)
DefaultEventGeneratorDelegate::GetInstance(); DefaultEventGeneratorDelegate::GetInstance();
}
} }
EventGeneratorDelegateAura::EventGeneratorDelegateAura() { EventGeneratorDelegateAura::EventGeneratorDelegateAura() {
......
...@@ -161,7 +161,10 @@ void TestScreen::OnWindowDestroying(Window* window) { ...@@ -161,7 +161,10 @@ void TestScreen::OnWindowDestroying(Window* window) {
} }
gfx::Point TestScreen::GetCursorScreenPoint() { gfx::Point TestScreen::GetCursorScreenPoint() {
return Env::GetInstance()->last_mouse_location(); // This may be hit during shutdown, after |host_| has been destroyed.
return host_ && host_->window()
? host_->window()->env()->last_mouse_location()
: gfx::Point();
} }
bool TestScreen::IsWindowUnderCursor(gfx::NativeWindow window) { bool TestScreen::IsWindowUnderCursor(gfx::NativeWindow window) {
......
...@@ -8,12 +8,22 @@ ...@@ -8,12 +8,22 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace aura { namespace aura {
namespace test { namespace test {
namespace {
static Env* g_env = nullptr;
} // namespace
void SetEnvForTestWindows(Env* env) {
g_env = env;
}
Window* CreateTestWindowWithId(int id, Window* parent) { Window* CreateTestWindowWithId(int id, Window* parent) {
return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent); return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent);
...@@ -45,9 +55,8 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate, ...@@ -45,9 +55,8 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
const gfx::Rect& bounds, const gfx::Rect& bounds,
Window* parent, Window* parent,
bool show_on_creation) { bool show_on_creation) {
Window* window = new Window(delegate); Window* window = new Window(delegate, type, g_env);
window->set_id(id); window->set_id(id);
window->SetType(type);
window->Init(ui::LAYER_TEXTURED); window->Init(ui::LAYER_TEXTURED);
window->SetProperty(aura::client::kResizeBehaviorKey, window->SetProperty(aura::client::kResizeBehaviorKey,
ui::mojom::kResizeBehaviorCanResize | ui::mojom::kResizeBehaviorCanResize |
......
...@@ -14,8 +14,14 @@ ...@@ -14,8 +14,14 @@
#include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_window_delegate.h"
namespace aura { namespace aura {
class Env;
namespace test { namespace test {
// Sets the Env to use for creation of new Windows. If null, Env::GetInstance()
// is used.
void SetEnvForTestWindows(Env* env);
Window* CreateTestWindowWithId(int id, Window* parent); Window* CreateTestWindowWithId(int id, Window* parent);
Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent); Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent);
Window* CreateTestWindow(SkColor color, Window* CreateTestWindow(SkColor color,
......
...@@ -144,7 +144,7 @@ class UIControlsX11 : public UIControlsAura { ...@@ -144,7 +144,7 @@ class UIControlsX11 : public UIControlsAura {
int accelerator_state) override { int accelerator_state) override {
XEvent xevent = {0}; XEvent xevent = {0};
XButtonEvent* xbutton = &xevent.xbutton; XButtonEvent* xbutton = &xevent.xbutton;
gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); gfx::Point mouse_loc = host_->window()->env()->last_mouse_location();
aura::client::ScreenPositionClient* screen_position_client = aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(host_->window()); aura::client::GetScreenPositionClient(host_->window());
if (screen_position_client) { if (screen_position_client) {
......
...@@ -155,7 +155,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura { ...@@ -155,7 +155,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
int button_state, int button_state,
base::OnceClosure closure, base::OnceClosure closure,
int accelerator_state) override { int accelerator_state) override {
gfx::Point root_location = aura::Env::GetInstance()->last_mouse_location(); gfx::Point root_location = host_->window()->env()->last_mouse_location();
aura::client::ScreenPositionClient* screen_position_client = aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(host_->window()); aura::client::GetScreenPositionClient(host_->window());
if (screen_position_client) { if (screen_position_client) {
...@@ -218,7 +218,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura { ...@@ -218,7 +218,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
private: private:
void SendEventToSink(ui::Event* event, base::OnceClosure closure) { void SendEventToSink(ui::Event* event, base::OnceClosure closure) {
if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) { if (host_->window()->env()->mode() == aura::Env::Mode::MUS) {
std::unique_ptr<ui::Event> event_to_send; std::unique_ptr<ui::Event> event_to_send;
if (event->IsMouseEvent()) { if (event->IsMouseEvent()) {
// WindowService expects MouseEvents as PointerEvents. // WindowService expects MouseEvents as PointerEvents.
...@@ -297,7 +297,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura { ...@@ -297,7 +297,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
// Returns the ui::mojom::EventInjector, which is used to send events // Returns the ui::mojom::EventInjector, which is used to send events
// to the Window Service for dispatch. // to the Window Service for dispatch.
ui::mojom::EventInjector* GetEventInjector() { ui::mojom::EventInjector* GetEventInjector() {
DCHECK_EQ(aura::Env::Mode::MUS, aura::Env::GetInstance()->mode()); DCHECK_EQ(aura::Env::Mode::MUS, host_->window()->env()->mode());
if (!event_injector_) { if (!event_injector_) {
DCHECK(aura::test::EnvTestHelper().GetWindowTreeClient()); DCHECK(aura::test::EnvTestHelper().GetWindowTreeClient());
aura::test::EnvTestHelper() aura::test::EnvTestHelper()
......
...@@ -52,13 +52,15 @@ ...@@ -52,13 +52,15 @@
namespace aura { namespace aura {
Window::Window(WindowDelegate* delegate, client::WindowType type) Window::Window(WindowDelegate* delegate, client::WindowType type, Env* env)
: Window(delegate, nullptr, type) {} : Window(delegate, nullptr, type, env) {}
Window::Window(WindowDelegate* delegate, Window::Window(WindowDelegate* delegate,
std::unique_ptr<WindowPort> port, std::unique_ptr<WindowPort> port,
client::WindowType type) client::WindowType type,
: port_owner_(std::move(port)), Env* env)
: env_(env ? env : Env::GetInstance()),
port_owner_(std::move(port)),
port_(port_owner_.get()), port_(port_owner_.get()),
host_(nullptr), host_(nullptr),
type_(type), type_(type),
...@@ -148,7 +150,7 @@ void Window::Init(ui::LayerType layer_type) { ...@@ -148,7 +150,7 @@ void Window::Init(ui::LayerType layer_type) {
WindowOcclusionTracker::ScopedPauseOcclusionTracking pause_occlusion_tracking; WindowOcclusionTracker::ScopedPauseOcclusionTracking pause_occlusion_tracking;
if (!port_owner_) { if (!port_owner_) {
port_owner_ = Env::GetInstance()->CreateWindowPort(this); port_owner_ = env_->CreateWindowPort(this);
port_ = port_owner_.get(); port_ = port_owner_.get();
} }
SetLayer(std::make_unique<ui::Layer>(layer_type)); SetLayer(std::make_unique<ui::Layer>(layer_type));
...@@ -157,7 +159,7 @@ void Window::Init(ui::LayerType layer_type) { ...@@ -157,7 +159,7 @@ void Window::Init(ui::LayerType layer_type) {
layer()->set_delegate(this); layer()->set_delegate(this);
UpdateLayerName(); UpdateLayerName();
layer()->SetFillsBoundsOpaquely(!transparent_); layer()->SetFillsBoundsOpaquely(!transparent_);
Env::GetInstance()->NotifyWindowInitialized(this); env_->NotifyWindowInitialized(this);
} }
void Window::SetType(client::WindowType type) { void Window::SetType(client::WindowType type) {
...@@ -358,6 +360,8 @@ void Window::AddChild(Window* child) { ...@@ -358,6 +360,8 @@ void Window::AddChild(Window* child) {
DCHECK(layer()) << "Parent has not been Init()ed yet."; DCHECK(layer()) << "Parent has not been Init()ed yet.";
DCHECK(child->layer()) << "Child has not been Init()ed yt."; DCHECK(child->layer()) << "Child has not been Init()ed yt.";
DCHECK_EQ(env_, child->env_) << "All windows in a hierarchy must share the "
" same Env.";
WindowObserver::HierarchyChangeParams params; WindowObserver::HierarchyChangeParams params;
params.target = child; params.target = child;
params.new_parent = this; params.new_parent = this;
...@@ -1211,9 +1215,9 @@ bool Window::CanAcceptEvent(const ui::Event& event) { ...@@ -1211,9 +1215,9 @@ bool Window::CanAcceptEvent(const ui::Event& event) {
ui::EventTarget* Window::GetParentTarget() { ui::EventTarget* Window::GetParentTarget() {
if (IsRootWindow()) { if (IsRootWindow()) {
return client::GetEventClient(this) ? return client::GetEventClient(this)
client::GetEventClient(this)->GetToplevelEventTarget() : ? client::GetEventClient(this)->GetToplevelEventTarget()
Env::GetInstance(); : env_;
} }
return parent_; return parent_;
} }
......
...@@ -57,6 +57,7 @@ enum class EventTargetingPolicy; ...@@ -57,6 +57,7 @@ enum class EventTargetingPolicy;
namespace aura { namespace aura {
class Env;
class LayoutManager; class LayoutManager;
class ScopedKeyboardHook; class ScopedKeyboardHook;
class WindowDelegate; class WindowDelegate;
...@@ -118,10 +119,12 @@ class AURA_EXPORT Window : public ui::LayerDelegate, ...@@ -118,10 +119,12 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
typedef std::vector<Window*> Windows; typedef std::vector<Window*> Windows;
explicit Window(WindowDelegate* delegate, explicit Window(WindowDelegate* delegate,
client::WindowType type = client::WINDOW_TYPE_UNKNOWN); client::WindowType type = client::WINDOW_TYPE_UNKNOWN,
Env* env = nullptr);
Window(WindowDelegate* delegate, Window(WindowDelegate* delegate,
std::unique_ptr<WindowPort> port, std::unique_ptr<WindowPort> port,
client::WindowType type = client::WINDOW_TYPE_UNKNOWN); client::WindowType type = client::WINDOW_TYPE_UNKNOWN,
Env* env = nullptr);
~Window() override; ~Window() override;
// Initializes the window. This creates the window's layer. // Initializes the window. This creates the window's layer.
...@@ -422,6 +425,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate, ...@@ -422,6 +425,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// Returns whether this window is embedding another client. // Returns whether this window is embedding another client.
bool IsEmbeddingClient() const; bool IsEmbeddingClient() const;
Env* env() { return env_; }
// ui::GestureConsumer: // ui::GestureConsumer:
bool RequiresDoubleTapGestureEvents() const override; bool RequiresDoubleTapGestureEvents() const override;
...@@ -554,6 +559,11 @@ class AURA_EXPORT Window : public ui::LayerDelegate, ...@@ -554,6 +559,11 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
void RegisterFrameSinkId(); void RegisterFrameSinkId();
void UnregisterFrameSinkId(); void UnregisterFrameSinkId();
// Env this window was created with. Env::GetInstance() if a null Env was
// supplied.
Env* const env_;
bool registered_frame_sink_id_ = false; bool registered_frame_sink_id_ = false;
bool disable_frame_sink_id_registration_ = false; bool disable_frame_sink_id_registration_ = false;
......
...@@ -81,16 +81,16 @@ void ConvertEventLocationToTarget(ui::EventTarget* event_target, ...@@ -81,16 +81,16 @@ void ConvertEventLocationToTarget(ui::EventTarget* event_target,
WindowEventDispatcher::ObserverNotifier::ObserverNotifier( WindowEventDispatcher::ObserverNotifier::ObserverNotifier(
WindowEventDispatcher* dispatcher, WindowEventDispatcher* dispatcher,
const ui::Event& event) const ui::Event& event)
: dispatcher_(dispatcher) { : env_(dispatcher->host()->window()->env()), dispatcher_(dispatcher) {
for (WindowEventDispatcherObserver& observer : for (WindowEventDispatcherObserver& observer :
Env::GetInstance()->window_event_dispatcher_observers()) { env_->window_event_dispatcher_observers()) {
observer.OnWindowEventDispatcherStartedProcessing(dispatcher, event); observer.OnWindowEventDispatcherStartedProcessing(dispatcher, event);
} }
} }
WindowEventDispatcher::ObserverNotifier::~ObserverNotifier() { WindowEventDispatcher::ObserverNotifier::~ObserverNotifier() {
for (WindowEventDispatcherObserver& observer : for (WindowEventDispatcherObserver& observer :
Env::GetInstance()->window_event_dispatcher_observers()) { env_->window_event_dispatcher_observers()) {
observer.OnWindowEventDispatcherFinishedProcessingEvent(dispatcher_); observer.OnWindowEventDispatcherFinishedProcessingEvent(dispatcher_);
} }
} }
...@@ -100,19 +100,20 @@ WindowEventDispatcher::ObserverNotifier::~ObserverNotifier() { ...@@ -100,19 +100,20 @@ WindowEventDispatcher::ObserverNotifier::~ObserverNotifier() {
WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host, WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host,
bool are_events_in_pixels) bool are_events_in_pixels)
: host_(host), : env_(host->window()->env()),
host_(host),
are_events_in_pixels_(are_events_in_pixels), are_events_in_pixels_(are_events_in_pixels),
observer_manager_(this), observer_manager_(this),
event_targeter_(std::make_unique<WindowTargeter>()) { event_targeter_(std::make_unique<WindowTargeter>()) {
ui::GestureRecognizer::Get()->AddGestureEventHelper(this); ui::GestureRecognizer::Get()->AddGestureEventHelper(this);
Env::GetInstance()->AddObserver(this); env_->AddObserver(this);
if (Env::GetInstance()->mode() == Env::Mode::MUS) if (env_->mode() == Env::Mode::MUS)
mus_mouse_location_updater_ = std::make_unique<MusMouseLocationUpdater>(); mus_mouse_location_updater_ = std::make_unique<MusMouseLocationUpdater>();
} }
WindowEventDispatcher::~WindowEventDispatcher() { WindowEventDispatcher::~WindowEventDispatcher() {
TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor");
Env::GetInstance()->RemoveObserver(this); env_->RemoveObserver(this);
ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this);
} }
...@@ -236,7 +237,7 @@ void WindowEventDispatcher::ReleasePointerMoves() { ...@@ -236,7 +237,7 @@ void WindowEventDispatcher::ReleasePointerMoves() {
} }
gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const {
gfx::Point location = Env::GetInstance()->last_mouse_location(); gfx::Point location = host_->window()->env()->last_mouse_location();
ConvertPointFromScreen(&location); ConvertPointFromScreen(&location);
return location; return location;
} }
...@@ -248,8 +249,8 @@ void WindowEventDispatcher::OnHostLostMouseGrab() { ...@@ -248,8 +249,8 @@ void WindowEventDispatcher::OnHostLostMouseGrab() {
void WindowEventDispatcher::OnCursorMovedToRootLocation( void WindowEventDispatcher::OnCursorMovedToRootLocation(
const gfx::Point& root_location) { const gfx::Point& root_location) {
Env::GetInstance()->env_controller()->SetLastMouseLocation(window(), host_->window()->env()->env_controller()->SetLastMouseLocation(window(),
root_location); root_location);
// Synthesize a mouse move in case the cursor's location in root coordinates // Synthesize a mouse move in case the cursor's location in root coordinates
// changed but its position in WindowTreeHost coordinates did not. // changed but its position in WindowTreeHost coordinates did not.
...@@ -305,8 +306,8 @@ ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( ...@@ -305,8 +306,8 @@ ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit(
Window* target, Window* target,
const ui::MouseEvent& event, const ui::MouseEvent& event,
ui::EventType type) { ui::EventType type) {
Env::GetInstance()->env_controller()->UpdateStateForMouseEvent(window(), host_->window()->env()->env_controller()->UpdateStateForMouseEvent(window(),
event); event);
if (!mouse_moved_handler_ || !mouse_moved_handler_->HasTargetHandler() || if (!mouse_moved_handler_ || !mouse_moved_handler_->HasTargetHandler() ||
!window()->Contains(mouse_moved_handler_)) !window()->Contains(mouse_moved_handler_))
return DispatchDetails(); return DispatchDetails();
...@@ -424,7 +425,7 @@ void WindowEventDispatcher::UpdateCapture(Window* old_capture, ...@@ -424,7 +425,7 @@ void WindowEventDispatcher::UpdateCapture(Window* old_capture,
if (new_capture) { if (new_capture) {
// Make all subsequent mouse events go to the capture window. We shouldn't // Make all subsequent mouse events go to the capture window. We shouldn't
// need to send an event here as OnCaptureLost() should take care of that. // need to send an event here as OnCaptureLost() should take care of that.
if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) if (mouse_moved_handler_ || host_->window()->env()->IsMouseButtonDown())
mouse_moved_handler_ = new_capture; mouse_moved_handler_ = new_capture;
} else { } else {
// Make sure mouse_moved_handler gets updated. // Make sure mouse_moved_handler gets updated.
...@@ -471,7 +472,7 @@ void WindowEventDispatcher::ReleaseNativeCapture() { ...@@ -471,7 +472,7 @@ void WindowEventDispatcher::ReleaseNativeCapture() {
ui::EventTarget* WindowEventDispatcher::GetInitialEventTarget( ui::EventTarget* WindowEventDispatcher::GetInitialEventTarget(
ui::Event* event) { ui::Event* event) {
if (Env::GetInstance()->mode() == Env::Mode::LOCAL || if (host_->window()->env()->mode() == Env::Mode::LOCAL ||
!event->IsLocatedEvent() || !event->target()) { !event->IsLocatedEvent() || !event->target()) {
return nullptr; return nullptr;
} }
...@@ -508,7 +509,7 @@ ui::EventTarget* WindowEventDispatcher::GetInitialEventTarget( ...@@ -508,7 +509,7 @@ ui::EventTarget* WindowEventDispatcher::GetInitialEventTarget(
} }
ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) { ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) {
if (Env::GetInstance()->mode() == Env::Mode::LOCAL) if (host_->window()->env()->mode() == Env::Mode::LOCAL)
return window(); return window();
if (!event->target()) if (!event->target())
...@@ -831,7 +832,7 @@ ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { ...@@ -831,7 +832,7 @@ ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() {
if (!dispatch_details.dispatcher_destroyed) { if (!dispatch_details.dispatcher_destroyed) {
dispatching_held_event_ = nullptr; dispatching_held_event_ = nullptr;
for (WindowEventDispatcherObserver& observer : for (WindowEventDispatcherObserver& observer :
Env::GetInstance()->window_event_dispatcher_observers()) { host_->window()->env()->window_event_dispatcher_observers()) {
observer.OnWindowEventDispatcherDispatchedHeldEvents(this); observer.OnWindowEventDispatcherDispatchedHeldEvents(this);
} }
if (did_dispatch_held_move_event_callback_) if (did_dispatch_held_move_event_callback_)
...@@ -880,7 +881,7 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { ...@@ -880,7 +881,7 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() {
// instead of a MOVED event, but in multi-display/multi-host scenarios, the // instead of a MOVED event, but in multi-display/multi-host scenarios, the
// DRAGGED event can be synthesized in the incorrect host. So avoid // DRAGGED event can be synthesized in the incorrect host. So avoid
// synthesizing any events at all. // synthesizing any events at all.
if (Env::GetInstance()->mouse_button_flags()) if (host_->window()->env()->mouse_button_flags())
return details; return details;
// Do not use GetLastMouseLocationInRoot here because it's not updated when // Do not use GetLastMouseLocationInRoot here because it's not updated when
...@@ -930,8 +931,8 @@ DispatchDetails WindowEventDispatcher::PreDispatchMouseEvent( ...@@ -930,8 +931,8 @@ DispatchDetails WindowEventDispatcher::PreDispatchMouseEvent(
return DispatchDetails(); return DispatchDetails();
} }
Env::GetInstance()->env_controller()->UpdateStateForMouseEvent(window(), host_->window()->env()->env_controller()->UpdateStateForMouseEvent(window(),
*event); *event);
if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { if (IsEventCandidateForHold(*event) && !dispatching_held_event_) {
if (move_hold_count_) { if (move_hold_count_) {
...@@ -1046,7 +1047,7 @@ DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent( ...@@ -1046,7 +1047,7 @@ DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent(
return DispatchDetails(); return DispatchDetails();
} }
Env::GetInstance()->env_controller()->UpdateStateForTouchEvent(*event); host_->window()->env()->env_controller()->UpdateStateForTouchEvent(*event);
ui::TouchEvent orig_event(*event, target, window()); ui::TouchEvent orig_event(*event, target, window());
if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event, if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event,
......
...@@ -38,6 +38,7 @@ class TouchEvent; ...@@ -38,6 +38,7 @@ class TouchEvent;
} }
namespace aura { namespace aura {
class Env;
class MusMouseLocationUpdater; class MusMouseLocationUpdater;
class TestScreen; class TestScreen;
class WindowTargeter; class WindowTargeter;
...@@ -153,6 +154,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, ...@@ -153,6 +154,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
~ObserverNotifier(); ~ObserverNotifier();
private: private:
Env* env_;
WindowEventDispatcher* dispatcher_; WindowEventDispatcher* dispatcher_;
DISALLOW_COPY_AND_ASSIGN(ObserverNotifier); DISALLOW_COPY_AND_ASSIGN(ObserverNotifier);
...@@ -281,6 +283,10 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, ...@@ -281,6 +283,10 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
ui::TouchEvent* event); ui::TouchEvent* event);
ui::EventDispatchDetails PreDispatchKeyEvent(ui::KeyEvent* event); ui::EventDispatchDetails PreDispatchKeyEvent(ui::KeyEvent* event);
// Comes from host_->window()->env(). Cached as it's needed in the destructor
// and at that time the window has been deleted.
Env* env_;
WindowTreeHost* host_; WindowTreeHost* host_;
const bool are_events_in_pixels_; const bool are_events_in_pixels_;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "ui/aura/scoped_simple_keyboard_hook.h" #include "ui/aura/scoped_simple_keyboard_hook.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_port.h"
#include "ui/aura/window_targeter.h" #include "ui/aura/window_targeter.h"
#include "ui/aura/window_tree_host_observer.h" #include "ui/aura/window_tree_host_observer.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
...@@ -47,11 +46,11 @@ namespace { ...@@ -47,11 +46,11 @@ namespace {
const char kWindowTreeHostForAcceleratedWidget[] = const char kWindowTreeHostForAcceleratedWidget[] =
"__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__";
bool ShouldAllocateLocalSurfaceId() { bool ShouldAllocateLocalSurfaceId(Window* window) {
// When running with the window service (either in 'mus' or 'mash' mode), the // When running with the window service (either in 'mus' or 'mash' mode), the
// LocalSurfaceId allocation for the WindowTreeHost is managed by the // LocalSurfaceId allocation for the WindowTreeHost is managed by the
// WindowTreeClient and WindowTreeHostMus. // WindowTreeClient and WindowTreeHostMus.
return Env::GetInstance()->mode() == Env::Mode::LOCAL; return window->env()->mode() == Env::Mode::LOCAL;
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
...@@ -62,9 +61,8 @@ class ScopedLocalSurfaceIdValidator { ...@@ -62,9 +61,8 @@ class ScopedLocalSurfaceIdValidator {
local_surface_id_(window ? window->GetLocalSurfaceId() local_surface_id_(window ? window->GetLocalSurfaceId()
: viz::LocalSurfaceId()) {} : viz::LocalSurfaceId()) {}
~ScopedLocalSurfaceIdValidator() { ~ScopedLocalSurfaceIdValidator() {
if (ShouldAllocateLocalSurfaceId() && window_) { if (window_ && ShouldAllocateLocalSurfaceId(window_))
DCHECK_EQ(local_surface_id_, window_->GetLocalSurfaceId()); DCHECK_EQ(local_surface_id_, window_->GetLocalSurfaceId());
}
} }
private: private:
...@@ -109,7 +107,7 @@ void WindowTreeHost::InitHost() { ...@@ -109,7 +107,7 @@ void WindowTreeHost::InitHost() {
UpdateRootWindowSizeInPixels(); UpdateRootWindowSizeInPixels();
InitCompositor(); InitCompositor();
Env::GetInstance()->NotifyHostInitialized(this); window()->env()->NotifyHostInitialized(this);
} }
void WindowTreeHost::AddObserver(WindowTreeHostObserver* observer) { void WindowTreeHost::AddObserver(WindowTreeHostObserver* observer) {
...@@ -291,15 +289,14 @@ std::unique_ptr<ScopedKeyboardHook> WindowTreeHost::CaptureSystemKeyEvents( ...@@ -291,15 +289,14 @@ std::unique_ptr<ScopedKeyboardHook> WindowTreeHost::CaptureSystemKeyEvents(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WindowTreeHost, protected: // WindowTreeHost, protected:
WindowTreeHost::WindowTreeHost() : WindowTreeHost(nullptr) { WindowTreeHost::WindowTreeHost(std::unique_ptr<Window> window)
} : window_(window.release()), // See header for details on ownership.
WindowTreeHost::WindowTreeHost(std::unique_ptr<WindowPort> window_port)
: window_(new Window(nullptr, std::move(window_port))),
last_cursor_(ui::CursorType::kNull), last_cursor_(ui::CursorType::kNull),
input_method_(nullptr), input_method_(nullptr),
owned_input_method_(false), owned_input_method_(false),
weak_factory_(this) { weak_factory_(this) {
if (!window_)
window_ = new Window(nullptr);
display::Screen::GetScreen()->AddObserver(this); display::Screen::GetScreen()->AddObserver(this);
} }
...@@ -329,13 +326,14 @@ void WindowTreeHost::CreateCompositor(const viz::FrameSinkId& frame_sink_id, ...@@ -329,13 +326,14 @@ void WindowTreeHost::CreateCompositor(const viz::FrameSinkId& frame_sink_id,
bool force_software_compositor, bool force_software_compositor,
bool external_begin_frames_enabled, bool external_begin_frames_enabled,
bool are_events_in_pixels) { bool are_events_in_pixels) {
DCHECK(Env::GetInstance()); DCHECK(window()->env());
ui::ContextFactory* context_factory = Env::GetInstance()->context_factory(); Env* env = window()->env();
ui::ContextFactory* context_factory = env->context_factory();
DCHECK(context_factory); DCHECK(context_factory);
ui::ContextFactoryPrivate* context_factory_private = ui::ContextFactoryPrivate* context_factory_private =
Env::GetInstance()->context_factory_private(); env->context_factory_private();
bool enable_surface_synchronization = bool enable_surface_synchronization =
aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS || env->mode() == aura::Env::Mode::MUS ||
features::IsSurfaceSynchronizationEnabled(); features::IsSurfaceSynchronizationEnabled();
compositor_.reset(new ui::Compositor( compositor_.reset(new ui::Compositor(
(!context_factory_private || frame_sink_id.is_valid()) (!context_factory_private || frame_sink_id.is_valid())
...@@ -393,7 +391,8 @@ void WindowTreeHost::OnHostResizedInPixels( ...@@ -393,7 +391,8 @@ void WindowTreeHost::OnHostResizedInPixels(
// Allocate a new LocalSurfaceId for the new state. // Allocate a new LocalSurfaceId for the new state.
auto local_surface_id = new_local_surface_id; auto local_surface_id = new_local_surface_id;
if (ShouldAllocateLocalSurfaceId() && !new_local_surface_id.is_valid()) { if (ShouldAllocateLocalSurfaceId(window()) &&
!new_local_surface_id.is_valid()) {
window_->AllocateLocalSurfaceId(); window_->AllocateLocalSurfaceId();
local_surface_id = window_->GetLocalSurfaceId(); local_surface_id = window_->GetLocalSurfaceId();
} }
...@@ -424,7 +423,7 @@ void WindowTreeHost::OnHostCloseRequested() { ...@@ -424,7 +423,7 @@ void WindowTreeHost::OnHostCloseRequested() {
} }
void WindowTreeHost::OnHostActivated() { void WindowTreeHost::OnHostActivated() {
Env::GetInstance()->NotifyHostActivated(this); window()->env()->NotifyHostActivated(this);
} }
void WindowTreeHost::OnHostLostWindowCapture() { void WindowTreeHost::OnHostLostWindowCapture() {
...@@ -503,7 +502,7 @@ void WindowTreeHost::OnCompositingLockStateChanged(ui::Compositor* compositor) { ...@@ -503,7 +502,7 @@ void WindowTreeHost::OnCompositingLockStateChanged(ui::Compositor* compositor) {
} }
void WindowTreeHost::OnCompositingChildResizing(ui::Compositor* compositor) { void WindowTreeHost::OnCompositingChildResizing(ui::Compositor* compositor) {
if (!Env::GetInstance()->throttle_input_on_resize() || holding_pointer_moves_) if (!window()->env()->throttle_input_on_resize() || holding_pointer_moves_)
return; return;
synchronization_start_time_ = base::TimeTicks::Now(); synchronization_start_time_ = base::TimeTicks::Now();
dispatcher_->HoldPointerMoves(); dispatcher_->HoldPointerMoves();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/viz/common/surfaces/frame_sink_id.h" #include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/common/surfaces/local_surface_id.h" #include "components/viz/common/surfaces/local_surface_id.h"
#include "ui/aura/aura_export.h" #include "ui/aura/aura_export.h"
#include "ui/aura/window.h"
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
#include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_delegate.h"
#include "ui/compositor/compositor_observer.h" #include "ui/compositor/compositor_observer.h"
...@@ -51,7 +52,6 @@ class WindowTreeHostTestApi; ...@@ -51,7 +52,6 @@ class WindowTreeHostTestApi;
} }
class WindowEventDispatcher; class WindowEventDispatcher;
class WindowPort;
class WindowTreeHostObserver; class WindowTreeHostObserver;
// WindowTreeHost bridges between a native window and the embedded RootWindow. // WindowTreeHost bridges between a native window and the embedded RootWindow.
...@@ -222,8 +222,7 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, ...@@ -222,8 +222,7 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
friend class ScopedKeyboardHook; friend class ScopedKeyboardHook;
friend class TestScreen; // TODO(beng): see if we can remove/consolidate. friend class TestScreen; // TODO(beng): see if we can remove/consolidate.
WindowTreeHost(); explicit WindowTreeHost(std::unique_ptr<Window> window = nullptr);
explicit WindowTreeHost(std::unique_ptr<WindowPort> window_port);
void DestroyCompositor(); void DestroyCompositor();
void DestroyDispatcher(); void DestroyDispatcher();
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_port.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -46,18 +46,16 @@ std::unique_ptr<WindowTreeHost> WindowTreeHost::Create( ...@@ -46,18 +46,16 @@ std::unique_ptr<WindowTreeHost> WindowTreeHost::Create(
} }
WindowTreeHostPlatform::WindowTreeHostPlatform( WindowTreeHostPlatform::WindowTreeHostPlatform(
ui::PlatformWindowInitProperties properties) { ui::PlatformWindowInitProperties properties,
std::unique_ptr<Window> window)
: WindowTreeHost(std::move(window)) {
bounds_ = properties.bounds; bounds_ = properties.bounds;
CreateCompositor(); CreateCompositor();
CreateAndSetPlatformWindow(std::move(properties)); CreateAndSetPlatformWindow(std::move(properties));
} }
WindowTreeHostPlatform::WindowTreeHostPlatform() WindowTreeHostPlatform::WindowTreeHostPlatform(std::unique_ptr<Window> window)
: WindowTreeHostPlatform(nullptr) {} : WindowTreeHost(std::move(window)),
WindowTreeHostPlatform::WindowTreeHostPlatform(
std::unique_ptr<WindowPort> window_port)
: WindowTreeHost(std::move(window_port)),
widget_(gfx::kNullAcceleratedWidget), widget_(gfx::kNullAcceleratedWidget),
current_cursor_(ui::CursorType::kNull) {} current_cursor_(ui::CursorType::kNull) {}
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/aura/aura_export.h" #include "ui/aura/aura_export.h"
#include "ui/aura/client/window_types.h" #include "ui/aura/client/window_types.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/platform_window/platform_window.h" #include "ui/platform_window/platform_window.h"
...@@ -24,14 +25,13 @@ struct PlatformWindowInitProperties; ...@@ -24,14 +25,13 @@ struct PlatformWindowInitProperties;
namespace aura { namespace aura {
class WindowPort;
// The unified WindowTreeHost implementation for platforms // The unified WindowTreeHost implementation for platforms
// that implement PlatformWindow. // that implement PlatformWindow.
class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost, class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost,
public ui::PlatformWindowDelegate { public ui::PlatformWindowDelegate {
public: public:
explicit WindowTreeHostPlatform(ui::PlatformWindowInitProperties properties); explicit WindowTreeHostPlatform(ui::PlatformWindowInitProperties properties,
std::unique_ptr<Window> = nullptr);
~WindowTreeHostPlatform() override; ~WindowTreeHostPlatform() override;
// WindowTreeHost: // WindowTreeHost:
...@@ -51,10 +51,9 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost, ...@@ -51,10 +51,9 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost,
void OnCursorVisibilityChangedNative(bool show) override; void OnCursorVisibilityChangedNative(bool show) override;
protected: protected:
// NOTE: neither of these calls CreateCompositor(); subclasses must call // NOTE: this does not call CreateCompositor(); subclasses must call
// CreateCompositor() at the appropriate time. // CreateCompositor() at the appropriate time.
WindowTreeHostPlatform(); explicit WindowTreeHostPlatform(std::unique_ptr<Window> window = nullptr);
explicit WindowTreeHostPlatform(std::unique_ptr<WindowPort> window_port);
// Creates a ui::PlatformWindow appropriate for the current platform and // Creates a ui::PlatformWindow appropriate for the current platform and
// installs it at as the PlatformWindow for this WindowTreeHostPlatform. // installs it at as the PlatformWindow for this WindowTreeHostPlatform.
......
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