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

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

Issue 549883003: Window controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: , Created 6 years, 3 months 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
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.cc ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/examples/wm_flow/wm/frame_controller.h"
5 #include "mojo/public/c/system/main.h" 6 #include "mojo/public/c/system/main.h"
6 #include "mojo/public/cpp/application/application_delegate.h" 7 #include "mojo/public/cpp/application/application_delegate.h"
7 #include "mojo/public/cpp/application/application_impl.h" 8 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/application/application_runner_chromium.h" 9 #include "mojo/public/cpp/application/application_runner_chromium.h"
9 #include "mojo/public/cpp/application/service_provider_impl.h" 10 #include "mojo/public/cpp/application/service_provider_impl.h"
10 #include "mojo/services/public/cpp/view_manager/view_manager.h" 11 #include "mojo/services/public/cpp/view_manager/view_manager.h"
11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
12 #include "mojo/services/public/cpp/view_manager/view_observer.h" 13 #include "mojo/services/public/cpp/view_manager/view_observer.h"
13 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" 14 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
14 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 15 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
15 #include "mojo/services/window_manager/window_manager_app.h" 16 #include "mojo/services/window_manager/window_manager_app.h"
17 #include "mojo/views/views_init.h"
16 18
17 namespace examples { 19 namespace examples {
18 20
19 class SimpleWM : public mojo::ApplicationDelegate, 21 class SimpleWM : public mojo::ApplicationDelegate,
20 public mojo::ViewManagerDelegate, 22 public mojo::ViewManagerDelegate,
21 public mojo::WindowManagerDelegate, 23 public mojo::WindowManagerDelegate,
22 public mojo::ViewObserver { 24 public mojo::ViewObserver {
23 public: 25 public:
24 SimpleWM() 26 SimpleWM()
25 : window_manager_app_(new mojo::WindowManagerApp(this, this)), 27 : window_manager_app_(new mojo::WindowManagerApp(this, this)),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 mojo::ViewManager* view_manager) MOJO_OVERRIDE { 60 mojo::ViewManager* view_manager) MOJO_OVERRIDE {
59 view_manager_ = NULL; 61 view_manager_ = NULL;
60 root_ = NULL; 62 root_ = NULL;
61 } 63 }
62 64
63 // Overridden from mojo::WindowManagerDelegate: 65 // Overridden from mojo::WindowManagerDelegate:
64 virtual void Embed( 66 virtual void Embed(
65 const mojo::String& url, 67 const mojo::String& url,
66 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) 68 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider)
67 MOJO_OVERRIDE { 69 MOJO_OVERRIDE {
68 mojo::View* frame_view = mojo::View::Create(view_manager_); 70 mojo::View* app_view = NULL;
71 mojo::View* frame_view = CreateTopLevelWindow(&app_view);
69 window_container_->AddChild(frame_view); 72 window_container_->AddChild(frame_view);
70 frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
71 frame_view->SetColor(SK_ColorBLUE);
72 frame_view->AddObserver(this);
73
74 mojo::View* embed_view = mojo::View::Create(view_manager_);
75 gfx::Rect client_bounds(frame_view->bounds().size());
76 client_bounds.Inset(10, 30, 10, 10);
77 embed_view->SetBounds(client_bounds);
78 frame_view->AddChild(embed_view);
79 73
80 // TODO(beng): We're dropping the |service_provider| passed from the client 74 // TODO(beng): We're dropping the |service_provider| passed from the client
81 // on the floor here and passing our own. Seems like we should 75 // on the floor here and passing our own. Seems like we should
82 // be sending both. I'm not yet sure how this sould work for 76 // be sending both. I'm not yet sure how this sould work for
83 // N levels of proxying. 77 // N levels of proxying.
84 embed_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>( 78 app_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
85 new mojo::ServiceProviderImpl).Pass()); 79 new mojo::ServiceProviderImpl).Pass());
86 next_window_origin_.Offset(50, 50);
87 } 80 }
88 virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {} 81 virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {}
89 82
90 // Overridden from mojo::ViewObserver: 83 // Overridden from mojo::ViewObserver:
91 virtual void OnViewInputEvent(mojo::View* view, 84 virtual void OnViewInputEvent(mojo::View* view,
92 const mojo::EventPtr& event) MOJO_OVERRIDE { 85 const mojo::EventPtr& event) MOJO_OVERRIDE {
93 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED && 86 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
94 event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON && 87 event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON &&
95 view->parent() == window_container_) { 88 view->parent() == window_container_) {
96 CloseWindow(view); 89 CloseWindow(view);
97 } 90 }
98 } 91 }
99 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE { 92 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE {
100 view->RemoveObserver(this); 93 view->RemoveObserver(this);
101 } 94 }
102 95
103 void CloseWindow(mojo::View* view) { 96 void CloseWindow(mojo::View* view) {
104 mojo::View* first_child = view->children().front(); 97 mojo::View* first_child = view->children().front();
105 first_child->Destroy(); 98 first_child->Destroy();
106 view->Destroy(); 99 view->Destroy();
107 next_window_origin_.Offset(-50, -50); 100 next_window_origin_.Offset(-50, -50);
108 } 101 }
109 102
103 mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
104 mojo::View* frame_view = mojo::View::Create(view_manager_);
105 frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
106 next_window_origin_.Offset(50, 50);
107
108 new FrameController(frame_view, app_view);
109 return frame_view;
110 }
111
110 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; 112 scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
111 113
112 mojo::ViewManager* view_manager_; 114 mojo::ViewManager* view_manager_;
113 mojo::View* root_; 115 mojo::View* root_;
114 mojo::View* window_container_; 116 mojo::View* window_container_;
115 117
116 gfx::Point next_window_origin_; 118 gfx::Point next_window_origin_;
117 119
118 DISALLOW_COPY_AND_ASSIGN(SimpleWM); 120 DISALLOW_COPY_AND_ASSIGN(SimpleWM);
119 }; 121 };
120 122
121 } // namespace examples 123 } // namespace examples
122 124
123 MojoResult MojoMain(MojoHandle shell_handle) { 125 MojoResult MojoMain(MojoHandle shell_handle) {
126 mojo::ViewsInit views_init;
124 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); 127 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM);
125 return runner.Run(shell_handle); 128 return runner.Run(shell_handle);
126 } 129 }
OLDNEW
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.cc ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698