Chromium Code Reviews| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 // Don't notify the delegate from the destructor. | 45 // Don't notify the delegate from the destructor. |
| 46 delegate_ = nullptr; | 46 delegate_ = nullptr; |
| 47 | 47 |
| 48 frame_generator_.reset(); | 48 frame_generator_.reset(); |
| 49 // Destroy the PlatformWindow early on as it may call us back during | 49 // Destroy the PlatformWindow early on as it may call us back during |
| 50 // destruction and we want to be in a known state. But destroy the surface | 50 // destruction and we want to be in a known state. But destroy the surface |
| 51 // first because it can still be using the platform window. | 51 // first because it can still be using the platform window. |
| 52 platform_window_.reset(); | 52 platform_window_.reset(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 EventSink* PlatformDisplayDefault::GetEventSink() { | |
| 56 return delegate_->GetEventSink(); | |
| 57 } | |
| 58 | |
| 55 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { | 59 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
| 56 delegate_ = delegate; | 60 delegate_ = delegate; |
| 57 | 61 |
| 58 const gfx::Rect& bounds = metrics_.bounds_in_pixels; | 62 const gfx::Rect& bounds = metrics_.bounds_in_pixels; |
| 59 DCHECK(!bounds.size().IsEmpty()); | 63 DCHECK(!bounds.size().IsEmpty()); |
| 60 | 64 |
| 61 #if defined(OS_WIN) | 65 #if defined(OS_WIN) |
| 62 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); | 66 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); |
| 63 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 67 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 64 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); | 68 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 152 |
| 149 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { | 153 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| 150 // TODO(riajiang): This is broken for HDPI because it mixes PPs and DIPs. See | 154 // TODO(riajiang): This is broken for HDPI because it mixes PPs and DIPs. See |
| 151 // http://crbug.com/701036 for details. | 155 // http://crbug.com/701036 for details. |
| 152 const display::Display& display = delegate_->GetDisplay(); | 156 const display::Display& display = delegate_->GetDisplay(); |
| 153 gfx::Point location = event->location(); | 157 gfx::Point location = event->location(); |
| 154 location.Offset(display.bounds().x(), display.bounds().y()); | 158 location.Offset(display.bounds().x(), display.bounds().y()); |
| 155 event->set_root_location(location); | 159 event->set_root_location(location); |
| 156 } | 160 } |
| 157 | 161 |
| 162 void PlatformDisplayDefault::DispatchEventToDelegate(const ui::Event& event) { | |
| 163 SendEventToSink(const_cast<ui::Event*>(&event)); | |
|
sky
2017/03/20 15:42:12
Don't cast away the const here. Instead make this
Peng
2017/03/20 17:24:14
Done.
| |
| 164 } | |
| 165 | |
| 158 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { | 166 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 159 // We only care if the window size has changed. | 167 // We only care if the window size has changed. |
| 160 if (new_bounds.size() == metrics_.bounds_in_pixels.size()) | 168 if (new_bounds.size() == metrics_.bounds_in_pixels.size()) |
| 161 return; | 169 return; |
| 162 | 170 |
| 163 // TODO(tonikitoo): Handle the bounds changing in external window mode. The | 171 // TODO(tonikitoo): Handle the bounds changing in external window mode. The |
| 164 // window should be resized by the WS and it shouldn't involve ScreenManager. | 172 // window should be resized by the WS and it shouldn't involve ScreenManager. |
| 165 } | 173 } |
| 166 | 174 |
| 167 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { | 175 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { |
| 168 if (frame_generator_) | 176 if (frame_generator_) |
| 169 frame_generator_->OnWindowDamaged(); | 177 frame_generator_->OnWindowDamaged(); |
| 170 } | 178 } |
| 171 | 179 |
| 172 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 180 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
| 173 if (event->IsLocatedEvent()) | 181 if (event->IsLocatedEvent()) |
| 174 UpdateEventRootLocation(event->AsLocatedEvent()); | 182 UpdateEventRootLocation(event->AsLocatedEvent()); |
| 175 | 183 |
| 176 if (event->IsScrollEvent()) { | 184 if (event->IsScrollEvent()) { |
| 177 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 185 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| 178 // they are once we have proper support for scroll events. | 186 // they are once we have proper support for scroll events. |
| 179 delegate_->OnEvent( | 187 DispatchEventToDelegate( |
| 180 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent()))); | 188 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent()))); |
| 181 } else if (event->IsMouseEvent()) { | 189 } else if (event->IsMouseEvent()) { |
| 182 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); | 190 DispatchEventToDelegate(ui::PointerEvent(*event->AsMouseEvent())); |
| 183 } else if (event->IsTouchEvent()) { | 191 } else if (event->IsTouchEvent()) { |
| 184 delegate_->OnEvent(ui::PointerEvent(*event->AsTouchEvent())); | 192 DispatchEventToDelegate(ui::PointerEvent(*event->AsTouchEvent())); |
| 185 } else { | 193 } else { |
| 186 delegate_->OnEvent(*event); | 194 DispatchEventToDelegate(*event); |
| 187 } | 195 } |
| 188 | 196 |
| 189 #if defined(USE_X11) || defined(USE_OZONE) | 197 #if defined(USE_X11) || defined(USE_OZONE) |
| 190 // We want to emulate the WM_CHAR generation behaviour of Windows. | 198 // We want to emulate the WM_CHAR generation behaviour of Windows. |
| 191 // | 199 // |
| 192 // On Linux, we've previously inserted characters by having | 200 // On Linux, we've previously inserted characters by having |
| 193 // InputMethodAuraLinux take all key down events and send a character event | 201 // InputMethodAuraLinux take all key down events and send a character event |
| 194 // to the TextInputClient. This causes a mismatch in code that has to be | 202 // to the TextInputClient. This causes a mismatch in code that has to be |
| 195 // shared between Windows and Linux, including blink code. Now that we're | 203 // shared between Windows and Linux, including blink code. Now that we're |
| 196 // trying to have one way of doing things, we need to standardize on and | 204 // trying to have one way of doing things, we need to standardize on and |
| 197 // emulate Windows character events. | 205 // emulate Windows character events. |
| 198 // | 206 // |
| 199 // This is equivalent to what we're doing in the current Linux port, but | 207 // This is equivalent to what we're doing in the current Linux port, but |
| 200 // done once instead of done multiple times in different places. | 208 // done once instead of done multiple times in different places. |
| 201 if (event->type() == ui::ET_KEY_PRESSED) { | 209 if (event->type() == ui::ET_KEY_PRESSED) { |
| 202 ui::KeyEvent* key_press_event = event->AsKeyEvent(); | 210 ui::KeyEvent* key_press_event = event->AsKeyEvent(); |
| 203 ui::KeyEvent char_event(key_press_event->GetCharacter(), | 211 ui::KeyEvent char_event(key_press_event->GetCharacter(), |
| 204 key_press_event->key_code(), | 212 key_press_event->key_code(), |
| 205 key_press_event->flags()); | 213 key_press_event->flags()); |
| 206 // We don't check that GetCharacter() is equal because changing a key event | 214 // We don't check that GetCharacter() is equal because changing a key event |
| 207 // with an accelerator to a character event can change the character, for | 215 // with an accelerator to a character event can change the character, for |
| 208 // example, from 'M' to '^M'. | 216 // example, from 'M' to '^M'. |
| 209 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 217 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 210 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 218 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 211 delegate_->OnEvent(char_event); | 219 DispatchEventToDelegate(char_event); |
| 212 } | 220 } |
| 213 #endif | 221 #endif |
| 214 } | 222 } |
| 215 | 223 |
| 216 void PlatformDisplayDefault::OnCloseRequest() { | 224 void PlatformDisplayDefault::OnCloseRequest() { |
| 217 // TODO(tonikitoo): Handle a close request in external window mode. The window | 225 // TODO(tonikitoo): Handle a close request in external window mode. The window |
| 218 // should be closed by the WS and it shouldn't involve ScreenManager. | 226 // should be closed by the WS and it shouldn't involve ScreenManager. |
| 219 const int64_t display_id = delegate_->GetDisplay().id(); | 227 const int64_t display_id = delegate_->GetDisplay().id(); |
| 220 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); | 228 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); |
| 221 } | 229 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 274 } |
| 267 | 275 |
| 268 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 276 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 269 | 277 |
| 270 bool PlatformDisplayDefault::IsInHighContrastMode() { | 278 bool PlatformDisplayDefault::IsInHighContrastMode() { |
| 271 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 279 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 272 } | 280 } |
| 273 | 281 |
| 274 } // namespace ws | 282 } // namespace ws |
| 275 } // namespace ui | 283 } // namespace ui |
| OLD | NEW |