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

Side by Side Diff: mojo/examples/browser/browser.cc

Issue 372273004: Shutdown cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "mojo/examples/window_manager/window_manager.mojom.h" 8 #include "mojo/examples/window_manager/window_manager.mojom.h"
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 198 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
199 view_manager::Node* root) OVERRIDE { 199 view_manager::Node* root) OVERRIDE {
200 // TODO: deal with OnRootAdded() being invoked multiple times. 200 // TODO: deal with OnRootAdded() being invoked multiple times.
201 view_manager_ = view_manager; 201 view_manager_ = view_manager;
202 root_ = root; 202 root_ = root;
203 root_->AddObserver(this); 203 root_->AddObserver(this);
204 root_->SetActiveView(view_manager::View::Create(view_manager)); 204 root_->SetActiveView(view_manager::View::Create(view_manager));
205 root_->SetFocus(); 205 root_->SetFocus();
206 CreateWidget(root_); 206 CreateWidget(root_);
207 } 207 }
208 virtual void OnViewManagerDisconnected(
209 view_manager::ViewManager* view_manager) OVERRIDE {
210 DCHECK_EQ(view_manager_, view_manager);
211 view_manager_ = NULL;
212 base::MessageLoop::current()->Quit();
213 }
208 214
209 // views::TextfieldController: 215 // views::TextfieldController:
210 virtual bool HandleKeyEvent(views::Textfield* sender, 216 virtual bool HandleKeyEvent(views::Textfield* sender,
211 const ui::KeyEvent& key_event) OVERRIDE { 217 const ui::KeyEvent& key_event) OVERRIDE {
212 if (key_event.key_code() == ui::VKEY_RETURN) { 218 if (key_event.key_code() == ui::VKEY_RETURN) {
213 GURL url(sender->text()); 219 GURL url(sender->text());
214 printf("User entered this URL: %s\n", url.spec().c_str()); 220 printf("User entered this URL: %s\n", url.spec().c_str());
215 navigation::NavigationDetailsPtr nav_details( 221 navigation::NavigationDetailsPtr nav_details(
216 navigation::NavigationDetails::New()); 222 navigation::NavigationDetails::New());
217 nav_details->url = url.spec(); 223 nav_details->url = url.spec();
218 navigator_host_->RequestNavigate(view_manager_->GetRoots().front()->id(), 224 navigator_host_->RequestNavigate(view_manager_->GetRoots().front()->id(),
219 navigation::NEW_NODE, 225 navigation::NEW_NODE,
220 nav_details.Pass()); 226 nav_details.Pass());
221 } 227 }
222 return false; 228 return false;
223 } 229 }
224 230
225 // NodeObserver: 231 // NodeObserver:
226 virtual void OnNodeFocusChanged(view_manager::Node* gained_focus, 232 virtual void OnNodeFocusChanged(view_manager::Node* gained_focus,
227 view_manager::Node* lost_focus) OVERRIDE { 233 view_manager::Node* lost_focus) OVERRIDE {
228 aura::client::FocusClient* focus_client = 234 aura::client::FocusClient* focus_client =
229 aura::client::GetFocusClient(widget_->GetNativeView()); 235 aura::client::GetFocusClient(widget_->GetNativeView());
230 if (lost_focus == root_) 236 if (lost_focus == root_)
231 focus_client->FocusWindow(NULL); 237 focus_client->FocusWindow(NULL);
232 else if (gained_focus == root_) 238 else if (gained_focus == root_)
233 focus_client->FocusWindow(widget_->GetNativeView()); 239 focus_client->FocusWindow(widget_->GetNativeView());
234 } 240 }
241 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE {
242 DCHECK_EQ(root_, node);
243 node->RemoveObserver(this);
244 }
235 245
236 scoped_ptr<ViewsInit> views_init_; 246 scoped_ptr<ViewsInit> views_init_;
237 247
238 view_manager::ViewManager* view_manager_; 248 view_manager::ViewManager* view_manager_;
239 view_manager::Node* root_; 249 view_manager::Node* root_;
240 views::Widget* widget_; 250 views::Widget* widget_;
241 navigation::NavigatorHostPtr navigator_host_; 251 navigation::NavigatorHostPtr navigator_host_;
242 IWindowManagerPtr window_manager_; 252 IWindowManagerPtr window_manager_;
243 253
244 DISALLOW_COPY_AND_ASSIGN(Browser); 254 DISALLOW_COPY_AND_ASSIGN(Browser);
245 }; 255 };
246 256
247 } // namespace examples 257 } // namespace examples
248 258
249 // static 259 // static
250 ApplicationDelegate* ApplicationDelegate::Create() { 260 ApplicationDelegate* ApplicationDelegate::Create() {
251 return new examples::Browser; 261 return new examples::Browser;
252 } 262 }
253 263
254 } // namespace mojo 264 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698