Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1421)

Unified Diff: mojo/examples/wm_flow/wm/wm.cc

Issue 599213002: First cut at supporting activation in the window manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: / Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.cc ('k') | mojo/services/view_manager/connection_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/wm_flow/wm/wm.cc
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
index bf4cafc7bafda143846822f1a6eaf2145650155b..f1f23e648e1561e14e8f618f39206df8085925a3 100644
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <vector>
+
#include "mojo/application/application_runner_chromium.h"
#include "mojo/examples/wm_flow/wm/frame_controller.h"
#include "mojo/public/c/system/main.h"
@@ -15,9 +17,75 @@
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h"
#include "mojo/views/views_init.h"
+#include "ui/aura/window.h"
+#include "ui/wm/core/focus_rules.h"
+#include "ui/wm/public/activation_client.h"
namespace examples {
+namespace {
+
+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 MOJO_OVERRIDE {
+ return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
+ window_container_;
+ }
+ virtual bool CanActivateWindow(aura::Window* window) const MOJO_OVERRIDE {
+ return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
+ window_container_;
+ }
+ virtual bool CanFocusWindow(aura::Window* window) const MOJO_OVERRIDE {
+ return true;
+ }
+ virtual aura::Window* GetToplevelWindow(
+ aura::Window* window) const MOJO_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 MOJO_OVERRIDE {
+ return GetToplevelWindow(window);
+ }
+ virtual aura::Window* GetFocusableWindow(
+ aura::Window* window) const MOJO_OVERRIDE {
+ return window;
+ }
+ virtual aura::Window* GetNextActivatableWindow(
+ aura::Window* ignore) const MOJO_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 SimpleWM : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate,
public mojo::WindowManagerDelegate,
@@ -55,6 +123,8 @@ class SimpleWM : public mojo::ApplicationDelegate,
window_container_->SetBounds(root_->bounds());
root_->AddChild(window_container_);
+ window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
+ window_container_));
}
virtual void OnViewManagerDisconnected(
mojo::ViewManager* view_manager) MOJO_OVERRIDE {
@@ -105,7 +175,10 @@ class SimpleWM : public mojo::ApplicationDelegate,
frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
next_window_origin_.Offset(50, 50);
- new FrameController(frame_view, app_view);
+ aura::client::ActivationClient* client = aura::client::GetActivationClient(
+ window_manager_app_->host()->window());
+ new FrameController(frame_view, app_view, client,
+ window_manager_app_.get());
return frame_view;
}
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.cc ('k') | mojo/services/view_manager/connection_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698