Skip to content

Commit

Permalink
Wires up necessary pieces to use views with view_manager
Browse files Browse the repository at this point in the history
The browser side obviously has to change rather extensively, but the
rest work on both linux and windows.

BUG=365012
TEST=none
R=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276070 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Jun 10, 2014
1 parent 6e0990e commit 33bc2bc
Show file tree
Hide file tree
Showing 19 changed files with 612 additions and 1 deletion.
26 changes: 26 additions & 0 deletions mojo/aura/aura_init.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 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/aura/aura_init.h"

#include "mojo/aura/context_factory_mojo.h"
#include "mojo/aura/screen_mojo.h"
#include "ui/aura/env.h"

namespace mojo {

AuraInit::AuraInit() {
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());
}

AuraInit::~AuraInit() {
}

} // namespace mojo
33 changes: 33 additions & 0 deletions mojo/aura/aura_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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_AURA_AURA_INIT_MOJO_H_
#define MOJO_AURA_AURA_INIT_MOJO_H_

#include "base/memory/scoped_ptr.h"

namespace ui {
class ContextFactory;
}

namespace mojo {

class ScreenMojo;

// Sets up necessary state for aura when run with the viewmanager.
class AuraInit {
public:
AuraInit();
~AuraInit();

private:
scoped_ptr<ui::ContextFactory> context_factory_;
scoped_ptr<ScreenMojo> screen_;

DISALLOW_COPY_AND_ASSIGN(AuraInit);
};

} // namespace mojo

#endif // MOJO_AURA_AURA_INIT_MOJO_H_
1 change: 1 addition & 0 deletions mojo/aura/window_tree_host_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ gfx::Rect WindowTreeHostMojo::GetBounds() const {
}

void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
window()->SetBounds(gfx::Rect(bounds.size()));
}

gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
Expand Down
4 changes: 4 additions & 0 deletions mojo/aura/window_tree_host_mojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource {
// delegate.
void SetContents(const SkBitmap& contents);

ui::EventDispatchDetails SendEventToProcessor(ui::Event* event) {
return ui::EventSource::SendEventToProcessor(event);
}

private:
// WindowTreeHost:
virtual ui::EventSource* GetEventSource() OVERRIDE;
Expand Down
10 changes: 10 additions & 0 deletions mojo/examples/browser/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include_rules = [
"+cc",
"+skia/ext",
"+ui/aura",
"+ui/base/hit_test.h",
"+ui/compositor",
"+ui/events",
"+ui/gfx",
"+ui/views",
]
85 changes: 85 additions & 0 deletions mojo/examples/browser/browser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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 "base/basictypes.h"
#include "mojo/public/cpp/application/application.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/cpp/view_manager/view_observer.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
#include "mojo/views/native_widget_view_manager.h"
#include "mojo/views/views_init.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"

namespace mojo {
namespace examples {

// This is the basics of creating a views widget with a textfield.
// TODO: cleanup!
class Browser : public Application, public view_manager::ViewManagerDelegate {
public:
Browser() : view_manager_(NULL), view_(NULL) {}

virtual ~Browser() {
}

private:
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
views_init_.reset(new ViewsInit);

view_manager::ViewManager::Create(this, this);
}

void CreateWidget() {
views::Textfield* textfield = new views::Textfield;

views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
widget_delegate->GetContentsView()->AddChildView(textfield);
widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout);

views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.native_widget = new NativeWidgetViewManager(widget, view_);
params.delegate = widget_delegate;
params.bounds = gfx::Rect(200, 200);
widget->Init(params);
widget->Show();
textfield->RequestFocus();
}

// view_manager::ViewManagerDelegate:
virtual void OnRootAdded(view_manager::ViewManager* view_manager,
view_manager::ViewTreeNode* root) OVERRIDE {
// TODO: deal with OnRootAdded() being invoked multiple times.
view_manager_ = view_manager;
view_ = view_manager::View::Create(view_manager_);
view_manager_->GetRoots().front()->SetActiveView(view_);

CreateWidget();
}
virtual void OnRootRemoved(view_manager::ViewManager* view_manager,
view_manager::ViewTreeNode* root) OVERRIDE {
}

scoped_ptr<ViewsInit> views_init_;

view_manager::ViewManager* view_manager_;
view_manager::View* view_;

DISALLOW_COPY_AND_ASSIGN(Browser);
};

} // namespace examples

// static
Application* Application::Create() {
return new examples::Browser;
}

} // namespace mojo
2 changes: 2 additions & 0 deletions mojo/examples/window_manager/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class WindowManager : public Application,
CreateWindow("mojo:mojo_embedded_app");
else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON)
CreateWindow("mojo:mojo_nesting_app");
else if (event->flags & ui::EF_MIDDLE_MOUSE_BUTTON)
CreateWindow("mojo:mojo_browser");
}
}

Expand Down
28 changes: 27 additions & 1 deletion mojo/mojo.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'dependencies': [
'mojo_aura_demo',
'mojo_aura_demo_init',
'mojo_browser',
'mojo_demo_launcher',
'mojo_embedded_app',
'mojo_nesting_app',
Expand Down Expand Up @@ -888,16 +889,18 @@
'dependencies': [
'../cc/cc.gyp:cc',
'../ui/aura/aura.gyp:aura',
'../ui/compositor/compositor.gyp:compositor',
'../ui/events/events.gyp:events',
'../ui/events/events.gyp:events_base',
'../ui/compositor/compositor.gyp:compositor',
'../ui/gl/gl.gyp:gl',
'../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu',
'mojo_cc_support',
'mojo_gles2',
'mojo_native_viewport_bindings',
],
'sources': [
'aura/aura_init.cc',
'aura/aura_init.h',
'aura/context_factory_mojo.cc',
'aura/context_factory_mojo.h',
'aura/screen_mojo.cc',
Expand All @@ -907,6 +910,29 @@
'aura/window_tree_host_mojo_delegate.h',
],
},
{
'target_name': 'mojo_views_support',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'../base/base.gyp:base_i18n',
'../skia/skia.gyp:skia',
'../skia/skia.gyp:skia',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
'../ui/aura/aura.gyp:aura',
'../ui/base/ui_base.gyp:ui_base',
'../ui/views/views.gyp:views',
'../ui/wm/wm.gyp:wm',
'mojo_aura_support',
],
'sources': [
'views/native_widget_view_manager.cc',
'views/native_widget_view_manager.h',
'views/views_init.cc',
'views/views_init.h',
],
},
],
}],
],
Expand Down
33 changes: 33 additions & 0 deletions mojo/mojo_examples.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,39 @@
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{
'target_name': 'mojo_browser',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../cc/cc.gyp:cc',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
'../ui/aura/aura.gyp:aura',
'../ui/base/ui_base.gyp:ui_base',
'../ui/compositor/compositor.gyp:compositor',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/resources/ui_resources.gyp:ui_resources',
'../ui/resources/ui_resources.gyp:ui_test_pak',
'../ui/views/views.gyp:views',
'mojo_application',
'mojo_aura_support',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_input_events_lib',
'mojo_system_impl',
'mojo_views_support',
'mojo_view_manager_bindings',
'mojo_view_manager_lib',
],
'sources': [
'examples/browser/browser.cc',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{
'target_name': 'package_mojo_aura_demo',
'variables': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_
#define MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_

#include "base/memory/scoped_ptr.h"
#include "mojo/services/public/cpp/input_events/mojo_input_events_export.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "ui/events/event.h"
Expand All @@ -17,6 +18,13 @@ class MOJO_INPUT_EVENTS_EXPORT TypeConverter<EventPtr, ui::Event> {
static EventPtr ConvertFrom(const ui::Event& input);
};

template<>
class MOJO_INPUT_EVENTS_EXPORT TypeConverter<EventPtr,
scoped_ptr<ui::Event> > {
public:
static scoped_ptr<ui::Event> ConvertTo(const EventPtr& input);
};

} // namespace mojo

#endif // MOJO_SERVICES_PUBLIC_CPP_INPUT_EVENTS_INPUT_EVENTS_TYPE_CONVERTERS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,27 @@ EventPtr TypeConverter<EventPtr, ui::Event>::ConvertFrom(
return event.Pass();
}

// static
scoped_ptr<ui::Event>
TypeConverter<EventPtr, scoped_ptr<ui::Event> >::ConvertTo(
const EventPtr& input) {
scoped_ptr<ui::Event> ui_event;
switch (input->action) {
case ui::ET_KEY_PRESSED:
case ui::ET_KEY_RELEASED:
ui_event.reset(new ui::KeyEvent(
static_cast<ui::EventType>(input->action),
static_cast<ui::KeyboardCode>(
input->key_data->key_code),
input->flags,
input->key_data->is_char));
break;
default:
// TODO: support other types.
NOTIMPLEMENTED();
}
// TODO: need to support time_stamp.
return ui_event.Pass();
}

} // namespace mojo
Loading

0 comments on commit 33bc2bc

Please sign in to comment.