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(accelerated_widget, 1.f); | |
sadrul
2016/05/30 14:42:11
Add a TODO here to find the correct device-scale-f
sadrul
2016/05/30 14:42:11
Since we are doing OnAcceleratedWidgetAvailable()
Mark Dittmer
2016/05/30 15:24:28
Done.
Mark Dittmer
2016/05/30 15:24:28
Done.
| |
42 | |
43 // If no connector was passed, then it's entirely possible that mojo has not | |
44 // been initialized and BitmapUploader will not work. This occurs, for | |
45 // example, in some unit test contexts. | |
46 if (connector) { | |
47 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(window)); | |
48 bitmap_uploader_->Init(connector); | |
49 prop_.reset(new ui::ViewProp( | |
50 accelerated_widget, | |
51 bitmap_uploader::kBitmapUploaderForAcceleratedWidget, | |
52 bitmap_uploader_.get())); | |
53 } | |
54 | |
55 SetPlatformWindow(base::WrapUnique( | |
56 new ui::StubWindow(nullptr, accelerated_widget))); | |
57 | |
26 // The location of events is already transformed, and there is no way to | 58 // 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 | 59 // correctly determine the reverse transform. So, don't attempt to transform |
28 // event locations, else the root location is wrong. | 60 // event locations, else the root location is wrong. |
29 // TODO(sky): we need to transform for device scale though. | 61 // TODO(sky): we need to transform for device scale though. |
30 dispatcher()->set_transform_events(false); | 62 dispatcher()->set_transform_events(false); |
31 compositor()->SetHostHasTransparentBackground(true); | 63 compositor()->SetHostHasTransparentBackground(true); |
32 | 64 |
33 input_method_.reset(new InputMethodMUS(this, window)); | 65 input_method_.reset(new InputMethodMUS(this, window)); |
34 SetSharedInputMethod(input_method_.get()); | 66 SetSharedInputMethod(input_method_.get()); |
35 } | 67 } |
36 | 68 |
37 WindowTreeHostMus::~WindowTreeHostMus() { | 69 WindowTreeHostMus::~WindowTreeHostMus() { |
38 DestroyCompositor(); | 70 DestroyCompositor(); |
39 DestroyDispatcher(); | 71 DestroyDispatcher(); |
40 } | 72 } |
41 | 73 |
42 PlatformWindowMus* WindowTreeHostMus::platform_window() { | |
43 return static_cast<PlatformWindowMus*>( | |
44 WindowTreeHostPlatform::platform_window()); | |
45 } | |
46 | |
47 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { | 74 void WindowTreeHostMus::DispatchEvent(ui::Event* event) { |
48 if (event->IsKeyEvent() && GetInputMethod()) { | 75 if (event->IsKeyEvent() && GetInputMethod()) { |
49 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); | 76 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); |
50 event->StopPropagation(); | 77 event->StopPropagation(); |
51 return; | 78 return; |
52 } | 79 } |
53 WindowTreeHostPlatform::DispatchEvent(event); | 80 WindowTreeHostPlatform::DispatchEvent(event); |
54 } | 81 } |
55 | 82 |
56 void WindowTreeHostMus::OnClosed() { | 83 void WindowTreeHostMus::OnClosed() { |
57 if (native_widget_) | 84 if (native_widget_) |
58 native_widget_->OnPlatformWindowClosed(); | 85 native_widget_->OnPlatformWindowClosed(); |
59 } | 86 } |
60 | 87 |
61 void WindowTreeHostMus::OnActivationChanged(bool active) { | 88 void WindowTreeHostMus::OnActivationChanged(bool active) { |
62 if (active) | 89 if (active) |
63 GetInputMethod()->OnFocus(); | 90 GetInputMethod()->OnFocus(); |
64 else | 91 else |
65 GetInputMethod()->OnBlur(); | 92 GetInputMethod()->OnBlur(); |
66 if (native_widget_) | 93 if (native_widget_) |
67 native_widget_->OnActivationChanged(active); | 94 native_widget_->OnActivationChanged(active); |
68 WindowTreeHostPlatform::OnActivationChanged(active); | 95 WindowTreeHostPlatform::OnActivationChanged(active); |
69 } | 96 } |
70 | 97 |
71 void WindowTreeHostMus::OnCloseRequest() { | 98 void WindowTreeHostMus::OnCloseRequest() { |
72 OnHostCloseRequested(); | 99 OnHostCloseRequested(); |
73 } | 100 } |
74 | 101 |
75 } // namespace views | 102 } // namespace views |
OLD | NEW |