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/macros.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/application/application_runner_chromium.h" | 8 #include "mojo/application/application_runner_chromium.h" |
9 #include "mojo/common/common_type_converters.h" | 9 #include "mojo/common/common_type_converters.h" |
10 #include "mojo/examples/window_manager/window_manager.mojom.h" | 10 #include "mojo/examples/window_manager/window_manager.mojom.h" |
11 #include "mojo/public/c/system/main.h" | 11 #include "mojo/public/c/system/main.h" |
12 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
13 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
15 #include "mojo/public/cpp/application/connect.h" | 15 #include "mojo/public/cpp/application/connect.h" |
(...skipping 21 matching lines...) Expand all Loading... |
37 namespace mojo { | 37 namespace mojo { |
38 namespace examples { | 38 namespace examples { |
39 | 39 |
40 class BrowserLayoutManager : public views::LayoutManager { | 40 class BrowserLayoutManager : public views::LayoutManager { |
41 public: | 41 public: |
42 BrowserLayoutManager() {} | 42 BrowserLayoutManager() {} |
43 virtual ~BrowserLayoutManager() {} | 43 virtual ~BrowserLayoutManager() {} |
44 | 44 |
45 private: | 45 private: |
46 // Overridden from views::LayoutManager: | 46 // Overridden from views::LayoutManager: |
47 virtual void Layout(views::View* host) OVERRIDE { | 47 virtual void Layout(views::View* host) override { |
48 // Browser view has one child, a text input field. | 48 // Browser view has one child, a text input field. |
49 DCHECK_EQ(1, host->child_count()); | 49 DCHECK_EQ(1, host->child_count()); |
50 views::View* text_field = host->child_at(0); | 50 views::View* text_field = host->child_at(0); |
51 gfx::Size ps = text_field->GetPreferredSize(); | 51 gfx::Size ps = text_field->GetPreferredSize(); |
52 text_field->SetBoundsRect(gfx::Rect(host->width(), ps.height())); | 52 text_field->SetBoundsRect(gfx::Rect(host->width(), ps.height())); |
53 } | 53 } |
54 virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE { | 54 virtual gfx::Size GetPreferredSize(const views::View* host) const override { |
55 return gfx::Size(); | 55 return gfx::Size(); |
56 } | 56 } |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager); | 58 DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager); |
59 }; | 59 }; |
60 | 60 |
61 // KeyboardManager handles notifying the windowmanager when views are focused. | 61 // KeyboardManager handles notifying the windowmanager when views are focused. |
62 // To use create one and KeyboardManager will take care of all other details. | 62 // To use create one and KeyboardManager will take care of all other details. |
63 // | 63 // |
64 // TODO(sky): it would be nice if this were put in NativeWidgetViewManager, but | 64 // TODO(sky): it would be nice if this were put in NativeWidgetViewManager, but |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 if (!focused_view_) | 108 if (!focused_view_) |
109 return; | 109 return; |
110 | 110 |
111 window_manager_->HideKeyboard(last_view_id_); | 111 window_manager_->HideKeyboard(last_view_id_); |
112 last_view_id_ = 0; | 112 last_view_id_ = 0; |
113 focused_view_ = NULL; | 113 focused_view_ = NULL; |
114 } | 114 } |
115 | 115 |
116 // views::FocusChangeListener: | 116 // views::FocusChangeListener: |
117 virtual void OnWillChangeFocus(views::View* focused_before, | 117 virtual void OnWillChangeFocus(views::View* focused_before, |
118 views::View* focused_now) OVERRIDE { | 118 views::View* focused_now) override { |
119 } | 119 } |
120 virtual void OnDidChangeFocus(views::View* focused_before, | 120 virtual void OnDidChangeFocus(views::View* focused_before, |
121 views::View* focused_now) OVERRIDE { | 121 views::View* focused_now) override { |
122 if (focused_view_ && focused_now != focused_view_) | 122 if (focused_view_ && focused_now != focused_view_) |
123 HideKeyboard(); | 123 HideKeyboard(); |
124 } | 124 } |
125 | 125 |
126 // ui::EventHandler: | 126 // ui::EventHandler: |
127 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 127 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
128 views::View* focused_now = widget_->GetFocusManager()->GetFocusedView(); | 128 views::View* focused_now = widget_->GetFocusManager()->GetFocusedView(); |
129 if (focused_now && | 129 if (focused_now && |
130 focused_now->GetClassName() == views::Textfield::kViewClassName && | 130 focused_now->GetClassName() == views::Textfield::kViewClassName && |
131 (event->flags() & ui::EF_FROM_TOUCH) != 0) { | 131 (event->flags() & ui::EF_FROM_TOUCH) != 0) { |
132 ShowKeyboard(focused_now); | 132 ShowKeyboard(focused_now); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 // views::WidgetObserver: | 136 // views::WidgetObserver: |
137 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { | 137 virtual void OnWidgetDestroying(views::Widget* widget) override { |
138 delete this; | 138 delete this; |
139 } | 139 } |
140 | 140 |
141 views::Widget* widget_; | 141 views::Widget* widget_; |
142 IWindowManager* window_manager_; | 142 IWindowManager* window_manager_; |
143 View* view_; | 143 View* view_; |
144 Id last_view_id_; | 144 Id last_view_id_; |
145 views::View* focused_view_; | 145 views::View* focused_view_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); | 147 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // KeyboardManager handles deleting itself when the widget is destroyed. | 200 // KeyboardManager handles deleting itself when the widget is destroyed. |
201 new KeyboardManager(widget_, window_manager_.get(), view); | 201 new KeyboardManager(widget_, window_manager_.get(), view); |
202 widget_->Show(); | 202 widget_->Show(); |
203 textfield->RequestFocus(); | 203 textfield->RequestFocus(); |
204 } | 204 } |
205 | 205 |
206 // ViewManagerDelegate: | 206 // ViewManagerDelegate: |
207 virtual void OnEmbed(ViewManager* view_manager, | 207 virtual void OnEmbed(ViewManager* view_manager, |
208 View* root, | 208 View* root, |
209 ServiceProviderImpl* exported_services, | 209 ServiceProviderImpl* exported_services, |
210 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 210 scoped_ptr<ServiceProvider> imported_services) override { |
211 // TODO: deal with OnEmbed() being invoked multiple times. | 211 // TODO: deal with OnEmbed() being invoked multiple times. |
212 ConnectToService(imported_services.get(), &navigator_host_); | 212 ConnectToService(imported_services.get(), &navigator_host_); |
213 view_manager_ = view_manager; | 213 view_manager_ = view_manager; |
214 root_ = root; | 214 root_ = root; |
215 root_->AddObserver(this); | 215 root_->AddObserver(this); |
216 root_->SetFocus(); | 216 root_->SetFocus(); |
217 CreateWidget(root_); | 217 CreateWidget(root_); |
218 } | 218 } |
219 virtual void OnViewManagerDisconnected( | 219 virtual void OnViewManagerDisconnected( |
220 ViewManager* view_manager) OVERRIDE { | 220 ViewManager* view_manager) override { |
221 DCHECK_EQ(view_manager_, view_manager); | 221 DCHECK_EQ(view_manager_, view_manager); |
222 view_manager_ = NULL; | 222 view_manager_ = NULL; |
223 base::MessageLoop::current()->Quit(); | 223 base::MessageLoop::current()->Quit(); |
224 } | 224 } |
225 | 225 |
226 // views::TextfieldController: | 226 // views::TextfieldController: |
227 virtual bool HandleKeyEvent(views::Textfield* sender, | 227 virtual bool HandleKeyEvent(views::Textfield* sender, |
228 const ui::KeyEvent& key_event) OVERRIDE { | 228 const ui::KeyEvent& key_event) override { |
229 if (key_event.key_code() == ui::VKEY_RETURN) { | 229 if (key_event.key_code() == ui::VKEY_RETURN) { |
230 GURL url(sender->text()); | 230 GURL url(sender->text()); |
231 printf("User entered this URL: %s\n", url.spec().c_str()); | 231 printf("User entered this URL: %s\n", url.spec().c_str()); |
232 URLRequestPtr request(URLRequest::New()); | 232 URLRequestPtr request(URLRequest::New()); |
233 request->url = String::From(url); | 233 request->url = String::From(url); |
234 navigator_host_->RequestNavigate(TARGET_NEW_NODE, request.Pass()); | 234 navigator_host_->RequestNavigate(TARGET_NEW_NODE, request.Pass()); |
235 } | 235 } |
236 return false; | 236 return false; |
237 } | 237 } |
238 | 238 |
239 // ViewObserver: | 239 // ViewObserver: |
240 virtual void OnViewFocusChanged(View* gained_focus, | 240 virtual void OnViewFocusChanged(View* gained_focus, |
241 View* lost_focus) OVERRIDE { | 241 View* lost_focus) override { |
242 aura::client::FocusClient* focus_client = | 242 aura::client::FocusClient* focus_client = |
243 aura::client::GetFocusClient(widget_->GetNativeView()); | 243 aura::client::GetFocusClient(widget_->GetNativeView()); |
244 if (lost_focus == root_) | 244 if (lost_focus == root_) |
245 focus_client->FocusWindow(NULL); | 245 focus_client->FocusWindow(NULL); |
246 else if (gained_focus == root_) | 246 else if (gained_focus == root_) |
247 focus_client->FocusWindow(widget_->GetNativeView()); | 247 focus_client->FocusWindow(widget_->GetNativeView()); |
248 } | 248 } |
249 virtual void OnViewDestroyed(View* view) OVERRIDE { | 249 virtual void OnViewDestroyed(View* view) override { |
250 DCHECK_EQ(root_, view); | 250 DCHECK_EQ(root_, view); |
251 view->RemoveObserver(this); | 251 view->RemoveObserver(this); |
252 root_ = NULL; | 252 root_ = NULL; |
253 } | 253 } |
254 | 254 |
255 scoped_ptr<ViewsInit> views_init_; | 255 scoped_ptr<ViewsInit> views_init_; |
256 | 256 |
257 ViewManager* view_manager_; | 257 ViewManager* view_manager_; |
258 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 258 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
259 View* root_; | 259 View* root_; |
260 views::Widget* widget_; | 260 views::Widget* widget_; |
261 NavigatorHostPtr navigator_host_; | 261 NavigatorHostPtr navigator_host_; |
262 IWindowManagerPtr window_manager_; | 262 IWindowManagerPtr window_manager_; |
263 | 263 |
264 DISALLOW_COPY_AND_ASSIGN(Browser); | 264 DISALLOW_COPY_AND_ASSIGN(Browser); |
265 }; | 265 }; |
266 | 266 |
267 } // namespace examples | 267 } // namespace examples |
268 } // namespace mojo | 268 } // namespace mojo |
269 | 269 |
270 MojoResult MojoMain(MojoHandle shell_handle) { | 270 MojoResult MojoMain(MojoHandle shell_handle) { |
271 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); | 271 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); |
272 return runner.Run(shell_handle); | 272 return runner.Run(shell_handle); |
273 } | 273 } |
OLD | NEW |