| 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/views/mus/window_tree_host_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/bitmap_uploader/bitmap_uploader.h" |
| 9 #include "components/mus/public/cpp/window.h" |
| 8 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_event_dispatcher.h" | 11 #include "ui/aura/window_event_dispatcher.h" |
| 12 #include "ui/base/view_prop.h" |
| 10 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/platform_window/stub/stub_window.h" |
| 11 #include "ui/views/mus/input_method_mus.h" | 15 #include "ui/views/mus/input_method_mus.h" |
| 12 #include "ui/views/mus/native_widget_mus.h" | 16 #include "ui/views/mus/native_widget_mus.h" |
| 13 #include "ui/views/mus/platform_window_mus.h" | |
| 14 | 17 |
| 15 namespace views { | 18 namespace views { |
| 16 | 19 |
| 20 namespace { |
| 21 static uint32_t accelerated_widget_count = 1; |
| 22 } |
| 23 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 18 // WindowTreeHostMus, public: | 25 // WindowTreeHostMus, public: |
| 19 | 26 |
| 20 WindowTreeHostMus::WindowTreeHostMus(shell::Connector* connector, | 27 WindowTreeHostMus::WindowTreeHostMus(shell::Connector* connector, |
| 21 NativeWidgetMus* native_widget, | 28 NativeWidgetMus* native_widget, |
| 22 mus::Window* window) | 29 mus::Window* window) |
| 23 : native_widget_(native_widget) { | 30 : native_widget_(native_widget) { |
| 24 SetPlatformWindow( | 31 // We need accelerated widget numbers to be different for each |
| 25 base::WrapUnique(new PlatformWindowMus(this, connector, window))); | 32 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
| 33 // has this property. |
| 34 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 35 gfx::AcceleratedWidget accelerated_widget = |
| 36 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 37 #else |
| 38 gfx::AcceleratedWidget accelerated_widget = |
| 39 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 40 #endif |
| 41 OnAcceleratedWidgetAvailable( |
| 42 accelerated_widget, window->viewport_metrics().device_pixel_ratio); |
| 43 |
| 44 // If no connector was passed, then it's entirely possible that mojo has not |
| 45 // been initialized and BitmapUploader will not work. This occurs, for |
| 46 // example, in some unit test contexts. |
| 47 if (connector) { |
| 48 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(window)); |
| 49 bitmap_uploader_->Init(connector); |
| 50 prop_.reset(new ui::ViewProp( |
| 51 accelerated_widget, |
| 52 bitmap_uploader::kBitmapUploaderForAcceleratedWidget, |
| 53 bitmap_uploader_.get())); |
| 54 } |
| 55 |
| 56 SetPlatformWindow(base::WrapUnique( |
| 57 new ui::StubWindow(nullptr, accelerated_widget))); |
| 58 |
| 26 // The location of events is already transformed, and there is no way to | 59 // The location of events is already transformed, and there is no way to |
| 27 // correctly determine the reverse transform. So, don't attempt to transform | 60 // correctly determine the reverse transform. So, don't attempt to transform |
| 28 // event locations, else the root location is wrong. | 61 // event locations, else the root location is wrong. |
| 29 // TODO(sky): we need to transform for device scale though. | 62 // TODO(sky): we need to transform for device scale though. |
| 30 dispatcher()->set_transform_events(false); | 63 dispatcher()->set_transform_events(false); |
| 31 compositor()->SetHostHasTransparentBackground(true); | 64 compositor()->SetHostHasTransparentBackground(true); |
| 32 | 65 |
| 33 input_method_.reset(new InputMethodMUS(this, window)); | 66 input_method_.reset(new InputMethodMUS(this, window)); |
| 34 SetSharedInputMethod(input_method_.get()); | 67 SetSharedInputMethod(input_method_.get()); |
| 35 } | 68 } |
| 36 | 69 |
| 37 WindowTreeHostMus::~WindowTreeHostMus() { | 70 WindowTreeHostMus::~WindowTreeHostMus() { |
| 38 DestroyCompositor(); | 71 DestroyCompositor(); |
| 39 DestroyDispatcher(); | 72 DestroyDispatcher(); |
| 40 } | 73 } |
| 41 | 74 |
| 42 PlatformWindowMus* WindowTreeHostMus::platform_window() { | |
| 43 return static_cast<PlatformWindowMus*>( | |
| 44 WindowTreeHostPlatform::platform_window()); | |
| 45 } | |
| 46 | |
| 47 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { | 75 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { |
| 48 if (event->IsKeyEvent() && GetInputMethod()) { | 76 if (event->IsKeyEvent() && GetInputMethod()) { |
| 49 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); | 77 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); |
| 50 event->StopPropagation(); | 78 event->StopPropagation(); |
| 51 return; | 79 return; |
| 52 } | 80 } |
| 53 WindowTreeHostPlatform::DispatchEvent(event); | 81 WindowTreeHostPlatform::DispatchEvent(event); |
| 54 } | 82 } |
| 55 | 83 |
| 56 void WindowTreeHostMus::OnClosed() { | 84 void WindowTreeHostMus::OnClosed() { |
| 57 if (native_widget_) | 85 if (native_widget_) |
| 58 native_widget_->OnPlatformWindowClosed(); | 86 native_widget_->OnPlatformWindowClosed(); |
| 59 } | 87 } |
| 60 | 88 |
| 61 void WindowTreeHostMus::OnActivationChanged(bool active) { | 89 void WindowTreeHostMus::OnActivationChanged(bool active) { |
| 62 if (active) | 90 if (active) |
| 63 GetInputMethod()->OnFocus(); | 91 GetInputMethod()->OnFocus(); |
| 64 else | 92 else |
| 65 GetInputMethod()->OnBlur(); | 93 GetInputMethod()->OnBlur(); |
| 66 if (native_widget_) | 94 if (native_widget_) |
| 67 native_widget_->OnActivationChanged(active); | 95 native_widget_->OnActivationChanged(active); |
| 68 WindowTreeHostPlatform::OnActivationChanged(active); | 96 WindowTreeHostPlatform::OnActivationChanged(active); |
| 69 } | 97 } |
| 70 | 98 |
| 71 void WindowTreeHostMus::OnCloseRequest() { | 99 void WindowTreeHostMus::OnCloseRequest() { |
| 72 OnHostCloseRequested(); | 100 OnHostCloseRequested(); |
| 73 } | 101 } |
| 74 | 102 |
| 75 } // namespace views | 103 } // namespace views |
| OLD | NEW |