| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "examples/wm_flow/wm/frame_controller.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" | |
| 10 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
| 11 #include "mojo/services/view_manager/cpp/view.h" | |
| 12 #include "mojo/services/view_manager/cpp/view_manager.h" | |
| 13 #include "services/window_manager/capture_controller.h" | |
| 14 #include "services/window_manager/window_manager_root.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 //////////////////////////////////////////////////////////////////////////////// | |
| 18 // FrameController, public: | |
| 19 | |
| 20 FrameController::FrameController( | |
| 21 const GURL& frame_app_url, | |
| 22 mojo::View* view, | |
| 23 mojo::View** app_view, | |
| 24 window_manager::WindowManagerRoot* window_manager_root) | |
| 25 : view_(view), | |
| 26 app_view_(view->view_manager()->CreateView()), | |
| 27 maximized_(false), | |
| 28 window_manager_root_(window_manager_root), | |
| 29 binding_(this) { | |
| 30 view_->AddObserver(this); | |
| 31 view_->SetVisible(true); // FIXME: This should not be our responsibility? | |
| 32 *app_view = app_view_; | |
| 33 | |
| 34 viewer_services_impl_.AddService(this); | |
| 35 mojo::ServiceProviderPtr viewer_services; | |
| 36 viewer_services_impl_.Bind(GetProxy(&viewer_services)); | |
| 37 | |
| 38 view_->Embed(frame_app_url.spec(), nullptr, viewer_services.Pass()); | |
| 39 | |
| 40 // We weren't observing when our initial bounds was set: | |
| 41 OnViewBoundsChanged(view, view->bounds(), view->bounds()); | |
| 42 | |
| 43 // Add the child view after embedding sky, since embed clears children. | |
| 44 view_->AddChild(app_view_); | |
| 45 app_view_->SetVisible(true); | |
| 46 } | |
| 47 | |
| 48 FrameController::~FrameController() {} | |
| 49 | |
| 50 void FrameController::Create( | |
| 51 mojo::ApplicationConnection* connection, | |
| 52 mojo::InterfaceRequest<examples::WindowFrameHost> request) { | |
| 53 binding_.Bind(request.Pass()); | |
| 54 } | |
| 55 | |
| 56 void FrameController::CloseWindow() { | |
| 57 // This destroys |app_view_| as it is a child of |view_|. | |
| 58 view_->Destroy(); | |
| 59 } | |
| 60 | |
| 61 void FrameController::ToggleMaximize() { | |
| 62 if (!maximized_) | |
| 63 restored_bounds_ = view_->bounds().To<gfx::Rect>(); | |
| 64 maximized_ = !maximized_; | |
| 65 if (maximized_) | |
| 66 view_->SetBounds(view_->parent()->bounds()); | |
| 67 else | |
| 68 view_->SetBounds(*mojo::Rect::From(restored_bounds_)); | |
| 69 } | |
| 70 | |
| 71 void FrameController::ActivateWindow() { | |
| 72 window_manager_root_->focus_controller()->ActivateView(view_); | |
| 73 } | |
| 74 | |
| 75 void FrameController::SetCapture(bool frame_has_capture) { | |
| 76 if (frame_has_capture) | |
| 77 window_manager_root_->capture_controller()->SetCapture(view_); | |
| 78 else | |
| 79 window_manager_root_->capture_controller()->ReleaseCapture(view_); | |
| 80 } | |
| 81 | |
| 82 //////////////////////////////////////////////////////////////////////////////// | |
| 83 // FrameController, mojo::ViewObserver implementation: | |
| 84 | |
| 85 void FrameController::OnViewDestroyed(mojo::View* view) { | |
| 86 view_->RemoveObserver(this); | |
| 87 delete this; | |
| 88 } | |
| 89 | |
| 90 void FrameController::OnViewBoundsChanged(mojo::View* view, | |
| 91 const mojo::Rect& old_bounds, | |
| 92 const mojo::Rect& new_bounds) { | |
| 93 CHECK(view == view_); | |
| 94 // Statically size the embedded view. Unclear if we should use a | |
| 95 // sky iframe to participate in sky layout or not. | |
| 96 const int kTopControlsAdditionalInset = 15; | |
| 97 const int kDefaultInset = 25; | |
| 98 mojo::Rect bounds; | |
| 99 bounds.x = bounds.y = kDefaultInset; | |
| 100 bounds.y += kTopControlsAdditionalInset; | |
| 101 bounds.width = view_->bounds().width - kDefaultInset * 2; | |
| 102 bounds.height = | |
| 103 view_->bounds().height - kDefaultInset * 2 - kTopControlsAdditionalInset; | |
| 104 app_view_->SetBounds(bounds); | |
| 105 } | |
| OLD | NEW |