Commit 74d9b7a7 authored by sky@chromium.org's avatar sky@chromium.org

Moves view_manager files to view_manager directory

The WindowTreeHost and ContextFactory implementations are specific to
the view manager and should be moved there. No one else should be
using these directly. I'm also nuking launcher as it was temporary and
the only other place that was using this code.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275453 0039d316-1c4b-4281-b951-d872f2087c98
parent 877dd945
include_rules = [
"+cc",
"+gpu/command_buffer/client",
"+ui/aura",
"+ui/base",
"+ui/compositor",
"+ui/events",
"+ui/gfx",
"+ui/gl",
"+ui/views",
"+ui/wm",
"+webkit/common/gpu",
]
// Copyright 2013 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 <stdio.h>
#include <string>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/i18n/icu_util.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/examples/launcher/launcher.mojom.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/native_viewport/native_viewport.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_focus_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_delegate.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/default_activation_client.h"
#include "url/gurl.h"
#if defined(WIN32)
#if !defined(CDECL)
#define CDECL __cdecl
#endif
#define LAUNCHER_EXPORT __declspec(dllexport)
#else
#define CDECL
#define LAUNCHER_EXPORT __attribute__((visibility("default")))
#endif
namespace mojo {
namespace examples {
class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
public ui::EventHandler {
public:
explicit MinimalInputEventFilter(aura::Window* root)
: root_(root),
input_method_(ui::CreateInputMethod(this,
gfx::kNullAcceleratedWidget)) {
ui::InitializeInputMethod();
input_method_->Init(true);
root_->AddPreTargetHandler(this);
root_->SetProperty(aura::client::kRootWindowInputMethodKey,
input_method_.get());
}
virtual ~MinimalInputEventFilter() {
root_->RemovePreTargetHandler(this);
root_->SetProperty(aura::client::kRootWindowInputMethodKey,
static_cast<ui::InputMethod*>(NULL));
}
private:
// ui::EventHandler:
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
// See the comment in InputMethodEventFilter::OnKeyEvent() for details.
if (event->IsTranslated()) {
event->SetTranslated(false);
} else {
if (input_method_->DispatchKeyEvent(*event))
event->StopPropagation();
}
}
// ui::internal::InputMethodDelegate:
virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
// See the comment in InputMethodEventFilter::DispatchKeyEventPostIME() for
// details.
ui::KeyEvent aura_event(event);
aura_event.SetTranslated(true);
ui::EventDispatchDetails details =
root_->GetHost()->dispatcher()->OnEventFromSource(&aura_event);
return aura_event.handled() || details.dispatcher_destroyed;
}
aura::Window* root_;
scoped_ptr<ui::InputMethod> input_method_;
DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter);
};
class LauncherWindowTreeClient : public aura::client::WindowTreeClient {
public:
explicit LauncherWindowTreeClient(aura::Window* window) : window_(window) {
aura::client::SetWindowTreeClient(window_, this);
}
virtual ~LauncherWindowTreeClient() {
aura::client::SetWindowTreeClient(window_, NULL);
}
// Overridden from aura::client::WindowTreeClient:
virtual aura::Window* GetDefaultParent(aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) OVERRIDE {
return window_;
}
private:
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(LauncherWindowTreeClient);
};
// Called when the user has submitted a URL by pressing Enter.
class URLReceiver {
public:
virtual void OnURLEntered(const std::string& url_text) = 0;
protected:
virtual ~URLReceiver() {}
};
class LauncherController : public views::TextfieldController {
public:
explicit LauncherController(URLReceiver* url_receiver)
: url_receiver_(url_receiver) {}
void InitInWindow(aura::Window* parent) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.parent = parent;
params.bounds = parent->bounds();
params.activatable = views::Widget::InitParams::ACTIVATABLE_YES;
widget->Init(params);
views::View* container = new views::View;
container->set_background(
views::Background::CreateSolidBackground(SK_ColorYELLOW));
container->SetBorder(
views::Border::CreateEmptyBorder(10, 10, 10, 10));
container->SetLayoutManager(new views::FillLayout);
widget->SetContentsView(container);
views::Textfield* textfield = new views::Textfield;
textfield->set_controller(this);
container->AddChildView(textfield);
textfield->RequestFocus();
container->Layout();
widget->Show();
}
private:
// Overridden from views::TextfieldController:
virtual bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) OVERRIDE {
if (key_event.key_code() == ui::VKEY_RETURN) {
GURL url(sender->text());
printf("Enter pressed with URL: %s\n", url.spec().c_str());
url_receiver_->OnURLEntered(url.spec());
}
return false;
}
URLReceiver* url_receiver_;
DISALLOW_COPY_AND_ASSIGN(LauncherController);
};
class LauncherImpl : public InterfaceImpl<Launcher>,
public URLReceiver {
public:
explicit LauncherImpl(Application* app)
: app_(app),
launcher_controller_(this),
pending_show_(false) {
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
NativeViewportPtr viewport;
app_->ConnectTo("mojo:mojo_native_viewport_service", &viewport);
window_tree_host_.reset(new WindowTreeHostMojo(
viewport.Pass(), gfx::Rect(50, 50, 450, 60),
base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this))));
}
private:
// Overridden from Launcher:
virtual void Show() OVERRIDE {
if (!window_tree_host_.get()) {
pending_show_ = true;
return;
}
window_tree_host_->Show();
}
virtual void Hide() OVERRIDE {
window_tree_host_->Hide();
}
// Overridden from URLReceiver:
virtual void OnURLEntered(const std::string& url_text) OVERRIDE {
client()->OnURLEntered(String::From(url_text));
}
void HostContextCreated() {
window_tree_host_->InitHost();
window_tree_host_->window()->SetBounds(gfx::Rect(450, 60));
focus_client_.reset(new aura::test::TestFocusClient());
aura::client::SetFocusClient(window_tree_host_->window(),
focus_client_.get());
new wm::DefaultActivationClient(window_tree_host_->window());
capture_client_.reset(
new aura::client::DefaultCaptureClient(window_tree_host_->window()));
ime_filter_.reset(new MinimalInputEventFilter(window_tree_host_->window()));
window_tree_client_.reset(
new LauncherWindowTreeClient(window_tree_host_->window()));
launcher_controller_.InitInWindow(window_tree_host_->window());
if (pending_show_) {
pending_show_ = false;
Show();
}
}
Application* app_;
scoped_ptr<ScreenMojo> screen_;
scoped_ptr<LauncherWindowTreeClient> window_tree_client_;
scoped_ptr<aura::client::FocusClient> focus_client_;
scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
scoped_ptr<ui::EventHandler> ime_filter_;
LauncherController launcher_controller_;
scoped_ptr<aura::WindowTreeHost> window_tree_host_;
bool pending_show_;
};
} // namespace examples
} // namespace mojo
extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain(
MojoHandle service_provider_handle) {
base::CommandLine::Init(0, NULL);
base::AtExitManager at_exit;
base::i18n::InitializeICU();
base::FilePath pak_dir;
PathService::Get(base::DIR_MODULE, &pak_dir);
base::FilePath pak_file;
pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak"));
ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
base::MessageLoop loop;
mojo::GLES2Initializer gles2;
// TODO(beng): This crashes in a DCHECK on X11 because this thread's
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance(true);
mojo::Application app(service_provider_handle);
app.AddService<mojo::examples::LauncherImpl>(&app);
loop.Run();
return MOJO_RESULT_OK;
}
// 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.
module mojo {
[Client=LauncherClient]
interface Launcher {
Show();
Hide();
};
interface LauncherClient {
// Called when the user has requested |url| be launched.
OnURLEntered(string url);
};
}
include_rules = [
"+ui/events",
"+ui/gfx",
]
// 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/at_exit.h"
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.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_observer.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/canvas.h"
namespace mojo {
namespace examples {
namespace {
std::string EventNameForAction(int32_t action) {
switch (action) {
case ui::ET_MOUSE_MOVED:
return "MouseMoved";
case ui::ET_MOUSE_PRESSED:
return "MousePressed";
case ui::ET_MOUSE_RELEASED:
return "MouseReleased";
case ui::ET_MOUSE_DRAGGED:
return "MouseDragged";
case ui::ET_KEY_PRESSED:
return "KeyPressed";
case ui::ET_KEY_RELEASED:
return "KeyReleased";
case ui::ET_TOUCH_PRESSED:
return "TouchPressed";
case ui::ET_TOUCH_RELEASED:
return "TouchReleased";
case ui::ET_TOUCH_MOVED:
return "TouchMoved";
}
return "Other";
}
} // namespace
class SampleApp : public Application, public mojo::view_manager::ViewObserver {
public:
SampleApp() {}
virtual ~SampleApp() {}
virtual void Initialize() MOJO_OVERRIDE {
view_manager_.reset(new view_manager::ViewManager(service_provider()));
view_manager_->Init();
view_manager::ViewTreeNode* node1 =
view_manager::ViewTreeNode::Create(view_manager_.get());
node1->SetBounds(gfx::Rect(800, 600));
view_manager::ViewTreeNode* node11 =
view_manager::ViewTreeNode::Create(view_manager_.get());
node11->SetBounds(gfx::Rect(800, 600));
view_manager::View* view11 =
view_manager::View::Create(view_manager_.get());
node11->SetActiveView(view11);
view_manager_->roots().front()->AddChild(node1);
node1->AddChild(node11);
view11->SetColor(SK_ColorRED);
view11->AddObserver(this);
}
private:
virtual void OnViewInputEvent(mojo::view_manager::View* view,
EventPtr event) OVERRIDE {
std::string event_name = EventNameForAction(event->action);
if (!event->location.is_null()) {
LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d",
event_name.c_str(),
event->location->x,
event->location->y);
} else {
LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str());
}
}
// SampleApp creates a ViewManager and a trivial node hierarchy.
scoped_ptr<view_manager::ViewManager> view_manager_;
DISALLOW_COPY_AND_ASSIGN(SampleApp);
};
} // namespace examples
// static
Application* Application::Create() {
return new examples::SampleApp();
}
} // namespace mojo
......@@ -66,7 +66,6 @@
'dependencies': [
'mojo_aura_demo',
'mojo_aura_demo_init',
'mojo_launcher',
'mojo_demo_launcher',
'mojo_embedded_app',
'mojo_window_manager',
......@@ -898,12 +897,8 @@
'mojo_native_viewport_bindings',
],
'sources': [
'aura/context_factory_mojo.cc',
'aura/context_factory_mojo.h',
'aura/screen_mojo.cc',
'aura/screen_mojo.h',
'aura/window_tree_host_mojo.cc',
'aura/window_tree_host_mojo.h',
],
},
],
......
......@@ -242,56 +242,6 @@
},
'includes': [ 'build/package_app.gypi' ],
},
{
'target_name': 'mojo_launcher_bindings',
'type': 'static_library',
'sources': [
'examples/launcher/launcher.mojom',
],
'includes': [ 'public/tools/bindings/mojom_bindings_generator.gypi' ],
'export_dependent_settings': [
'mojo_cpp_bindings',
],
'dependencies': [
'mojo_cpp_bindings',
],
},
{
'target_name': 'mojo_launcher',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../base/base.gyp:base_i18n',
'../base/base.gyp:test_support_base',
'../ui/aura/aura.gyp:aura',
'../ui/aura/aura.gyp:aura_test_support',
'../ui/base/ui_base.gyp:ui_base',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/views/views.gyp:views',
'../ui/wm/wm.gyp:wm',
'../url/url.gyp:url_lib',
'mojo_application',
'mojo_aura_support',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2',
'mojo_launcher_bindings',
'mojo_system_impl',
],
'sources': [
'examples/launcher/launcher.cc',
],
},
{
'target_name': 'package_mojo_launcher',
'variables': {
'app_name': 'mojo_launcher',
},
'includes': [ 'build/package_app.gypi' ],
},
{
'target_name': 'mojo_demo_launcher',
'type': 'shared_library',
......
......@@ -326,11 +326,17 @@
'type': '<(component)',
'dependencies': [
'../base/base.gyp:base',
'../cc/cc.gyp:cc',
'../skia/skia.gyp:skia',
'../ui/aura/aura.gyp:aura',
'../ui/base/ui_base.gyp:ui_base',
'../ui/compositor/compositor.gyp:compositor',
'../ui/events/events.gyp:events',
'../ui/events/events.gyp:events_base',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl',
'../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu',
'mojo_application',
'mojo_aura_support',
'mojo_common_lib',
......@@ -340,7 +346,6 @@
'mojo_gles2',
'mojo_input_events_bindings',
'mojo_input_events_lib',
'mojo_launcher_bindings',
'mojo_native_viewport_bindings',
'mojo_system_impl',
'mojo_view_manager_bindings',
......@@ -365,6 +370,10 @@
'services/view_manager/view_manager_init_connection.cc',
'services/view_manager/view_manager_init_connection.h',
'services/view_manager/view_manager_export.h',
'services/view_manager/context_factory_impl.cc',
'services/view_manager/context_factory_impl.h',
'services/view_manager/window_tree_host_impl.cc',
'services/view_manager/window_tree_host_impl.h',
],
'defines': [
'MOJO_VIEW_MANAGER_IMPLEMENTATION',
......
include_rules = [
"+cc",
"+mojo/aura",
"+mojo/cc",
"+mojo/geometry",
"+mojo/services",
"+third_party/skia",
"+ui/aura",
"+ui/base/cursor/cursor.h",
"+ui/base/hit_test.h",
"+ui/compositor",
"+ui/events",
"+ui/gfx",
"+ui/gl",
"+webkit/common/gpu",
]
specific_include_rules = {
......
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/aura/context_factory_mojo.h"
#include "mojo/services/view_manager/context_factory_impl.h"
#include "cc/output/output_surface.h"
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/cc/context_provider_mojo.h"
#include "ui/compositor/reflector.h"
#include "ui/gl/gl_implementation.h"
......@@ -15,34 +14,36 @@
#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
namespace mojo {
namespace view_manager {
namespace service {
ContextFactoryMojo::ContextFactoryMojo(
ContextFactoryImpl::ContextFactoryImpl(
ScopedMessagePipeHandle command_buffer_handle)
: command_buffer_handle_(command_buffer_handle.Pass()) {
}
ContextFactoryMojo::~ContextFactoryMojo() {
ContextFactoryImpl::~ContextFactoryImpl() {
}
scoped_ptr<cc::OutputSurface> ContextFactoryMojo::CreateOutputSurface(
scoped_ptr<cc::OutputSurface> ContextFactoryImpl::CreateOutputSurface(
ui::Compositor* compositor, bool software_fallback) {
return make_scoped_ptr(
new cc::OutputSurface(
new ContextProviderMojo(command_buffer_handle_.Pass())));
}
scoped_refptr<ui::Reflector> ContextFactoryMojo::CreateReflector(
scoped_refptr<ui::Reflector> ContextFactoryImpl::CreateReflector(
ui::Compositor* mirroed_compositor,
ui::Layer* mirroring_layer) {
return NULL;
}
void ContextFactoryMojo::RemoveReflector(
void ContextFactoryImpl::RemoveReflector(
scoped_refptr<ui::Reflector> reflector) {
}
scoped_refptr<cc::ContextProvider>
ContextFactoryMojo::SharedMainThreadContextProvider() {
ContextFactoryImpl::SharedMainThreadContextProvider() {
if (!shared_main_thread_contexts_ ||
shared_main_thread_contexts_->DestroyedOnMainThread()) {
bool lose_context_when_out_of_memory = false;
......@@ -56,17 +57,19 @@ ContextFactoryMojo::SharedMainThreadContextProvider() {
return shared_main_thread_contexts_;
}
void ContextFactoryMojo::RemoveCompositor(ui::Compositor* compositor) {
void ContextFactoryImpl::RemoveCompositor(ui::Compositor* compositor) {
}
bool ContextFactoryMojo::DoesCreateTestContexts() { return false; }
bool ContextFactoryImpl::DoesCreateTestContexts() { return false; }
cc::SharedBitmapManager* ContextFactoryMojo::GetSharedBitmapManager() {
cc::SharedBitmapManager* ContextFactoryImpl::GetSharedBitmapManager() {
return NULL;
}
base::MessageLoopProxy* ContextFactoryMojo::GetCompositorMessageLoop() {
base::MessageLoopProxy* ContextFactoryImpl::GetCompositorMessageLoop() {
return NULL;
}
} // namespace service
} // namespace view_manager
} // namespace mojo
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_AURA_CONTEXT_FACTORY_MOJO_H_
#define MOJO_AURA_CONTEXT_FACTORY_MOJO_H_
#ifndef MOJO_SERVICES_VIEW_MANAGER_CONTEXT_FACTORY_IMPL_H_
#define MOJO_SERVICES_VIEW_MANAGER_CONTEXT_FACTORY_IMPL_H_
#include "mojo/public/cpp/system/core.h"
#include "ui/compositor/compositor.h"
......@@ -15,12 +15,14 @@ class ContextProviderInProcess;
}
namespace mojo {
namespace view_manager {
namespace service {
// The default factory that creates in-process contexts.
class ContextFactoryMojo : public ui::ContextFactory {
class ContextFactoryImpl : public ui::ContextFactory {
public:
explicit ContextFactoryMojo(ScopedMessagePipeHandle command_buffer_handle);
virtual ~ContextFactoryMojo();
explicit ContextFactoryImpl(ScopedMessagePipeHandle command_buffer_handle);
virtual ~ContextFactoryImpl();
// ContextFactory implementation
virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
......@@ -44,9 +46,11 @@ class ContextFactoryMojo : public ui::ContextFactory {
ScopedMessagePipeHandle command_buffer_handle_;
DISALLOW_COPY_AND_ASSIGN(ContextFactoryMojo);
DISALLOW_COPY_AND_ASSIGN(ContextFactoryImpl);
};
} // namespace service
} // namespace view_manager
} // namespace mojo
#endif // MOJO_AURA_CONTEXT_FACTORY_MOJO_H_
#endif // MOJO_SERVICES_VIEW_MANAGER_CONTEXT_FACTORY_IMPL_H_
......@@ -6,10 +6,10 @@
#include "base/auto_reset.h"
#include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/public/cpp/application/connect.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/window_tree_host_impl.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
......@@ -59,7 +59,7 @@ RootViewManager::RootViewManager(ServiceProvider* service_provider,
ConnectToService(service_provider,
"mojo:mojo_native_viewport_service",
&viewport);
window_tree_host_.reset(new WindowTreeHostMojo(
window_tree_host_.reset(new WindowTreeHostImpl(
viewport.Pass(),
gfx::Rect(800, 600),
base::Bind(&RootViewManager::OnCompositorCreated,
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/services/view_manager/window_tree_host_impl.h"
#include "mojo/aura/context_factory_mojo.h"
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/view_manager/context_factory_impl.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
......@@ -17,14 +17,17 @@
#include "ui/gfx/geometry/rect.h"
namespace mojo {
namespace view_manager {
namespace service {
// TODO(sky): nuke this. It shouldn't be static.
// static
mojo::ContextFactoryMojo* WindowTreeHostMojo::context_factory_ = NULL;
ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL;
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, public:
// WindowTreeHostImpl, public:
WindowTreeHostMojo::WindowTreeHostMojo(
WindowTreeHostImpl::WindowTreeHostImpl(
NativeViewportPtr viewport,
const gfx::Rect& bounds,
const base::Callback<void()>& compositor_created_callback)
......@@ -43,105 +46,105 @@ WindowTreeHostMojo::WindowTreeHostMojo(
delete context_factory_;
context_factory_ = NULL;
}
context_factory_ = new ContextFactoryMojo(pipe.handle1.Pass());
context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass());
aura::Env::GetInstance()->set_context_factory(context_factory_);
CHECK(context_factory_) << "No GL bindings.";
}
WindowTreeHostMojo::~WindowTreeHostMojo() {
WindowTreeHostImpl::~WindowTreeHostImpl() {
DestroyCompositor();
DestroyDispatcher();
}
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, aura::WindowTreeHost implementation:
// WindowTreeHostImpl, aura::WindowTreeHost implementation:
ui::EventSource* WindowTreeHostMojo::GetEventSource() {
ui::EventSource* WindowTreeHostImpl::GetEventSource() {
return this;
}
gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() {
gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() {
NOTIMPLEMENTED() << "GetAcceleratedWidget";
return gfx::kNullAcceleratedWidget;
}
void WindowTreeHostMojo::Show() {
void WindowTreeHostImpl::Show() {
window()->Show();
native_viewport_->Show();
}
void WindowTreeHostMojo::Hide() {
void WindowTreeHostImpl::Hide() {
native_viewport_->Hide();
window()->Hide();
}
gfx::Rect WindowTreeHostMojo::GetBounds() const {
gfx::Rect WindowTreeHostImpl::GetBounds() const {
return bounds_;
}
void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
void WindowTreeHostImpl::SetBounds(const gfx::Rect& bounds) {
native_viewport_->SetBounds(Rect::From(bounds));
}
gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
gfx::Point WindowTreeHostImpl::GetLocationOnNativeScreen() const {
return gfx::Point(0, 0);
}
void WindowTreeHostMojo::SetCapture() {
void WindowTreeHostImpl::SetCapture() {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::ReleaseCapture() {
void WindowTreeHostImpl::ReleaseCapture() {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::PostNativeEvent(
void WindowTreeHostImpl::PostNativeEvent(
const base::NativeEvent& native_event) {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::OnDeviceScaleFactorChanged(float device_scale_factor) {
void WindowTreeHostImpl::OnDeviceScaleFactorChanged(float device_scale_factor) {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) {
void WindowTreeHostImpl::SetCursorNative(gfx::NativeCursor cursor) {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) {
void WindowTreeHostImpl::MoveCursorToNative(const gfx::Point& location) {
NOTIMPLEMENTED();
}
void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) {
void WindowTreeHostImpl::OnCursorVisibilityChangedNative(bool show) {
NOTIMPLEMENTED();
}
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, ui::EventSource implementation:
// WindowTreeHostImpl, ui::EventSource implementation:
ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
ui::EventProcessor* WindowTreeHostImpl::GetEventProcessor() {
return dispatcher();
}
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, NativeViewportClient implementation:
// WindowTreeHostImpl, NativeViewportClient implementation:
void WindowTreeHostMojo::OnCreated() {
void WindowTreeHostImpl::OnCreated() {
CreateCompositor(GetAcceleratedWidget());
compositor_created_callback_.Run();
}
void WindowTreeHostMojo::OnBoundsChanged(RectPtr bounds) {
void WindowTreeHostImpl::OnBoundsChanged(RectPtr bounds) {
bounds_ = bounds.To<gfx::Rect>();
window()->SetBounds(gfx::Rect(bounds_.size()));
OnHostResized(bounds_.size());
}
void WindowTreeHostMojo::OnDestroyed() {
void WindowTreeHostImpl::OnDestroyed() {
base::MessageLoop::current()->Quit();
}
void WindowTreeHostMojo::OnEvent(EventPtr event,
void WindowTreeHostImpl::OnEvent(EventPtr event,
const mojo::Callback<void()>& callback) {
switch (event->action) {
case ui::ET_MOUSE_PRESSED:
......@@ -170,4 +173,6 @@ void WindowTreeHostMojo::OnEvent(EventPtr event,
callback.Run();
};
} // namespace service
} // namespace view_manager
} // namespace mojo
......@@ -16,17 +16,19 @@ class ContextFactory;
}
namespace mojo {
namespace view_manager {
namespace service {
class ContextFactoryMojo;
class ContextFactoryImpl;
class WindowTreeHostMojo : public aura::WindowTreeHost,
class WindowTreeHostImpl : public aura::WindowTreeHost,
public ui::EventSource,
public NativeViewportClient {
public:
WindowTreeHostMojo(NativeViewportPtr viewport,
WindowTreeHostImpl(NativeViewportPtr viewport,
const gfx::Rect& bounds,
const base::Callback<void()>& compositor_created_callback);
virtual ~WindowTreeHostMojo();
virtual ~WindowTreeHostImpl();
gfx::Rect bounds() const { return bounds_; }
......@@ -57,16 +59,18 @@ class WindowTreeHostMojo : public aura::WindowTreeHost,
virtual void OnEvent(EventPtr event,
const mojo::Callback<void()>& callback) OVERRIDE;
static ContextFactoryMojo* context_factory_;
static ContextFactoryImpl* context_factory_;
NativeViewportPtr native_viewport_;
base::Callback<void()> compositor_created_callback_;
gfx::Rect bounds_;
DISALLOW_COPY_AND_ASSIGN(WindowTreeHostMojo);
DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl);
};
} // namespace service
} // namespace view_manager
} // namespace mojo
#endif // MOJO_AURA_WINDOW_TREE_HOST_MOJO_H_
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