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