Eric Seidel 84064defab Make it possible to change the viewport size
This makes it possible to change the viewport size
which mojo is using.  The sky debugger uses this new
API to set the viewport to something closer to mobile
instead of 800x600 ancient desktop size. :)

Still the (800, 600) constant is prevelant throughout
mojo (just search for it) and mojo does not seem to
fully update when the viewport size changes, so we actually
only see 320x600 pixels instead of 320x640 in
sky debugger after this change.

Mostly this change is about validating that this is the
correct way to plumb this information.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/692693002
2014-10-30 14:20:45 -07:00

143 lines
4.8 KiB
C++

// 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/application/application_runner_chromium.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/application/service_provider_impl.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/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h"
#include "mojo/services/window_manager/window_manager_delegate.h"
#include "sky/tools/debugger/focus_rules.h"
#include "sky/tools/debugger/debugger.mojom.h"
#include "sky/viewer/services/inspector.mojom.h"
namespace sky {
class SkyDebugger : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate,
public mojo::ViewObserver,
public mojo::InterfaceFactory<Debugger>,
public mojo::InterfaceImpl<Debugger> {
public:
SkyDebugger()
: window_manager_app_(new mojo::WindowManagerApp(this, nullptr)),
view_manager_(nullptr),
root_(nullptr),
content_(nullptr) {}
virtual ~SkyDebugger() {}
private:
// Overridden from mojo::ApplicationDelegate:
virtual void Initialize(mojo::ApplicationImpl* app) override {
window_manager_app_->Initialize(app);
app->ConnectToApplication("mojo:sky_debugger_prompt");
}
virtual bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
window_manager_app_->ConfigureIncomingConnection(connection);
connection->AddService(this);
return true;
}
virtual bool ConfigureOutgoingConnection(
mojo::ApplicationConnection* connection) override {
window_manager_app_->ConfigureOutgoingConnection(connection);
connection->AddService(this);
return true;
}
// Overridden from mojo::ViewManagerDelegate:
virtual void OnEmbed(
mojo::ViewManager* view_manager,
mojo::View* root,
mojo::ServiceProviderImpl* exported_services,
scoped_ptr<mojo::ServiceProvider> imported_services) override {
view_manager_ = view_manager;
root_ = root;
root_->AddObserver(this);
window_manager_app_->SetViewportSize(gfx::Size(320, 640));
content_ = mojo::View::Create(view_manager_);
content_->SetBounds(root_->bounds());
root_->AddChild(content_);
window_manager_app_->InitFocus(
new FocusRules(window_manager_app_.get(), content_));
if (!pending_url_.empty())
NavigateToURL(pending_url_);
}
virtual void OnViewManagerDisconnected(
mojo::ViewManager* view_manager) override {
CHECK(false); // FIXME: This is dead code, why?
view_manager_ = nullptr;
root_ = nullptr;
}
virtual void OnViewDestroyed(mojo::View* view) override {
CHECK(false); // FIXME: This is dead code, why?
view->RemoveObserver(this);
}
virtual void OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) override {
content_->SetBounds(new_bounds);
}
// Overridden from InterfaceFactory<Debugger>
virtual void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<Debugger> request) override {
mojo::WeakBindToRequest(this, &request);
}
// Overridden from Debugger
virtual void NavigateToURL(const mojo::String& url) override {
// We can get Navigate commands before we've actually been
// embedded into the view and content_ created.
// Just save the last one.
if (content_) {
scoped_ptr<mojo::ServiceProviderImpl> exported_services(
new mojo::ServiceProviderImpl());
viewer_services_ = content_->Embed(url, exported_services.Pass());
} else {
pending_url_ = url;
}
}
virtual void InjectInspector() override {
InspectorServicePtr inspector_service;
mojo::ConnectToService(viewer_services_.get(), &inspector_service);
inspector_service->Inject();
}
scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
mojo::ViewManager* view_manager_;
mojo::View* root_;
mojo::View* content_;
std::string pending_url_;
scoped_ptr<mojo::ServiceProvider> viewer_services_;
DISALLOW_COPY_AND_ASSIGN(SkyDebugger);
};
} // namespace sky
MojoResult MojoMain(MojoHandle shell_handle) {
mojo::ApplicationRunnerChromium runner(new sky::SkyDebugger);
return runner.Run(shell_handle);
}