| Index: examples/window_manager/window_manager.cc
|
| diff --git a/examples/window_manager/window_manager.cc b/examples/window_manager/window_manager.cc
|
| index 90c63d21fed5fd215e03b0801f4ec2eb5dd42cb0..45c99b468d8122e8b3d3c01957c90e6a6a75bf96 100644
|
| --- a/examples/window_manager/window_manager.cc
|
| +++ b/examples/window_manager/window_manager.cc
|
| @@ -22,14 +22,14 @@
|
| #include "mojo/services/public/cpp/view_manager/view_observer.h"
|
| #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
|
| #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
|
| -#include "mojo/services/window_manager/basic_focus_rules.h"
|
| -#include "mojo/services/window_manager/view_target.h"
|
| #include "mojo/services/window_manager/window_manager_app.h"
|
| #include "mojo/services/window_manager/window_manager_delegate.h"
|
| #include "mojo/views/views_init.h"
|
| +#include "ui/aura/window.h"
|
| #include "ui/events/event.h"
|
| #include "ui/events/event_constants.h"
|
| #include "ui/gfx/geometry/size_conversions.h"
|
| +#include "ui/wm/core/focus_rules.h"
|
|
|
| #if defined CreateWindow
|
| #undef CreateWindow
|
| @@ -46,6 +46,64 @@ const int kBorderInset = 25;
|
| const int kControlPanelWidth = 200;
|
| const int kTextfieldHeight = 25;
|
|
|
| +class WMFocusRules : public wm::FocusRules {
|
| + public:
|
| + WMFocusRules(mojo::WindowManagerApp* window_manager_app,
|
| + mojo::View* window_container)
|
| + : window_container_(window_container),
|
| + window_manager_app_(window_manager_app) {}
|
| + virtual ~WMFocusRules() {}
|
| +
|
| + private:
|
| + // Overridden from wm::FocusRules:
|
| + virtual bool IsToplevelWindow(aura::Window* window) const override {
|
| + return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
|
| + window_container_;
|
| + }
|
| + virtual bool CanActivateWindow(aura::Window* window) const override {
|
| + return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
|
| + window_container_;
|
| + }
|
| + virtual bool CanFocusWindow(aura::Window* window) const override {
|
| + return true;
|
| + }
|
| + virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
|
| + mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
|
| + while (view->parent() != window_container_) {
|
| + view = view->parent();
|
| + // Unparented hierarchy, there is no "top level" window.
|
| + if (!view)
|
| + return NULL;
|
| + }
|
| +
|
| + return window_manager_app_->GetWindowForViewId(view->id());
|
| + }
|
| + virtual aura::Window* GetActivatableWindow(
|
| + aura::Window* window) const override {
|
| + return GetToplevelWindow(window);
|
| + }
|
| + virtual aura::Window* GetFocusableWindow(
|
| + aura::Window* window) const override {
|
| + return window;
|
| + }
|
| + virtual aura::Window* GetNextActivatableWindow(
|
| + aura::Window* ignore) const override {
|
| + aura::Window* activatable = GetActivatableWindow(ignore);
|
| + const aura::Window::Windows& children = activatable->parent()->children();
|
| + for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
|
| + it != children.rend(); ++it) {
|
| + if (*it != ignore)
|
| + return *it;
|
| + }
|
| + return NULL;
|
| + }
|
| +
|
| + mojo::View* window_container_;
|
| + mojo::WindowManagerApp* window_manager_app_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
|
| +};
|
| +
|
| } // namespace
|
|
|
| class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
|
| @@ -270,10 +328,8 @@ class WindowManager
|
| virtual ~WindowManager() {
|
| // host() may be destroyed by the time we get here.
|
| // TODO: figure out a way to always cleanly remove handler.
|
| -
|
| - // TODO(erg): In the aura version, we removed ourselves from the
|
| - // PreTargetHandler list here. We may need to do something analogous when
|
| - // we get event handling without aura working.
|
| + if (window_manager_app_->host())
|
| + window_manager_app_->host()->window()->RemovePreTargetHandler(this);
|
| }
|
|
|
| void CloseWindow(Id view_id) {
|
| @@ -372,13 +428,10 @@ class WindowManager
|
| control_panel_id));
|
| root->AddObserver(root_layout_manager_.get());
|
|
|
| - // TODO(erg): In the aura version, we explicitly added ourselves as a
|
| - // PreTargetHandler to the window() here. We probably have to do something
|
| - // analogous here.
|
| + window_manager_app_->host()->window()->AddPreTargetHandler(this);
|
|
|
| - window_manager_app_->InitFocus(scoped_ptr<mojo::FocusRules>(
|
| - new mojo::BasicFocusRules(window_manager_app_.get(),
|
| - view)));
|
| + window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
|
| + view));
|
| }
|
| virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
|
| DCHECK_EQ(view_manager_, view_manager);
|
| @@ -396,8 +449,8 @@ class WindowManager
|
|
|
| // Overridden from ui::EventHandler:
|
| virtual void OnEvent(ui::Event* event) override {
|
| - View* view = WindowManagerApp::GetViewForViewTarget(
|
| - static_cast<ViewTarget*>(event->target()));
|
| + View* view = WindowManagerApp::GetViewForWindow(
|
| + static_cast<aura::Window*>(event->target()));
|
| if (event->type() == ui::ET_MOUSE_PRESSED &&
|
| !IsDescendantOfKeyboard(view)) {
|
| view->SetFocus();
|
|
|