Commit c3d7eb25 authored by ben's avatar ben Committed by Commit bot

Hook up FocusController.

R=sky@chromium.org
BUG=

Review URL: https://codereview.chromium.org/599213002

Cr-Commit-Position: refs/heads/master@{#297245}
parent 71ce1027
include_rules = [ include_rules = [
"+ui/aura",
"+ui/gfx/geometry", "+ui/gfx/geometry",
"+ui/views", "+ui/views",
"+ui/wm/core",
"+ui/wm/public",
] ]
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/window_manager/window_manager_app.h"
#include "mojo/views/native_widget_view_manager.h" #include "mojo/views/native_widget_view_manager.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/public/activation_client.h"
class FrameController::LayoutManager : public views::LayoutManager, class FrameController::LayoutManager : public views::LayoutManager,
public views::ButtonListener { public views::ButtonListener {
...@@ -69,22 +71,49 @@ class FrameController::LayoutManager : public views::LayoutManager, ...@@ -69,22 +71,49 @@ class FrameController::LayoutManager : public views::LayoutManager,
DISALLOW_COPY_AND_ASSIGN(LayoutManager); DISALLOW_COPY_AND_ASSIGN(LayoutManager);
}; };
class FrameController::FrameEventHandler : public ui::EventHandler {
public:
explicit FrameEventHandler(FrameController* frame_controller)
: frame_controller_(frame_controller) {}
virtual ~FrameEventHandler() {}
private:
// Overriden from ui::EventHandler:
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
if (event->type() == ui::ET_MOUSE_PRESSED)
frame_controller_->ActivateWindow();
}
FrameController* frame_controller_;
DISALLOW_COPY_AND_ASSIGN(FrameEventHandler);
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FrameController, public: // FrameController, public:
FrameController::FrameController(mojo::View* view, mojo::View** app_view) FrameController::FrameController(
mojo::View* view,
mojo::View** app_view,
aura::client::ActivationClient* activation_client,
mojo::WindowManagerApp* window_manager_app)
: view_(view), : view_(view),
app_view_(mojo::View::Create(view->view_manager())), app_view_(mojo::View::Create(view->view_manager())),
frame_view_(new views::View), frame_view_(new views::View),
frame_view_layout_manager_(new LayoutManager(this)), frame_view_layout_manager_(new LayoutManager(this)),
widget_(new views::Widget), widget_(new views::Widget),
maximized_(false) { maximized_(false),
activation_client_(activation_client),
window_manager_app_(window_manager_app) {
view_->AddChild(app_view_); view_->AddChild(app_view_);
view_->AddObserver(this); view_->AddObserver(this);
*app_view = app_view_; *app_view = app_view_;
frame_view_->set_background( frame_view_->set_background(
views::Background::CreateSolidBackground(SK_ColorBLUE)); views::Background::CreateSolidBackground(SK_ColorBLUE));
frame_view_->SetLayoutManager(frame_view_layout_manager_); frame_view_->SetLayoutManager(frame_view_layout_manager_);
frame_event_handler_.reset(new FrameEventHandler(this));
frame_view_->AddPreTargetHandler(frame_event_handler_.get());
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_); params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_);
...@@ -111,6 +140,11 @@ void FrameController::ToggleMaximize() { ...@@ -111,6 +140,11 @@ void FrameController::ToggleMaximize() {
view_->SetBounds(restored_bounds_); view_->SetBounds(restored_bounds_);
} }
void FrameController::ActivateWindow() {
aura::Window* window = window_manager_app_->GetWindowForViewId(view_->id());
activation_client_->ActivateWindow(window);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FrameController, mojo::ViewObserver implementation: // FrameController, mojo::ViewObserver implementation:
......
...@@ -5,12 +5,20 @@ ...@@ -5,12 +5,20 @@
#ifndef MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_ #ifndef MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_
#define MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_ #define MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_
#include "base/memory/scoped_ptr.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h" #include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace aura {
namespace client {
class ActivationClient;
}
}
namespace mojo { namespace mojo {
class NativeWidgetViewManager; class NativeWidgetViewManager;
class View; class View;
class WindowManagerApp;
} }
namespace views { namespace views {
...@@ -23,15 +31,21 @@ class Widget; ...@@ -23,15 +31,21 @@ class Widget;
// to any events targeted at it. // to any events targeted at it.
class FrameController : mojo::ViewObserver { class FrameController : mojo::ViewObserver {
public: public:
FrameController(mojo::View* view, mojo::View** app_view); FrameController(mojo::View* view,
mojo::View** app_view,
aura::client::ActivationClient* activation_client,
mojo::WindowManagerApp* window_manager_app);
virtual ~FrameController(); virtual ~FrameController();
void CloseWindow(); void CloseWindow();
void ToggleMaximize(); void ToggleMaximize();
void ActivateWindow();
private: private:
class LayoutManager; class LayoutManager;
friend class LayoutManager; friend class LayoutManager;
class FrameEventHandler;
virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE; virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE;
...@@ -42,6 +56,9 @@ class FrameController : mojo::ViewObserver { ...@@ -42,6 +56,9 @@ class FrameController : mojo::ViewObserver {
views::Widget* widget_; views::Widget* widget_;
bool maximized_; bool maximized_;
gfx::Rect restored_bounds_; gfx::Rect restored_bounds_;
aura::client::ActivationClient* activation_client_;
mojo::WindowManagerApp* window_manager_app_;
scoped_ptr<FrameEventHandler> frame_event_handler_;
DISALLOW_COPY_AND_ASSIGN(FrameController); DISALLOW_COPY_AND_ASSIGN(FrameController);
}; };
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <vector>
#include "mojo/application/application_runner_chromium.h" #include "mojo/application/application_runner_chromium.h"
#include "mojo/examples/wm_flow/wm/frame_controller.h" #include "mojo/examples/wm_flow/wm/frame_controller.h"
#include "mojo/public/c/system/main.h" #include "mojo/public/c/system/main.h"
...@@ -15,9 +17,75 @@ ...@@ -15,9 +17,75 @@
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h" #include "mojo/services/window_manager/window_manager_app.h"
#include "mojo/views/views_init.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 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, class SimpleWM : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate, public mojo::ViewManagerDelegate,
public mojo::WindowManagerDelegate, public mojo::WindowManagerDelegate,
...@@ -55,6 +123,8 @@ class SimpleWM : public mojo::ApplicationDelegate, ...@@ -55,6 +123,8 @@ class SimpleWM : public mojo::ApplicationDelegate,
window_container_->SetBounds(root_->bounds()); window_container_->SetBounds(root_->bounds());
root_->AddChild(window_container_); root_->AddChild(window_container_);
window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
window_container_));
} }
virtual void OnViewManagerDisconnected( virtual void OnViewManagerDisconnected(
mojo::ViewManager* view_manager) MOJO_OVERRIDE { mojo::ViewManager* view_manager) MOJO_OVERRIDE {
...@@ -105,7 +175,10 @@ class SimpleWM : public mojo::ApplicationDelegate, ...@@ -105,7 +175,10 @@ class SimpleWM : public mojo::ApplicationDelegate,
frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
next_window_origin_.Offset(50, 50); 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; return frame_view;
} }
......
...@@ -279,6 +279,12 @@ void ConnectionManager::OnViewSurfaceIdChanged(const ServerView* view) { ...@@ -279,6 +279,12 @@ void ConnectionManager::OnViewSurfaceIdChanged(const ServerView* view) {
display_manager_.SchedulePaint(view, gfx::Rect(view->bounds().size())); display_manager_.SchedulePaint(view, gfx::Rect(view->bounds().size()));
} }
void ConnectionManager::OnViewReordered(const ServerView* view,
const ServerView* relative,
OrderDirection direction) {
display_manager_.SchedulePaint(view, gfx::Rect(view->bounds().size()));
}
void ConnectionManager::OnWillChangeViewVisibility(const ServerView* view) { void ConnectionManager::OnWillChangeViewVisibility(const ServerView* view) {
for (ConnectionMap::iterator i = connection_map_.begin(); for (ConnectionMap::iterator i = connection_map_.begin();
i != connection_map_.end(); i != connection_map_.end();
......
...@@ -172,6 +172,9 @@ class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate { ...@@ -172,6 +172,9 @@ class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
const gfx::Rect& old_bounds, const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnViewSurfaceIdChanged(const ServerView* view) OVERRIDE; virtual void OnViewSurfaceIdChanged(const ServerView* view) OVERRIDE;
virtual void OnViewReordered(const ServerView* view,
const ServerView* relative,
OrderDirection direction) OVERRIDE;
virtual void OnWillChangeViewVisibility(const ServerView* view) OVERRIDE; virtual void OnWillChangeViewVisibility(const ServerView* view) OVERRIDE;
ApplicationConnection* app_connection_; ApplicationConnection* app_connection_;
......
...@@ -73,6 +73,7 @@ void ServerView::Reorder(ServerView* child, ...@@ -73,6 +73,7 @@ void ServerView::Reorder(ServerView* child,
DCHECK(i != children_.end()); DCHECK(i != children_.end());
children_.insert(i, child); children_.insert(i, child);
} }
delegate_->OnViewReordered(this, relative, direction);
} }
void ServerView::SetBounds(const gfx::Rect& bounds) { void ServerView::SetBounds(const gfx::Rect& bounds) {
......
...@@ -36,6 +36,10 @@ class MOJO_VIEW_MANAGER_EXPORT ServerViewDelegate { ...@@ -36,6 +36,10 @@ class MOJO_VIEW_MANAGER_EXPORT ServerViewDelegate {
virtual void OnViewSurfaceIdChanged(const ServerView* view) = 0; virtual void OnViewSurfaceIdChanged(const ServerView* view) = 0;
virtual void OnViewReordered(const ServerView* view,
const ServerView* relative,
OrderDirection direction) = 0;
virtual void OnWillChangeViewVisibility(const ServerView* view) = 0; virtual void OnWillChangeViewVisibility(const ServerView* view) = 0;
protected: protected:
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/focus_controller.h" #include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/focus_rules.h"
#include "ui/wm/public/activation_client.h" #include "ui/wm/public/activation_client.h"
DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*); DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*);
...@@ -72,42 +71,6 @@ Id GetIdForWindow(aura::Window* window) { ...@@ -72,42 +71,6 @@ Id GetIdForWindow(aura::Window* window) {
return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0; return window ? WindowManagerApp::GetViewForWindow(window)->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 } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -131,6 +94,11 @@ View* WindowManagerApp::GetViewForWindow(aura::Window* window) { ...@@ -131,6 +94,11 @@ View* WindowManagerApp::GetViewForWindow(aura::Window* window) {
return window->GetProperty(kViewKey); return window->GetProperty(kViewKey);
} }
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(WindowManagerServiceImpl* connection) { void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) {
DCHECK(connections_.find(connection) == connections_.end()); DCHECK(connections_.find(connection) == connections_.end());
connections_.insert(connection); connections_.insert(connection);
...@@ -163,6 +131,18 @@ bool WindowManagerApp::IsReady() const { ...@@ -163,6 +131,18 @@ bool WindowManagerApp::IsReady() const {
return view_manager_ && root_; return view_manager_ && root_;
} }
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);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, ApplicationDelegate implementation: // WindowManagerApp, ApplicationDelegate implementation:
...@@ -199,14 +179,6 @@ void WindowManagerApp::OnEmbed(ViewManager* view_manager, ...@@ -199,14 +179,6 @@ void WindowManagerApp::OnEmbed(ViewManager* view_manager,
capture_client_.reset( capture_client_.reset(
new wm::ScopedCaptureClient(window_tree_host_->window())); 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);
aura::client::SetFocusClient(window_tree_host_->window(), focus_controller);
focus_client_->AddObserver(this);
activation_client_->AddObserver(this);
if (wrapped_view_manager_delegate_) { if (wrapped_view_manager_delegate_) {
wrapped_view_manager_delegate_->OnEmbed( wrapped_view_manager_delegate_->OnEmbed(
...@@ -327,16 +299,15 @@ void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, ...@@ -327,16 +299,15 @@ void WindowManagerApp::OnWindowActivated(aura::Window* gained_active,
(*it)->NotifyWindowActivated(GetIdForWindow(gained_active), (*it)->NotifyWindowActivated(GetIdForWindow(gained_active),
GetIdForWindow(lost_active)); GetIdForWindow(lost_active));
} }
if (gained_active) {
View* view = GetViewForWindow(gained_active);
view->MoveToFront();
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, private: // WindowManagerApp, private:
aura::Window* WindowManagerApp::GetWindowForViewId(Id view) const {
ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view);
return it != view_id_to_window_map_.end() ? it->second : NULL;
}
void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) { void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) {
view->AddObserver(this); view->AddObserver(this);
DCHECK(view_id_to_window_map_.find(view->id()) == DCHECK(view_id_to_window_map_.find(view->id()) ==
......
...@@ -32,6 +32,7 @@ class Window; ...@@ -32,6 +32,7 @@ class Window;
} }
namespace wm { namespace wm {
class FocusRules;
class ScopedCaptureClient; class ScopedCaptureClient;
} }
...@@ -68,6 +69,7 @@ class WindowManagerApp ...@@ -68,6 +69,7 @@ class WindowManagerApp
virtual ~WindowManagerApp(); virtual ~WindowManagerApp();
static View* GetViewForWindow(aura::Window* window); static View* GetViewForWindow(aura::Window* window);
aura::Window* GetWindowForViewId(Id view);
// Register/deregister new connections to the window manager service. // Register/deregister new connections to the window manager service.
void AddConnection(WindowManagerServiceImpl* connection); void AddConnection(WindowManagerServiceImpl* connection);
...@@ -84,6 +86,8 @@ class WindowManagerApp ...@@ -84,6 +86,8 @@ class WindowManagerApp
// aura::Window hierarchy and attach event handlers. // aura::Window hierarchy and attach event handlers.
aura::WindowTreeHost* host() { return window_tree_host_.get(); } aura::WindowTreeHost* host() { return window_tree_host_.get(); }
void InitFocus(wm::FocusRules* rules);
// Overridden from ApplicationDelegate: // Overridden from ApplicationDelegate:
virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE; virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE;
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
...@@ -130,8 +134,6 @@ class WindowManagerApp ...@@ -130,8 +134,6 @@ class WindowManagerApp
virtual void OnWindowActivated(aura::Window* gained_active, virtual void OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) MOJO_OVERRIDE; aura::Window* lost_active) MOJO_OVERRIDE;
aura::Window* GetWindowForViewId(Id view) const;
// Creates an aura::Window for every view in the hierarchy beneath |view|, // Creates an aura::Window for every view in the hierarchy beneath |view|,
// and adds to the registry so that it can be retrieved later via // and adds to the registry so that it can be retrieved later via
// GetWindowForViewId(). // GetWindowForViewId().
......
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