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