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

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: Use WindowTreeHostObserver instead. 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
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // NOTIMPLEMENTED(); 806 // NOTIMPLEMENTED();
798 } 807 }
799 808
800 // These methods are wrong in mojo. They're not usually used to associate 809 // 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 810 // 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" 811 // 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 812 // 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 813 // used safely in a world where we separate things with mojo. They should be
805 // removed; not ported. 814 // removed; not ported.
806 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { 815 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) {
807 // TODO(beng): push properties to mus::Window. 816 native_window_properties_[name] = value;
808 // NOTIMPLEMENTED();
809 } 817 }
810 818
811 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { 819 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const {
812 // TODO(beng): pull properties to mus::Window. 820 auto it = native_window_properties_.find(name);
813 // NOTIMPLEMENTED(); 821 if (it == native_window_properties_.end())
814 return nullptr; 822 return nullptr;
823 return it->second;
815 } 824 }
816 825
817 TooltipManager* NativeWidgetMus::GetTooltipManager() const { 826 TooltipManager* NativeWidgetMus::GetTooltipManager() const {
818 // NOTIMPLEMENTED(); 827 // NOTIMPLEMENTED();
819 return nullptr; 828 return nullptr;
820 } 829 }
821 830
822 void NativeWidgetMus::SetCapture() { 831 void NativeWidgetMus::SetCapture() {
823 if (content_) 832 if (content_)
824 content_->SetCapture(); 833 content_->SetCapture();
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1168
1160 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { 1169 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const {
1161 // NOTIMPLEMENTED(); 1170 // NOTIMPLEMENTED();
1162 return gfx::Rect(); 1171 return gfx::Rect();
1163 } 1172 }
1164 1173
1165 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( 1174 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop(
1166 const gfx::Vector2d& drag_offset, 1175 const gfx::Vector2d& drag_offset,
1167 Widget::MoveLoopSource source, 1176 Widget::MoveLoopSource source,
1168 Widget::MoveLoopEscapeBehavior escape_behavior) { 1177 Widget::MoveLoopEscapeBehavior escape_behavior) {
1169 // NOTIMPLEMENTED(); 1178 ReleaseCapture();
1170 return Widget::MOVE_LOOP_CANCELED; 1179
1180 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1181 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
1182 base::RunLoop run_loop;
1183
1184 mus::mojom::MoveLoopSource mus_source =
1185 source == Widget::MOVE_LOOP_SOURCE_MOUSE ?
1186 mus::mojom::MoveLoopSource::MOUSE :
1187 mus::mojom::MoveLoopSource::TOUCH;
1188
1189 bool success = false;
1190 gfx::Point cursor_location =
1191 display::Screen::GetScreen()->GetCursorScreenPoint();
1192 window_->PerformWindowMove(
1193 mus_source, cursor_location,
1194 base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure()));
1195
1196 run_loop.Run();
1197
1198 return success ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED;
1171 } 1199 }
1172 1200
1173 void NativeWidgetMus::EndMoveLoop() { 1201 void NativeWidgetMus::EndMoveLoop() {
1174 // NOTIMPLEMENTED(); 1202 window_->CancelWindowMove();
1175 } 1203 }
1176 1204
1177 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { 1205 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) {
1178 // NOTIMPLEMENTED(); 1206 // NOTIMPLEMENTED();
1179 } 1207 }
1180 1208
1181 void NativeWidgetMus::SetVisibilityAnimationDuration( 1209 void NativeWidgetMus::SetVisibilityAnimationDuration(
1182 const base::TimeDelta& duration) { 1210 const base::TimeDelta& duration) {
1183 // NOTIMPLEMENTED(); 1211 // NOTIMPLEMENTED();
1184 } 1212 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 event->SetHandled(); 1366 event->SetHandled();
1339 } else { 1367 } else {
1340 native_widget_delegate_->OnScrollEvent(event); 1368 native_widget_delegate_->OnScrollEvent(event);
1341 } 1369 }
1342 } 1370 }
1343 1371
1344 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { 1372 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) {
1345 native_widget_delegate_->OnGestureEvent(event); 1373 native_widget_delegate_->OnGestureEvent(event);
1346 } 1374 }
1347 1375
1376 void NativeWidgetMus::OnHostResized(const aura::WindowTreeHost* host) {
sky 2016/06/30 23:23:54 How come both this and NativeWidgetMus::OnBoundsCh
Elliot Glaysher 2016/07/01 00:09:58 I changed it, didn't notice any problems locally a
1377 gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size());
1378 content_->SetBounds(new_bounds);
1379 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
1380 }
1381
1382 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host,
1383 const gfx::Point& new_origin) {
1384 native_widget_delegate_->OnNativeWidgetMove();
1385 }
1386
1348 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { 1387 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
1349 GetWidget()->Close(); 1388 GetWidget()->Close();
1350 } 1389 }
1351 1390
1352 void NativeWidgetMus::OnWindowInputEvent( 1391 void NativeWidgetMus::OnWindowInputEvent(
1353 mus::Window* view, 1392 mus::Window* view,
1354 const ui::Event& event_in, 1393 const ui::Event& event_in,
1355 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { 1394 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
1356 // Take ownership of the callback, indicating that we will handle it. 1395 // Take ownership of the callback, indicating that we will handle it.
1357 EventAckHandler ack_handler(std::move(*ack_callback)); 1396 EventAckHandler ack_handler(std::move(*ack_callback));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 1439
1401 gfx::Path mask_path; 1440 gfx::Path mask_path;
1402 native_widget_delegate_->GetHitTestMask(&mask_path); 1441 native_widget_delegate_->GetHitTestMask(&mask_path);
1403 // TODO(jamescook): Use the full path for the mask. 1442 // TODO(jamescook): Use the full path for the mask.
1404 gfx::Rect mask_rect = 1443 gfx::Rect mask_rect =
1405 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1444 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1406 window_->SetHitTestMask(mask_rect); 1445 window_->SetHitTestMask(mask_rect);
1407 } 1446 }
1408 1447
1409 } // namespace views 1448 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698