OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/views/mus/window_tree_host_mus.h" | 5 #include "ui/aura/mus/window_tree_host_mus.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "services/ui/public/cpp/window.h" | |
9 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
| 9 #include "ui/aura/mus/input_method_mus.h" |
| 10 #include "ui/aura/mus/window_port_mus.h" |
10 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
11 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/aura/window_observer.h" |
12 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
13 #include "ui/platform_window/stub/stub_window.h" | 15 #include "ui/platform_window/stub/stub_window.h" |
14 #include "ui/views/mus/input_method_mus.h" | |
15 #include "ui/views/mus/native_widget_mus.h" | |
16 | 16 |
17 namespace views { | 17 namespace aura { |
18 | 18 |
19 namespace { | 19 namespace { |
20 static uint32_t accelerated_widget_count = 1; | 20 static uint32_t accelerated_widget_count = 1; |
21 | 21 |
22 bool IsUsingTestContext() { | 22 bool IsUsingTestContext() { |
23 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); | 23 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); |
24 } | 24 } |
25 | 25 |
26 } | 26 } // namespace |
| 27 |
| 28 class WindowTreeHostMus::ContentWindowObserver : public WindowObserver { |
| 29 public: |
| 30 ContentWindowObserver(WindowTreeHostMus* window_tree_host_mus, Window* window) |
| 31 : window_tree_host_mus_(window_tree_host_mus), window_(window) { |
| 32 window_->AddObserver(this); |
| 33 } |
| 34 ~ContentWindowObserver() override { window_->RemoveObserver(this); } |
| 35 |
| 36 // WindowObserver: |
| 37 void OnWindowDestroyed(Window* window) override { |
| 38 window_tree_host_mus_->ContentWindowDestroyed(); |
| 39 } |
| 40 void OnWindowBoundsChanged(Window* window, |
| 41 const gfx::Rect& old_bounds, |
| 42 const gfx::Rect& new_bounds) override { |
| 43 if (old_bounds.size() != new_bounds.size()) |
| 44 window_tree_host_mus_->ContentWindowResized(); |
| 45 } |
| 46 void OnWindowVisibilityChanging(Window* window, bool visible) override { |
| 47 window_tree_host_mus_->ContentWindowVisibilityChanging(visible); |
| 48 } |
| 49 |
| 50 private: |
| 51 WindowTreeHostMus* window_tree_host_mus_; |
| 52 Window* window_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(ContentWindowObserver); |
| 55 }; |
27 | 56 |
28 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
29 // WindowTreeHostMus, public: | 58 // WindowTreeHostMus, public: |
30 | 59 |
31 WindowTreeHostMus::WindowTreeHostMus(NativeWidgetMus* native_widget, | 60 WindowTreeHostMus::WindowTreeHostMus(std::unique_ptr<WindowPortMus> window_port, |
32 ui::Window* window) | 61 Window* content_window) |
33 : native_widget_(native_widget) { | 62 : WindowTreeHostPlatform(std::move(window_port)), |
| 63 content_window_(content_window) { |
34 gfx::AcceleratedWidget accelerated_widget; | 64 gfx::AcceleratedWidget accelerated_widget; |
35 if (IsUsingTestContext()) { | 65 if (IsUsingTestContext()) { |
36 accelerated_widget = gfx::kNullAcceleratedWidget; | 66 accelerated_widget = gfx::kNullAcceleratedWidget; |
37 } else { | 67 } else { |
38 // We need accelerated widget numbers to be different for each | 68 // We need accelerated widget numbers to be different for each |
39 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t | 69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
40 // has this property. | 70 // has this property. |
41 #if defined(OS_WIN) || defined(OS_ANDROID) | 71 #if defined(OS_WIN) || defined(OS_ANDROID) |
42 accelerated_widget = | 72 accelerated_widget = |
43 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 73 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
44 #else | 74 #else |
45 accelerated_widget = | 75 accelerated_widget = |
46 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 76 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
47 #endif | 77 #endif |
48 } | 78 } |
49 // TODO(markdittmer): Use correct device-scale-factor from |window|. | 79 // TODO(markdittmer): Use correct device-scale-factor from |window|. |
50 OnAcceleratedWidgetAvailable(accelerated_widget, 1.f); | 80 OnAcceleratedWidgetAvailable(accelerated_widget, 1.f); |
51 | 81 |
52 SetPlatformWindow(base::MakeUnique<ui::StubWindow>( | 82 SetPlatformWindow(base::MakeUnique<ui::StubWindow>( |
53 this, | 83 this, |
54 false)); // Do not advertise accelerated widget; already set manually. | 84 false)); // Do not advertise accelerated widget; already set manually. |
55 | 85 |
56 compositor()->SetWindow(window); | 86 if (content_window_) { |
| 87 window()->AddChild(content_window_); |
| 88 window()->SetBounds(gfx::Rect(content_window_->bounds().size())); |
| 89 content_window_observer_ = |
| 90 base::MakeUnique<ContentWindowObserver>(this, content_window_); |
| 91 } else { |
| 92 // Initialize the stub platform window bounds to those of the ui::Window. |
| 93 platform_window()->SetBounds(window()->bounds()); |
| 94 } |
57 | 95 |
58 // Initialize the stub platform window bounds to those of the ui::Window. | 96 input_method_ = base::MakeUnique<InputMethodMus>( |
59 platform_window()->SetBounds(window->bounds()); | 97 this, content_window_ ? content_window_ : window()); |
| 98 |
| 99 // TODO: resolve |
| 100 // compositor()->SetWindow(window); |
60 | 101 |
61 compositor()->SetHostHasTransparentBackground(true); | 102 compositor()->SetHostHasTransparentBackground(true); |
62 } | 103 } |
63 | 104 |
64 WindowTreeHostMus::~WindowTreeHostMus() { | 105 WindowTreeHostMus::~WindowTreeHostMus() { |
65 DestroyCompositor(); | 106 DestroyCompositor(); |
66 DestroyDispatcher(); | 107 DestroyDispatcher(); |
67 } | 108 } |
68 | 109 |
| 110 void WindowTreeHostMus::ContentWindowDestroyed() { |
| 111 delete this; |
| 112 } |
| 113 |
| 114 void WindowTreeHostMus::ContentWindowResized() { |
| 115 window()->SetBounds(gfx::Rect(content_window_->bounds().size())); |
| 116 } |
| 117 |
| 118 void WindowTreeHostMus::ContentWindowVisibilityChanging(bool visible) { |
| 119 if (visible) |
| 120 window()->Show(); |
| 121 else |
| 122 window()->Hide(); |
| 123 } |
| 124 |
69 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { | 125 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { |
70 // Key events are sent to InputMethodMus directly from NativeWidgetMus. | |
71 DCHECK(!event->IsKeyEvent()); | 126 DCHECK(!event->IsKeyEvent()); |
72 WindowTreeHostPlatform::DispatchEvent(event); | 127 WindowTreeHostPlatform::DispatchEvent(event); |
73 } | 128 } |
74 | 129 |
75 void WindowTreeHostMus::OnClosed() { | 130 void WindowTreeHostMus::OnClosed() { |
| 131 // TODO: figure out if needed. |
| 132 /* |
76 if (native_widget_) | 133 if (native_widget_) |
77 native_widget_->OnPlatformWindowClosed(); | 134 native_widget_->OnPlatformWindowClosed(); |
| 135 */ |
78 } | 136 } |
79 | 137 |
80 void WindowTreeHostMus::OnActivationChanged(bool active) { | 138 void WindowTreeHostMus::OnActivationChanged(bool active) { |
81 if (active) | 139 if (active) |
82 GetInputMethod()->OnFocus(); | 140 GetInputMethod()->OnFocus(); |
83 else | 141 else |
84 GetInputMethod()->OnBlur(); | 142 GetInputMethod()->OnBlur(); |
| 143 // TODO: figure out if needed. |
| 144 /* |
85 if (native_widget_) | 145 if (native_widget_) |
86 native_widget_->OnActivationChanged(active); | 146 native_widget_->OnActivationChanged(active); |
| 147 */ |
87 WindowTreeHostPlatform::OnActivationChanged(active); | 148 WindowTreeHostPlatform::OnActivationChanged(active); |
88 } | 149 } |
89 | 150 |
90 void WindowTreeHostMus::OnCloseRequest() { | 151 void WindowTreeHostMus::OnCloseRequest() { |
91 OnHostCloseRequested(); | 152 OnHostCloseRequested(); |
92 } | 153 } |
93 | 154 |
94 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() { | 155 gfx::ICCProfile WindowTreeHostMus::GetICCProfileForCurrentDisplay() { |
95 // TODO: This should read the profile from mus. crbug.com/647510 | 156 // TODO: This should read the profile from mus. crbug.com/647510 |
96 return gfx::ICCProfile(); | 157 return gfx::ICCProfile(); |
97 } | 158 } |
98 | 159 |
99 } // namespace views | 160 } // namespace aura |
OLD | NEW |