OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/platform_display_default.h" | 5 #include "services/ui/ws/platform_display_default.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "gpu/ipc/client/gpu_channel_host.h" | 8 #include "gpu/ipc/client/gpu_channel_host.h" |
9 #include "services/ui/display/screen_manager.h" | 9 #include "services/ui/display/screen_manager.h" |
10 #include "services/ui/ws/display_client_compositor_frame_sink.h" | 10 #include "services/ui/ws/display_client_compositor_frame_sink.h" |
11 #include "services/ui/ws/platform_display_init_params.h" | |
12 #include "services/ui/ws/server_window.h" | 11 #include "services/ui/ws/server_window.h" |
13 #include "ui/base/cursor/image_cursors.h" | 12 #include "ui/base/cursor/image_cursors.h" |
14 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
15 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
16 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
16 #include "ui/gfx/geometry/dip_util.h" | |
17 #include "ui/platform_window/platform_ime_controller.h" | 17 #include "ui/platform_window/platform_ime_controller.h" |
18 #include "ui/platform_window/platform_window.h" | 18 #include "ui/platform_window/platform_window.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include "ui/platform_window/win/win_window.h" | 21 #include "ui/platform_window/win/win_window.h" |
22 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 22 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
23 #include "ui/platform_window/x11/x11_window.h" | 23 #include "ui/platform_window/x11/x11_window.h" |
24 #elif defined(OS_ANDROID) | 24 #elif defined(OS_ANDROID) |
25 #include "ui/platform_window/android/platform_window_android.h" | 25 #include "ui/platform_window/android/platform_window_android.h" |
26 #elif defined(USE_OZONE) | 26 #elif defined(USE_OZONE) |
27 #include "ui/ozone/public/ozone_platform.h" | 27 #include "ui/ozone/public/ozone_platform.h" |
28 #endif | 28 #endif |
29 | 29 |
30 namespace ui { | 30 namespace ui { |
31 namespace ws { | 31 namespace ws { |
32 | 32 |
33 PlatformDisplayDefault::PlatformDisplayDefault( | 33 PlatformDisplayDefault::PlatformDisplayDefault( |
34 const PlatformDisplayInitParams& init_params) | 34 ServerWindow* root_window, |
35 : display_id_(init_params.display_id), | 35 const display::ViewportMetrics& metrics) |
36 : root_window_(root_window), | |
36 #if !defined(OS_ANDROID) | 37 #if !defined(OS_ANDROID) |
37 image_cursors_(new ImageCursors), | 38 image_cursors_(new ImageCursors), |
38 #endif | 39 #endif |
39 metrics_(init_params.metrics), | 40 metrics_(metrics), |
40 widget_(gfx::kNullAcceleratedWidget), | 41 widget_(gfx::kNullAcceleratedWidget), |
41 root_window_(init_params.root_window), | 42 init_device_scale_factor_(metrics.device_scale_factor) { |
42 init_device_scale_factor_(init_params.metrics.device_scale_factor) { | |
43 } | 43 } |
44 | 44 |
45 PlatformDisplayDefault::~PlatformDisplayDefault() { | 45 PlatformDisplayDefault::~PlatformDisplayDefault() { |
46 // Don't notify the delegate from the destructor. | 46 // Don't notify the delegate from the destructor. |
47 delegate_ = nullptr; | 47 delegate_ = nullptr; |
48 | 48 |
49 frame_generator_.reset(); | 49 frame_generator_.reset(); |
50 // Destroy the PlatformWindow early on as it may call us back during | 50 // Destroy the PlatformWindow early on as it may call us back during |
51 // destruction and we want to be in a known state. But destroy the surface | 51 // destruction and we want to be in a known state. But destroy the surface |
52 // first because it can still be using the platform window. | 52 // first because it can still be using the platform window. |
53 platform_window_.reset(); | 53 platform_window_.reset(); |
54 } | 54 } |
55 | 55 |
56 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { | 56 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
57 delegate_ = delegate; | 57 delegate_ = delegate; |
58 | 58 |
59 DCHECK(!metrics_.pixel_size.IsEmpty()); | 59 DCHECK(!metrics_.bounds.size().IsEmpty()); |
60 | 60 |
61 // TODO(kylechar): The origin here isn't right if any displays have | |
62 // scale_factor other than 1.0 but will prevent windows from being stacked. | |
63 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); | |
64 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
65 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); | 62 platform_window_ = base::MakeUnique<ui::WinWindow>(this, metrics_.bounds); |
66 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 63 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
67 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); | 64 platform_window_ = base::MakeUnique<ui::X11Window>(this, metrics_.bounds); |
68 #elif defined(OS_ANDROID) | 65 #elif defined(OS_ANDROID) |
69 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); | 66 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); |
70 platform_window_->SetBounds(bounds); | 67 platform_window_->SetBounds(metrics_.bounds); |
71 #elif defined(USE_OZONE) | 68 #elif defined(USE_OZONE) |
72 platform_window_ = | 69 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
73 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 70 this, metrics_.bounds); |
74 #else | 71 #else |
75 NOTREACHED() << "Unsupported platform"; | 72 NOTREACHED() << "Unsupported platform"; |
76 #endif | 73 #endif |
77 | 74 |
78 platform_window_->Show(); | 75 platform_window_->Show(); |
79 #if !defined(OS_ANDROID) | 76 #if !defined(OS_ANDROID) |
80 image_cursors_->SetDisplay(delegate_->GetDisplay(), | 77 image_cursors_->SetDisplay(delegate_->GetDisplay(), |
81 metrics_.device_scale_factor); | 78 metrics_.device_scale_factor); |
82 #endif | 79 #endif |
83 } | 80 } |
84 | 81 |
85 int64_t PlatformDisplayDefault::GetId() const { | |
86 return display_id_; | |
87 } | |
88 | |
89 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { | 82 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { |
90 platform_window_->SetBounds(gfx::Rect(size)); | 83 platform_window_->SetBounds(gfx::Rect(size)); |
91 } | 84 } |
92 | 85 |
93 void PlatformDisplayDefault::SetTitle(const base::string16& title) { | 86 void PlatformDisplayDefault::SetTitle(const base::string16& title) { |
94 platform_window_->SetTitle(title); | 87 platform_window_->SetTitle(title); |
95 } | 88 } |
96 | 89 |
97 void PlatformDisplayDefault::SetCapture() { | 90 void PlatformDisplayDefault::SetCapture() { |
98 platform_window_->SetCapture(); | 91 platform_window_->SetCapture(); |
(...skipping 22 matching lines...) Expand all Loading... | |
121 if (ime) | 114 if (ime) |
122 ime->UpdateTextInputState(state); | 115 ime->UpdateTextInputState(state); |
123 } | 116 } |
124 | 117 |
125 void PlatformDisplayDefault::SetImeVisibility(bool visible) { | 118 void PlatformDisplayDefault::SetImeVisibility(bool visible) { |
126 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 119 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
127 if (ime) | 120 if (ime) |
128 ime->SetImeVisibility(visible); | 121 ime->SetImeVisibility(visible); |
129 } | 122 } |
130 | 123 |
131 gfx::Rect PlatformDisplayDefault::GetBounds() const { | |
132 return metrics_.bounds; | |
133 } | |
134 | |
135 FrameGenerator* PlatformDisplayDefault::GetFrameGenerator() { | 124 FrameGenerator* PlatformDisplayDefault::GetFrameGenerator() { |
136 return frame_generator_.get(); | 125 return frame_generator_.get(); |
137 } | 126 } |
138 | 127 |
139 bool PlatformDisplayDefault::UpdateViewportMetrics( | 128 bool PlatformDisplayDefault::UpdateViewportMetrics( |
140 const display::ViewportMetrics& metrics) { | 129 const display::ViewportMetrics& metrics) { |
141 if (metrics_ == metrics) | 130 if (metrics_ == metrics) |
142 return false; | 131 return false; |
143 | 132 |
144 gfx::Rect bounds = platform_window_->GetBounds(); | 133 gfx::Rect bounds = platform_window_->GetBounds(); |
145 if (bounds.size() != metrics.pixel_size) { | 134 if (bounds.size() != metrics.bounds.size()) { |
146 bounds.set_size(metrics.pixel_size); | 135 bounds.set_size(metrics.bounds.size()); |
147 platform_window_->SetBounds(bounds); | 136 platform_window_->SetBounds(bounds); |
148 } | 137 } |
149 | 138 |
150 metrics_ = metrics; | 139 metrics_ = metrics; |
151 if (frame_generator_) | 140 if (frame_generator_) |
152 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | 141 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); |
153 return true; | 142 return true; |
154 } | 143 } |
155 | 144 |
156 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() | |
157 const { | |
158 return metrics_; | |
159 } | |
160 | |
161 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { | 145 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { |
162 return widget_; | 146 return widget_; |
163 } | 147 } |
164 | 148 |
165 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { | 149 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
150 // TODO(riajiang): This is broken for HDPI because it mixes PPs and DIPs. | |
sky
2017/03/13 18:29:07
Please file a bug on this to make sure we don't mi
kylechar
2017/03/13 19:28:02
Done. I've referenced the bug here.
| |
151 const display::Display& display = delegate_->GetDisplay(); | |
166 gfx::Point location = event->location(); | 152 gfx::Point location = event->location(); |
167 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 153 location.Offset(display.bounds().x(), display.bounds().y()); |
168 event->set_root_location(location); | 154 event->set_root_location(location); |
169 } | 155 } |
170 | 156 |
171 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { | 157 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
172 // We only care if the window size has changed. | 158 // We only care if the window size has changed. |
173 if (new_bounds.size() == metrics_.pixel_size) | 159 if (new_bounds.size() == metrics_.bounds.size()) |
174 return; | 160 return; |
175 | 161 |
176 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support | 162 // TODO(tonikitoo): Handle the bounds changing in external window mode. The |
177 // PlatformWindow initiated resizes. For other platforms we need to do | 163 // window should be resized by the WS and it shouldn't involve ScreenManager. |
178 // something but that isn't fully flushed out. | |
179 } | 164 } |
180 | 165 |
181 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { | 166 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { |
182 if (frame_generator_) | 167 if (frame_generator_) |
183 frame_generator_->OnWindowDamaged(); | 168 frame_generator_->OnWindowDamaged(); |
184 } | 169 } |
185 | 170 |
186 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 171 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
187 if (event->IsLocatedEvent()) | 172 if (event->IsLocatedEvent()) |
188 UpdateEventRootLocation(event->AsLocatedEvent()); | 173 UpdateEventRootLocation(event->AsLocatedEvent()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 // with an accelerator to a character event can change the character, for | 206 // with an accelerator to a character event can change the character, for |
222 // example, from 'M' to '^M'. | 207 // example, from 'M' to '^M'. |
223 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 208 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
224 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 209 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
225 delegate_->OnEvent(char_event); | 210 delegate_->OnEvent(char_event); |
226 } | 211 } |
227 #endif | 212 #endif |
228 } | 213 } |
229 | 214 |
230 void PlatformDisplayDefault::OnCloseRequest() { | 215 void PlatformDisplayDefault::OnCloseRequest() { |
231 display::ScreenManager::GetInstance()->RequestCloseDisplay(GetId()); | 216 // TODO(tonikitoo): Handle a close request in external window mode. The window |
217 // should be closed by the WS and it shouldn't involve ScreenManager. | |
218 const int64_t display_id = delegate_->GetDisplay().id(); | |
219 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); | |
232 } | 220 } |
233 | 221 |
234 void PlatformDisplayDefault::OnClosed() {} | 222 void PlatformDisplayDefault::OnClosed() {} |
235 | 223 |
236 void PlatformDisplayDefault::OnWindowStateChanged( | 224 void PlatformDisplayDefault::OnWindowStateChanged( |
237 ui::PlatformWindowState new_state) {} | 225 ui::PlatformWindowState new_state) {} |
238 | 226 |
239 void PlatformDisplayDefault::OnLostCapture() { | 227 void PlatformDisplayDefault::OnLostCapture() { |
240 delegate_->OnNativeCaptureLost(); | 228 delegate_->OnNativeCaptureLost(); |
241 } | 229 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 265 } |
278 | 266 |
279 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 267 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
280 | 268 |
281 bool PlatformDisplayDefault::IsInHighContrastMode() { | 269 bool PlatformDisplayDefault::IsInHighContrastMode() { |
282 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 270 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
283 } | 271 } |
284 | 272 |
285 } // namespace ws | 273 } // namespace ws |
286 } // namespace ui | 274 } // namespace ui |
OLD | NEW |