| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
| 8 #include "mojo/converters/geometry/geometry_type_converters.h" | 8 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 9 #include "mojo/converters/input_events/input_events_type_converters.h" | 9 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 10 #include "mojo/examples/keyboard/keyboard.mojom.h" | 10 #include "mojo/examples/keyboard/keyboard.mojom.h" |
| 11 #include "mojo/examples/window_manager/debug_panel.h" | 11 #include "mojo/examples/window_manager/debug_panel.h" |
| 12 #include "mojo/examples/window_manager/window_manager.mojom.h" | 12 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 13 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
| 14 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
| 15 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
| 16 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
| 17 #include "mojo/public/cpp/application/interface_factory_impl.h" | 17 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 18 #include "mojo/public/cpp/application/service_provider_impl.h" | 18 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 19 #include "mojo/services/public/cpp/view_manager/view.h" | 19 #include "mojo/services/public/cpp/view_manager/view.h" |
| 20 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 22 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 22 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 23 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | |
| 24 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
| 25 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 26 #include "mojo/services/window_manager/window_manager_app.h" | 25 #include "mojo/services/window_manager/window_manager_app.h" |
| 26 #include "mojo/services/window_manager/window_manager_delegate.h" |
| 27 #include "mojo/views/views_init.h" | 27 #include "mojo/views/views_init.h" |
| 28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 29 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 30 #include "ui/events/event_constants.h" | 30 #include "ui/events/event_constants.h" |
| 31 #include "ui/gfx/geometry/size_conversions.h" | 31 #include "ui/gfx/geometry/size_conversions.h" |
| 32 #include "ui/wm/core/focus_rules.h" | 32 #include "ui/wm/core/focus_rules.h" |
| 33 | 33 |
| 34 #if defined CreateWindow | 34 #if defined CreateWindow |
| 35 #undef CreateWindow | 35 #undef CreateWindow |
| 36 #endif | 36 #endif |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 void Hide(Id view_id) { | 174 void Hide(Id view_id) { |
| 175 keyboard_service_->SetTarget(0); | 175 keyboard_service_->SetTarget(0); |
| 176 view_->SetVisible(false); | 176 view_->SetVisible(false); |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 // KeyboardClient: | 180 // KeyboardClient: |
| 181 virtual void OnKeyboardEvent(Id view_id, | 181 virtual void OnKeyboardEvent(Id view_id, |
| 182 int32_t code, | 182 int32_t code, |
| 183 int32_t flags) override { | 183 int32_t flags) override { |
| 184 View* view = view_manager_->GetViewById(view_id); | 184 // TODO(sky): figure this out. Code use to dispatch events, but that's a |
| 185 if (!view) | 185 // hack. Instead strings should be passed through, or maybe a richer text |
| 186 return; | 186 // input interface. |
| 187 #if defined(OS_WIN) | |
| 188 const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN; | |
| 189 #else | |
| 190 const bool is_char = false; | |
| 191 #endif | |
| 192 if (is_char) { | |
| 193 view_manager_->DispatchEvent( | |
| 194 view, | |
| 195 Event::From(ui::KeyEvent(ui::ET_KEY_PRESSED, | |
| 196 static_cast<ui::KeyboardCode>(code), | |
| 197 flags))); | |
| 198 } else { | |
| 199 view_manager_->DispatchEvent( | |
| 200 view, | |
| 201 Event::From(ui::KeyEvent(static_cast<base::char16>(code), | |
| 202 static_cast<ui::KeyboardCode>(code), | |
| 203 flags))); | |
| 204 } | |
| 205 view_manager_->DispatchEvent( | |
| 206 view, | |
| 207 Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED, | |
| 208 static_cast<ui::KeyboardCode>(code), | |
| 209 flags))); | |
| 210 } | 187 } |
| 211 | 188 |
| 212 // Overridden from ViewObserver: | 189 // Overridden from ViewObserver: |
| 213 virtual void OnViewBoundsChanged(View* parent, | 190 virtual void OnViewBoundsChanged(View* parent, |
| 214 const gfx::Rect& old_bounds, | 191 const gfx::Rect& old_bounds, |
| 215 const gfx::Rect& new_bounds) override { | 192 const gfx::Rect& new_bounds) override { |
| 216 gfx::Rect keyboard_bounds(view_->bounds()); | 193 gfx::Rect keyboard_bounds(view_->bounds()); |
| 217 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height()); | 194 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height()); |
| 218 keyboard_bounds.set_width(keyboard_bounds.width() + | 195 keyboard_bounds.set_width(keyboard_bounds.width() + |
| 219 new_bounds.width() - old_bounds.width()); | 196 new_bounds.width() - old_bounds.width()); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 base::MessageLoop::current()->Quit(); | 433 base::MessageLoop::current()->Quit(); |
| 457 } | 434 } |
| 458 | 435 |
| 459 // Overridden from WindowManagerDelegate: | 436 // Overridden from WindowManagerDelegate: |
| 460 virtual void Embed( | 437 virtual void Embed( |
| 461 const String& url, | 438 const String& url, |
| 462 InterfaceRequest<ServiceProvider> service_provider) override { | 439 InterfaceRequest<ServiceProvider> service_provider) override { |
| 463 const Id kInvalidSourceViewId = 0; | 440 const Id kInvalidSourceViewId = 0; |
| 464 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); | 441 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); |
| 465 } | 442 } |
| 466 virtual void DispatchEvent(EventPtr event) override {} | |
| 467 | 443 |
| 468 // Overridden from ui::EventHandler: | 444 // Overridden from ui::EventHandler: |
| 469 virtual void OnEvent(ui::Event* event) override { | 445 virtual void OnEvent(ui::Event* event) override { |
| 470 View* view = WindowManagerApp::GetViewForWindow( | 446 View* view = WindowManagerApp::GetViewForWindow( |
| 471 static_cast<aura::Window*>(event->target())); | 447 static_cast<aura::Window*>(event->target())); |
| 472 if (event->type() == ui::ET_MOUSE_PRESSED && | 448 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 473 !IsDescendantOfKeyboard(view)) { | 449 !IsDescendantOfKeyboard(view)) { |
| 474 view->SetFocus(); | 450 view->SetFocus(); |
| 475 } | 451 } |
| 476 } | 452 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 window_manager_->RequestNavigate(view_id_, target, request.Pass()); | 594 window_manager_->RequestNavigate(view_id_, target, request.Pass()); |
| 619 } | 595 } |
| 620 | 596 |
| 621 } // namespace examples | 597 } // namespace examples |
| 622 } // namespace mojo | 598 } // namespace mojo |
| 623 | 599 |
| 624 MojoResult MojoMain(MojoHandle shell_handle) { | 600 MojoResult MojoMain(MojoHandle shell_handle) { |
| 625 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 601 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
| 626 return runner.Run(shell_handle); | 602 return runner.Run(shell_handle); |
| 627 } | 603 } |
| OLD | NEW |