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

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

Issue 337563002: Launcher flow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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
« no previous file with comments | « mojo/aura/window_tree_host_mojo.cc ('k') | mojo/examples/html_viewer/html_viewer.cc » ('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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "mojo/public/cpp/application/application.h" 6 #include "mojo/public/cpp/application/application.h"
7 #include "mojo/services/public/cpp/view_manager/view.h" 7 #include "mojo/services/public/cpp/view_manager/view.h"
8 #include "mojo/services/public/cpp/view_manager/view_manager.h" 8 #include "mojo/services/public/cpp/view_manager/view_manager.h"
9 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 9 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
10 #include "mojo/services/public/cpp/view_manager/view_observer.h" 10 #include "mojo/services/public/cpp/view_manager/view_observer.h"
11 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" 11 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
12 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
12 #include "mojo/views/native_widget_view_manager.h" 13 #include "mojo/views/native_widget_view_manager.h"
13 #include "mojo/views/views_init.h" 14 #include "mojo/views/views_init.h"
14 #include "ui/views/controls/textfield/textfield.h" 15 #include "ui/views/controls/textfield/textfield.h"
16 #include "ui/views/controls/textfield/textfield_controller.h"
15 #include "ui/views/layout/fill_layout.h" 17 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h" 19 #include "ui/views/widget/widget_delegate.h"
20 #include "url/gurl.h"
18 21
19 namespace mojo { 22 namespace mojo {
20 namespace examples { 23 namespace examples {
21 24
22 // This is the basics of creating a views widget with a textfield. 25 // This is the basics of creating a views widget with a textfield.
23 // TODO: cleanup! 26 // TODO: cleanup!
24 class Browser : public Application, public view_manager::ViewManagerDelegate { 27 class Browser : public Application,
28 public view_manager::ViewManagerDelegate,
29 public views::TextfieldController {
25 public: 30 public:
26 Browser() : view_manager_(NULL), view_(NULL) {} 31 Browser() : view_manager_(NULL), view_(NULL) {}
27 32
28 virtual ~Browser() { 33 virtual ~Browser() {
29 } 34 }
30 35
31 private: 36 private:
32 // Overridden from Application: 37 // Overridden from Application:
33 virtual void Initialize() MOJO_OVERRIDE { 38 virtual void Initialize() MOJO_OVERRIDE {
34 views_init_.reset(new ViewsInit); 39 views_init_.reset(new ViewsInit);
35 40
36 view_manager::ViewManager::Create(this, this); 41 view_manager::ViewManager::Create(this, this);
42
43 ConnectTo("mojo:mojo_launcher", &launcher_);
37 } 44 }
38 45
39 void CreateWidget() { 46 void CreateWidget() {
40 views::Textfield* textfield = new views::Textfield; 47 views::Textfield* textfield = new views::Textfield;
48 textfield->set_controller(this);
41 49
42 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; 50 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
43 widget_delegate->GetContentsView()->AddChildView(textfield); 51 widget_delegate->GetContentsView()->AddChildView(textfield);
44 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); 52 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout);
45 53
46 views::Widget* widget = new views::Widget; 54 views::Widget* widget = new views::Widget;
47 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 55 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
48 params.native_widget = new NativeWidgetViewManager(widget, view_); 56 params.native_widget = new NativeWidgetViewManager(widget, view_);
49 params.delegate = widget_delegate; 57 params.delegate = widget_delegate;
50 params.bounds = gfx::Rect(200, 200); 58 params.bounds = gfx::Rect(200, 200);
51 widget->Init(params); 59 widget->Init(params);
52 widget->Show(); 60 widget->Show();
53 textfield->RequestFocus(); 61 textfield->RequestFocus();
54 } 62 }
55 63
56 // view_manager::ViewManagerDelegate: 64 // view_manager::ViewManagerDelegate:
57 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 65 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
58 view_manager::ViewTreeNode* root) OVERRIDE { 66 view_manager::ViewTreeNode* root) OVERRIDE {
59 // TODO: deal with OnRootAdded() being invoked multiple times. 67 // TODO: deal with OnRootAdded() being invoked multiple times.
60 view_manager_ = view_manager; 68 view_manager_ = view_manager;
61 view_ = view_manager::View::Create(view_manager_); 69 view_ = view_manager::View::Create(view_manager_);
62 view_manager_->GetRoots().front()->SetActiveView(view_); 70 view_manager_->GetRoots().front()->SetActiveView(view_);
63 71
64 CreateWidget(); 72 CreateWidget();
65 } 73 }
66 virtual void OnRootRemoved(view_manager::ViewManager* view_manager, 74 virtual void OnRootRemoved(view_manager::ViewManager* view_manager,
67 view_manager::ViewTreeNode* root) OVERRIDE { 75 view_manager::ViewTreeNode* root) OVERRIDE {
68 } 76 }
69 77
78 // views::TextfieldController:
79 virtual bool HandleKeyEvent(views::Textfield* sender,
80 const ui::KeyEvent& key_event) OVERRIDE {
81 if (key_event.key_code() == ui::VKEY_RETURN) {
82 GURL url(sender->text());
83 printf("User entered this URL: %s\n", url.spec().c_str());
84 launcher_->Launch(url.spec());
85 }
86 return false;
87 }
88
70 scoped_ptr<ViewsInit> views_init_; 89 scoped_ptr<ViewsInit> views_init_;
71 90
72 view_manager::ViewManager* view_manager_; 91 view_manager::ViewManager* view_manager_;
73 view_manager::View* view_; 92 view_manager::View* view_;
93 launcher::LauncherPtr launcher_;
74 94
75 DISALLOW_COPY_AND_ASSIGN(Browser); 95 DISALLOW_COPY_AND_ASSIGN(Browser);
76 }; 96 };
77 97
78 } // namespace examples 98 } // namespace examples
79 99
80 // static 100 // static
81 Application* Application::Create() { 101 Application* Application::Create() {
82 return new examples::Browser; 102 return new examples::Browser;
83 } 103 }
84 104
85 } // namespace mojo 105 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/aura/window_tree_host_mojo.cc ('k') | mojo/examples/html_viewer/html_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698