OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell.h" | 5 #include "content/shell/browser/shell.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/render_widget_host_view.h" | 9 #include "content/public/browser/render_widget_host_view.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "ui/views/layout/fill_layout.h" | 32 #include "ui/views/layout/fill_layout.h" |
33 #include "ui/views/layout/grid_layout.h" | 33 #include "ui/views/layout/grid_layout.h" |
34 #include "ui/views/test/desktop_test_views_delegate.h" | 34 #include "ui/views/test/desktop_test_views_delegate.h" |
35 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
36 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 36 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
37 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
38 #include "ui/views/widget/widget_delegate.h" | 38 #include "ui/views/widget/widget_delegate.h" |
39 | 39 |
40 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
41 #include "chromeos/dbus/dbus_thread_manager.h" | 41 #include "chromeos/dbus/dbus_thread_manager.h" |
| 42 #include "ui/aura/client/window_tree_client.h" |
| 43 #include "ui/aura/test/test_focus_client.h" |
42 #include "ui/aura/test/test_screen.h" | 44 #include "ui/aura/test/test_screen.h" |
43 #include "ui/wm/test/wm_test_helper.h" | 45 #include "ui/aura/window_observer.h" |
| 46 #include "ui/aura/window_tree_host.h" |
| 47 #include "ui/wm/core/compound_event_filter.h" |
| 48 #include "ui/wm/core/input_method_event_filter.h" |
44 #endif | 49 #endif |
45 | 50 |
46 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
47 #include <fcntl.h> | 52 #include <fcntl.h> |
48 #include <io.h> | 53 #include <io.h> |
49 #endif | 54 #endif |
50 | 55 |
51 namespace content { | 56 namespace content { |
52 | 57 |
53 namespace { | 58 namespace { |
54 // ViewDelegate implementation for aura content shell | 59 // ViewDelegate implementation for aura content shell |
55 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { | 60 class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { |
56 public: | 61 public: |
57 ShellViewsDelegateAura() : use_transparent_windows_(false) { | 62 ShellViewsDelegateAura() : use_transparent_windows_(false) { |
58 } | 63 } |
59 | 64 |
60 virtual ~ShellViewsDelegateAura() { | 65 virtual ~ShellViewsDelegateAura() { |
61 } | 66 } |
62 | 67 |
63 void SetUseTransparentWindows(bool transparent) { | 68 void SetUseTransparentWindows(bool transparent) { |
64 use_transparent_windows_ = transparent; | 69 use_transparent_windows_ = transparent; |
65 } | 70 } |
66 | 71 |
67 private: | 72 private: |
68 bool use_transparent_windows_; | 73 bool use_transparent_windows_; |
69 | 74 |
70 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura); | 75 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura); |
71 }; | 76 }; |
72 | 77 |
| 78 #if defined(OS_CHROMEOS) |
| 79 class ShellWindowTreeClient : public aura::client::WindowTreeClient, |
| 80 public aura::WindowObserver { |
| 81 public: |
| 82 ShellWindowTreeClient(aura::WindowTreeHost* host) : host_(host) { |
| 83 host_->window()->AddObserver(this); |
| 84 aura::client::SetWindowTreeClient(host_->window(), this); |
| 85 input_method_filter_.reset( |
| 86 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); |
| 87 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window()); |
| 88 } |
| 89 virtual ~ShellWindowTreeClient() { |
| 90 host_->window()->RemoveObserver(this); |
| 91 } |
| 92 |
| 93 private: |
| 94 // Overridden from aura::client::WindowTreeClient: |
| 95 virtual aura::Window* GetDefaultParent( |
| 96 aura::Window* context, |
| 97 aura::Window* window, |
| 98 const gfx::Rect& bounds) OVERRIDE { |
| 99 return host_->window(); |
| 100 } |
| 101 |
| 102 // Overridden from aura::WindowObserver: |
| 103 virtual void OnWindowDestroyed(aura::Window* window) { |
| 104 DCHECK_EQ(window, host_->window()); |
| 105 delete this; |
| 106 } |
| 107 |
| 108 aura::WindowTreeHost* host_; |
| 109 wm::CompoundEventFilter* root_window_event_filter_; |
| 110 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
| 111 scoped_ptr<wm::InputMethodEventFilter> input_method_filter_; |
| 112 scoped_ptr<wm::DefaultActivationClient> activation_client_; |
| 113 scoped_ptr<aura::client::FocusClient> focus_client_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(ShellWindowTreeClient); |
| 116 }; |
| 117 #endif // OS_CHROMEOS |
| 118 |
73 // Model for the "Debug" menu | 119 // Model for the "Debug" menu |
74 class ContextMenuModel : public ui::SimpleMenuModel, | 120 class ContextMenuModel : public ui::SimpleMenuModel, |
75 public ui::SimpleMenuModel::Delegate { | 121 public ui::SimpleMenuModel::Delegate { |
76 public: | 122 public: |
77 explicit ContextMenuModel( | 123 explicit ContextMenuModel( |
78 Shell* shell, const content::ContextMenuParams& params) | 124 Shell* shell, const content::ContextMenuParams& params) |
79 : ui::SimpleMenuModel(this), | 125 : ui::SimpleMenuModel(this), |
80 shell_(shell), | 126 shell_(shell), |
81 params_(params) { | 127 params_(params) { |
82 AddItem(COMMAND_OPEN_DEVTOOLS, base::ASCIIToUTF16("Inspect Element")); | 128 AddItem(COMMAND_OPEN_DEVTOOLS, base::ASCIIToUTF16("Inspect Element")); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // Contents view contains the web contents view | 447 // Contents view contains the web contents view |
402 View* contents_view_; | 448 View* contents_view_; |
403 views::WebView* web_view_; | 449 views::WebView* web_view_; |
404 | 450 |
405 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); | 451 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); |
406 }; | 452 }; |
407 | 453 |
408 } // namespace | 454 } // namespace |
409 | 455 |
410 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
411 wm::WMTestHelper* Shell::wm_test_helper_ = NULL; | 457 aura::WindowTreeHost* Shell::shell_host_ = NULL; |
412 #endif | 458 #endif |
413 views::ViewsDelegate* Shell::views_delegate_ = NULL; | 459 views::ViewsDelegate* Shell::views_delegate_ = NULL; |
414 | 460 |
415 // static | 461 // static |
416 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { | 462 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
417 #if defined(OS_WIN) | 463 #if defined(OS_WIN) |
418 _setmode(_fileno(stdout), _O_BINARY); | 464 _setmode(_fileno(stdout), _O_BINARY); |
419 _setmode(_fileno(stderr), _O_BINARY); | 465 _setmode(_fileno(stderr), _O_BINARY); |
420 #endif | 466 #endif |
421 #if defined(OS_CHROMEOS) | 467 #if defined(OS_CHROMEOS) |
422 chromeos::DBusThreadManager::Initialize(); | 468 chromeos::DBusThreadManager::Initialize(); |
423 gfx::Screen::SetScreenInstance( | 469 gfx::Screen::SetScreenInstance( |
424 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); | 470 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); |
425 wm_test_helper_ = new wm::WMTestHelper(default_window_size); | 471 aura::Env::CreateInstance(); |
| 472 shell_host_ = aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600)); |
| 473 new ShellWindowTreeClient(shell_host_); // Deletes itself when host dies. |
426 #else | 474 #else |
427 gfx::Screen::SetScreenInstance( | 475 gfx::Screen::SetScreenInstance( |
428 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 476 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
429 #endif | 477 #endif |
430 views_delegate_ = new ShellViewsDelegateAura(); | 478 views_delegate_ = new ShellViewsDelegateAura(); |
431 } | 479 } |
432 | 480 |
433 void Shell::PlatformExit() { | 481 void Shell::PlatformExit() { |
434 #if defined(OS_CHROMEOS) | 482 #if defined(OS_CHROMEOS) |
435 delete wm_test_helper_; | 483 delete shell_host_; |
| 484 aura::Env::DeleteInstance(); |
436 #endif | 485 #endif |
437 delete views_delegate_; | 486 delete views_delegate_; |
438 views_delegate_ = NULL; | 487 views_delegate_ = NULL; |
439 delete platform_; | 488 delete platform_; |
440 platform_ = NULL; | 489 platform_ = NULL; |
441 #if defined(OS_CHROMEOS) | 490 #if defined(OS_CHROMEOS) |
442 chromeos::DBusThreadManager::Shutdown(); | 491 chromeos::DBusThreadManager::Shutdown(); |
443 #endif | 492 #endif |
444 aura::Env::DeleteInstance(); | 493 aura::Env::DeleteInstance(); |
445 } | 494 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 content_size_ = gfx::Size(width, height); | 529 content_size_ = gfx::Size(width, height); |
481 if (!platform_) | 530 if (!platform_) |
482 platform_ = new ShellPlatformDataAura(content_size_); | 531 platform_ = new ShellPlatformDataAura(content_size_); |
483 else | 532 else |
484 platform_->ResizeWindow(content_size_); | 533 platform_->ResizeWindow(content_size_); |
485 return; | 534 return; |
486 } | 535 } |
487 #if defined(OS_CHROMEOS) | 536 #if defined(OS_CHROMEOS) |
488 window_widget_ = views::Widget::CreateWindowWithContextAndBounds( | 537 window_widget_ = views::Widget::CreateWindowWithContextAndBounds( |
489 new ShellWindowDelegateView(this), | 538 new ShellWindowDelegateView(this), |
490 wm_test_helper_->GetDefaultParent(NULL, NULL, gfx::Rect()), | 539 shell_host_->window(), |
491 gfx::Rect(0, 0, width, height)); | 540 gfx::Rect(0, 0, width, height)); |
492 #else | 541 #else |
493 window_widget_ = new views::Widget; | 542 window_widget_ = new views::Widget; |
494 views::Widget::InitParams params; | 543 views::Widget::InitParams params; |
495 params.bounds = gfx::Rect(0, 0, width, height); | 544 params.bounds = gfx::Rect(0, 0, width, height); |
496 params.delegate = new ShellWindowDelegateView(this); | 545 params.delegate = new ShellWindowDelegateView(this); |
497 params.top_level = true; | 546 params.top_level = true; |
498 params.remove_standard_frame = true; | 547 params.remove_standard_frame = true; |
499 window_widget_->Init(params); | 548 window_widget_->Init(params); |
500 #endif | 549 #endif |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 | 609 |
561 void Shell::PlatformWebContentsFocused(WebContents* contents) { | 610 void Shell::PlatformWebContentsFocused(WebContents* contents) { |
562 if (headless_) | 611 if (headless_) |
563 return; | 612 return; |
564 ShellWindowDelegateView* delegate_view = | 613 ShellWindowDelegateView* delegate_view = |
565 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 614 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
566 delegate_view->OnWebContentsFocused(contents); | 615 delegate_view->OnWebContentsFocused(contents); |
567 } | 616 } |
568 | 617 |
569 } // namespace content | 618 } // namespace content |
OLD | NEW |