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

Unified Diff: mojo/services/window_manager/window_manager_app.cc

Issue 405523002: Add ability APIs for opening a window with a url embedded, focusing and activating a window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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
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 dc60fdd849b90ad63de9268e2780b75a65a2799e..0a89f6886b0e42905b8ddef666bccd75e609f3d2 100644
--- a/mojo/services/window_manager/window_manager_app.cc
+++ b/mojo/services/window_manager/window_manager_app.cc
@@ -11,9 +11,61 @@
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/window_manager/window_manager_service_impl.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_property.h"
#include "ui/wm/core/capture_controller.h"
+#include "ui/wm/core/focus_controller.h"
+#include "ui/wm/core/focus_rules.h"
+#include "ui/wm/public/activation_client.h"
+
+DECLARE_WINDOW_PROPERTY_TYPE(mojo::view_manager::Node*);
namespace mojo {
+namespace {
+
+DEFINE_WINDOW_PROPERTY_KEY(view_manager::Node*, kNodeKey, NULL);
+
+view_manager::Id GetIdForWindow(aura::Window* window) {
+ return window ? window->GetProperty(kNodeKey)->id() : 0;
+}
+
+class WMFocusRules : public wm::FocusRules {
+ public:
+ WMFocusRules() {}
+ virtual ~WMFocusRules() {}
+
+ private:
+ // Overridden from wm::FocusRules:
+ virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE {
+ return true;
+ }
+ virtual bool CanActivateWindow(aura::Window* window) const MOJO_OVERRIDE {
+ return true;
+ }
+ virtual bool CanFocusWindow(aura::Window* window) const MOJO_OVERRIDE {
+ return true;
+ }
+ virtual aura::Window* GetToplevelWindow(
+ aura::Window* window) const MOJO_OVERRIDE {
+ return window;
+ }
+ virtual aura::Window* GetActivatableWindow(
+ aura::Window* window) const MOJO_OVERRIDE {
+ return window;
+ }
+ virtual aura::Window* GetFocusableWindow(
+ aura::Window* window) const MOJO_OVERRIDE {
+ return window;
+ }
+ virtual aura::Window* GetNextActivatableWindow(
+ aura::Window* ignore) const MOJO_OVERRIDE {
+ return NULL;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
+};
+
+} // namespace
////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, public:
@@ -37,12 +89,31 @@ view_manager::Id WindowManagerApp::OpenWindow() {
return node->id();
}
+view_manager::Id WindowManagerApp::OpenWindowWithURL(const String& url) {
+ view_manager::Node* node = view_manager::Node::Create(view_manager_);
+ root_->AddChild(node);
+ node->Embed(url);
+ return node->id();
+}
+
void WindowManagerApp::SetCapture(view_manager::Id node) {
capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node));
// TODO(beng): notify connected clients that capture has changed, probably
// by implementing some capture-client observer.
}
+void WindowManagerApp::FocusWindow(view_manager::Id node) {
+ aura::Window* window = GetWindowForNodeId(node);
+ DCHECK(window);
+ focus_client_->FocusWindow(window);
+}
+
+void WindowManagerApp::ActivateWindow(view_manager::Id node) {
+ aura::Window* window = GetWindowForNodeId(node);
+ DCHECK(window);
+ activation_client_->ActivateWindow(window);
+}
+
bool WindowManagerApp::IsReady() const {
return view_manager_ && root_;
}
@@ -69,11 +140,21 @@ void WindowManagerApp::OnRootAdded(view_manager::ViewManager* view_manager,
DCHECK(!view_manager_ && !root_);
view_manager_ = view_manager;
root_ = root;
+ root_->AddObserver(this);
sky 2014/07/17 23:15:42 Do you need to remove this in the destructor if no
window_tree_host_.reset(new WindowTreeHostMojo(root_, this));
+ RegisterSubtree(root_->id(), window_tree_host_->window());
+
capture_client_.reset(
new wm::ScopedCaptureClient(window_tree_host_->window()));
+ wm::FocusController* focus_controller =
+ new wm::FocusController(new WMFocusRules);
+ activation_client_ = focus_controller;
+ focus_client_.reset(focus_controller);
+
+ focus_client_->AddObserver(this);
sky 2014/07/17 23:15:42 Remove these observers?
+ activation_client_->AddObserver(this);
// TODO(beng): Create the universe.
@@ -91,6 +172,35 @@ void WindowManagerApp::OnViewManagerDisconnected(
}
////////////////////////////////////////////////////////////////////////////////
+// WindowManagerApp, view_manager::NodeObserver implementation:
+
+void WindowManagerApp::OnTreeChanged(
+ const view_manager::NodeObserver::TreeChangeParams& params) {
+ DCHECK_EQ(params.receiver, root_);
+ DCHECK(params.old_parent || params.new_parent);
+ if (!params.target)
+ return;
+
+ if (params.new_parent) {
+ if (node_id_to_window_map_.find(params.target->id()) ==
+ node_id_to_window_map_.end()) {
+ NodeIdToWindowMap::const_iterator it =
+ node_id_to_window_map_.find(params.new_parent->id());
+ DCHECK(it != node_id_to_window_map_.end());
+ RegisterSubtree(params.target->id(), it->second);
+ }
+ } else if (params.old_parent) {
+ UnregisterSubtree(params.target->id());
+ }
+}
+
+void WindowManagerApp::OnNodeDestroyed(view_manager::Node* node) {
+ DCHECK_EQ(root_, node);
+ root_->RemoveObserver(this);
+ root_ = NULL;
+}
sky 2014/07/17 23:15:42 Do you need to UnregisterSubstree here? If not, wh
Ben Goodger (Google) 2014/07/18 19:50:44 I removed this method. It's actually never called
+
+////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, WindowTreeHostMojoDelegate implementation:
void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) {
@@ -99,12 +209,61 @@ void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) {
}
////////////////////////////////////////////////////////////////////////////////
+// WindowManagerApp, aura::client::FocusChangeObserver implementation:
+
+void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus,
+ aura::Window* lost_focus) {
+ for (Connections::const_iterator it = connections_.begin();
+ it != connections_.end(); ++it) {
+ (*it)->NotifyNodeFocused(GetIdForWindow(gained_focus),
+ GetIdForWindow(lost_focus));
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// 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(GetIdForWindow(gained_active),
+ GetIdForWindow(lost_active));
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, private:
aura::Window* WindowManagerApp::GetWindowForNodeId(
view_manager::Id node) const {
- NOTIMPLEMENTED();
- return NULL;
+ NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(node);
+ return it != node_id_to_window_map_.end() ? it->second : NULL;
+}
+
+void WindowManagerApp::RegisterSubtree(view_manager::Id id,
+ aura::Window* parent) {
+ view_manager::Node* node = view_manager_->GetNodeById(id);
+ DCHECK(node_id_to_window_map_.find(id) == node_id_to_window_map_.end());
+ aura::Window* window = new aura::Window(NULL);
+ window->SetProperty(kNodeKey, node);
+ parent->AddChild(window);
+ node_id_to_window_map_[id] = window;
+ view_manager::Node::Children::const_iterator it = node->children().begin();
+ for (; it != node->children().end(); ++it)
+ RegisterSubtree((*it)->id(), window);
+}
+
+void WindowManagerApp::UnregisterSubtree(view_manager::Id id) {
+ view_manager::Node* node = view_manager_->GetNodeById(id);
+ NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(id);
+ DCHECK(it != node_id_to_window_map_.end());
+ aura::Window* window = it->second;
sky 2014/07/17 23:15:42 put in scoped_ptr so you don't need delete on 266.
+ node_id_to_window_map_.erase(it);
+ view_manager::Node::Children::const_iterator child = node->children().begin();
+ for (; child != node->children().end(); ++child)
+ UnregisterSubtree((*child)->id());
+ delete window;
}
////////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698