| 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/macros.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 "examples/keyboard/keyboard.mojom.h" | 8 #include "examples/keyboard/keyboard.mojom.h" |
| 9 #include "examples/keyboard/keyboard_delegate.h" | 9 #include "examples/keyboard/keyboard_delegate.h" |
| 10 #include "examples/keyboard/keyboard_view.h" | 10 #include "examples/keyboard/keyboard_view.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); | 46 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class Keyboard : public ApplicationDelegate, | 49 class Keyboard : public ApplicationDelegate, |
| 50 public ViewManagerDelegate, | 50 public ViewManagerDelegate, |
| 51 public KeyboardDelegate { | 51 public KeyboardDelegate { |
| 52 public: | 52 public: |
| 53 Keyboard() | 53 Keyboard() |
| 54 : shell_(nullptr), | 54 : shell_(nullptr), |
| 55 keyboard_service_factory_(this), | 55 keyboard_service_factory_(this), |
| 56 view_manager_(NULL), | |
| 57 keyboard_service_(NULL), | 56 keyboard_service_(NULL), |
| 58 target_(0) {} | 57 target_(0) {} |
| 59 | 58 |
| 60 virtual ~Keyboard() { | 59 virtual ~Keyboard() { |
| 61 } | 60 } |
| 62 | 61 |
| 63 void set_target(Id id) { target_ = id; } | 62 void set_target(Id id) { target_ = id; } |
| 64 | 63 |
| 65 void set_keyboard_service(KeyboardServiceImpl* keyboard) { | 64 void set_keyboard_service(KeyboardServiceImpl* keyboard) { |
| 66 keyboard_service_ = keyboard; | 65 keyboard_service_ = keyboard; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 91 views::Widget::InitParams params( | 90 views::Widget::InitParams params( |
| 92 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 93 params.native_widget = new NativeWidgetViewManager(widget, shell_, view); | 92 params.native_widget = new NativeWidgetViewManager(widget, shell_, view); |
| 94 params.delegate = widget_delegate; | 93 params.delegate = widget_delegate; |
| 95 params.bounds = gfx::Rect(view->bounds().width, view->bounds().height); | 94 params.bounds = gfx::Rect(view->bounds().width, view->bounds().height); |
| 96 widget->Init(params); | 95 widget->Init(params); |
| 97 widget->Show(); | 96 widget->Show(); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // ViewManagerDelegate: | 99 // ViewManagerDelegate: |
| 101 virtual void OnEmbed(ViewManager* view_manager, | 100 virtual void OnEmbed(View* root, |
| 102 View* root, | |
| 103 ServiceProviderImpl* exported_services, | 101 ServiceProviderImpl* exported_services, |
| 104 scoped_ptr<ServiceProvider> imported_services) override { | 102 scoped_ptr<ServiceProvider> imported_services) override { |
| 105 // TODO: deal with OnEmbed() being invoked multiple times. | 103 // TODO: deal with OnEmbed() being invoked multiple times. |
| 106 view_manager_ = view_manager; | |
| 107 CreateWidget(root); | 104 CreateWidget(root); |
| 108 } | 105 } |
| 109 virtual void OnViewManagerDisconnected( | 106 virtual void OnViewManagerDisconnected( |
| 110 ViewManager* view_manager) override { | 107 ViewManager* view_manager) override { |
| 111 DCHECK_EQ(view_manager_, view_manager); | |
| 112 view_manager_ = NULL; | |
| 113 base::MessageLoop::current()->Quit(); | 108 base::MessageLoop::current()->Quit(); |
| 114 } | 109 } |
| 115 | 110 |
| 116 // KeyboardDelegate: | 111 // KeyboardDelegate: |
| 117 virtual void OnKeyPressed(int key_code, int event_flags) override { | 112 virtual void OnKeyPressed(int key_code, int event_flags) override { |
| 118 if (!target_) | 113 if (!target_) |
| 119 return; | 114 return; |
| 120 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, | 115 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, |
| 121 event_flags); | 116 event_flags); |
| 122 } | 117 } |
| 123 | 118 |
| 124 Shell* shell_; | 119 Shell* shell_; |
| 125 | 120 |
| 126 InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard> | 121 InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard> |
| 127 keyboard_service_factory_; | 122 keyboard_service_factory_; |
| 128 | 123 |
| 129 scoped_ptr<ViewsInit> views_init_; | 124 scoped_ptr<ViewsInit> views_init_; |
| 130 | 125 |
| 131 ViewManager* view_manager_; | |
| 132 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 126 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
| 133 | 127 |
| 134 KeyboardServiceImpl* keyboard_service_; | 128 KeyboardServiceImpl* keyboard_service_; |
| 135 | 129 |
| 136 Id target_; | 130 Id target_; |
| 137 | 131 |
| 138 DISALLOW_COPY_AND_ASSIGN(Keyboard); | 132 DISALLOW_COPY_AND_ASSIGN(Keyboard); |
| 139 }; | 133 }; |
| 140 | 134 |
| 141 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) | 135 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) |
| 142 : keyboard_(keyboard) { | 136 : keyboard_(keyboard) { |
| 143 keyboard_->set_keyboard_service(this); | 137 keyboard_->set_keyboard_service(this); |
| 144 } | 138 } |
| 145 | 139 |
| 146 void KeyboardServiceImpl::SetTarget(uint32_t view_id) { | 140 void KeyboardServiceImpl::SetTarget(uint32_t view_id) { |
| 147 keyboard_->set_target(view_id); | 141 keyboard_->set_target(view_id); |
| 148 } | 142 } |
| 149 | 143 |
| 150 } // namespace examples | 144 } // namespace examples |
| 151 } // namespace mojo | 145 } // namespace mojo |
| 152 | 146 |
| 153 MojoResult MojoMain(MojoHandle shell_handle) { | 147 MojoResult MojoMain(MojoHandle shell_handle) { |
| 154 mojo::ApplicationRunnerChromium runner(new mojo::examples::Keyboard); | 148 mojo::ApplicationRunnerChromium runner(new mojo::examples::Keyboard); |
| 155 return runner.Run(shell_handle); | 149 return runner.Run(shell_handle); |
| 156 } | 150 } |
| OLD | NEW |