OLD | NEW |
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/node.h" |
7 #include "mojo/services/public/cpp/view_manager/view.h" | 8 #include "mojo/services/public/cpp/view_manager/view.h" |
8 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 9 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
9 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 10 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
10 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 11 #include "mojo/services/public/cpp/view_manager/view_observer.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/services/public/interfaces/launcher/launcher.mojom.h" |
13 #include "mojo/views/native_widget_view_manager.h" | 13 #include "mojo/views/native_widget_view_manager.h" |
14 #include "mojo/views/views_init.h" | 14 #include "mojo/views/views_init.h" |
15 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/textfield/textfield.h" |
16 #include "ui/views/controls/textfield/textfield_controller.h" | 16 #include "ui/views/controls/textfield/textfield_controller.h" |
17 #include "ui/views/layout/layout_manager.h" | 17 #include "ui/views/layout/layout_manager.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 namespace examples { | 23 namespace examples { |
24 | 24 |
25 class NodeView : public views::View { | 25 class NodeView : public views::View { |
26 public: | 26 public: |
27 explicit NodeView(view_manager::ViewTreeNode* node) : node_(node) { | 27 explicit NodeView(view_manager::Node* node) : node_(node) { |
28 // This class is provisional and assumes that the node has already been | 28 // This class is provisional and assumes that the node has already been |
29 // added to a parent. I suspect we'll want to make an improved version of | 29 // added to a parent. I suspect we'll want to make an improved version of |
30 // this that lives in ui/views akin to NativeViewHost that properly | 30 // this that lives in ui/views akin to NativeViewHost that properly |
31 // attaches/detaches when the view is. | 31 // attaches/detaches when the view is. |
32 DCHECK(node->parent()); | 32 DCHECK(node->parent()); |
33 } | 33 } |
34 virtual ~NodeView() {} | 34 virtual ~NodeView() {} |
35 | 35 |
36 // Overridden from views::View: | 36 // Overridden from views::View: |
37 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { | 37 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { |
38 node_->SetBounds(ConvertRectToWidget(GetLocalBounds())); | 38 node_->SetBounds(ConvertRectToWidget(GetLocalBounds())); |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 view_manager::ViewTreeNode* node_; | 42 view_manager::Node* node_; |
43 | 43 |
44 DISALLOW_COPY_AND_ASSIGN(NodeView); | 44 DISALLOW_COPY_AND_ASSIGN(NodeView); |
45 }; | 45 }; |
46 | 46 |
47 class BrowserLayoutManager : public views::LayoutManager { | 47 class BrowserLayoutManager : public views::LayoutManager { |
48 public: | 48 public: |
49 BrowserLayoutManager() {} | 49 BrowserLayoutManager() {} |
50 virtual ~BrowserLayoutManager() {} | 50 virtual ~BrowserLayoutManager() {} |
51 | 51 |
52 private: | 52 private: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 params.native_widget = new NativeWidgetViewManager(widget, view_); | 107 params.native_widget = new NativeWidgetViewManager(widget, view_); |
108 params.delegate = widget_delegate; | 108 params.delegate = widget_delegate; |
109 params.bounds = gfx::Rect(size.width(), size.height()); | 109 params.bounds = gfx::Rect(size.width(), size.height()); |
110 widget->Init(params); | 110 widget->Init(params); |
111 widget->Show(); | 111 widget->Show(); |
112 textfield->RequestFocus(); | 112 textfield->RequestFocus(); |
113 } | 113 } |
114 | 114 |
115 // view_manager::ViewManagerDelegate: | 115 // view_manager::ViewManagerDelegate: |
116 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | 116 virtual void OnRootAdded(view_manager::ViewManager* view_manager, |
117 view_manager::ViewTreeNode* root) OVERRIDE { | 117 view_manager::Node* root) OVERRIDE { |
118 // TODO: deal with OnRootAdded() being invoked multiple times. | 118 // TODO: deal with OnRootAdded() being invoked multiple times. |
119 view_manager_ = view_manager; | 119 view_manager_ = view_manager; |
120 view_ = view_manager::View::Create(view_manager_); | 120 view_ = view_manager::View::Create(view_manager_); |
121 view_manager_->GetRoots().front()->SetActiveView(view_); | 121 view_manager_->GetRoots().front()->SetActiveView(view_); |
122 | 122 |
123 content_node_ = view_manager::ViewTreeNode::Create(view_manager_); | 123 content_node_ = view_manager::Node::Create(view_manager_); |
124 root->AddChild(content_node_); | 124 root->AddChild(content_node_); |
125 | 125 |
126 root->SetFocus(); | 126 root->SetFocus(); |
127 | 127 |
128 CreateWidget(root->bounds().size()); | 128 CreateWidget(root->bounds().size()); |
129 } | 129 } |
130 virtual void OnRootRemoved(view_manager::ViewManager* view_manager, | 130 virtual void OnRootRemoved(view_manager::ViewManager* view_manager, |
131 view_manager::ViewTreeNode* root) OVERRIDE { | 131 view_manager::Node* root) OVERRIDE { |
132 } | 132 } |
133 | 133 |
134 // views::TextfieldController: | 134 // views::TextfieldController: |
135 virtual bool HandleKeyEvent(views::Textfield* sender, | 135 virtual bool HandleKeyEvent(views::Textfield* sender, |
136 const ui::KeyEvent& key_event) OVERRIDE { | 136 const ui::KeyEvent& key_event) OVERRIDE { |
137 if (key_event.key_code() == ui::VKEY_RETURN) { | 137 if (key_event.key_code() == ui::VKEY_RETURN) { |
138 GURL url(sender->text()); | 138 GURL url(sender->text()); |
139 printf("User entered this URL: %s\n", url.spec().c_str()); | 139 printf("User entered this URL: %s\n", url.spec().c_str()); |
140 launcher_->Launch(url.spec()); | 140 launcher_->Launch(url.spec()); |
141 } | 141 } |
(...skipping 11 matching lines...) Expand all Loading... |
153 ConnectTo(handler_url, &launchable); | 153 ConnectTo(handler_url, &launchable); |
154 launchable->OnLaunch(response.Pass(), | 154 launchable->OnLaunch(response.Pass(), |
155 response_body_stream.Pass(), | 155 response_body_stream.Pass(), |
156 content_node_->id()); | 156 content_node_->id()); |
157 } | 157 } |
158 | 158 |
159 scoped_ptr<ViewsInit> views_init_; | 159 scoped_ptr<ViewsInit> views_init_; |
160 | 160 |
161 view_manager::ViewManager* view_manager_; | 161 view_manager::ViewManager* view_manager_; |
162 view_manager::View* view_; | 162 view_manager::View* view_; |
163 view_manager::ViewTreeNode* content_node_; | 163 view_manager::Node* content_node_; |
164 launcher::LauncherPtr launcher_; | 164 launcher::LauncherPtr launcher_; |
165 | 165 |
166 DISALLOW_COPY_AND_ASSIGN(Browser); | 166 DISALLOW_COPY_AND_ASSIGN(Browser); |
167 }; | 167 }; |
168 | 168 |
169 } // namespace examples | 169 } // namespace examples |
170 | 170 |
171 // static | 171 // static |
172 Application* Application::Create() { | 172 Application* Application::Create() { |
173 return new examples::Browser; | 173 return new examples::Browser; |
174 } | 174 } |
175 | 175 |
176 } // namespace mojo | 176 } // namespace mojo |
OLD | NEW |