| 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 "blimp/client/app/linux/blimp_display_manager.h" | 5 #include "blimp/client/app/linux/blimp_display_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "blimp/client/app/compositor/browser_compositor.h" | 8 #include "blimp/client/app/compositor/browser_compositor.h" |
| 8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 9 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 9 #include "blimp/client/core/compositor/blimp_compositor_manager.h" | 10 #include "blimp/client/public/contents/blimp_contents.h" |
| 10 #include "blimp/client/core/contents/tab_control_feature.h" | 11 #include "blimp/client/public/contents/blimp_contents_view.h" |
| 11 #include "blimp/client/core/render_widget/render_widget_feature.h" | 12 #include "blimp/client/public/contents/blimp_navigation_controller.h" |
| 12 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" | |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/gesture_detection/motion_event_generic.h" | 14 #include "ui/events/gesture_detection/motion_event_generic.h" |
| 15 #include "ui/events/gestures/motion_event_aura.h" | 15 #include "ui/events/gestures/motion_event_aura.h" |
| 16 #include "ui/events/platform/platform_event_source.h" |
| 16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/platform_window/platform_window.h" | 18 #include "ui/platform_window/platform_window.h" |
| 18 #include "ui/platform_window/x11/x11_window.h" | 19 #include "ui/platform_window/x11/x11_window.h" |
| 19 | 20 |
| 20 namespace blimp { | 21 namespace blimp { |
| 21 namespace { | 22 namespace { |
| 22 constexpr int kDummyBlimpContentsId = 0; | |
| 23 constexpr int kPointer1Id = 0; | 23 constexpr int kPointer1Id = 0; |
| 24 constexpr int kPointer2Id = 1; | 24 constexpr int kPointer2Id = 1; |
| 25 constexpr int kZoomOffsetMultiplier = 4; | 25 constexpr int kZoomOffsetMultiplier = 4; |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 namespace client { | 28 namespace client { |
| 29 | 29 |
| 30 BlimpDisplayManager::BlimpDisplayManager( | 30 BlimpDisplayManager::BlimpDisplayManager( |
| 31 const gfx::Size& window_size, | |
| 32 BlimpDisplayManagerDelegate* delegate, | 31 BlimpDisplayManagerDelegate* delegate, |
| 33 RenderWidgetFeature* render_widget_feature, | 32 CompositorDependencies* compositor_dependencies) |
| 34 TabControlFeature* tab_control_feature) | |
| 35 : device_pixel_ratio_(1.f), | 33 : device_pixel_ratio_(1.f), |
| 36 delegate_(delegate), | 34 delegate_(delegate), |
| 37 tab_control_feature_(tab_control_feature), | 35 platform_event_source_(ui::PlatformEventSource::CreateDefault()), |
| 38 platform_window_(new ui::X11Window(this)) { | 36 platform_window_(new ui::X11Window(this)) { |
| 39 platform_window_->SetBounds(gfx::Rect(window_size)); | 37 compositor_ = base::MakeUnique<BrowserCompositor>(compositor_dependencies); |
| 40 | |
| 41 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | |
| 42 base::MakeUnique<CompositorDependenciesImpl>()); | |
| 43 | |
| 44 compositor_ = base::MakeUnique<BrowserCompositor>( | |
| 45 compositor_dependencies_->GetEmbedderDependencies()); | |
| 46 compositor_->SetSize(platform_window_->GetBounds().size()); | |
| 47 | |
| 48 compositor_manager_ = base::MakeUnique<BlimpCompositorManager>( | |
| 49 kDummyBlimpContentsId, render_widget_feature, | |
| 50 compositor_dependencies_.get()); | |
| 51 | |
| 52 compositor_->SetContentLayer(compositor_manager_->layer()); | |
| 53 | |
| 54 platform_window_->Show(); | |
| 55 | |
| 56 tab_control_feature_->SetSizeAndScale(platform_window_->GetBounds().size(), | |
| 57 device_pixel_ratio_); | |
| 58 } | 38 } |
| 59 | 39 |
| 60 BlimpDisplayManager::~BlimpDisplayManager() {} | 40 BlimpDisplayManager::~BlimpDisplayManager() = default; |
| 41 |
| 42 void BlimpDisplayManager::SetWindowSize(const gfx::Size& window_size) { |
| 43 platform_window_->SetBounds(gfx::Rect(window_size)); |
| 44 } |
| 45 |
| 46 void BlimpDisplayManager::SetBlimpContents( |
| 47 std::unique_ptr<BlimpContents> contents) { |
| 48 contents_ = std::move(contents); |
| 49 compositor_->SetContentLayer(contents_->GetView()->GetLayer()); |
| 50 platform_window_->Show(); |
| 51 } |
| 61 | 52 |
| 62 void BlimpDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { | 53 void BlimpDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 63 compositor_->SetSize(new_bounds.size()); | 54 compositor_->SetSize(new_bounds.size()); |
| 64 tab_control_feature_->SetSizeAndScale(new_bounds.size(), device_pixel_ratio_); | 55 if (contents_) { |
| 56 contents_->GetView()->SetSizeAndScale(new_bounds.size(), |
| 57 device_pixel_ratio_); |
| 58 } |
| 65 } | 59 } |
| 66 | 60 |
| 67 void BlimpDisplayManager::DispatchEvent(ui::Event* event) { | 61 void BlimpDisplayManager::DispatchEvent(ui::Event* event) { |
| 68 if (event->IsMouseWheelEvent()) { | 62 if (event->IsMouseWheelEvent()) { |
| 69 DispatchMouseWheelEvent(event->AsMouseWheelEvent()); | 63 DispatchMouseWheelEvent(event->AsMouseWheelEvent()); |
| 70 } else if (event->IsMouseEvent()) { | 64 } else if (event->IsMouseEvent()) { |
| 71 DispatchMouseEvent(event->AsMouseEvent()); | 65 DispatchMouseEvent(event->AsMouseEvent()); |
| 72 } | 66 } |
| 73 } | 67 } |
| 74 | 68 |
| 75 void BlimpDisplayManager::DispatchMotionEventAura( | 69 void BlimpDisplayManager::DispatchMotionEventAura( |
| 76 ui::MotionEventAura* touch_event_stream, | 70 ui::MotionEventAura* touch_event_stream, |
| 77 ui::EventType event_type, | 71 ui::EventType event_type, |
| 78 int pointer_id, | 72 int pointer_id, |
| 79 int pointer_x, | 73 int pointer_x, |
| 80 int pointer_y) { | 74 int pointer_y) { |
| 75 DCHECK(contents_); |
| 76 |
| 81 touch_event_stream->OnTouch( | 77 touch_event_stream->OnTouch( |
| 82 ui::TouchEvent(event_type, gfx::Point(pointer_x, pointer_y), pointer_id, | 78 ui::TouchEvent(event_type, gfx::Point(pointer_x, pointer_y), pointer_id, |
| 83 base::TimeTicks::Now())); | 79 base::TimeTicks::Now())); |
| 84 compositor_manager_->OnTouchEvent(*touch_event_stream); | 80 contents_->GetView()->OnTouchEvent(*touch_event_stream); |
| 85 } | 81 } |
| 86 | 82 |
| 87 void BlimpDisplayManager::DispatchMouseWheelEvent( | 83 void BlimpDisplayManager::DispatchMouseWheelEvent( |
| 88 ui::MouseWheelEvent* wheel_event) { | 84 ui::MouseWheelEvent* wheel_event) { |
| 89 // In order to better simulate the Android experience on the Linux client | 85 // In order to better simulate the Android experience on the Linux client |
| 90 // we convert mousewheel scrolling events into pinch/zoom events. | 86 // we convert mousewheel scrolling events into pinch/zoom events. |
| 91 bool zoom_out = wheel_event->y_offset() < 0; | 87 bool zoom_out = wheel_event->y_offset() < 0; |
| 92 Zoom(wheel_event->x(), wheel_event->y(), wheel_event->y_offset(), zoom_out); | 88 Zoom(wheel_event->x(), wheel_event->y(), wheel_event->y_offset(), zoom_out); |
| 93 } | 89 } |
| 94 | 90 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 default: | 133 default: |
| 138 return ui::MotionEvent::ACTION_NONE; | 134 return ui::MotionEvent::ACTION_NONE; |
| 139 } | 135 } |
| 140 } | 136 } |
| 141 | 137 |
| 142 void BlimpDisplayManager::DispatchMouseEvent(ui::MouseEvent* mouse_event) { | 138 void BlimpDisplayManager::DispatchMouseEvent(ui::MouseEvent* mouse_event) { |
| 143 ui::MotionEvent::Action action = MouseEventToAction(mouse_event); | 139 ui::MotionEvent::Action action = MouseEventToAction(mouse_event); |
| 144 | 140 |
| 145 if (action != ui::MotionEvent::ACTION_NONE && | 141 if (action != ui::MotionEvent::ACTION_NONE && |
| 146 mouse_event->IsOnlyLeftMouseButton()) { | 142 mouse_event->IsOnlyLeftMouseButton()) { |
| 143 DCHECK(contents_); |
| 144 |
| 147 ui::PointerProperties mouse_properties(mouse_event->x(), mouse_event->y(), | 145 ui::PointerProperties mouse_properties(mouse_event->x(), mouse_event->y(), |
| 148 0); | 146 0); |
| 149 ui::MotionEventGeneric motion_event(action, mouse_event->time_stamp(), | 147 ui::MotionEventGeneric motion_event(action, mouse_event->time_stamp(), |
| 150 mouse_properties); | 148 mouse_properties); |
| 151 compositor_manager_->OnTouchEvent(motion_event); | 149 contents_->GetView()->OnTouchEvent(motion_event); |
| 152 } | 150 } |
| 153 } | 151 } |
| 154 | 152 |
| 155 void BlimpDisplayManager::OnCloseRequest() { | 153 void BlimpDisplayManager::OnCloseRequest() { |
| 156 compositor_manager_->SetVisible(false); | 154 DCHECK(contents_); |
| 155 |
| 156 contents_->Hide(); |
| 157 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 157 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 158 platform_window_->Close(); | 158 platform_window_->Close(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void BlimpDisplayManager::OnClosed() { | 161 void BlimpDisplayManager::OnClosed() { |
| 162 if (delegate_) | 162 if (delegate_) |
| 163 delegate_->OnClosed(); | 163 delegate_->OnClosed(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void BlimpDisplayManager::OnAcceleratedWidgetAvailable( | 166 void BlimpDisplayManager::OnAcceleratedWidgetAvailable( |
| 167 gfx::AcceleratedWidget widget, | 167 gfx::AcceleratedWidget widget, |
| 168 float device_pixel_ratio) { | 168 float device_pixel_ratio) { |
| 169 DCHECK(contents_); |
| 170 |
| 169 device_pixel_ratio_ = device_pixel_ratio; | 171 device_pixel_ratio_ = device_pixel_ratio; |
| 170 tab_control_feature_->SetSizeAndScale(platform_window_->GetBounds().size(), | 172 contents_->GetView()->SetSizeAndScale(platform_window_->GetBounds().size(), |
| 171 device_pixel_ratio_); | 173 device_pixel_ratio_); |
| 172 | 174 |
| 173 if (widget != gfx::kNullAcceleratedWidget) { | 175 if (widget != gfx::kNullAcceleratedWidget) { |
| 174 compositor_manager_->SetVisible(true); | 176 contents_->Show(); |
| 175 compositor_->SetAcceleratedWidget(widget); | 177 compositor_->SetAcceleratedWidget(widget); |
| 176 } | 178 } |
| 177 } | 179 } |
| 178 | 180 |
| 179 void BlimpDisplayManager::OnAcceleratedWidgetDestroyed() { | 181 void BlimpDisplayManager::OnAcceleratedWidgetDestroyed() { |
| 180 compositor_manager_->SetVisible(false); | 182 DCHECK(contents_); |
| 183 contents_->Hide(); |
| 181 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 184 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 182 } | 185 } |
| 183 | 186 |
| 184 } // namespace client | 187 } // namespace client |
| 185 } // namespace blimp | 188 } // namespace blimp |
| OLD | NEW |