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

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

Issue 341953002: Clean up WTH creation (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/examples/aura_demo/aura_demo.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 "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/public/cpp/application/application.h" 8 #include "mojo/public/cpp/application/application.h"
9 #include "mojo/services/navigation/navigation.mojom.h" 9 #include "mojo/services/navigation/navigation.mojom.h"
10 #include "mojo/services/public/cpp/view_manager/node.h" 10 #include "mojo/services/public/cpp/view_manager/node.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager); 46 DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager);
47 }; 47 };
48 48
49 // This is the basics of creating a views widget with a textfield. 49 // This is the basics of creating a views widget with a textfield.
50 // TODO: cleanup! 50 // TODO: cleanup!
51 class Browser : public Application, 51 class Browser : public Application,
52 public view_manager::ViewManagerDelegate, 52 public view_manager::ViewManagerDelegate,
53 public views::TextfieldController { 53 public views::TextfieldController {
54 public: 54 public:
55 Browser() : view_manager_(NULL), view_(NULL) {} 55 Browser() : view_manager_(NULL) {}
56 56
57 virtual ~Browser() { 57 virtual ~Browser() {
58 } 58 }
59 59
60 private: 60 private:
61 // Overridden from Application: 61 // Overridden from Application:
62 virtual void Initialize() MOJO_OVERRIDE { 62 virtual void Initialize() MOJO_OVERRIDE {
63 views_init_.reset(new ViewsInit); 63 views_init_.reset(new ViewsInit);
64 view_manager::ViewManager::Create(this, this); 64 view_manager::ViewManager::Create(this, this);
65 ConnectTo("mojo:mojo_window_manager", &navigator_host_); 65 ConnectTo("mojo:mojo_window_manager", &navigator_host_);
66 } 66 }
67 67
68 void CreateWidget(const gfx::Size& size) { 68 void CreateWidget(view_manager::Node* node) {
69 views::Textfield* textfield = new views::Textfield; 69 views::Textfield* textfield = new views::Textfield;
70 textfield->set_controller(this); 70 textfield->set_controller(this);
71 71
72 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; 72 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
73 widget_delegate->GetContentsView()->AddChildView(textfield); 73 widget_delegate->GetContentsView()->AddChildView(textfield);
74 widget_delegate->GetContentsView()->SetLayoutManager( 74 widget_delegate->GetContentsView()->SetLayoutManager(
75 new BrowserLayoutManager); 75 new BrowserLayoutManager);
76 76
77 views::Widget* widget = new views::Widget; 77 views::Widget* widget = new views::Widget;
78 views::Widget::InitParams params( 78 views::Widget::InitParams params(
79 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 79 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
80 params.native_widget = new NativeWidgetViewManager(widget, view_); 80 params.native_widget = new NativeWidgetViewManager(widget, node);
81 params.delegate = widget_delegate; 81 params.delegate = widget_delegate;
82 params.bounds = gfx::Rect(size.width(), size.height()); 82 params.bounds = gfx::Rect(node->bounds().width(), node->bounds().height());
83 widget->Init(params); 83 widget->Init(params);
84 widget->Show(); 84 widget->Show();
85 textfield->RequestFocus(); 85 textfield->RequestFocus();
86 } 86 }
87 87
88 // view_manager::ViewManagerDelegate: 88 // view_manager::ViewManagerDelegate:
89 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 89 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
90 view_manager::Node* root) OVERRIDE { 90 view_manager::Node* root) OVERRIDE {
91 // TODO: deal with OnRootAdded() being invoked multiple times. 91 // TODO: deal with OnRootAdded() being invoked multiple times.
92 view_manager_ = view_manager; 92 view_manager_ = view_manager;
93 view_ = view_manager::View::Create(view_manager_); 93 root->SetActiveView(view_manager::View::Create(view_manager));
94 view_manager_->GetRoots().front()->SetActiveView(view_);
95 root->SetFocus(); 94 root->SetFocus();
96 CreateWidget(root->bounds().size()); 95 CreateWidget(root);
97 } 96 }
98 97
99 // views::TextfieldController: 98 // views::TextfieldController:
100 virtual bool HandleKeyEvent(views::Textfield* sender, 99 virtual bool HandleKeyEvent(views::Textfield* sender,
101 const ui::KeyEvent& key_event) OVERRIDE { 100 const ui::KeyEvent& key_event) OVERRIDE {
102 if (key_event.key_code() == ui::VKEY_RETURN) { 101 if (key_event.key_code() == ui::VKEY_RETURN) {
103 GURL url(sender->text()); 102 GURL url(sender->text());
104 printf("User entered this URL: %s\n", url.spec().c_str()); 103 printf("User entered this URL: %s\n", url.spec().c_str());
105 navigation::NavigationDetailsPtr nav_details( 104 navigation::NavigationDetailsPtr nav_details(
106 navigation::NavigationDetails::New()); 105 navigation::NavigationDetails::New());
(...skipping 10 matching lines...) Expand all
117 if (EndsWith(new_contents, base::ASCIIToUTF16("]"), false)) { 116 if (EndsWith(new_contents, base::ASCIIToUTF16("]"), false)) {
118 sender->SetText(new_contents.substr(0, new_contents.size() - 1)); 117 sender->SetText(new_contents.substr(0, new_contents.size() - 1));
119 HandleKeyEvent(sender, ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_RETURN, 118 HandleKeyEvent(sender, ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_RETURN,
120 0, false)); 119 0, false));
121 } 120 }
122 } 121 }
123 122
124 scoped_ptr<ViewsInit> views_init_; 123 scoped_ptr<ViewsInit> views_init_;
125 124
126 view_manager::ViewManager* view_manager_; 125 view_manager::ViewManager* view_manager_;
127 view_manager::View* view_;
128 navigation::NavigatorHostPtr navigator_host_; 126 navigation::NavigatorHostPtr navigator_host_;
129 127
130 DISALLOW_COPY_AND_ASSIGN(Browser); 128 DISALLOW_COPY_AND_ASSIGN(Browser);
131 }; 129 };
132 130
133 } // namespace examples 131 } // namespace examples
134 132
135 // static 133 // static
136 Application* Application::Create() { 134 Application* Application::Create() {
137 return new examples::Browser; 135 return new examples::Browser;
138 } 136 }
139 137
140 } // namespace mojo 138 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/aura_demo/aura_demo.cc ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698