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/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | |
10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
11 #include "components/bitmap_uploader/bitmap_uploader.h" | 12 #include "components/bitmap_uploader/bitmap_uploader.h" |
12 #include "services/ui/public/cpp/property_type_converters.h" | 13 #include "services/ui/public/cpp/property_type_converters.h" |
13 #include "services/ui/public/cpp/window.h" | 14 #include "services/ui/public/cpp/window.h" |
14 #include "services/ui/public/cpp/window_observer.h" | 15 #include "services/ui/public/cpp/window_observer.h" |
15 #include "services/ui/public/cpp/window_property.h" | 16 #include "services/ui/public/cpp/window_property.h" |
16 #include "services/ui/public/cpp/window_tree_client.h" | 17 #include "services/ui/public/cpp/window_tree_client.h" |
17 #include "services/ui/public/interfaces/cursor.mojom.h" | 18 #include "services/ui/public/interfaces/cursor.mojom.h" |
18 #include "services/ui/public/interfaces/window_manager.mojom.h" | 19 #include "services/ui/public/interfaces/window_manager.mojom.h" |
19 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 20 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
20 #include "services/ui/public/interfaces/window_tree.mojom.h" | 21 #include "services/ui/public/interfaces/window_tree.mojom.h" |
21 #include "ui/aura/client/default_capture_client.h" | 22 #include "ui/aura/client/default_capture_client.h" |
22 #include "ui/aura/client/window_tree_client.h" | 23 #include "ui/aura/client/window_tree_client.h" |
23 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
24 #include "ui/aura/layout_manager.h" | 25 #include "ui/aura/layout_manager.h" |
25 #include "ui/aura/mus/mus_util.h" | 26 #include "ui/aura/mus/mus_util.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/aura/window_property.h" | 28 #include "ui/aura/window_property.h" |
28 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
29 #include "ui/base/view_prop.h" | 30 #include "ui/base/view_prop.h" |
30 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
31 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
33 #include "ui/display/screen.h" | |
32 #include "ui/events/event.h" | 34 #include "ui/events/event.h" |
33 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
34 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
35 #include "ui/native_theme/native_theme_aura.h" | 37 #include "ui/native_theme/native_theme_aura.h" |
36 #include "ui/platform_window/platform_window_delegate.h" | 38 #include "ui/platform_window/platform_window_delegate.h" |
37 #include "ui/views/mus/surface_context_factory.h" | 39 #include "ui/views/mus/surface_context_factory.h" |
38 #include "ui/views/mus/window_manager_constants_converters.h" | 40 #include "ui/views/mus/window_manager_constants_converters.h" |
39 #include "ui/views/mus/window_manager_frame_values.h" | 41 #include "ui/views/mus/window_manager_frame_values.h" |
40 #include "ui/views/mus/window_tree_host_mus.h" | 42 #include "ui/views/mus/window_tree_host_mus.h" |
41 #include "ui/views/widget/native_widget_aura.h" | 43 #include "ui/views/widget/native_widget_aura.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 // TODO(jamescook): Support other scale factors. | 322 // TODO(jamescook): Support other scale factors. |
321 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { | 323 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { |
322 if (!delegate) | 324 if (!delegate) |
323 return SkBitmap(); | 325 return SkBitmap(); |
324 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); | 326 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); |
325 if (app_icon.isNull()) | 327 if (app_icon.isNull()) |
326 return SkBitmap(); | 328 return SkBitmap(); |
327 return app_icon.GetRepresentation(1.f).sk_bitmap(); | 329 return app_icon.GetRepresentation(1.f).sk_bitmap(); |
328 } | 330 } |
329 | 331 |
330 // Handles acknowledgement of an input event, either immediately when a nested | 332 // Handles acknowledgment of an input event, either immediately when a nested |
331 // message loop starts, or upon destruction. | 333 // message loop starts, or upon destruction. |
332 class EventAckHandler : public base::MessageLoop::NestingObserver { | 334 class EventAckHandler : public base::MessageLoop::NestingObserver { |
333 public: | 335 public: |
334 explicit EventAckHandler( | 336 explicit EventAckHandler( |
335 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) | 337 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) |
336 : ack_callback_(std::move(ack_callback)) { | 338 : ack_callback_(std::move(ack_callback)) { |
337 DCHECK(ack_callback_); | 339 DCHECK(ack_callback_); |
338 base::MessageLoop::current()->AddNestingObserver(this); | 340 base::MessageLoop::current()->AddNestingObserver(this); |
339 } | 341 } |
340 | 342 |
(...skipping 17 matching lines...) Expand all Loading... | |
358 } | 360 } |
359 } | 361 } |
360 | 362 |
361 private: | 363 private: |
362 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; | 364 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; |
363 bool handled_ = false; | 365 bool handled_ = false; |
364 | 366 |
365 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); | 367 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
366 }; | 368 }; |
367 | 369 |
370 void OnMoveLoopEnd(bool* out_success, | |
371 base::Closure quit_closure, | |
372 bool in_success) { | |
373 *out_success = in_success; | |
374 quit_closure.Run(); | |
375 } | |
376 | |
368 } // namespace | 377 } // namespace |
369 | 378 |
370 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { | 379 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { |
371 public: | 380 public: |
372 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) | 381 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) |
373 : native_widget_mus_(native_widget_mus), | 382 : native_widget_mus_(native_widget_mus), |
374 show_state_(ui::mojom::ShowState::DEFAULT) { | 383 show_state_(ui::mojom::ShowState::DEFAULT) { |
375 mus_window()->AddObserver(this); | 384 mus_window()->AddObserver(this); |
376 } | 385 } |
377 | 386 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 // NOTIMPLEMENTED(); | 807 // NOTIMPLEMENTED(); |
799 } | 808 } |
800 | 809 |
801 // These methods are wrong in mojo. They're not usually used to associate | 810 // These methods are wrong in mojo. They're not usually used to associate |
802 // data with a window; they are used exclusively in chrome/ to unsafely pass | 811 // data with a window; they are used exclusively in chrome/ to unsafely pass |
803 // raw pointers around. I can only find two places where we do the "safe" | 812 // raw pointers around. I can only find two places where we do the "safe" |
804 // thing (and even that requires casting an integer to a void*). They can't be | 813 // thing (and even that requires casting an integer to a void*). They can't be |
805 // used safely in a world where we separate things with mojo. They should be | 814 // used safely in a world where we separate things with mojo. They should be |
806 // removed; not ported. | 815 // removed; not ported. |
807 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { | 816 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { |
808 // TODO(beng): push properties to ui::Window. | 817 native_window_properties_[name] = value; |
809 // NOTIMPLEMENTED(); | |
810 } | 818 } |
811 | 819 |
812 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { | 820 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { |
813 // TODO(beng): pull properties to ui::Window. | 821 auto it = native_window_properties_.find(name); |
814 // NOTIMPLEMENTED(); | 822 if (it == native_window_properties_.end()) |
815 return nullptr; | 823 return nullptr; |
824 return it->second; | |
816 } | 825 } |
817 | 826 |
818 TooltipManager* NativeWidgetMus::GetTooltipManager() const { | 827 TooltipManager* NativeWidgetMus::GetTooltipManager() const { |
819 // NOTIMPLEMENTED(); | 828 // NOTIMPLEMENTED(); |
820 return nullptr; | 829 return nullptr; |
821 } | 830 } |
822 | 831 |
823 void NativeWidgetMus::SetCapture() { | 832 void NativeWidgetMus::SetCapture() { |
824 if (content_) | 833 if (content_) |
825 content_->SetCapture(); | 834 content_->SetCapture(); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 | 1169 |
1161 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { | 1170 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { |
1162 // NOTIMPLEMENTED(); | 1171 // NOTIMPLEMENTED(); |
1163 return gfx::Rect(); | 1172 return gfx::Rect(); |
1164 } | 1173 } |
1165 | 1174 |
1166 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( | 1175 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( |
1167 const gfx::Vector2d& drag_offset, | 1176 const gfx::Vector2d& drag_offset, |
1168 Widget::MoveLoopSource source, | 1177 Widget::MoveLoopSource source, |
1169 Widget::MoveLoopEscapeBehavior escape_behavior) { | 1178 Widget::MoveLoopEscapeBehavior escape_behavior) { |
1170 // NOTIMPLEMENTED(); | 1179 ReleaseCapture(); |
1171 return Widget::MOVE_LOOP_CANCELED; | 1180 |
1181 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
1182 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | |
1183 base::RunLoop run_loop; | |
1184 | |
1185 ui::mojom::MoveLoopSource mus_source = | |
1186 source == Widget::MOVE_LOOP_SOURCE_MOUSE | |
1187 ? ui::mojom::MoveLoopSource::MOUSE | |
1188 : ui::mojom::MoveLoopSource::TOUCH; | |
1189 | |
1190 bool success = false; | |
1191 gfx::Point cursor_location = | |
1192 display::Screen::GetScreen()->GetCursorScreenPoint(); | |
1193 window_->PerformWindowMove( | |
1194 mus_source, cursor_location, | |
1195 base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure())); | |
1196 | |
1197 run_loop.Run(); | |
1198 | |
1199 return success ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; | |
1172 } | 1200 } |
1173 | 1201 |
1174 void NativeWidgetMus::EndMoveLoop() { | 1202 void NativeWidgetMus::EndMoveLoop() { |
1175 // NOTIMPLEMENTED(); | 1203 window_->CancelWindowMove(); |
1176 } | 1204 } |
1177 | 1205 |
1178 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { | 1206 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { |
1179 // NOTIMPLEMENTED(); | 1207 // NOTIMPLEMENTED(); |
1180 } | 1208 } |
1181 | 1209 |
1182 void NativeWidgetMus::SetVisibilityAnimationDuration( | 1210 void NativeWidgetMus::SetVisibilityAnimationDuration( |
1183 const base::TimeDelta& duration) { | 1211 const base::TimeDelta& duration) { |
1184 // NOTIMPLEMENTED(); | 1212 // NOTIMPLEMENTED(); |
1185 } | 1213 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1225 gfx::Size NativeWidgetMus::GetMinimumSize() const { | 1253 gfx::Size NativeWidgetMus::GetMinimumSize() const { |
1226 return native_widget_delegate_->GetMinimumSize(); | 1254 return native_widget_delegate_->GetMinimumSize(); |
1227 } | 1255 } |
1228 | 1256 |
1229 gfx::Size NativeWidgetMus::GetMaximumSize() const { | 1257 gfx::Size NativeWidgetMus::GetMaximumSize() const { |
1230 return native_widget_delegate_->GetMaximumSize(); | 1258 return native_widget_delegate_->GetMaximumSize(); |
1231 } | 1259 } |
1232 | 1260 |
1233 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds, | 1261 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds, |
1234 const gfx::Rect& new_bounds) { | 1262 const gfx::Rect& new_bounds) { |
1235 // Assume that if the old bounds was completely empty a move happened. This | 1263 // This is handled in OnHost{Resized,Moved}() like DesktopNativeWidgetAura |
1236 // handles the case of a maximize animation acquiring the layer (acquiring a | 1264 // instead of here like in NativeWidgetAura. |
1237 // layer results in clearing the bounds). | |
1238 if (old_bounds.origin() != new_bounds.origin() || | |
1239 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) { | |
1240 native_widget_delegate_->OnNativeWidgetMove(); | |
1241 } | |
1242 if (old_bounds.size() != new_bounds.size()) { | |
1243 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
1244 UpdateClientArea(); | |
1245 UpdateHitTestMask(); | |
1246 } | |
1247 } | 1265 } |
1248 | 1266 |
1249 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { | 1267 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { |
1250 return gfx::NativeCursor(); | 1268 return gfx::NativeCursor(); |
1251 } | 1269 } |
1252 | 1270 |
1253 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { | 1271 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { |
1254 return native_widget_delegate_->GetNonClientComponent(point); | 1272 return native_widget_delegate_->GetNonClientComponent(point); |
1255 } | 1273 } |
1256 | 1274 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1339 event->SetHandled(); | 1357 event->SetHandled(); |
1340 } else { | 1358 } else { |
1341 native_widget_delegate_->OnScrollEvent(event); | 1359 native_widget_delegate_->OnScrollEvent(event); |
1342 } | 1360 } |
1343 } | 1361 } |
1344 | 1362 |
1345 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 1363 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
1346 native_widget_delegate_->OnGestureEvent(event); | 1364 native_widget_delegate_->OnGestureEvent(event); |
1347 } | 1365 } |
1348 | 1366 |
1367 void NativeWidgetMus::OnHostResized(const aura::WindowTreeHost* host) { | |
1368 gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size()); | |
1369 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
sadrul
2016/07/08 00:24:05
No reason to create |new_bounds| anymore.
| |
1370 UpdateClientArea(); | |
1371 UpdateHitTestMask(); | |
1372 } | |
1373 | |
1374 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host, | |
1375 const gfx::Point& new_origin) { | |
1376 native_widget_delegate_->OnNativeWidgetMove(); | |
1377 } | |
1378 | |
1349 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 1379 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
1350 GetWidget()->Close(); | 1380 GetWidget()->Close(); |
1351 } | 1381 } |
1352 | 1382 |
1353 void NativeWidgetMus::OnWindowInputEvent( | 1383 void NativeWidgetMus::OnWindowInputEvent( |
1354 ui::Window* view, | 1384 ui::Window* view, |
1355 const ui::Event& event_in, | 1385 const ui::Event& event_in, |
1356 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 1386 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
1357 // Take ownership of the callback, indicating that we will handle it. | 1387 // Take ownership of the callback, indicating that we will handle it. |
1358 EventAckHandler ack_handler(std::move(*ack_callback)); | 1388 EventAckHandler ack_handler(std::move(*ack_callback)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 | 1431 |
1402 gfx::Path mask_path; | 1432 gfx::Path mask_path; |
1403 native_widget_delegate_->GetHitTestMask(&mask_path); | 1433 native_widget_delegate_->GetHitTestMask(&mask_path); |
1404 // TODO(jamescook): Use the full path for the mask. | 1434 // TODO(jamescook): Use the full path for the mask. |
1405 gfx::Rect mask_rect = | 1435 gfx::Rect mask_rect = |
1406 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 1436 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
1407 window_->SetHitTestMask(mask_rect); | 1437 window_->SetHitTestMask(mask_rect); |
1408 } | 1438 } |
1409 | 1439 |
1410 } // namespace views | 1440 } // namespace views |
OLD | NEW |