| Index: mojo/services/window_manager/window_manager_app.cc
|
| diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
|
| index 9c055b4008c755b6648b05ed8c4848a8a294adba..2ba436a291a4bb42f41e83d83b71e734b79d6add 100644
|
| --- a/mojo/services/window_manager/window_manager_app.cc
|
| +++ b/mojo/services/window_manager/window_manager_app.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/stl_util.h"
|
| +#include "mojo/aura/aura_init.h"
|
| #include "mojo/converters/geometry/geometry_type_converters.h"
|
| #include "mojo/converters/input_events/input_events_type_converters.h"
|
| #include "mojo/public/cpp/application/application_connection.h"
|
| @@ -13,20 +14,66 @@
|
| #include "mojo/public/interfaces/application/shell.mojom.h"
|
| #include "mojo/services/public/cpp/view_manager/view.h"
|
| #include "mojo/services/public/cpp/view_manager/view_manager.h"
|
| -#include "mojo/services/window_manager/focus_controller.h"
|
| -#include "mojo/services/window_manager/focus_rules.h"
|
| -#include "mojo/services/window_manager/view_event_dispatcher.h"
|
| -#include "mojo/services/window_manager/view_target.h"
|
| -#include "mojo/services/window_manager/view_targeter.h"
|
| #include "mojo/services/window_manager/window_manager_delegate.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/aura/window_delegate.h"
|
| +#include "ui/aura/window_property.h"
|
| #include "ui/base/hit_test.h"
|
| +#include "ui/wm/core/capture_controller.h"
|
| +#include "ui/wm/core/focus_controller.h"
|
| +#include "ui/wm/public/activation_client.h"
|
| +
|
| +DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*);
|
|
|
| namespace mojo {
|
|
|
| +// The aura::Windows we use to track Views don't render, so we don't actually
|
| +// need to supply a fully functional WindowDelegate. We do need to provide _a_
|
| +// delegate however, otherwise the event dispatcher won't dispatch events to
|
| +// these windows. (The aura WindowTargeter won't allow a delegate-less window
|
| +// to be the target of an event, since the window delegate is considered the
|
| +// "target handler").
|
| +class DummyDelegate : public aura::WindowDelegate {
|
| + public:
|
| + DummyDelegate() {}
|
| + ~DummyDelegate() override {}
|
| +
|
| + private:
|
| + // WindowDelegate overrides:
|
| + gfx::Size GetMinimumSize() const override { return gfx::Size(); }
|
| + gfx::Size GetMaximumSize() const override { return gfx::Size(); }
|
| + void OnBoundsChanged(const gfx::Rect& old_bounds,
|
| + const gfx::Rect& new_bounds) override {}
|
| + gfx::NativeCursor GetCursor(const gfx::Point& point) override {
|
| + return gfx::kNullCursor;
|
| + }
|
| + int GetNonClientComponent(const gfx::Point& point) const override {
|
| + return HTCAPTION;
|
| + }
|
| + bool ShouldDescendIntoChildForEventHandling(
|
| + aura::Window* child,
|
| + const gfx::Point& location) override {
|
| + return true;
|
| + }
|
| + bool CanFocus() override { return true; }
|
| + void OnCaptureLost() override {}
|
| + void OnPaint(gfx::Canvas* canvas) override {}
|
| + void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
|
| + void OnWindowDestroying(aura::Window* window) override {}
|
| + void OnWindowDestroyed(aura::Window* window) override {}
|
| + void OnWindowTargetVisibilityChanged(bool visible) override {}
|
| + bool HasHitTestMask() const override { return false; }
|
| + void GetHitTestMask(gfx::Path* mask) const override {}
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DummyDelegate);
|
| +};
|
| +
|
| namespace {
|
|
|
| -Id GetIdForView(View* view) {
|
| - return view ? view->id() : 0;
|
| +DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL);
|
| +
|
| +Id GetIdForWindow(aura::Window* window) {
|
| + return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0;
|
| }
|
|
|
| } // namespace
|
| @@ -76,8 +123,9 @@ WindowManagerApp::WindowManagerApp(
|
| native_viewport_event_dispatcher_factory_(this),
|
| wrapped_view_manager_delegate_(view_manager_delegate),
|
| window_manager_delegate_(window_manager_delegate),
|
| - view_manager_(nullptr),
|
| - root_(nullptr) {
|
| + view_manager_(NULL),
|
| + root_(NULL),
|
| + dummy_delegate_(new DummyDelegate) {
|
| }
|
|
|
| WindowManagerApp::~WindowManagerApp() {
|
| @@ -85,14 +133,13 @@ WindowManagerApp::~WindowManagerApp() {
|
| }
|
|
|
| // static
|
| -View* WindowManagerApp::GetViewForViewTarget(ViewTarget* target) {
|
| - return target->view();
|
| +View* WindowManagerApp::GetViewForWindow(aura::Window* window) {
|
| + return window->GetProperty(kViewKey);
|
| }
|
|
|
| -ViewTarget* WindowManagerApp::GetViewTargetForViewId(Id view) {
|
| - ViewIdToViewTargetMap::const_iterator it =
|
| - view_id_to_view_target_map_.find(view);
|
| - return it != view_id_to_view_target_map_.end() ? it->second : nullptr;
|
| +aura::Window* WindowManagerApp::GetWindowForViewId(Id view) {
|
| + ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view);
|
| + return it != view_id_to_window_map_.end() ? it->second : NULL;
|
| }
|
|
|
| void WindowManagerApp::AddConnection(WindowManagerImpl* connection) {
|
| @@ -106,33 +153,37 @@ void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) {
|
| }
|
|
|
| void WindowManagerApp::SetCapture(Id view) {
|
| - // TODO(erg): Capture. Another pile of worms that is mixed in here.
|
| -
|
| - // capture_client_->capture_client()->SetCapture(GetWindowForViewId(view));
|
| -
|
| + capture_client_->capture_client()->SetCapture(GetWindowForViewId(view));
|
| // TODO(beng): notify connected clients that capture has changed, probably
|
| // by implementing some capture-client observer.
|
| }
|
|
|
| -void WindowManagerApp::FocusWindow(Id view_id) {
|
| - View* view = view_manager_->GetViewById(view_id);
|
| - DCHECK(view);
|
| - focus_controller_->FocusView(view);
|
| +void WindowManagerApp::FocusWindow(Id view) {
|
| + aura::Window* window = GetWindowForViewId(view);
|
| + DCHECK(window);
|
| + focus_client_->FocusWindow(window);
|
| }
|
|
|
| -void WindowManagerApp::ActivateWindow(Id view_id) {
|
| - View* view = view_manager_->GetViewById(view_id);
|
| - DCHECK(view);
|
| - focus_controller_->ActivateView(view);
|
| +void WindowManagerApp::ActivateWindow(Id view) {
|
| + aura::Window* window = GetWindowForViewId(view);
|
| + DCHECK(window);
|
| + activation_client_->ActivateWindow(window);
|
| }
|
|
|
| bool WindowManagerApp::IsReady() const {
|
| return view_manager_ && root_;
|
| }
|
|
|
| -void WindowManagerApp::InitFocus(scoped_ptr<mojo::FocusRules> rules) {
|
| - focus_controller_.reset(new mojo::FocusController(rules.Pass()));
|
| - focus_controller_->AddObserver(this);
|
| +void WindowManagerApp::InitFocus(wm::FocusRules* rules) {
|
| + wm::FocusController* focus_controller = new wm::FocusController(rules);
|
| + activation_client_ = focus_controller;
|
| + focus_client_.reset(focus_controller);
|
| + aura::client::SetFocusClient(window_tree_host_->window(), focus_controller);
|
| + aura::client::SetActivationClient(window_tree_host_->window(),
|
| + focus_controller);
|
| +
|
| + focus_client_->AddObserver(this);
|
| + activation_client_->AddObserver(this);
|
| }
|
|
|
| void WindowManagerApp::Embed(
|
| @@ -153,6 +204,7 @@ void WindowManagerApp::Embed(
|
|
|
| void WindowManagerApp::Initialize(ApplicationImpl* impl) {
|
| shell_ = impl->shell();
|
| + aura_init_.reset(new AuraInit);
|
| LaunchViewManager(impl);
|
| }
|
|
|
| @@ -173,14 +225,14 @@ void WindowManagerApp::OnEmbed(ViewManager* view_manager,
|
| view_manager_ = view_manager;
|
| root_ = root;
|
|
|
| - view_event_dispatcher_.reset(new ViewEventDispatcher());
|
| + window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_));
|
| + window_tree_host_->window()->SetBounds(root->bounds().To<gfx::Rect>());
|
| + window_tree_host_->window()->Show();
|
|
|
| - RegisterSubtree(root_, nullptr);
|
| + RegisterSubtree(root_, window_tree_host_->window());
|
|
|
| - // TODO(erg): Also move the capture client over.
|
| - //
|
| - // capture_client_.reset(
|
| - // new wm::ScopedCaptureClient(window_tree_host_->window()));
|
| + capture_client_.reset(
|
| + new wm::ScopedCaptureClient(window_tree_host_->window()));
|
|
|
| if (wrapped_view_manager_delegate_) {
|
| wrapped_view_manager_delegate_->OnEmbed(
|
| @@ -197,7 +249,7 @@ void WindowManagerApp::OnViewManagerDisconnected(
|
| DCHECK_EQ(view_manager_, view_manager);
|
| if (wrapped_view_manager_delegate_)
|
| wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager);
|
| - view_manager_ = nullptr;
|
| + view_manager_ = NULL;
|
| base::MessageLoop::current()->Quit();
|
| }
|
|
|
| @@ -213,11 +265,11 @@ void WindowManagerApp::OnTreeChanged(
|
| return;
|
|
|
| if (params.new_parent) {
|
| - if (view_id_to_view_target_map_.find(params.target->id()) ==
|
| - view_id_to_view_target_map_.end()) {
|
| - ViewIdToViewTargetMap::const_iterator it =
|
| - view_id_to_view_target_map_.find(params.new_parent->id());
|
| - DCHECK(it != view_id_to_view_target_map_.end());
|
| + if (view_id_to_window_map_.find(params.target->id()) ==
|
| + view_id_to_window_map_.end()) {
|
| + ViewIdToWindowMap::const_iterator it =
|
| + view_id_to_window_map_.find(params.new_parent->id());
|
| + DCHECK(it != view_id_to_window_map_.end());
|
| RegisterSubtree(params.target, it->second);
|
| }
|
| } else if (params.old_parent) {
|
| @@ -230,16 +282,22 @@ void WindowManagerApp::OnViewDestroying(View* view) {
|
| Unregister(view);
|
| return;
|
| }
|
| - root_ = nullptr;
|
| - if (focus_controller_)
|
| - focus_controller_->RemoveObserver(this);
|
| + aura::Window* window = GetWindowForViewId(view->id());
|
| + window->RemovePreTargetHandler(this);
|
| + root_ = NULL;
|
| + STLDeleteValues(&view_id_to_window_map_);
|
| + if (focus_client_.get())
|
| + focus_client_->RemoveObserver(this);
|
| + if (activation_client_)
|
| + activation_client_->RemoveObserver(this);
|
| + window_tree_host_.reset();
|
| }
|
|
|
| void WindowManagerApp::OnViewBoundsChanged(View* view,
|
| const Rect& old_bounds,
|
| const Rect& new_bounds) {
|
| - // aura::Window* window = GetWindowForViewId(view->id());
|
| - // window->SetBounds(new_bounds.To<gfx::Rect>());
|
| + aura::Window* window = GetWindowForViewId(view->id());
|
| + window->SetBounds(new_bounds.To<gfx::Rect>());
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -249,61 +307,63 @@ void WindowManagerApp::OnEvent(ui::Event* event) {
|
| if (!window_manager_client_)
|
| return;
|
|
|
| - View* view = GetViewForViewTarget(static_cast<ViewTarget*>(event->target()));
|
| + View* view = GetViewForWindow(static_cast<aura::Window*>(event->target()));
|
| if (!view)
|
| return;
|
|
|
| - if (focus_controller_)
|
| - focus_controller_->OnEvent(event);
|
| -
|
| window_manager_client_->DispatchInputEventToView(view->id(),
|
| Event::From(*event));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// WindowManagerApp, mojo::FocusControllerObserver implementation:
|
| +// WindowManagerApp, aura::client::FocusChangeObserver implementation:
|
|
|
| -void WindowManagerApp::OnViewFocused(View* gained_focus,
|
| - View* lost_focus) {
|
| +void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus,
|
| + aura::Window* lost_focus) {
|
| for (Connections::const_iterator it = connections_.begin();
|
| it != connections_.end(); ++it) {
|
| - (*it)->NotifyViewFocused(GetIdForView(gained_focus),
|
| - GetIdForView(lost_focus));
|
| + (*it)->NotifyViewFocused(GetIdForWindow(gained_focus),
|
| + GetIdForWindow(lost_focus));
|
| }
|
| }
|
|
|
| -void WindowManagerApp::OnViewActivated(View* gained_active,
|
| - View* lost_active) {
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WindowManagerApp, aura::client::ActivationChangeObserver implementation:
|
| +
|
| +void WindowManagerApp::OnWindowActivated(aura::Window* gained_active,
|
| + aura::Window* lost_active) {
|
| for (Connections::const_iterator it = connections_.begin();
|
| it != connections_.end(); ++it) {
|
| - (*it)->NotifyWindowActivated(GetIdForView(gained_active),
|
| - GetIdForView(lost_active));
|
| + (*it)->NotifyWindowActivated(GetIdForWindow(gained_active),
|
| + GetIdForWindow(lost_active));
|
| + }
|
| + if (gained_active) {
|
| + View* view = GetViewForWindow(gained_active);
|
| + view->MoveToFront();
|
| }
|
| - if (gained_active)
|
| - gained_active->MoveToFront();
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // WindowManagerApp, private:
|
|
|
| -void WindowManagerApp::RegisterSubtree(View* view, ViewTarget* parent) {
|
| +void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) {
|
| view->AddObserver(this);
|
| - DCHECK(view_id_to_view_target_map_.find(view->id()) ==
|
| - view_id_to_view_target_map_.end());
|
| - ViewTarget* target = new ViewTarget(this, view);
|
| + DCHECK(view_id_to_window_map_.find(view->id()) ==
|
| + view_id_to_window_map_.end());
|
| + aura::Window* window = new aura::Window(dummy_delegate_.get());
|
| + window->set_id(view->id());
|
| + window->SetProperty(kViewKey, view);
|
| // All events pass through the root during dispatch, so we only need a handler
|
| // installed there.
|
| - if (view == root_) {
|
| - target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter()));
|
| - target->AddPreTargetHandler(this);
|
| - view_event_dispatcher_->SetRootViewTarget(target);
|
| - }
|
| - // TODO(erg): Why is there no matching RemoveChild()? How does that work in
|
| - // the aura version?
|
| - view_id_to_view_target_map_[view->id()] = target;
|
| + if (view == root_)
|
| + window->AddPreTargetHandler(this);
|
| + parent->AddChild(window);
|
| + window->SetBounds(view->bounds().To<gfx::Rect>());
|
| + window->Show();
|
| + view_id_to_window_map_[view->id()] = window;
|
| View::Children::const_iterator it = view->children().begin();
|
| for (; it != view->children().end(); ++it)
|
| - RegisterSubtree(*it, target);
|
| + RegisterSubtree(*it, window);
|
| }
|
|
|
| void WindowManagerApp::UnregisterSubtree(View* view) {
|
| @@ -313,19 +373,18 @@ void WindowManagerApp::UnregisterSubtree(View* view) {
|
| }
|
|
|
| void WindowManagerApp::Unregister(View* view) {
|
| - ViewIdToViewTargetMap::iterator it =
|
| - view_id_to_view_target_map_.find(view->id());
|
| - if (it == view_id_to_view_target_map_.end()) {
|
| + ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id());
|
| + if (it == view_id_to_window_map_.end()) {
|
| // Because we unregister in OnViewDestroying() we can still get a subsequent
|
| // OnTreeChanged for the same view. Ignore this one.
|
| return;
|
| }
|
| view->RemoveObserver(this);
|
| - DCHECK(it != view_id_to_view_target_map_.end());
|
| + DCHECK(it != view_id_to_window_map_.end());
|
| // Delete before we remove from map as destruction may want to look up view
|
| // for window.
|
| delete it->second;
|
| - view_id_to_view_target_map_.erase(it);
|
| + view_id_to_window_map_.erase(it);
|
| }
|
|
|
| void WindowManagerApp::SetViewportSize(const gfx::Size& size) {
|
|
|