Chromium Code Reviews| 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 "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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
| 1234 // Assume that if the old bounds was completely empty a move happened. This | 1262 // This is handled in OnHost{Resized,Moved}() like DesktopNativeWidgetAura |
| 1235 // handles the case of a maximize animation acquiring the layer (acquiring a | 1263 // instead of here like in NativeWidgetAura. |
| 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 } | 1264 } |
| 1247 | 1265 |
| 1248 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { | 1266 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { |
| 1249 return gfx::NativeCursor(); | 1267 return gfx::NativeCursor(); |
| 1250 } | 1268 } |
| 1251 | 1269 |
| 1252 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { | 1270 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { |
| 1253 return native_widget_delegate_->GetNonClientComponent(point); | 1271 return native_widget_delegate_->GetNonClientComponent(point); |
| 1254 } | 1272 } |
| 1255 | 1273 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 event->SetHandled(); | 1356 event->SetHandled(); |
| 1339 } else { | 1357 } else { |
| 1340 native_widget_delegate_->OnScrollEvent(event); | 1358 native_widget_delegate_->OnScrollEvent(event); |
| 1341 } | 1359 } |
| 1342 } | 1360 } |
| 1343 | 1361 |
| 1344 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 1362 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
| 1345 native_widget_delegate_->OnGestureEvent(event); | 1363 native_widget_delegate_->OnGestureEvent(event); |
| 1346 } | 1364 } |
| 1347 | 1365 |
| 1366 void NativeWidgetMus::OnHostResized(const aura::WindowTreeHost* host) { | |
| 1367 gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size()); | |
| 1368 content_->SetBounds(new_bounds); | |
|
sadrul
2016/07/04 20:11:38
Do you need to SetBounds() here? It should already
Elliot Glaysher
2016/07/07 19:12:06
You're right that it isn't needed; I removed the c
| |
| 1369 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
| 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 | |
| 1348 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 1379 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
| 1349 GetWidget()->Close(); | 1380 GetWidget()->Close(); |
| 1350 } | 1381 } |
| 1351 | 1382 |
| 1352 void NativeWidgetMus::OnWindowInputEvent( | 1383 void NativeWidgetMus::OnWindowInputEvent( |
| 1353 mus::Window* view, | 1384 mus::Window* view, |
| 1354 const ui::Event& event_in, | 1385 const ui::Event& event_in, |
| 1355 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 1386 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
| 1356 // Take ownership of the callback, indicating that we will handle it. | 1387 // Take ownership of the callback, indicating that we will handle it. |
| 1357 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... | |
| 1400 | 1431 |
| 1401 gfx::Path mask_path; | 1432 gfx::Path mask_path; |
| 1402 native_widget_delegate_->GetHitTestMask(&mask_path); | 1433 native_widget_delegate_->GetHitTestMask(&mask_path); |
| 1403 // TODO(jamescook): Use the full path for the mask. | 1434 // TODO(jamescook): Use the full path for the mask. |
| 1404 gfx::Rect mask_rect = | 1435 gfx::Rect mask_rect = |
| 1405 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 1436 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
| 1406 window_->SetHitTestMask(mask_rect); | 1437 window_->SetHitTestMask(mask_rect); |
| 1407 } | 1438 } |
| 1408 | 1439 |
| 1409 } // namespace views | 1440 } // namespace views |
| OLD | NEW |