Commit cce694a7 authored by ben@chromium.org's avatar ben@chromium.org

Clean up WTH creation

WTHMojo was unable to observe bounds changes from its associated Node. Instead WTHMojo is now bound to a Node & derives bounds from it.

R=sky@chromium.org
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278614 0039d316-1c4b-4281-b951-d872f2087c98
parent 60cbaaa1
...@@ -61,16 +61,19 @@ class TreeHosts : public base::SupportsUserData::Data { ...@@ -61,16 +61,19 @@ class TreeHosts : public base::SupportsUserData::Data {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, public: // WindowTreeHostMojo, public:
WindowTreeHostMojo::WindowTreeHostMojo(const gfx::Rect& bounds, WindowTreeHostMojo::WindowTreeHostMojo(view_manager::Node* node,
WindowTreeHostMojoDelegate* delegate) WindowTreeHostMojoDelegate* delegate)
: bounds_(bounds), : node_(node),
bounds_(node->bounds()),
delegate_(delegate) { delegate_(delegate) {
node_->AddObserver(this);
CreateCompositor(GetAcceleratedWidget()); CreateCompositor(GetAcceleratedWidget());
TreeHosts::Get()->Add(this); TreeHosts::Get()->Add(this);
} }
WindowTreeHostMojo::~WindowTreeHostMojo() { WindowTreeHostMojo::~WindowTreeHostMojo() {
node_->RemoveObserver(this);
TreeHosts::Get()->Remove(this); TreeHosts::Get()->Remove(this);
DestroyCompositor(); DestroyCompositor();
DestroyDispatcher(); DestroyDispatcher();
...@@ -158,4 +161,19 @@ ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() { ...@@ -158,4 +161,19 @@ ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
return dispatcher(); return dispatcher();
} }
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, view_manager::NodeObserver implementation:
void WindowTreeHostMojo::OnNodeBoundsChange(
view_manager::Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds,
view_manager::NodeObserver::DispositionChangePhase phase) {
bounds_ = new_bounds;
if (old_bounds.origin() != new_bounds.origin())
OnHostMoved(bounds_.origin());
if (old_bounds.size() != new_bounds.size())
OnHostResized(bounds_.size());
}
} // namespace mojo } // namespace mojo
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_ #ifndef MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_
#define MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_ #define MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/events/event_source.h" #include "ui/events/event_source.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -19,9 +20,11 @@ namespace mojo { ...@@ -19,9 +20,11 @@ namespace mojo {
class WindowTreeHostMojoDelegate; class WindowTreeHostMojoDelegate;
class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource { class WindowTreeHostMojo : public aura::WindowTreeHost,
public ui::EventSource,
public view_manager::NodeObserver {
public: public:
WindowTreeHostMojo(const gfx::Rect& bounds, WindowTreeHostMojo(view_manager::Node* node,
WindowTreeHostMojoDelegate* delegate); WindowTreeHostMojoDelegate* delegate);
virtual ~WindowTreeHostMojo(); virtual ~WindowTreeHostMojo();
...@@ -58,6 +61,15 @@ class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource { ...@@ -58,6 +61,15 @@ class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource {
// ui::EventSource: // ui::EventSource:
virtual ui::EventProcessor* GetEventProcessor() OVERRIDE; virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
// view_manager::NodeObserver:
virtual void OnNodeBoundsChange(
view_manager::Node* node,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds,
view_manager::NodeObserver::DispositionChangePhase phase) OVERRIDE;
view_manager::Node* node_;
gfx::Rect bounds_; gfx::Rect bounds_;
WindowTreeHostMojoDelegate* delegate_; WindowTreeHostMojoDelegate* delegate_;
......
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
#include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/window_tree_client.h" #include "ui/aura/client/window_tree_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
...@@ -27,34 +30,6 @@ ...@@ -27,34 +30,6 @@
namespace mojo { namespace mojo {
namespace examples { namespace examples {
void OnSetViewContentsDone(bool value) {
VLOG(1) << "OnSetViewContentsDone " << value;
DCHECK(value);
}
bool CreateMapAndDupSharedBuffer(size_t size,
void** memory,
ScopedSharedBufferHandle* handle,
ScopedSharedBufferHandle* duped) {
MojoResult result = CreateSharedBuffer(NULL, size, handle);
if (result != MOJO_RESULT_OK)
return false;
DCHECK(handle->is_valid());
result = DuplicateBuffer(handle->get(), NULL, duped);
if (result != MOJO_RESULT_OK)
return false;
DCHECK(duped->is_valid());
result = MapBuffer(
handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE);
if (result != MOJO_RESULT_OK)
return false;
DCHECK(*memory);
return true;
}
// Trivial WindowDelegate implementation that draws a colored background. // Trivial WindowDelegate implementation that draws a colored background.
class DemoWindowDelegate : public aura::WindowDelegate { class DemoWindowDelegate : public aura::WindowDelegate {
public: public:
...@@ -128,97 +103,28 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient { ...@@ -128,97 +103,28 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
}; };
class AuraDemo; class AuraDemo : public Application,
public WindowTreeHostMojoDelegate,
// Trivial ViewManagerClient implementation. Forwards to AuraDemo when public view_manager::ViewManagerDelegate {
// connection established.
class ViewManagerClientImpl
: public InterfaceImpl<view_manager::ViewManagerClient> {
public:
explicit ViewManagerClientImpl(AuraDemo* aura_demo)
: aura_demo_(aura_demo) {}
virtual ~ViewManagerClientImpl() {}
private:
void OnResult(bool result) {
VLOG(1) << "ViewManagerClientImpl::::OnResult result=" << result;
DCHECK(result);
}
// ViewManagerClient:
virtual void OnViewManagerConnectionEstablished(
uint16_t connection_id,
const String& creator_url,
uint32_t next_server_change_id,
mojo::Array<view_manager::NodeDataPtr> nodes) OVERRIDE;
virtual void OnRootsAdded(Array<view_manager::NodeDataPtr> nodes) OVERRIDE {
NOTREACHED();
}
virtual void OnServerChangeIdAdvanced(
uint32_t next_server_change_id) OVERRIDE {
}
virtual void OnNodeBoundsChanged(uint32_t node,
mojo::RectPtr old_bounds,
mojo::RectPtr new_bounds) OVERRIDE {
}
virtual void OnNodeHierarchyChanged(
uint32_t node,
uint32_t new_parent,
uint32_t old_parent,
uint32_t server_change_id,
mojo::Array<view_manager::NodeDataPtr> nodes) OVERRIDE {
}
virtual void OnNodeReordered(
uint32_t node_id,
uint32_t relative_node_id,
view_manager::OrderDirection direction,
uint32_t server_change_id) OVERRIDE {
}
virtual void OnNodeDeleted(uint32_t node, uint32_t server_change_id)
OVERRIDE {
}
virtual void OnNodeViewReplaced(uint32_t node,
uint32_t new_view_id,
uint32_t old_view_id) OVERRIDE {
}
virtual void OnViewDeleted(uint32_t view) OVERRIDE {
}
virtual void OnViewInputEvent(uint32_t view_id,
EventPtr event,
const Callback<void()>& callback) OVERRIDE {
}
virtual void DispatchOnViewInputEvent(uint32_t view_id,
EventPtr event) OVERRIDE {
}
AuraDemo* aura_demo_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl);
};
class AuraDemo : public Application, public WindowTreeHostMojoDelegate {
public: public:
AuraDemo() AuraDemo()
: view_manager_(NULL), : window1_(NULL),
window1_(NULL),
window2_(NULL), window2_(NULL),
window21_(NULL), window21_(NULL),
view_id_(0) { view_(NULL) {
AddService<ViewManagerClientImpl>(this); view_manager::ViewManager::Create(this, this);
} }
virtual ~AuraDemo() {} virtual ~AuraDemo() {}
void SetRoot(view_manager::ViewManagerService* view_manager, private:
uint32_t view_id) { // Overridden from view_manager::ViewManagerDelegate:
aura::Env::CreateInstance(true); virtual void OnRootAdded(view_manager::ViewManager* view_manager,
view_manager_ = view_manager; view_manager::Node* root) OVERRIDE {
view_id_ = view_id; // TODO(beng): this function could be called multiple times!
context_factory_.reset(new ContextFactoryMojo); view_ = view_manager::View::Create(view_manager);
aura::Env::GetInstance()->set_context_factory(context_factory_.get()); root->SetActiveView(view_);
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); window_tree_host_.reset(new WindowTreeHostMojo(root, this));
window_tree_host_.reset(new WindowTreeHostMojo(gfx::Rect(800, 600), this));
window_tree_host_->InitHost(); window_tree_host_->InitHost();
window_tree_client_.reset( window_tree_client_.reset(
...@@ -250,26 +156,15 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate { ...@@ -250,26 +156,15 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate {
// WindowTreeHostMojoDelegate: // WindowTreeHostMojoDelegate:
virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE { virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE {
std::vector<unsigned char> data; view_->SetContents(bitmap);
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data);
void* memory = NULL;
ScopedSharedBufferHandle duped;
bool result = CreateMapAndDupSharedBuffer(data.size(),
&memory,
&shared_state_handle_,
&duped);
if (!result)
return;
memcpy(memory, &data[0], data.size());
view_manager_->SetViewContents(
view_id_, duped.Pass(), static_cast<uint32_t>(data.size()),
base::Bind(&OnSetViewContentsDone));
} }
virtual void Initialize() OVERRIDE { virtual void Initialize() OVERRIDE {
aura::Env::CreateInstance(true);
context_factory_.reset(new ContextFactoryMojo);
aura::Env::GetInstance()->set_context_factory(context_factory_.get());
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
} }
scoped_ptr<DemoWindowTreeClient> window_tree_client_; scoped_ptr<DemoWindowTreeClient> window_tree_client_;
...@@ -282,36 +177,17 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate { ...@@ -282,36 +177,17 @@ class AuraDemo : public Application, public WindowTreeHostMojoDelegate {
scoped_ptr<DemoWindowDelegate> delegate2_; scoped_ptr<DemoWindowDelegate> delegate2_;
scoped_ptr<DemoWindowDelegate> delegate21_; scoped_ptr<DemoWindowDelegate> delegate21_;
view_manager::ViewManagerService* view_manager_;
aura::Window* window1_; aura::Window* window1_;
aura::Window* window2_; aura::Window* window2_;
aura::Window* window21_; aura::Window* window21_;
uint32_t view_id_; view_manager::View* view_;
scoped_ptr<aura::WindowTreeHost> window_tree_host_; scoped_ptr<aura::WindowTreeHost> window_tree_host_;
ScopedSharedBufferHandle shared_state_handle_;
DISALLOW_COPY_AND_ASSIGN(AuraDemo); DISALLOW_COPY_AND_ASSIGN(AuraDemo);
}; };
void ViewManagerClientImpl::OnViewManagerConnectionEstablished(
uint16_t connection_id,
const String& creator_url,
uint32_t next_server_change_id,
mojo::Array<view_manager::NodeDataPtr> nodes) {
const uint32_t view_id = connection_id << 16 | 1;
client()->CreateView(view_id, base::Bind(&ViewManagerClientImpl::OnResult,
base::Unretained(this)));
client()->SetView(nodes[0]->node_id, view_id,
base::Bind(&ViewManagerClientImpl::OnResult,
base::Unretained(this)));
aura_demo_->SetRoot(client(), view_id);
}
} // namespace examples } // namespace examples
// static // static
......
...@@ -52,7 +52,7 @@ class Browser : public Application, ...@@ -52,7 +52,7 @@ class Browser : public Application,
public view_manager::ViewManagerDelegate, public view_manager::ViewManagerDelegate,
public views::TextfieldController { public views::TextfieldController {
public: public:
Browser() : view_manager_(NULL), view_(NULL) {} Browser() : view_manager_(NULL) {}
virtual ~Browser() { virtual ~Browser() {
} }
...@@ -65,7 +65,7 @@ class Browser : public Application, ...@@ -65,7 +65,7 @@ class Browser : public Application,
ConnectTo("mojo:mojo_window_manager", &navigator_host_); ConnectTo("mojo:mojo_window_manager", &navigator_host_);
} }
void CreateWidget(const gfx::Size& size) { void CreateWidget(view_manager::Node* node) {
views::Textfield* textfield = new views::Textfield; views::Textfield* textfield = new views::Textfield;
textfield->set_controller(this); textfield->set_controller(this);
...@@ -77,9 +77,9 @@ class Browser : public Application, ...@@ -77,9 +77,9 @@ class Browser : public Application,
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.native_widget = new NativeWidgetViewManager(widget, view_); params.native_widget = new NativeWidgetViewManager(widget, node);
params.delegate = widget_delegate; params.delegate = widget_delegate;
params.bounds = gfx::Rect(size.width(), size.height()); params.bounds = gfx::Rect(node->bounds().width(), node->bounds().height());
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
textfield->RequestFocus(); textfield->RequestFocus();
...@@ -90,10 +90,9 @@ class Browser : public Application, ...@@ -90,10 +90,9 @@ class Browser : public Application,
view_manager::Node* root) OVERRIDE { view_manager::Node* root) OVERRIDE {
// TODO: deal with OnRootAdded() being invoked multiple times. // TODO: deal with OnRootAdded() being invoked multiple times.
view_manager_ = view_manager; view_manager_ = view_manager;
view_ = view_manager::View::Create(view_manager_); root->SetActiveView(view_manager::View::Create(view_manager));
view_manager_->GetRoots().front()->SetActiveView(view_);
root->SetFocus(); root->SetFocus();
CreateWidget(root->bounds().size()); CreateWidget(root);
} }
// views::TextfieldController: // views::TextfieldController:
...@@ -114,7 +113,6 @@ class Browser : public Application, ...@@ -114,7 +113,6 @@ class Browser : public Application,
scoped_ptr<ViewsInit> views_init_; scoped_ptr<ViewsInit> views_init_;
view_manager::ViewManager* view_manager_; view_manager::ViewManager* view_manager_;
view_manager::View* view_;
navigation::NavigatorHostPtr navigator_host_; navigation::NavigatorHostPtr navigator_host_;
DISALLOW_COPY_AND_ASSIGN(Browser); DISALLOW_COPY_AND_ASSIGN(Browser);
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_geometry_lib', 'mojo_geometry_lib',
'mojo_system_impl', 'mojo_system_impl',
'mojo_view_manager_bindings', 'mojo_view_manager_lib',
], ],
'sources': [ 'sources': [
'examples/aura_demo/aura_demo.cc', 'examples/aura_demo/aura_demo.cc',
......
...@@ -431,7 +431,7 @@ ...@@ -431,7 +431,7 @@
'../ui/gl/gl.gyp:gl', '../ui/gl/gl.gyp:gl',
'../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', '../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu',
'mojo_application', 'mojo_application',
'mojo_aura_support', 'mojo_cc_support',
'mojo_common_lib', 'mojo_common_lib',
'mojo_environment_chromium', 'mojo_environment_chromium',
'mojo_geometry_bindings', 'mojo_geometry_bindings',
...@@ -456,6 +456,8 @@ ...@@ -456,6 +456,8 @@
'services/view_manager/root_view_manager.cc', 'services/view_manager/root_view_manager.cc',
'services/view_manager/root_view_manager.h', 'services/view_manager/root_view_manager.h',
'services/view_manager/root_view_manager_delegate.h', 'services/view_manager/root_view_manager_delegate.h',
'services/view_manager/screen_impl.cc',
'services/view_manager/screen_impl.h',
'services/view_manager/view.cc', 'services/view_manager/view.cc',
'services/view_manager/view.h', 'services/view_manager/view.h',
'services/view_manager/view_manager_export.h', 'services/view_manager/view_manager_export.h',
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "mojo/aura/screen_mojo.h"
#include "mojo/public/cpp/application/connect.h" #include "mojo/public/cpp/application/connect.h"
#include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/root_view_manager_delegate.h" #include "mojo/services/view_manager/root_view_manager_delegate.h"
#include "mojo/services/view_manager/screen_impl.h"
#include "mojo/services/view_manager/window_tree_host_impl.h" #include "mojo/services/view_manager/window_tree_host_impl.h"
#include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/focus_change_observer.h" #include "ui/aura/client/focus_change_observer.h"
...@@ -114,7 +114,7 @@ RootViewManager::RootViewManager(ServiceProvider* service_provider, ...@@ -114,7 +114,7 @@ RootViewManager::RootViewManager(ServiceProvider* service_provider,
: delegate_(delegate), : delegate_(delegate),
root_node_manager_(root_node), root_node_manager_(root_node),
in_setup_(false) { in_setup_(false) {
screen_.reset(ScreenMojo::Create()); screen_.reset(ScreenImpl::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
NativeViewportPtr viewport; NativeViewportPtr viewport;
ConnectToService(service_provider, ConnectToService(service_provider,
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/services/view_manager/screen_impl.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect_conversions.h"
namespace mojo {
namespace view_manager {
namespace service {
// static
gfx::Screen* ScreenImpl::Create() {
return new ScreenImpl(gfx::Rect(0, 0, 800, 600));
}
ScreenImpl::~ScreenImpl() {
}
bool ScreenImpl::IsDIPEnabled() {
NOTIMPLEMENTED();
return true;
}
gfx::Point ScreenImpl::GetCursorScreenPoint() {
NOTIMPLEMENTED();
return gfx::Point();
}
gfx::NativeWindow ScreenImpl::GetWindowUnderCursor() {
return GetWindowAtScreenPoint(GetCursorScreenPoint());
}
gfx::NativeWindow ScreenImpl::GetWindowAtScreenPoint(const gfx::Point& point) {
NOTIMPLEMENTED();
return NULL;
}
int ScreenImpl::GetNumDisplays() const {
return 1;
}
std::vector<gfx::Display> ScreenImpl::GetAllDisplays() const {
return std::vector<gfx::Display>(1, display_);
}
gfx::Display ScreenImpl::GetDisplayNearestWindow(
gfx::NativeWindow window) const {
return display_;
}
gfx::Display ScreenImpl::GetDisplayNearestPoint(const gfx::Point& point) const {
return display_;
}
gfx::Display ScreenImpl::GetDisplayMatching(const gfx::Rect& match_rect) const {
return display_;
}
gfx::Display ScreenImpl::GetPrimaryDisplay() const {
return display_;
}
void ScreenImpl::AddObserver(gfx::DisplayObserver* observer) {
}
void ScreenImpl::RemoveObserver(gfx::DisplayObserver* observer) {
}
ScreenImpl::ScreenImpl(const gfx::Rect& screen_bounds) {
static int64 synthesized_display_id = 2000;
display_.set_id(synthesized_display_id++);
display_.SetScaleAndBounds(1.0f, screen_bounds);
}
} // namespace service
} // namespace view_manager
} // namespace mojo
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_SERVICES_VIEW_MANAGER_SCREEN_IMPL_H_
#define MOJO_SERVICES_VIEW_MANAGER_SCREEN_IMPL_H_
#include "base/compiler_specific.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
namespace gfx {
class Rect;
class Transform;
}
namespace mojo {
namespace view_manager {
namespace service {
// A minimal implementation of gfx::Screen for the view manager.
class ScreenImpl : public gfx::Screen {
public:
static gfx::Screen* Create();
virtual ~ScreenImpl();
protected:
// gfx::Screen overrides:
virtual bool IsDIPEnabled() OVERRIDE;
virtual gfx::Point GetCursorScreenPoint() OVERRIDE;
virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE;
virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
OVERRIDE;
virtual int GetNumDisplays() const OVERRIDE;
virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE;
virtual gfx::Display GetDisplayNearestWindow(
gfx::NativeView view) const OVERRIDE;
virtual gfx::Display GetDisplayNearestPoint(
const gfx::Point& point) const OVERRIDE;
virtual gfx::Display GetDisplayMatching(
const gfx::Rect& match_rect) const OVERRIDE;
virtual gfx::Display GetPrimaryDisplay() const OVERRIDE;
virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE;
virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE;
private:
explicit ScreenImpl(const gfx::Rect& screen_bounds);
gfx::Display display_;
DISALLOW_COPY_AND_ASSIGN(ScreenImpl);
};
} // namespace service
} // namespace view_manager
} // namespace mojo
#endif // MOJO_SERVICES_VIEW_MANAGER_SCREEN_IMPL_H_
...@@ -86,11 +86,11 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, ...@@ -86,11 +86,11 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
} // namespace } // namespace
NativeWidgetViewManager::NativeWidgetViewManager( NativeWidgetViewManager::NativeWidgetViewManager(
views::internal::NativeWidgetDelegate* delegate, view_manager::View* view) views::internal::NativeWidgetDelegate* delegate, view_manager::Node* node)
: NativeWidgetAura(delegate), : NativeWidgetAura(delegate),
view_(view) { node_(node) {
view_->AddObserver(this); node_->active_view()->AddObserver(this);
window_tree_host_.reset(new WindowTreeHostMojo(gfx::Rect(800, 600), this)); window_tree_host_.reset(new WindowTreeHostMojo(node_, this));
window_tree_host_->InitHost(); window_tree_host_->InitHost();
ime_filter_.reset( ime_filter_.reset(
...@@ -106,7 +106,7 @@ NativeWidgetViewManager::NativeWidgetViewManager( ...@@ -106,7 +106,7 @@ NativeWidgetViewManager::NativeWidgetViewManager(
} }
NativeWidgetViewManager::~NativeWidgetViewManager() { NativeWidgetViewManager::~NativeWidgetViewManager() {
view_->RemoveObserver(this); node_->active_view()->RemoveObserver(this);
} }
void NativeWidgetViewManager::InitNativeWidget( void NativeWidgetViewManager::InitNativeWidget(
...@@ -118,7 +118,7 @@ void NativeWidgetViewManager::InitNativeWidget( ...@@ -118,7 +118,7 @@ void NativeWidgetViewManager::InitNativeWidget(
void NativeWidgetViewManager::CompositorContentsChanged( void NativeWidgetViewManager::CompositorContentsChanged(
const SkBitmap& bitmap) { const SkBitmap& bitmap) {
view_->SetContents(bitmap); node_->active_view()->SetContents(bitmap);
} }
void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view, void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MOJO_VIEWS_NATIVE_WIDGET_VIEW_MANAGER_H_ #define MOJO_VIEWS_NATIVE_WIDGET_VIEW_MANAGER_H_
#include "mojo/aura/window_tree_host_mojo_delegate.h" #include "mojo/aura/window_tree_host_mojo_delegate.h"
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h" #include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "ui/views/widget/native_widget_aura.h" #include "ui/views/widget/native_widget_aura.h"
...@@ -25,10 +26,11 @@ class WindowTreeHostMojo; ...@@ -25,10 +26,11 @@ class WindowTreeHostMojo;
class NativeWidgetViewManager : public views::NativeWidgetAura, class NativeWidgetViewManager : public views::NativeWidgetAura,
public WindowTreeHostMojoDelegate, public WindowTreeHostMojoDelegate,
public view_manager::ViewObserver { public view_manager::ViewObserver,
public view_manager::NodeObserver {
public: public:
NativeWidgetViewManager(views::internal::NativeWidgetDelegate* delegate, NativeWidgetViewManager(views::internal::NativeWidgetDelegate* delegate,
view_manager::View* view); view_manager::Node* node);
virtual ~NativeWidgetViewManager(); virtual ~NativeWidgetViewManager();
private: private:
...@@ -49,7 +51,7 @@ class NativeWidgetViewManager : public views::NativeWidgetAura, ...@@ -49,7 +51,7 @@ class NativeWidgetViewManager : public views::NativeWidgetAura,
scoped_ptr<ui::internal::InputMethodDelegate> ime_filter_; scoped_ptr<ui::internal::InputMethodDelegate> ime_filter_;
view_manager::View* view_; view_manager::Node* node_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetViewManager); DISALLOW_COPY_AND_ASSIGN(NativeWidgetViewManager);
}; };
......
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