Index: examples/wm_flow/wm/frame_controller.cc |
diff --git a/examples/wm_flow/wm/frame_controller.cc b/examples/wm_flow/wm/frame_controller.cc |
index 895044525bd61e8fe6b42ad71e4838b452232bf6..7ddfe6aca851a680e0fc7bc639e744c43c4be939 100644 |
--- a/examples/wm_flow/wm/frame_controller.cc |
+++ b/examples/wm_flow/wm/frame_controller.cc |
@@ -7,141 +7,53 @@ |
#include "base/macros.h" |
#include "base/strings/utf_string_conversions.h" |
#include "mojo/converters/geometry/geometry_type_converters.h" |
+#include "mojo/public/cpp/application/service_provider_impl.h" |
#include "mojo/services/view_manager/public/cpp/view.h" |
#include "mojo/services/view_manager/public/cpp/view_manager.h" |
-#include "mojo/views/native_widget_mojo.h" |
#include "services/window_manager/capture_controller.h" |
#include "services/window_manager/window_manager_app.h" |
-#include "ui/views/background.h" |
-#include "ui/views/controls/button/checkbox.h" |
-#include "ui/views/controls/button/label_button.h" |
-#include "ui/views/layout/layout_manager.h" |
-#include "ui/views/widget/widget.h" |
-#include "ui/wm/public/activation_client.h" |
- |
-class FrameController::LayoutManager : public views::LayoutManager, |
- public views::ButtonListener { |
- public: |
- explicit LayoutManager(FrameController* controller) |
- : controller_(controller), |
- capture_checkbox_( |
- new views::Checkbox(base::ASCIIToUTF16("Capture"))), |
- close_button_( |
- new views::LabelButton(this, base::ASCIIToUTF16("Begone"))), |
- maximize_button_( |
- new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) { |
- capture_checkbox_->set_listener(this); |
- } |
- virtual ~LayoutManager() {} |
- |
- private: |
- static const int kButtonFrameMargin = 5; |
- static const int kButtonFrameSpacing = 2; |
- static const int kFrameSize = 10; |
- |
- // Overridden from views::LayoutManager: |
- virtual void Installed(views::View* host) override { |
- host->AddChildView(capture_checkbox_); |
- host->AddChildView(close_button_); |
- host->AddChildView(maximize_button_); |
- } |
- virtual void Layout(views::View* host) override { |
- gfx::Size ps = capture_checkbox_->GetPreferredSize(); |
- capture_checkbox_->SetBounds(kButtonFrameMargin, kButtonFrameMargin, |
- ps.width(), ps.height()); |
- |
- ps = close_button_->GetPreferredSize(); |
- gfx::Rect bounds = host->GetLocalBounds(); |
- close_button_->SetBounds(bounds.right() - kButtonFrameMargin - ps.width(), |
- kButtonFrameMargin, ps.width(), ps.height()); |
- |
- ps = maximize_button_->GetPreferredSize(); |
- maximize_button_->SetBounds( |
- close_button_->x() - kButtonFrameSpacing - ps.width(), |
- kButtonFrameMargin, ps.width(), ps.height()); |
- |
- bounds.Inset(kFrameSize, |
- close_button_->bounds().bottom() + kButtonFrameMargin, |
- kFrameSize, kFrameSize); |
- controller_->app_view_->SetBounds(*mojo::Rect::From(bounds)); |
- } |
- virtual gfx::Size GetPreferredSize(const views::View* host) const override { |
- return gfx::Size(); |
- } |
- |
- // Overridden from views::ButtonListener: |
- virtual void ButtonPressed(views::Button* sender, |
- const ui::Event& event) override { |
- if (sender == close_button_) |
- controller_->CloseWindow(); |
- else if (sender == maximize_button_) |
- controller_->ToggleMaximize(); |
- else if (sender == capture_checkbox_) |
- controller_->SetCapture(capture_checkbox_->checked()); |
- } |
- |
- FrameController* controller_; |
- views::Checkbox* capture_checkbox_; |
- views::Button* close_button_; |
- views::Button* maximize_button_; |
- |
- DISALLOW_COPY_AND_ASSIGN(LayoutManager); |
-}; |
- |
-class FrameController::FrameEventHandler : public ui::EventHandler { |
- public: |
- explicit FrameEventHandler(FrameController* frame_controller) |
- : frame_controller_(frame_controller) {} |
- virtual ~FrameEventHandler() {} |
- |
- private: |
- |
- // Overriden from ui::EventHandler: |
- virtual void OnMouseEvent(ui::MouseEvent* event) override { |
- if (event->type() == ui::ET_MOUSE_PRESSED) |
- frame_controller_->ActivateWindow(); |
- } |
- |
- FrameController* frame_controller_; |
- |
- DISALLOW_COPY_AND_ASSIGN(FrameEventHandler); |
-}; |
+#include "url/gurl.h" |
//////////////////////////////////////////////////////////////////////////////// |
// FrameController, public: |
FrameController::FrameController( |
- mojo::Shell* shell, |
+ const GURL& frame_app_url, |
mojo::View* view, |
mojo::View** app_view, |
window_manager::WindowManagerApp* window_manager_app) |
: view_(view), |
app_view_(view->view_manager()->CreateView()), |
- frame_view_(new views::View), |
- frame_view_layout_manager_(new LayoutManager(this)), |
- widget_(new views::Widget), |
maximized_(false), |
- window_manager_app_(window_manager_app) { |
- view_->AddChild(app_view_); |
- app_view_->SetVisible(true); |
+ window_manager_app_(window_manager_app), |
+ binding_(this) { |
view_->AddObserver(this); |
+ view_->SetVisible(true); // FIXME: This should not be our responsibility? |
*app_view = app_view_; |
- frame_view_->set_background( |
- views::Background::CreateSolidBackground(SK_ColorBLUE)); |
- frame_view_->SetLayoutManager(frame_view_layout_manager_); |
- frame_event_handler_.reset(new FrameEventHandler(this)); |
- frame_view_->AddPreTargetHandler(frame_event_handler_.get()); |
- views::Widget::InitParams params( |
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
- params.native_widget = new mojo::NativeWidgetMojo(widget_, shell, view_); |
- params.bounds = view_->bounds().To<gfx::Rect>(); |
- widget_->Init(params); |
- widget_->SetContentsView(frame_view_); |
- widget_->Show(); |
+ |
+ scoped_ptr<mojo::ServiceProviderImpl> exported_services( |
+ new mojo::ServiceProviderImpl()); |
+ exported_services->AddService(this); |
+ |
+ viewer_services_ = |
+ view_->Embed(frame_app_url.spec(), exported_services.Pass()); |
+ |
+ // We weren't observing when our initial bounds was set: |
+ OnViewBoundsChanged(view, view->bounds(), view->bounds()); |
+ |
+ // Add the child view after embedding sky, since embed clears children. |
+ view_->AddChild(app_view_); |
+ app_view_->SetVisible(true); |
} |
FrameController::~FrameController() {} |
+void FrameController::Create( |
+ mojo::ApplicationConnection* connection, |
+ mojo::InterfaceRequest<examples::WindowFrameHost> request) { |
+ binding_.Bind(request.Pass()); |
+} |
+ |
void FrameController::CloseWindow() { |
// This destroys |app_view_| as it is a child of |view_|. |
view_->Destroy(); |
@@ -175,3 +87,20 @@ void FrameController::OnViewDestroyed(mojo::View* view) { |
view_->RemoveObserver(this); |
delete this; |
} |
+ |
+void FrameController::OnViewBoundsChanged(mojo::View* view, |
+ const mojo::Rect& old_bounds, |
+ const mojo::Rect& new_bounds) { |
+ CHECK(view == view_); |
+ // Statically size the embedded view. Unclear if we should use a |
+ // sky iframe to participate in sky layout or not. |
+ const int kTopControlsAdditionalInset = 15; |
+ const int kDefaultInset = 25; |
+ mojo::Rect bounds; |
+ bounds.x = bounds.y = kDefaultInset; |
+ bounds.y += kTopControlsAdditionalInset; |
+ bounds.width = view_->bounds().width - kDefaultInset * 2; |
+ bounds.height = |
+ view_->bounds().height - kDefaultInset * 2 - kTopControlsAdditionalInset; |
+ app_view_->SetBounds(bounds); |
+} |