| 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 "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/common/common_type_converters.h" | 8 #include "mojo/common/common_type_converters.h" |
| 9 #include "mojo/examples/window_manager/window_manager.mojom.h" | 9 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
| 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 14 #include "mojo/services/public/cpp/view_manager/node.h" | 14 #include "mojo/services/public/cpp/view_manager/node.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view.h" | 15 #include "mojo/services/public/cpp/view_manager/view.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 19 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 20 #include "mojo/views/native_widget_view_manager.h" | 21 #include "mojo/views/native_widget_view_manager.h" |
| 21 #include "mojo/views/views_init.h" | 22 #include "mojo/views/views_init.h" |
| 22 #include "ui/aura/client/focus_client.h" | 23 #include "ui/aura/client/focus_client.h" |
| 23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 25 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 26 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); | 146 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 // This is the basics of creating a views widget with a textfield. | 149 // This is the basics of creating a views widget with a textfield. |
| 149 // TODO: cleanup! | 150 // TODO: cleanup! |
| 150 class Browser : public ApplicationDelegate, | 151 class Browser : public ApplicationDelegate, |
| 151 public view_manager::ViewManagerDelegate, | 152 public view_manager::ViewManagerDelegate, |
| 152 public views::TextfieldController, | 153 public views::TextfieldController, |
| 153 public view_manager::NodeObserver { | 154 public view_manager::NodeObserver { |
| 154 public: | 155 public: |
| 155 Browser() : view_manager_(NULL), root_(NULL), widget_(NULL) {} | 156 Browser() |
| 157 : view_manager_(NULL), |
| 158 view_manager_client_factory_(this), |
| 159 root_(NULL), |
| 160 widget_(NULL) {} |
| 156 | 161 |
| 157 virtual ~Browser() { | 162 virtual ~Browser() { |
| 158 if (root_) | 163 if (root_) |
| 159 root_->RemoveObserver(this); | 164 root_->RemoveObserver(this); |
| 160 } | 165 } |
| 161 | 166 |
| 162 private: | 167 private: |
| 163 // Overridden from ApplicationDelegate: | 168 // Overridden from ApplicationDelegate: |
| 164 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 169 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 165 views_init_.reset(new ViewsInit); | 170 views_init_.reset(new ViewsInit); |
| 166 app->ConnectToService("mojo:mojo_window_manager", &navigator_host_); | 171 app->ConnectToService("mojo:mojo_window_manager", &navigator_host_); |
| 167 app->ConnectToService("mojo:mojo_window_manager", &window_manager_); | 172 app->ConnectToService("mojo:mojo_window_manager", &window_manager_); |
| 168 } | 173 } |
| 169 | 174 |
| 170 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 175 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 171 MOJO_OVERRIDE { | 176 MOJO_OVERRIDE { |
| 172 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | 177 connection->AddService(&view_manager_client_factory_); |
| 173 return true; | 178 return true; |
| 174 } | 179 } |
| 175 | 180 |
| 176 void CreateWidget(view_manager::Node* node) { | 181 void CreateWidget(view_manager::Node* node) { |
| 177 views::Textfield* textfield = new views::Textfield; | 182 views::Textfield* textfield = new views::Textfield; |
| 178 textfield->set_controller(this); | 183 textfield->set_controller(this); |
| 179 | 184 |
| 180 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 185 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 181 widget_delegate->GetContentsView()->set_background( | 186 widget_delegate->GetContentsView()->set_background( |
| 182 views::Background::CreateSolidBackground(SK_ColorBLUE)); | 187 views::Background::CreateSolidBackground(SK_ColorBLUE)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 248 } |
| 244 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE { | 249 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE { |
| 245 DCHECK_EQ(root_, node); | 250 DCHECK_EQ(root_, node); |
| 246 node->RemoveObserver(this); | 251 node->RemoveObserver(this); |
| 247 root_ = NULL; | 252 root_ = NULL; |
| 248 } | 253 } |
| 249 | 254 |
| 250 scoped_ptr<ViewsInit> views_init_; | 255 scoped_ptr<ViewsInit> views_init_; |
| 251 | 256 |
| 252 view_manager::ViewManager* view_manager_; | 257 view_manager::ViewManager* view_manager_; |
| 258 view_manager::ViewManagerClientFactory view_manager_client_factory_; |
| 253 view_manager::Node* root_; | 259 view_manager::Node* root_; |
| 254 views::Widget* widget_; | 260 views::Widget* widget_; |
| 255 navigation::NavigatorHostPtr navigator_host_; | 261 navigation::NavigatorHostPtr navigator_host_; |
| 256 IWindowManagerPtr window_manager_; | 262 IWindowManagerPtr window_manager_; |
| 257 | 263 |
| 258 DISALLOW_COPY_AND_ASSIGN(Browser); | 264 DISALLOW_COPY_AND_ASSIGN(Browser); |
| 259 }; | 265 }; |
| 260 | 266 |
| 261 } // namespace examples | 267 } // namespace examples |
| 262 | 268 |
| 263 // static | 269 // static |
| 264 ApplicationDelegate* ApplicationDelegate::Create() { | 270 ApplicationDelegate* ApplicationDelegate::Create() { |
| 265 return new examples::Browser; | 271 return new examples::Browser; |
| 266 } | 272 } |
| 267 | 273 |
| 268 } // namespace mojo | 274 } // namespace mojo |
| OLD | NEW |