Commit def5bc67 authored by sky's avatar sky Committed by Commit bot

Makes browser resize content when root bounds change

Without this on android we don't open the browser to fill the screen,
nor resize when the rotation changes.

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

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

Cr-Commit-Position: refs/heads/master@{#329289}
parent a1d10e49
......@@ -5,6 +5,8 @@
#include "mandoline/ui/browser/android/android_ui.h"
#include "components/view_manager/public/cpp/view.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "ui/gfx/geometry/rect.h"
namespace mandoline {
......@@ -13,15 +15,26 @@ AndroidUI::AndroidUI(Browser* browser, mojo::Shell* shell)
shell_(shell),
root_(nullptr),
content_(nullptr) {}
AndroidUI::~AndroidUI() {}
AndroidUI::~AndroidUI() {
root_->RemoveObserver(this);
}
void AndroidUI::Init(mojo::View* root, mojo::View* content) {
root_ = root;
root_->AddObserver(this);
content_ = content;
content_->SetBounds(root_->bounds());
}
void AndroidUI::OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) {
content_->SetBounds(
*mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height)));
}
// static
BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) {
return new AndroidUI(browser, shell);
......
......@@ -6,6 +6,7 @@
#define MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_
#include "base/macros.h"
#include "components/view_manager/public/cpp/view_observer.h"
#include "mandoline/ui/browser/browser_ui.h"
namespace mojo {
......@@ -17,7 +18,8 @@ namespace mandoline {
class Browser;
class AndroidUI : public BrowserUI {
class AndroidUI : public BrowserUI,
public mojo::ViewObserver {
public:
AndroidUI(Browser* browser, mojo::Shell* shell);
~AndroidUI() override;
......@@ -26,6 +28,11 @@ class AndroidUI : public BrowserUI {
// Overridden from BrowserUI:
void Init(mojo::View* root, mojo::View* content) override;
// Overriden from mojo::ViewObserver:
virtual void OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) override;
Browser* browser_;
mojo::Shell* shell_;
mojo::View* root_;
......
......@@ -31,6 +31,11 @@ base::WeakPtr<Browser> Browser::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
// Convenience method:
void Browser::ReplaceContentWithURL(const mojo::String& url) {
Embed(url, nullptr, nullptr);
}
void Browser::Initialize(mojo::ApplicationImpl* app) {
window_manager_app_->Initialize(app);
ui_.reset(BrowserUI::Create(this, app->shell()));
......@@ -94,6 +99,12 @@ void Browser::OnEmbed(
Embed(default_url_, services.Pass(), exposed_services.Pass());
}
void Browser::OnViewManagerDisconnected(
mojo::ViewManager* view_manager) {
ui_.reset();
root_ = nullptr;
}
void Browser::Embed(const mojo::String& url,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services) {
......@@ -125,14 +136,4 @@ void Browser::Create(mojo::ApplicationConnection* connection,
navigator_host_.Bind(request.Pass());
}
void Browser::OnViewManagerDisconnected(
mojo::ViewManager* view_manager) {
root_ = nullptr;
}
// Convenience method:
void Browser::ReplaceContentWithURL(const mojo::String& url) {
Embed(url, nullptr, nullptr);
}
} // namespace mandoline
......@@ -61,8 +61,6 @@ class Browser : public mojo::ApplicationDelegate,
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NavigatorHost> request) override;
void LayoutContent();
scoped_ptr<window_manager::WindowManagerApp> window_manager_app_;
// Only support being embedded once, so both application-level
......
......@@ -20,6 +20,9 @@ class BrowserUI {
static BrowserUI* Create(Browser* browser, mojo::Shell* shell);
// Called when the Browser UI is embedded within the specified view.
// BrowserUI is destroyed prior to |root| being destroyed. That is, the
// BrowserUI implementations can assume |root| is never deleted out from under
// them.
virtual void Init(mojo::View* root, mojo::View* content) = 0;
};
......
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