Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: services/ui/ws/platform_display_default.cc

Issue 2795503002: mash: Don't synthesize extra key press events in the window server (Closed)
Patch Set: remove InputMethodBridge workaround Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
8
7 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
8 #include "gpu/ipc/client/gpu_channel_host.h" 10 #include "gpu/ipc/client/gpu_channel_host.h"
9 #include "services/ui/display/screen_manager.h" 11 #include "services/ui/display/screen_manager.h"
10 #include "services/ui/ws/display_client_compositor_frame_sink.h" 12 #include "services/ui/ws/display_client_compositor_frame_sink.h"
11 #include "services/ui/ws/server_window.h" 13 #include "services/ui/ws/server_window.h"
12 #include "ui/base/cursor/image_cursors.h" 14 #include "ui/base/cursor/image_cursors.h"
13 #include "ui/display/display.h" 15 #include "ui/display/display.h"
14 #include "ui/events/event.h" 16 #include "ui/events/event.h"
15 #include "ui/events/event_utils.h" 17 #include "ui/events/event_utils.h"
16 #include "ui/platform_window/platform_ime_controller.h" 18 #include "ui/platform_window/platform_ime_controller.h"
17 #include "ui/platform_window/platform_window.h" 19 #include "ui/platform_window/platform_window.h"
18 20
19 #if defined(OS_WIN) 21 #if defined(OS_WIN)
20 #include "ui/platform_window/win/win_window.h" 22 #include "ui/platform_window/win/win_window.h"
21 #elif defined(USE_X11) && !defined(OS_CHROMEOS) 23 #elif defined(USE_X11) && !defined(OS_CHROMEOS)
22 #include "ui/platform_window/x11/x11_window.h" 24 #include "ui/platform_window/x11/x11_window.h"
23 #elif defined(OS_ANDROID) 25 #elif defined(OS_ANDROID)
24 #include "ui/platform_window/android/platform_window_android.h" 26 #include "ui/platform_window/android/platform_window_android.h"
25 #elif defined(USE_OZONE) 27 #elif defined(USE_OZONE)
26 #include "ui/ozone/public/ozone_platform.h" 28 #include "ui/ozone/public/ozone_platform.h"
27 #endif 29 #endif
28 30
29 namespace ui { 31 namespace ui {
30 namespace ws { 32 namespace ws {
31 33
32 PlatformDisplayDefault::PlatformDisplayDefault( 34 PlatformDisplayDefault::PlatformDisplayDefault(
33 ServerWindow* root_window, 35 ServerWindow* root_window,
34 const display::ViewportMetrics& metrics) 36 const display::ViewportMetrics& metrics,
37 std::unique_ptr<ImageCursors> image_cursors)
35 : root_window_(root_window), 38 : root_window_(root_window),
36 #if !defined(OS_ANDROID) 39 image_cursors_(std::move(image_cursors)),
37 image_cursors_(new ImageCursors),
38 #endif
39 metrics_(metrics), 40 metrics_(metrics),
40 widget_(gfx::kNullAcceleratedWidget) { 41 widget_(gfx::kNullAcceleratedWidget) {}
41 }
42 42
43 PlatformDisplayDefault::~PlatformDisplayDefault() { 43 PlatformDisplayDefault::~PlatformDisplayDefault() {
44 // Don't notify the delegate from the destructor. 44 // Don't notify the delegate from the destructor.
45 delegate_ = nullptr; 45 delegate_ = nullptr;
46 46
47 frame_generator_.reset(); 47 frame_generator_.reset();
48 // Destroy the PlatformWindow early on as it may call us back during 48 // Destroy the PlatformWindow early on as it may call us back during
49 // destruction and we want to be in a known state. But destroy the surface 49 // destruction and we want to be in a known state. But destroy the surface
50 // first because it can still be using the platform window. 50 // first because it can still be using the platform window.
51 platform_window_.reset(); 51 platform_window_.reset();
52 } 52 }
53 53
54 EventSink* PlatformDisplayDefault::GetEventSink() { 54 EventSink* PlatformDisplayDefault::GetEventSink() {
55 return delegate_->GetEventSink(); 55 return delegate_->GetEventSink();
56 } 56 }
57 57
58 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { 58 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) {
59 DCHECK(delegate);
59 delegate_ = delegate; 60 delegate_ = delegate;
60 61
61 const gfx::Rect& bounds = metrics_.bounds_in_pixels; 62 const gfx::Rect& bounds = metrics_.bounds_in_pixels;
62 DCHECK(!bounds.size().IsEmpty()); 63 DCHECK(!bounds.size().IsEmpty());
63 64
64 #if defined(OS_WIN) 65 #if defined(OS_WIN)
65 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); 66 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds);
66 #elif defined(USE_X11) && !defined(OS_CHROMEOS) 67 #elif defined(USE_X11) && !defined(OS_CHROMEOS)
67 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); 68 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds);
68 #elif defined(OS_ANDROID) 69 #elif defined(OS_ANDROID)
69 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); 70 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this);
70 platform_window_->SetBounds(bounds); 71 platform_window_->SetBounds(bounds);
71 #elif defined(USE_OZONE) 72 #elif defined(USE_OZONE)
72 platform_window_ = 73 platform_window_ =
73 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); 74 delegate_->GetOzonePlatform()->CreatePlatformWindow(this, bounds);
74 #else 75 #else
75 NOTREACHED() << "Unsupported platform"; 76 NOTREACHED() << "Unsupported platform";
76 #endif 77 #endif
77 78
78 platform_window_->Show(); 79 platform_window_->Show();
79 #if !defined(OS_ANDROID) 80 if (image_cursors_) {
80 image_cursors_->SetDisplay(delegate_->GetDisplay(), 81 image_cursors_->SetDisplay(delegate_->GetDisplay(),
81 metrics_.device_scale_factor); 82 metrics_.device_scale_factor);
82 #endif 83 }
83 } 84 }
84 85
85 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { 86 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) {
86 platform_window_->SetBounds(gfx::Rect(size)); 87 platform_window_->SetBounds(gfx::Rect(size));
87 } 88 }
88 89
89 void PlatformDisplayDefault::SetTitle(const base::string16& title) { 90 void PlatformDisplayDefault::SetTitle(const base::string16& title) {
90 platform_window_->SetTitle(title); 91 platform_window_->SetTitle(title);
91 } 92 }
92 93
93 void PlatformDisplayDefault::SetCapture() { 94 void PlatformDisplayDefault::SetCapture() {
94 platform_window_->SetCapture(); 95 platform_window_->SetCapture();
95 } 96 }
96 97
97 void PlatformDisplayDefault::ReleaseCapture() { 98 void PlatformDisplayDefault::ReleaseCapture() {
98 platform_window_->ReleaseCapture(); 99 platform_window_->ReleaseCapture();
99 } 100 }
100 101
101 void PlatformDisplayDefault::SetCursorById(mojom::CursorType cursor_id) { 102 void PlatformDisplayDefault::SetCursorById(mojom::CursorType cursor_id) {
102 #if !defined(OS_ANDROID) 103 if (!image_cursors_)
104 return;
105
103 // TODO(erg): This still isn't sufficient, and will only use native cursors 106 // TODO(erg): This still isn't sufficient, and will only use native cursors
104 // that chrome would use, not custom image cursors. For that, we should 107 // that chrome would use, not custom image cursors. For that, we should
105 // delegate to the window manager to load images from resource packs. 108 // delegate to the window manager to load images from resource packs.
106 // 109 //
107 // We probably also need to deal with different DPIs. 110 // We probably also need to deal with different DPIs.
108 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); 111 ui::Cursor cursor(static_cast<int32_t>(cursor_id));
109 image_cursors_->SetPlatformCursor(&cursor); 112 image_cursors_->SetPlatformCursor(&cursor);
110 platform_window_->SetCursor(cursor.platform()); 113 platform_window_->SetCursor(cursor.platform());
111 #endif
112 } 114 }
113 115
114 void PlatformDisplayDefault::UpdateTextInputState( 116 void PlatformDisplayDefault::UpdateTextInputState(
115 const ui::TextInputState& state) { 117 const ui::TextInputState& state) {
116 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); 118 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController();
117 if (ime) 119 if (ime)
118 ime->UpdateTextInputState(state); 120 ime->UpdateTextInputState(state);
119 } 121 }
120 122
121 void PlatformDisplayDefault::SetImeVisibility(bool visible) { 123 void PlatformDisplayDefault::SetImeVisibility(bool visible) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 SendEventToSink(&pointer_event); 188 SendEventToSink(&pointer_event);
187 } else if (event->IsMouseEvent()) { 189 } else if (event->IsMouseEvent()) {
188 ui::PointerEvent pointer_event(*event->AsMouseEvent()); 190 ui::PointerEvent pointer_event(*event->AsMouseEvent());
189 SendEventToSink(&pointer_event); 191 SendEventToSink(&pointer_event);
190 } else if (event->IsTouchEvent()) { 192 } else if (event->IsTouchEvent()) {
191 ui::PointerEvent pointer_event(*event->AsTouchEvent()); 193 ui::PointerEvent pointer_event(*event->AsTouchEvent());
192 SendEventToSink(&pointer_event); 194 SendEventToSink(&pointer_event);
193 } else { 195 } else {
194 SendEventToSink(event); 196 SendEventToSink(event);
195 } 197 }
196
197 #if defined(USE_X11) || defined(USE_OZONE)
198 // We want to emulate the WM_CHAR generation behaviour of Windows.
199 //
200 // On Linux, we've previously inserted characters by having
201 // InputMethodAuraLinux take all key down events and send a character event
202 // to the TextInputClient. This causes a mismatch in code that has to be
203 // shared between Windows and Linux, including blink code. Now that we're
204 // trying to have one way of doing things, we need to standardize on and
205 // emulate Windows character events.
206 //
207 // This is equivalent to what we're doing in the current Linux port, but
208 // done once instead of done multiple times in different places.
209 if (event->type() == ui::ET_KEY_PRESSED) {
210 ui::KeyEvent* key_press_event = event->AsKeyEvent();
211 ui::KeyEvent char_event(key_press_event->GetCharacter(),
212 key_press_event->key_code(),
213 key_press_event->flags());
214 // We don't check that GetCharacter() is equal because changing a key event
215 // with an accelerator to a character event can change the character, for
216 // example, from 'M' to '^M'.
217 DCHECK_EQ(key_press_event->key_code(), char_event.key_code());
218 DCHECK_EQ(key_press_event->flags(), char_event.flags());
219 SendEventToSink(&char_event);
220 }
221 #endif
222 } 198 }
223 199
224 void PlatformDisplayDefault::OnCloseRequest() { 200 void PlatformDisplayDefault::OnCloseRequest() {
225 // TODO(tonikitoo): Handle a close request in external window mode. The window 201 // TODO(tonikitoo): Handle a close request in external window mode. The window
226 // should be closed by the WS and it shouldn't involve ScreenManager. 202 // should be closed by the WS and it shouldn't involve ScreenManager.
227 const int64_t display_id = delegate_->GetDisplay().id(); 203 const int64_t display_id = delegate_->GetDisplay().id();
228 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); 204 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id);
229 } 205 }
230 206
231 void PlatformDisplayDefault::OnClosed() {} 207 void PlatformDisplayDefault::OnClosed() {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 247 }
272 248
273 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { 249 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() {
274 NOTREACHED(); 250 NOTREACHED();
275 } 251 }
276 252
277 void PlatformDisplayDefault::OnActivationChanged(bool active) {} 253 void PlatformDisplayDefault::OnActivationChanged(bool active) {}
278 254
279 } // namespace ws 255 } // namespace ws
280 } // namespace ui 256 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/platform_display_default.h ('k') | services/ui/ws/platform_display_default_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698