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 "components/mus/public/cpp/property_type_converters.h" | |
8 #include "components/mus/public/cpp/window_observer.h" | |
9 #include "components/mus/public/cpp/window_property.h" | |
10 #include "components/mus/public/cpp/window_tree_connection.h" | |
11 #include "components/mus/public/interfaces/window_manager.mojom.h" | |
12 #include "mojo/application/public/interfaces/shell.mojom.h" | 7 #include "mojo/application/public/interfaces/shell.mojom.h" |
13 #include "mojo/converters/geometry/geometry_type_converters.h" | |
14 #include "mojo/converters/input_events/input_events_type_converters.h" | |
15 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
16 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
17 #include "ui/aura/window_event_dispatcher.h" | |
18 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
19 #include "ui/events/event_constants.h" | |
20 #include "ui/platform_window/platform_window.h" | |
21 #include "ui/platform_window/platform_window_delegate.h" | |
22 #include "ui/views/mus/input_method_mus.h" | 11 #include "ui/views/mus/input_method_mus.h" |
23 #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" |
24 #include "ui/views/mus/surface_context_factory.h" | 14 #include "ui/views/mus/surface_context_factory.h" |
25 #include "ui/views/mus/window_manager_connection.h" | |
26 | 15 |
27 namespace views { | 16 namespace views { |
28 namespace { | |
29 | |
30 void WindowManagerCallback(mus::mojom::WindowManagerErrorCode error_code) {} | |
31 | |
32 class PlatformWindowMus : public ui::PlatformWindow, | |
33 public mus::WindowObserver { | |
34 public: | |
35 PlatformWindowMus(ui::PlatformWindowDelegate* delegate, | |
36 mus::Window* mus_window) | |
37 : delegate_(delegate), | |
38 mus_window_(mus_window), | |
39 show_state_(mus::mojom::SHOW_STATE_RESTORED) { | |
40 DCHECK(delegate_); | |
41 DCHECK(mus_window_); | |
42 mus_window_->AddObserver(this); | |
43 | |
44 delegate_->OnAcceleratedWidgetAvailable(gfx::kNullAcceleratedWidget, | |
45 mus_window_->viewport_metrics().device_pixel_ratio); | |
46 } | |
47 | |
48 ~PlatformWindowMus() override { | |
49 if (!mus_window_) | |
50 return; | |
51 mus_window_->RemoveObserver(this); | |
52 mus_window_->Destroy(); | |
53 } | |
54 | |
55 private: | |
56 void SetShowState(mus::mojom::ShowState show_state) { | |
57 WindowManagerConnection::Get()->window_manager()->SetShowState( | |
58 mus_window_->id(), show_state, base::Bind(&WindowManagerCallback)); | |
59 } | |
60 | |
61 // ui::PlatformWindow: | |
62 void Show() override { mus_window_->SetVisible(true); } | |
63 void Hide() override { mus_window_->SetVisible(false); } | |
64 void Close() override { NOTIMPLEMENTED(); } | |
65 | |
66 void SetBounds(const gfx::Rect& bounds) override { | |
67 mus_window_->SetBounds(bounds); | |
68 } | |
69 gfx::Rect GetBounds() override { return mus_window_->bounds(); } | |
70 void SetTitle(const base::string16& title) override { NOTIMPLEMENTED(); } | |
71 void SetCapture() override { NOTIMPLEMENTED(); } | |
72 void ReleaseCapture() override { NOTIMPLEMENTED(); } | |
73 void ToggleFullscreen() override { NOTIMPLEMENTED(); } | |
74 void Maximize() override { | |
75 SetShowState(mus::mojom::SHOW_STATE_MAXIMIZED); | |
76 } | |
77 void Minimize() override { | |
78 SetShowState(mus::mojom::SHOW_STATE_MINIMIZED); | |
79 } | |
80 void Restore() override { | |
81 SetShowState(mus::mojom::SHOW_STATE_RESTORED); | |
82 } | |
83 void SetCursor(ui::PlatformCursor cursor) override { NOTIMPLEMENTED(); } | |
84 void MoveCursorTo(const gfx::Point& location) override { NOTIMPLEMENTED(); } | |
85 void ConfineCursorToBounds(const gfx::Rect& bounds) override { | |
86 NOTIMPLEMENTED(); | |
87 } | |
88 ui::PlatformImeController* GetPlatformImeController() override { | |
89 return nullptr; | |
90 } | |
91 | |
92 // mus::WindowObserver: | |
93 void OnWindowDestroyed(mus::Window* window) override { | |
94 DCHECK_EQ(mus_window_, window); | |
95 delegate_->OnClosed(); | |
96 mus_window_ = nullptr; | |
97 } | |
98 | |
99 void OnWindowBoundsChanged(mus::Window* window, | |
100 const gfx::Rect& old_bounds, | |
101 const gfx::Rect& new_bounds) override { | |
102 delegate_->OnBoundsChanged(new_bounds); | |
103 } | |
104 | |
105 void OnWindowFocusChanged(mus::Window* gained_focus, | |
106 mus::Window* lost_focus) override { | |
107 if (gained_focus == mus_window_) | |
108 delegate_->OnActivationChanged(true); | |
109 else if (lost_focus == mus_window_) | |
110 delegate_->OnActivationChanged(false); | |
111 } | |
112 | |
113 void OnWindowInputEvent(mus::Window* view, | |
114 const mus::mojom::EventPtr& event) override { | |
115 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>()); | |
116 delegate_->DispatchEvent(ui_event.get()); | |
117 } | |
118 | |
119 void OnWindowSharedPropertyChanged( | |
120 mus::Window* window, | |
121 const std::string& name, | |
122 const std::vector<uint8_t>* old_data, | |
123 const std::vector<uint8_t>* new_data) override { | |
124 if (name != mus::mojom::WindowManager::kShowState_Property) | |
125 return; | |
126 mus::mojom::ShowState show_state = static_cast<mus::mojom::ShowState>( | |
127 window->GetSharedProperty<int32_t>( | |
128 mus::mojom::WindowManager::kShowState_Property)); | |
129 if (show_state == show_state_) | |
130 return; | |
131 show_state_ = show_state; | |
132 ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN; | |
133 switch (show_state_) { | |
134 case mus::mojom::SHOW_STATE_MINIMIZED: | |
135 state = ui::PLATFORM_WINDOW_STATE_MINIMIZED; | |
136 break; | |
137 case mus::mojom::SHOW_STATE_MAXIMIZED: | |
138 state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED; | |
139 break; | |
140 case mus::mojom::SHOW_STATE_RESTORED: | |
141 state = ui::PLATFORM_WINDOW_STATE_NORMAL; | |
142 break; | |
143 case mus::mojom::SHOW_STATE_IMMERSIVE: | |
144 case mus::mojom::SHOW_STATE_PRESENTATION: | |
145 // This may not be sufficient. | |
146 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; | |
147 break; | |
148 } | |
149 delegate_->OnWindowStateChanged(state); | |
150 } | |
151 | |
152 ui::PlatformWindowDelegate* delegate_; | |
153 mus::Window* mus_window_; | |
154 mus::mojom::ShowState show_state_; | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(PlatformWindowMus); | |
157 }; | |
158 | |
159 } // namespace | |
160 | 17 |
161 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
162 // WindowTreeHostMus, public: | 19 // WindowTreeHostMus, public: |
163 | 20 |
164 WindowTreeHostMus::WindowTreeHostMus(mojo::Shell* shell, | 21 WindowTreeHostMus::WindowTreeHostMus(mojo::Shell* shell, |
165 NativeWidgetMus* native_widget, | 22 NativeWidgetMus* native_widget, |
166 mus::Window* window, | 23 mus::Window* window, |
167 mus::mojom::SurfaceType surface_type) | 24 mus::mojom::SurfaceType surface_type) |
168 : native_widget_(native_widget), | 25 : native_widget_(native_widget), |
169 show_state_(ui::PLATFORM_WINDOW_STATE_UNKNOWN) { | 26 show_state_(ui::PLATFORM_WINDOW_STATE_UNKNOWN) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (active) | 68 if (active) |
212 GetInputMethod()->OnFocus(); | 69 GetInputMethod()->OnFocus(); |
213 else | 70 else |
214 GetInputMethod()->OnBlur(); | 71 GetInputMethod()->OnBlur(); |
215 if (native_widget_) | 72 if (native_widget_) |
216 native_widget_->OnActivationChanged(active); | 73 native_widget_->OnActivationChanged(active); |
217 WindowTreeHostPlatform::OnActivationChanged(active); | 74 WindowTreeHostPlatform::OnActivationChanged(active); |
218 } | 75 } |
219 | 76 |
220 } // namespace views | 77 } // namespace views |
OLD | NEW |