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

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: Add some comments to window finder interface. 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 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 1251
1224 gfx::Size NativeWidgetMus::GetMinimumSize() const { 1252 gfx::Size NativeWidgetMus::GetMinimumSize() const {
1225 return native_widget_delegate_->GetMinimumSize(); 1253 return native_widget_delegate_->GetMinimumSize();
1226 } 1254 }
1227 1255
1228 gfx::Size NativeWidgetMus::GetMaximumSize() const { 1256 gfx::Size NativeWidgetMus::GetMaximumSize() const {
1229 return native_widget_delegate_->GetMaximumSize(); 1257 return native_widget_delegate_->GetMaximumSize();
1230 } 1258 }
1231 1259
1232 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds, 1260 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds,
1233 const gfx::Rect& new_bounds) { 1261 const gfx::Rect& new_bounds) {}
sky 2016/07/01 16:01:16 I know if I saw this I would wonder why there is n
1234 // Assume that if the old bounds was completely empty a move happened. This
1235 // handles the case of a maximize animation acquiring the layer (acquiring a
1236 // layer results in clearing the bounds).
1237 if (old_bounds.origin() != new_bounds.origin() ||
1238 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) {
1239 native_widget_delegate_->OnNativeWidgetMove();
1240 }
1241 if (old_bounds.size() != new_bounds.size()) {
1242 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
1243 UpdateClientArea();
1244 UpdateHitTestMask();
1245 }
1246 }
1247 1262
1248 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { 1263 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) {
1249 return gfx::NativeCursor(); 1264 return gfx::NativeCursor();
1250 } 1265 }
1251 1266
1252 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { 1267 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const {
1253 return native_widget_delegate_->GetNonClientComponent(point); 1268 return native_widget_delegate_->GetNonClientComponent(point);
1254 } 1269 }
1255 1270
1256 bool NativeWidgetMus::ShouldDescendIntoChildForEventHandling( 1271 bool NativeWidgetMus::ShouldDescendIntoChildForEventHandling(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 event->SetHandled(); 1353 event->SetHandled();
1339 } else { 1354 } else {
1340 native_widget_delegate_->OnScrollEvent(event); 1355 native_widget_delegate_->OnScrollEvent(event);
1341 } 1356 }
1342 } 1357 }
1343 1358
1344 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { 1359 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) {
1345 native_widget_delegate_->OnGestureEvent(event); 1360 native_widget_delegate_->OnGestureEvent(event);
1346 } 1361 }
1347 1362
1363 void NativeWidgetMus::OnHostResized(const aura::WindowTreeHost* host) {
1364 gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size());
1365 content_->SetBounds(new_bounds);
1366 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
1367 UpdateClientArea();
1368 UpdateHitTestMask();
1369 }
1370
1371 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host,
1372 const gfx::Point& new_origin) {
1373 native_widget_delegate_->OnNativeWidgetMove();
1374 }
1375
1348 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { 1376 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
1349 GetWidget()->Close(); 1377 GetWidget()->Close();
1350 } 1378 }
1351 1379
1352 void NativeWidgetMus::OnWindowInputEvent( 1380 void NativeWidgetMus::OnWindowInputEvent(
1353 mus::Window* view, 1381 mus::Window* view,
1354 const ui::Event& event_in, 1382 const ui::Event& event_in,
1355 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { 1383 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
1356 // Take ownership of the callback, indicating that we will handle it. 1384 // Take ownership of the callback, indicating that we will handle it.
1357 EventAckHandler ack_handler(std::move(*ack_callback)); 1385 EventAckHandler ack_handler(std::move(*ack_callback));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 1428
1401 gfx::Path mask_path; 1429 gfx::Path mask_path;
1402 native_widget_delegate_->GetHitTestMask(&mask_path); 1430 native_widget_delegate_->GetHitTestMask(&mask_path);
1403 // TODO(jamescook): Use the full path for the mask. 1431 // TODO(jamescook): Use the full path for the mask.
1404 gfx::Rect mask_rect = 1432 gfx::Rect mask_rect =
1405 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1433 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1406 window_->SetHitTestMask(mask_rect); 1434 window_->SetHitTestMask(mask_rect);
1407 } 1435 }
1408 1436
1409 } // namespace views 1437 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698