Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: ui/views/mus/native_widget_mus.cc

Issue 2099513003: mus: Use the new drag API to implement tab dragging in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dragging-part-1
Patch Set: Minor pruning Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/mus/public/cpp/property_type_converters.h" 13 #include "components/mus/public/cpp/property_type_converters.h"
13 #include "components/mus/public/cpp/window.h" 14 #include "components/mus/public/cpp/window.h"
14 #include "components/mus/public/cpp/window_observer.h" 15 #include "components/mus/public/cpp/window_observer.h"
15 #include "components/mus/public/cpp/window_property.h" 16 #include "components/mus/public/cpp/window_property.h"
16 #include "components/mus/public/cpp/window_tree_client.h" 17 #include "components/mus/public/cpp/window_tree_client.h"
17 #include "components/mus/public/interfaces/cursor.mojom.h" 18 #include "components/mus/public/interfaces/cursor.mojom.h"
18 #include "components/mus/public/interfaces/window_manager.mojom.h" 19 #include "components/mus/public/interfaces/window_manager.mojom.h"
19 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" 20 #include "components/mus/public/interfaces/window_manager_constants.mojom.h"
20 #include "components/mus/public/interfaces/window_tree.mojom.h" 21 #include "components/mus/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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // TODO(jamescook): Support other scale factors. 323 // TODO(jamescook): Support other scale factors.
322 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { 324 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) {
323 if (!delegate) 325 if (!delegate)
324 return SkBitmap(); 326 return SkBitmap();
325 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); 327 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon();
326 if (app_icon.isNull()) 328 if (app_icon.isNull())
327 return SkBitmap(); 329 return SkBitmap();
328 return app_icon.GetRepresentation(1.f).sk_bitmap(); 330 return app_icon.GetRepresentation(1.f).sk_bitmap();
329 } 331 }
330 332
331 // Handles acknowledgement of an input event, either immediately when a nested 333 // Handles acknowledgment of an input event, either immediately when a nested
332 // message loop starts, or upon destruction. 334 // message loop starts, or upon destruction.
333 class EventAckHandler : public base::MessageLoop::NestingObserver { 335 class EventAckHandler : public base::MessageLoop::NestingObserver {
334 public: 336 public:
335 explicit EventAckHandler( 337 explicit EventAckHandler(
336 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) 338 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback)
337 : ack_callback_(std::move(ack_callback)) { 339 : ack_callback_(std::move(ack_callback)) {
338 DCHECK(ack_callback_); 340 DCHECK(ack_callback_);
339 base::MessageLoop::current()->AddNestingObserver(this); 341 base::MessageLoop::current()->AddNestingObserver(this);
340 } 342 }
341 343
(...skipping 17 matching lines...) Expand all
359 } 361 }
360 } 362 }
361 363
362 private: 364 private:
363 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; 365 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_;
364 bool handled_ = false; 366 bool handled_ = false;
365 367
366 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); 368 DISALLOW_COPY_AND_ASSIGN(EventAckHandler);
367 }; 369 };
368 370
371 void OnMoveLoopEnd(bool* out_success,
372 base::Closure quit_closure,
373 bool in_success) {
374 *out_success = in_success;
375 quit_closure.Run();
376 }
377
369 } // namespace 378 } // namespace
370 379
371 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { 380 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver {
372 public: 381 public:
373 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) 382 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus)
374 : native_widget_mus_(native_widget_mus), 383 : native_widget_mus_(native_widget_mus),
375 show_state_(mus::mojom::ShowState::DEFAULT) { 384 show_state_(mus::mojom::ShowState::DEFAULT) {
376 mus_window()->AddObserver(this); 385 mus_window()->AddObserver(this);
377 } 386 }
378 387
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 void OnWindowDestroyed(mus::Window* window) override { 440 void OnWindowDestroyed(mus::Window* window) override {
432 DCHECK_EQ(mus_window(), window); 441 DCHECK_EQ(mus_window(), window);
433 platform_window_delegate()->OnClosed(); 442 platform_window_delegate()->OnClosed();
434 } 443 }
435 void OnWindowBoundsChanging(mus::Window* window, 444 void OnWindowBoundsChanging(mus::Window* window,
436 const gfx::Rect& old_bounds, 445 const gfx::Rect& old_bounds,
437 const gfx::Rect& new_bounds) override { 446 const gfx::Rect& new_bounds) override {
438 DCHECK_EQ(window, mus_window()); 447 DCHECK_EQ(window, mus_window());
439 window_tree_host()->SetBounds(new_bounds); 448 window_tree_host()->SetBounds(new_bounds);
440 } 449 }
450 void OnWindowBoundsChanged(mus::Window* window,
451 const gfx::Rect& old_bounds,
452 const gfx::Rect& new_bounds) override {
453 Widget* widget = NativeWidgetMus::GetWidgetForWindow(window);
sky 2016/06/30 00:18:31 How come NativeWidgetMus::OnBoundsChanged doesn't
Elliot Glaysher 2016/06/30 19:48:25 Because it doesn't get called in response to this.
454 if (widget)
455 widget->OnNativeWidgetMove();
456 }
441 void OnWindowFocusChanged(mus::Window* gained_focus, 457 void OnWindowFocusChanged(mus::Window* gained_focus,
442 mus::Window* lost_focus) override { 458 mus::Window* lost_focus) override {
443 if (gained_focus == mus_window()) 459 if (gained_focus == mus_window())
444 platform_window_delegate()->OnActivationChanged(true); 460 platform_window_delegate()->OnActivationChanged(true);
445 else if (lost_focus == mus_window()) 461 else if (lost_focus == mus_window())
446 platform_window_delegate()->OnActivationChanged(false); 462 platform_window_delegate()->OnActivationChanged(false);
447 } 463 }
448 void OnRequestClose(mus::Window* window) override { 464 void OnRequestClose(mus::Window* window) override {
449 platform_window_delegate()->OnCloseRequest(); 465 platform_window_delegate()->OnCloseRequest();
450 } 466 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // NOTIMPLEMENTED(); 813 // NOTIMPLEMENTED();
798 } 814 }
799 815
800 // These methods are wrong in mojo. They're not usually used to associate 816 // These methods are wrong in mojo. They're not usually used to associate
801 // data with a window; they are used exclusively in chrome/ to unsafely pass 817 // data with a window; they are used exclusively in chrome/ to unsafely pass
802 // raw pointers around. I can only find two places where we do the "safe" 818 // raw pointers around. I can only find two places where we do the "safe"
803 // thing (and even that requires casting an integer to a void*). They can't be 819 // thing (and even that requires casting an integer to a void*). They can't be
804 // used safely in a world where we separate things with mojo. They should be 820 // used safely in a world where we separate things with mojo. They should be
805 // removed; not ported. 821 // removed; not ported.
806 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { 822 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) {
807 // TODO(beng): push properties to mus::Window. 823 native_window_properties_[name] = value;
808 // NOTIMPLEMENTED();
809 } 824 }
810 825
811 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { 826 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const {
812 // TODO(beng): pull properties to mus::Window. 827 auto it = native_window_properties_.find(name);
813 // NOTIMPLEMENTED(); 828 if (it == native_window_properties_.end())
814 return nullptr; 829 return nullptr;
830 return it->second;
815 } 831 }
816 832
817 TooltipManager* NativeWidgetMus::GetTooltipManager() const { 833 TooltipManager* NativeWidgetMus::GetTooltipManager() const {
818 // NOTIMPLEMENTED(); 834 // NOTIMPLEMENTED();
819 return nullptr; 835 return nullptr;
820 } 836 }
821 837
822 void NativeWidgetMus::SetCapture() { 838 void NativeWidgetMus::SetCapture() {
823 if (content_) 839 if (content_)
824 content_->SetCapture(); 840 content_->SetCapture();
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1175
1160 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { 1176 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const {
1161 // NOTIMPLEMENTED(); 1177 // NOTIMPLEMENTED();
1162 return gfx::Rect(); 1178 return gfx::Rect();
1163 } 1179 }
1164 1180
1165 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( 1181 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop(
1166 const gfx::Vector2d& drag_offset, 1182 const gfx::Vector2d& drag_offset,
1167 Widget::MoveLoopSource source, 1183 Widget::MoveLoopSource source,
1168 Widget::MoveLoopEscapeBehavior escape_behavior) { 1184 Widget::MoveLoopEscapeBehavior escape_behavior) {
1169 // NOTIMPLEMENTED(); 1185 ReleaseCapture();
1170 return Widget::MOVE_LOOP_CANCELED; 1186
1187 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1188 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
1189 base::RunLoop run_loop;
1190
1191 mus::mojom::MoveLoopSource mus_source =
1192 source == Widget::MOVE_LOOP_SOURCE_MOUSE ?
1193 mus::mojom::MoveLoopSource::MOUSE :
1194 mus::mojom::MoveLoopSource::TOUCH;
1195
1196 bool success = false;
1197 gfx::Point cursor_location =
1198 display::Screen::GetScreen()->GetCursorScreenPoint();
1199 window_->PerformWindowMove(
1200 mus_source, cursor_location,
1201 base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure()));
1202
1203 run_loop.Run();
1204
1205 return success ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED;
1171 } 1206 }
1172 1207
1173 void NativeWidgetMus::EndMoveLoop() { 1208 void NativeWidgetMus::EndMoveLoop() {
1174 // NOTIMPLEMENTED(); 1209 window_->CancelWindowMove();
1175 } 1210 }
1176 1211
1177 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { 1212 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) {
1178 // NOTIMPLEMENTED(); 1213 // NOTIMPLEMENTED();
1179 } 1214 }
1180 1215
1181 void NativeWidgetMus::SetVisibilityAnimationDuration( 1216 void NativeWidgetMus::SetVisibilityAnimationDuration(
1182 const base::TimeDelta& duration) { 1217 const base::TimeDelta& duration) {
1183 // NOTIMPLEMENTED(); 1218 // NOTIMPLEMENTED();
1184 } 1219 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 1435
1401 gfx::Path mask_path; 1436 gfx::Path mask_path;
1402 native_widget_delegate_->GetHitTestMask(&mask_path); 1437 native_widget_delegate_->GetHitTestMask(&mask_path);
1403 // TODO(jamescook): Use the full path for the mask. 1438 // TODO(jamescook): Use the full path for the mask.
1404 gfx::Rect mask_rect = 1439 gfx::Rect mask_rect =
1405 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1440 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1406 window_->SetHitTestMask(mask_rect); 1441 window_->SetHitTestMask(mask_rect);
1407 } 1442 }
1408 1443
1409 } // namespace views 1444 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698