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 "examples/window_manager/debug_panel_host.mojom.h" | 7 #include "examples/window_manager/debug_panel_host.mojom.h" |
8 #include "examples/window_manager/window_manager.mojom.h" | 8 #include "examples/window_manager/window_manager.mojom.h" |
9 #include "mojo/application/application_runner_chromium.h" | 9 #include "mojo/application/application_runner_chromium.h" |
10 #include "mojo/common/binding_set.h" | 10 #include "mojo/common/binding_set.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 public InterfaceFactory<::examples::IWindowManager> { | 208 public InterfaceFactory<::examples::IWindowManager> { |
209 public: | 209 public: |
210 WindowManagerController(Shell* shell, | 210 WindowManagerController(Shell* shell, |
211 ApplicationImpl* app, | 211 ApplicationImpl* app, |
212 ApplicationConnection* connection, | 212 ApplicationConnection* connection, |
213 window_manager::WindowManagerRoot* wm_root) | 213 window_manager::WindowManagerRoot* wm_root) |
214 : shell_(shell), | 214 : shell_(shell), |
215 launcher_ui_(NULL), | 215 launcher_ui_(NULL), |
216 view_manager_(NULL), | 216 view_manager_(NULL), |
217 window_manager_root_(wm_root), | 217 window_manager_root_(wm_root), |
218 navigation_target_(TARGET_DEFAULT), | 218 navigation_target_(Target::DEFAULT), |
219 app_(app), | 219 app_(app), |
220 binding_(this) { | 220 binding_(this) { |
221 connection->AddService<::examples::IWindowManager>(this); | 221 connection->AddService<::examples::IWindowManager>(this); |
222 } | 222 } |
223 | 223 |
224 ~WindowManagerController() override { | 224 ~WindowManagerController() override { |
225 // host() may be destroyed by the time we get here. | 225 // host() may be destroyed by the time we get here. |
226 // TODO: figure out a way to always cleanly remove handler. | 226 // TODO: figure out a way to always cleanly remove handler. |
227 | 227 |
228 // TODO(erg): In the aura version, we removed ourselves from the | 228 // TODO(erg): In the aura version, we removed ourselves from the |
(...skipping 20 matching lines...) Expand all Loading... |
249 OnLaunch(source_view_id, target, url); | 249 OnLaunch(source_view_id, target, url); |
250 } | 250 } |
251 | 251 |
252 // Overridden from mojo::DebugPanelHost: | 252 // Overridden from mojo::DebugPanelHost: |
253 void CloseTopWindow() override { | 253 void CloseTopWindow() override { |
254 if (!windows_.empty()) | 254 if (!windows_.empty()) |
255 CloseWindow(windows_.back()->view()->id()); | 255 CloseWindow(windows_.back()->view()->id()); |
256 } | 256 } |
257 | 257 |
258 void NavigateTo(const String& url) override { | 258 void NavigateTo(const String& url) override { |
259 OnLaunch(control_panel_id_, TARGET_NEW_NODE, url); | 259 OnLaunch(control_panel_id_, Target::NEW_NODE, url); |
260 } | 260 } |
261 | 261 |
262 void SetNavigationTarget(Target t) override { navigation_target_ = t; } | 262 void SetNavigationTarget(Target t) override { navigation_target_ = t; } |
263 | 263 |
264 // mojo::InterfaceFactory<examples::DebugPanelHost> implementation. | 264 // mojo::InterfaceFactory<examples::DebugPanelHost> implementation. |
265 void Create( | 265 void Create( |
266 mojo::ApplicationConnection* connection, | 266 mojo::ApplicationConnection* connection, |
267 mojo::InterfaceRequest<examples::DebugPanelHost> request) override { | 267 mojo::InterfaceRequest<examples::DebugPanelHost> request) override { |
268 binding_.Bind(request.Pass()); | 268 binding_.Bind(request.Pass()); |
269 } | 269 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 DCHECK_EQ(view_manager_, view_manager); | 316 DCHECK_EQ(view_manager_, view_manager); |
317 view_manager_ = NULL; | 317 view_manager_ = NULL; |
318 base::MessageLoop::current()->Quit(); | 318 base::MessageLoop::current()->Quit(); |
319 } | 319 } |
320 | 320 |
321 // Overridden from WindowManagerDelegate: | 321 // Overridden from WindowManagerDelegate: |
322 void Embed(const String& url, | 322 void Embed(const String& url, |
323 InterfaceRequest<ServiceProvider> services, | 323 InterfaceRequest<ServiceProvider> services, |
324 ServiceProviderPtr exposed_services) override { | 324 ServiceProviderPtr exposed_services) override { |
325 const Id kInvalidSourceViewId = 0; | 325 const Id kInvalidSourceViewId = 0; |
326 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); | 326 OnLaunch(kInvalidSourceViewId, Target::DEFAULT, url); |
327 } | 327 } |
328 | 328 |
329 // Overridden from ui::EventHandler: | 329 // Overridden from ui::EventHandler: |
330 void OnEvent(ui::Event* event) override { | 330 void OnEvent(ui::Event* event) override { |
331 View* view = | 331 View* view = |
332 static_cast<window_manager::ViewTarget*>(event->target())->view(); | 332 static_cast<window_manager::ViewTarget*>(event->target())->view(); |
333 if (event->type() == ui::ET_MOUSE_PRESSED) | 333 if (event->type() == ui::ET_MOUSE_PRESSED) |
334 view->SetFocus(); | 334 view->SetFocus(); |
335 } | 335 } |
336 | 336 |
(...skipping 10 matching lines...) Expand all Loading... |
347 return true; | 347 return true; |
348 } | 348 } |
349 | 349 |
350 // Overriden from ui::AcceleratorTarget: | 350 // Overriden from ui::AcceleratorTarget: |
351 bool CanHandleAccelerators() const override { return true; } | 351 bool CanHandleAccelerators() const override { return true; } |
352 | 352 |
353 void OnLaunch(uint32 source_view_id, | 353 void OnLaunch(uint32 source_view_id, |
354 Target requested_target, | 354 Target requested_target, |
355 const mojo::String& url) { | 355 const mojo::String& url) { |
356 Target target = navigation_target_; | 356 Target target = navigation_target_; |
357 if (target == TARGET_DEFAULT) { | 357 if (target == Target::DEFAULT) { |
358 if (requested_target != TARGET_DEFAULT) { | 358 if (requested_target != Target::DEFAULT) { |
359 target = requested_target; | 359 target = requested_target; |
360 } else { | 360 } else { |
361 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin | 361 // TODO(aa): Should be Target::NEW_NODE if source origin and dest origin |
362 // are different? | 362 // are different? |
363 target = TARGET_SOURCE_NODE; | 363 target = Target::SOURCE_NODE; |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 Window* dest_view = NULL; | 367 Window* dest_view = NULL; |
368 if (target == TARGET_SOURCE_NODE) { | 368 if (target == Target::SOURCE_NODE) { |
369 WindowVector::iterator source_view = GetWindowByViewId(source_view_id); | 369 WindowVector::iterator source_view = GetWindowByViewId(source_view_id); |
370 bool app_initiated = source_view != windows_.end(); | 370 bool app_initiated = source_view != windows_.end(); |
371 if (app_initiated) | 371 if (app_initiated) |
372 dest_view = *source_view; | 372 dest_view = *source_view; |
373 else if (!windows_.empty()) | 373 else if (!windows_.empty()) |
374 dest_view = windows_.back(); | 374 dest_view = windows_.back(); |
375 } | 375 } |
376 | 376 |
377 if (!dest_view) { | 377 if (!dest_view) { |
378 dest_view = CreateWindow(); | 378 dest_view = CreateWindow(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 void NavigatorHostImpl::RequestNavigate(Target target, URLRequestPtr request) { | 530 void NavigatorHostImpl::RequestNavigate(Target target, URLRequestPtr request) { |
531 window_manager_->RequestNavigate(view_id_, target, request->url); | 531 window_manager_->RequestNavigate(view_id_, target, request->url); |
532 } | 532 } |
533 | 533 |
534 void NavigatorHostImpl::RequestNavigateHistory(int32_t delta) { | 534 void NavigatorHostImpl::RequestNavigateHistory(int32_t delta) { |
535 if (history_.empty()) | 535 if (history_.empty()) |
536 return; | 536 return; |
537 current_index_ = | 537 current_index_ = |
538 std::max(0, std::min(current_index_ + delta, | 538 std::max(0, std::min(current_index_ + delta, |
539 static_cast<int32_t>(history_.size()) - 1)); | 539 static_cast<int32_t>(history_.size()) - 1)); |
540 window_manager_->RequestNavigate(view_id_, TARGET_SOURCE_NODE, | 540 window_manager_->RequestNavigate(view_id_, Target::SOURCE_NODE, |
541 history_[current_index_]); | 541 history_[current_index_]); |
542 } | 542 } |
543 | 543 |
544 void NavigatorHostImpl::RecordNavigation(const std::string& url) { | 544 void NavigatorHostImpl::RecordNavigation(const std::string& url) { |
545 if (current_index_ >= 0 && history_[current_index_] == url) { | 545 if (current_index_ >= 0 && history_[current_index_] == url) { |
546 // This is a navigation to the current entry, ignore. | 546 // This is a navigation to the current entry, ignore. |
547 return; | 547 return; |
548 } | 548 } |
549 history_.erase(history_.begin() + (current_index_ + 1), history_.end()); | 549 history_.erase(history_.begin() + (current_index_ + 1), history_.end()); |
550 history_.push_back(url); | 550 history_.push_back(url); |
551 ++current_index_; | 551 ++current_index_; |
552 } | 552 } |
553 | 553 |
554 } // namespace examples | 554 } // namespace examples |
555 } // namespace mojo | 555 } // namespace mojo |
556 | 556 |
557 MojoResult MojoMain(MojoHandle application_request) { | 557 MojoResult MojoMain(MojoHandle application_request) { |
558 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 558 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
559 return runner.Run(application_request); | 559 return runner.Run(application_request); |
560 } | 560 } |
OLD | NEW |