Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: examples/wm_flow/wm/wm.cc

Issue 815003002: Nukes ViewManager arg from ViewManagerDelegate::OnEmbed (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: format Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "examples/wm_flow/wm/frame_controller.h" 7 #include "examples/wm_flow/wm/frame_controller.h"
8 #include "mojo/application/application_runner_chromium.h" 8 #include "mojo/application/application_runner_chromium.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
(...skipping 11 matching lines...) Expand all
22 namespace examples { 22 namespace examples {
23 23
24 class SimpleWM : public mojo::ApplicationDelegate, 24 class SimpleWM : public mojo::ApplicationDelegate,
25 public mojo::ViewManagerDelegate, 25 public mojo::ViewManagerDelegate,
26 public window_manager::WindowManagerDelegate, 26 public window_manager::WindowManagerDelegate,
27 public mojo::ViewObserver { 27 public mojo::ViewObserver {
28 public: 28 public:
29 SimpleWM() 29 SimpleWM()
30 : shell_(nullptr), 30 : shell_(nullptr),
31 window_manager_app_(new window_manager::WindowManagerApp(this, this)), 31 window_manager_app_(new window_manager::WindowManagerApp(this, this)),
32 view_manager_(NULL),
33 root_(NULL), 32 root_(NULL),
34 window_container_(NULL), 33 window_container_(NULL),
35 next_window_origin_(10, 10) {} 34 next_window_origin_(10, 10) {}
36 virtual ~SimpleWM() {} 35 virtual ~SimpleWM() {}
37 36
38 private: 37 private:
39 // Overridden from mojo::ApplicationDelegate: 38 // Overridden from mojo::ApplicationDelegate:
40 virtual void Initialize(mojo::ApplicationImpl* impl) override { 39 virtual void Initialize(mojo::ApplicationImpl* impl) override {
41 // Create views_init here as we need ApplicationRunnerChromium to install 40 // Create views_init here as we need ApplicationRunnerChromium to install
42 // an AtExitManager and CommandLine. 41 // an AtExitManager and CommandLine.
43 if (!views_init_.get()) 42 if (!views_init_.get())
44 views_init_.reset(new mojo::ViewsInit); 43 views_init_.reset(new mojo::ViewsInit);
45 shell_ = impl->shell(); 44 shell_ = impl->shell();
46 window_manager_app_->Initialize(impl); 45 window_manager_app_->Initialize(impl);
47 } 46 }
48 virtual bool ConfigureIncomingConnection( 47 virtual bool ConfigureIncomingConnection(
49 mojo::ApplicationConnection* connection) override { 48 mojo::ApplicationConnection* connection) override {
50 window_manager_app_->ConfigureIncomingConnection(connection); 49 window_manager_app_->ConfigureIncomingConnection(connection);
51 return true; 50 return true;
52 } 51 }
53 52
54 // Overridden from mojo::ViewManagerDelegate: 53 // Overridden from mojo::ViewManagerDelegate:
55 virtual void OnEmbed( 54 virtual void OnEmbed(
56 mojo::ViewManager* view_manager,
57 mojo::View* root, 55 mojo::View* root,
58 mojo::ServiceProviderImpl* exported_services, 56 mojo::ServiceProviderImpl* exported_services,
59 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { 57 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
60 view_manager_ = view_manager;
61 root_ = root; 58 root_ = root;
62 59
63 window_container_ = mojo::View::Create(view_manager_); 60 window_container_ = mojo::View::Create(root->view_manager());
64 window_container_->SetBounds(root_->bounds()); 61 window_container_->SetBounds(root_->bounds());
65 root_->AddChild(window_container_); 62 root_->AddChild(window_container_);
66 window_container_->SetVisible(true); 63 window_container_->SetVisible(true);
67 64
68 window_manager_app_->InitFocus(make_scoped_ptr( 65 window_manager_app_->InitFocus(make_scoped_ptr(
69 new window_manager::BasicFocusRules(window_container_))); 66 new window_manager::BasicFocusRules(window_container_)));
70 } 67 }
71 virtual void OnViewManagerDisconnected( 68 virtual void OnViewManagerDisconnected(
72 mojo::ViewManager* view_manager) override { 69 mojo::ViewManager* view_manager) override {
73 view_manager_ = NULL;
74 root_ = NULL; 70 root_ = NULL;
75 } 71 }
76 72
77 // Overridden from mojo::WindowManagerDelegate: 73 // Overridden from mojo::WindowManagerDelegate:
78 virtual void Embed( 74 virtual void Embed(
79 const mojo::String& url, 75 const mojo::String& url,
80 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override { 76 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override {
81 DCHECK(view_manager_); 77 DCHECK(root_);
82 mojo::View* app_view = NULL; 78 mojo::View* app_view = NULL;
83 CreateTopLevelWindow(&app_view); 79 CreateTopLevelWindow(&app_view);
84 80
85 // TODO(beng): We're dropping the |service_provider| passed from the client 81 // TODO(beng): We're dropping the |service_provider| passed from the client
86 // on the floor here and passing our own. Seems like we should 82 // on the floor here and passing our own. Seems like we should
87 // be sending both. I'm not yet sure how this sould work for 83 // be sending both. I'm not yet sure how this sould work for
88 // N levels of proxying. 84 // N levels of proxying.
89 app_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>( 85 app_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
90 new mojo::ServiceProviderImpl).Pass()); 86 new mojo::ServiceProviderImpl).Pass());
91 } 87 }
(...skipping 12 matching lines...) Expand all
104 } 100 }
105 101
106 void CloseWindow(mojo::View* view) { 102 void CloseWindow(mojo::View* view) {
107 mojo::View* first_child = view->children().front(); 103 mojo::View* first_child = view->children().front();
108 first_child->Destroy(); 104 first_child->Destroy();
109 view->Destroy(); 105 view->Destroy();
110 next_window_origin_.Offset(-50, -50); 106 next_window_origin_.Offset(-50, -50);
111 } 107 }
112 108
113 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { 109 mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
114 mojo::View* frame_view = mojo::View::Create(view_manager_); 110 mojo::View* frame_view = mojo::View::Create(root_->view_manager());
115 // Add the View to it's parent before showing so that animations can happen. 111 // Add the View to it's parent before showing so that animations can happen.
116 window_container_->AddChild(frame_view); 112 window_container_->AddChild(frame_view);
117 mojo::Rect rect; 113 mojo::Rect rect;
118 rect.x = next_window_origin_.x(); 114 rect.x = next_window_origin_.x();
119 rect.y = next_window_origin_.y(); 115 rect.y = next_window_origin_.y();
120 rect.width = rect.height = 400; 116 rect.width = rect.height = 400;
121 frame_view->SetBounds(rect); 117 frame_view->SetBounds(rect);
122 next_window_origin_.Offset(50, 50); 118 next_window_origin_.Offset(50, 50);
123 119
124 new FrameController( 120 new FrameController(
125 shell_, frame_view, app_view, window_manager_app_.get()); 121 shell_, frame_view, app_view, window_manager_app_.get());
126 return frame_view; 122 return frame_view;
127 } 123 }
128 124
129 mojo::Shell* shell_; 125 mojo::Shell* shell_;
130 126
131 scoped_ptr<mojo::ViewsInit> views_init_; 127 scoped_ptr<mojo::ViewsInit> views_init_;
132 128
133 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; 129 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_;
134 130
135 mojo::ViewManager* view_manager_;
136 mojo::View* root_; 131 mojo::View* root_;
137 mojo::View* window_container_; 132 mojo::View* window_container_;
138 133
139 gfx::Point next_window_origin_; 134 gfx::Point next_window_origin_;
140 135
141 DISALLOW_COPY_AND_ASSIGN(SimpleWM); 136 DISALLOW_COPY_AND_ASSIGN(SimpleWM);
142 }; 137 };
143 138
144 } // namespace examples 139 } // namespace examples
145 140
146 MojoResult MojoMain(MojoHandle shell_handle) { 141 MojoResult MojoMain(MojoHandle shell_handle) {
147 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); 142 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM);
148 return runner.Run(shell_handle); 143 return runner.Run(shell_handle);
149 } 144 }
OLDNEW
« no previous file with comments | « examples/wm_flow/embedded/embedded.cc ('k') | mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698