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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
| 10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
| 11 #include "components/mus/public/cpp/window_observer.h" | 11 #include "components/mus/public/cpp/window_observer.h" |
| 12 #include "components/mus/public/cpp/window_property.h" | 12 #include "components/mus/public/cpp/window_property.h" |
| 13 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
| 14 #include "components/mus/public/interfaces/cursor.mojom.h" | 14 #include "components/mus/public/interfaces/cursor.mojom.h" |
| 15 #include "components/mus/public/interfaces/window_manager.mojom.h" | |
| 16 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | |
| 15 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 16 #include "ui/aura/client/default_capture_client.h" | 18 #include "ui/aura/client/default_capture_client.h" |
| 17 #include "ui/aura/client/window_tree_client.h" | 19 #include "ui/aura/client/window_tree_client.h" |
| 18 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
| 19 #include "ui/aura/layout_manager.h" | 21 #include "ui/aura/layout_manager.h" |
| 20 #include "ui/aura/mus/mus_util.h" | 22 #include "ui/aura/mus/mus_util.h" |
| 21 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_property.h" | 24 #include "ui/aura/window_property.h" |
| 23 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
| 24 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 if (app_icon.isNull()) | 293 if (app_icon.isNull()) |
| 292 return SkBitmap(); | 294 return SkBitmap(); |
| 293 return app_icon.GetRepresentation(1.f).sk_bitmap(); | 295 return app_icon.GetRepresentation(1.f).sk_bitmap(); |
| 294 } | 296 } |
| 295 | 297 |
| 296 } // namespace | 298 } // namespace |
| 297 | 299 |
| 298 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { | 300 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { |
| 299 public: | 301 public: |
| 300 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) | 302 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) |
| 301 : native_widget_mus_(native_widget_mus) { | 303 : native_widget_mus_(native_widget_mus), |
| 304 show_state_(mus::mojom::ShowState::DEFAULT) { | |
| 302 mus_window()->AddObserver(this); | 305 mus_window()->AddObserver(this); |
| 303 } | 306 } |
| 304 | 307 |
| 305 ~MusWindowObserver() override { | 308 ~MusWindowObserver() override { |
| 306 mus_window()->RemoveObserver(this); | 309 mus_window()->RemoveObserver(this); |
| 307 } | 310 } |
| 308 | 311 |
| 309 // mus::WindowObserver: | 312 // mus::WindowObserver: |
| 310 void OnWindowVisibilityChanging(mus::Window* window) override { | 313 void OnWindowVisibilityChanging(mus::Window* window) override { |
| 311 native_widget_mus_->OnMusWindowVisibilityChanging(window); | 314 native_widget_mus_->OnMusWindowVisibilityChanging(window); |
| 312 } | 315 } |
| 313 void OnWindowVisibilityChanged(mus::Window* window) override { | 316 void OnWindowVisibilityChanged(mus::Window* window) override { |
| 314 native_widget_mus_->OnMusWindowVisibilityChanged(window); | 317 native_widget_mus_->OnMusWindowVisibilityChanged(window); |
| 315 } | 318 } |
| 316 void OnWindowBoundsChanged(mus::Window* window, | 319 void OnWindowBoundsChanged(mus::Window* window, |
| 317 const gfx::Rect& old_bounds, | 320 const gfx::Rect& old_bounds, |
| 318 const gfx::Rect& new_bounds) override { | 321 const gfx::Rect& new_bounds) override { |
| 319 platform_window_delegate()->OnBoundsChanged(new_bounds); | 322 platform_window_delegate()->OnBoundsChanged(new_bounds); |
| 320 } | 323 } |
| 324 void OnWindowSharedPropertyChanged( | |
| 325 mus::Window* window, | |
| 326 const std::string& name, | |
| 327 const std::vector<uint8_t>* old_data, | |
| 328 const std::vector<uint8_t>* new_data) override { | |
| 329 if (name != mus::mojom::WindowManager::kShowState_Property) | |
| 330 return; | |
| 331 mus::mojom::ShowState show_state = | |
| 332 static_cast<mus::mojom::ShowState>(window->GetSharedProperty<int32_t>( | |
| 333 mus::mojom::WindowManager::kShowState_Property)); | |
| 334 if (show_state == show_state_) | |
| 335 return; | |
| 336 show_state_ = show_state; | |
| 337 ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN; | |
| 338 switch (show_state_) { | |
| 339 case mus::mojom::ShowState::MINIMIZED: | |
| 340 state = ui::PLATFORM_WINDOW_STATE_MINIMIZED; | |
| 341 break; | |
| 342 case mus::mojom::ShowState::MAXIMIZED: | |
| 343 state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED; | |
| 344 break; | |
| 345 case mus::mojom::ShowState::DEFAULT: | |
| 346 case mus::mojom::ShowState::INACTIVE: | |
| 347 case mus::mojom::ShowState::NORMAL: | |
| 348 case mus::mojom::ShowState::DOCKED: | |
| 349 // TODO(sky): support docked. | |
| 350 state = ui::PLATFORM_WINDOW_STATE_NORMAL; | |
| 351 break; | |
| 352 case mus::mojom::ShowState::FULLSCREEN: | |
| 353 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; | |
| 354 break; | |
| 355 } | |
| 356 platform_window_delegate()->OnWindowStateChanged(state); | |
| 357 } | |
| 321 | 358 |
| 322 private: | 359 private: |
| 323 mus::Window* mus_window() { return native_widget_mus_->window(); } | 360 mus::Window* mus_window() { return native_widget_mus_->window(); } |
| 324 WindowTreeHostMus* window_tree_host() { | 361 WindowTreeHostMus* window_tree_host() { |
| 325 return native_widget_mus_->window_tree_host(); | 362 return native_widget_mus_->window_tree_host(); |
| 326 } | 363 } |
| 327 ui::PlatformWindowDelegate* platform_window_delegate() { | 364 ui::PlatformWindowDelegate* platform_window_delegate() { |
| 328 return static_cast<ui::PlatformWindowDelegate*>( | 365 return static_cast<ui::PlatformWindowDelegate*>( |
|
sadrul
2016/05/11 05:35:33
btw: this static_cast<> isn't necessary, is it?
Mark Dittmer
2016/05/11 13:37:37
It is not. I was thinking downcast when it's an up
| |
| 329 native_widget_mus_->window_tree_host()); | 366 native_widget_mus_->window_tree_host()); |
| 330 } | 367 } |
| 331 | 368 |
| 332 NativeWidgetMus* native_widget_mus_; | 369 NativeWidgetMus* native_widget_mus_; |
| 370 mus::mojom::ShowState show_state_; | |
| 333 | 371 |
| 334 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver); | 372 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver); |
| 335 }; | 373 }; |
| 336 | 374 |
| 337 //////////////////////////////////////////////////////////////////////////////// | 375 //////////////////////////////////////////////////////////////////////////////// |
| 338 // NativeWidgetMus, public: | 376 // NativeWidgetMus, public: |
| 339 | 377 |
| 340 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, | 378 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, |
| 341 shell::Connector* connector, | 379 shell::Connector* connector, |
| 342 mus::Window* window, | 380 mus::Window* window, |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 bool NativeWidgetMus::IsAlwaysOnTop() const { | 887 bool NativeWidgetMus::IsAlwaysOnTop() const { |
| 850 // NOTIMPLEMENTED(); | 888 // NOTIMPLEMENTED(); |
| 851 return false; | 889 return false; |
| 852 } | 890 } |
| 853 | 891 |
| 854 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) { | 892 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) { |
| 855 // NOTIMPLEMENTED(); | 893 // NOTIMPLEMENTED(); |
| 856 } | 894 } |
| 857 | 895 |
| 858 void NativeWidgetMus::Maximize() { | 896 void NativeWidgetMus::Maximize() { |
| 859 if (window_tree_host_) | 897 if (!(window_ && window_tree_host_)) |
| 860 window_tree_host_->platform_window()->Maximize(); | 898 return; |
| 899 | |
| 900 window_tree_host_->platform_window()->Maximize(); | |
|
sadrul
2016/05/11 05:12:47
Remove these calls to platform_window()
Mark Dittmer
2016/05/11 13:37:37
Done.
| |
| 901 SetShowState(mus::mojom::ShowState::MAXIMIZED); | |
| 861 } | 902 } |
| 862 | 903 |
| 863 void NativeWidgetMus::Minimize() { | 904 void NativeWidgetMus::Minimize() { |
| 864 if (window_tree_host_) | 905 if (!(window_ && window_tree_host_)) |
| 865 window_tree_host_->platform_window()->Minimize(); | 906 return; |
| 907 | |
| 908 window_tree_host_->platform_window()->Minimize(); | |
| 909 SetShowState(mus::mojom::ShowState::MINIMIZED); | |
| 866 } | 910 } |
| 867 | 911 |
| 868 bool NativeWidgetMus::IsMaximized() const { | 912 bool NativeWidgetMus::IsMaximized() const { |
| 869 return window_tree_host_ && | 913 return window_tree_host_ && |
| 870 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MAXIMIZED; | 914 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MAXIMIZED; |
|
sadrul
2016/05/11 05:12:47
We should look at |mus_window_obserer_->show_state
Mark Dittmer
2016/05/11 13:37:37
Done.
| |
| 871 } | 915 } |
| 872 | 916 |
| 873 bool NativeWidgetMus::IsMinimized() const { | 917 bool NativeWidgetMus::IsMinimized() const { |
| 874 return window_tree_host_ && | 918 return window_tree_host_ && |
| 875 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MINIMIZED; | 919 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MINIMIZED; |
| 876 } | 920 } |
| 877 | 921 |
| 878 void NativeWidgetMus::Restore() { | 922 void NativeWidgetMus::Restore() { |
| 879 if (window_tree_host_) | 923 if (!(window_ && window_tree_host_)) |
| 880 window_tree_host_->platform_window()->Restore(); | 924 return; |
| 925 | |
| 926 window_tree_host_->platform_window()->Restore(); | |
| 927 SetShowState(mus::mojom::ShowState::NORMAL); | |
| 881 } | 928 } |
| 882 | 929 |
| 883 void NativeWidgetMus::SetFullscreen(bool fullscreen) { | 930 void NativeWidgetMus::SetFullscreen(bool fullscreen) { |
| 884 if (!window_tree_host_ || IsFullscreen() == fullscreen) | 931 if (!window_tree_host_ || IsFullscreen() == fullscreen) |
| 885 return; | 932 return; |
| 886 if (fullscreen) { | 933 if (fullscreen) { |
| 887 show_state_before_fullscreen_ = window_tree_host_->show_state(); | 934 show_state_before_fullscreen_ = window_tree_host_->show_state(); |
| 888 window_tree_host_->platform_window()->ToggleFullscreen(); | 935 window_tree_host_->platform_window()->ToggleFullscreen(); |
| 889 } else { | 936 } else { |
| 890 switch (show_state_before_fullscreen_) { | 937 switch (show_state_before_fullscreen_) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1089 } | 1136 } |
| 1090 | 1137 |
| 1091 bool NativeWidgetMus::HasHitTestMask() const { | 1138 bool NativeWidgetMus::HasHitTestMask() const { |
| 1092 return native_widget_delegate_->HasHitTestMask(); | 1139 return native_widget_delegate_->HasHitTestMask(); |
| 1093 } | 1140 } |
| 1094 | 1141 |
| 1095 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const { | 1142 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const { |
| 1096 native_widget_delegate_->GetHitTestMask(mask); | 1143 native_widget_delegate_->GetHitTestMask(mask); |
| 1097 } | 1144 } |
| 1098 | 1145 |
| 1146 void NativeWidgetMus::SetShowState(mus::mojom::ShowState show_state) { | |
| 1147 window_->SetSharedProperty<int32_t>( | |
| 1148 mus::mojom::WindowManager::kShowState_Property, | |
| 1149 static_cast<int32_t>(show_state)); | |
| 1150 } | |
| 1151 | |
| 1099 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) { | 1152 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) { |
| 1100 if (event->is_char()) { | 1153 if (event->is_char()) { |
| 1101 // If a ui::InputMethod object is attached to the root window, character | 1154 // If a ui::InputMethod object is attached to the root window, character |
| 1102 // events are handled inside the object and are not passed to this function. | 1155 // events are handled inside the object and are not passed to this function. |
| 1103 // If such object is not attached, character events might be sent (e.g. on | 1156 // If such object is not attached, character events might be sent (e.g. on |
| 1104 // Windows). In this case, we just skip these. | 1157 // Windows). In this case, we just skip these. |
| 1105 return; | 1158 return; |
| 1106 } | 1159 } |
| 1107 // Renderer may send a key event back to us if the key event wasn't handled, | 1160 // Renderer may send a key event back to us if the key event wasn't handled, |
| 1108 // and the window may be invisible by that time. | 1161 // and the window may be invisible by that time. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 GetNativeWindow()->Show(); | 1207 GetNativeWindow()->Show(); |
| 1155 } else { | 1208 } else { |
| 1156 window_tree_host_->Hide(); | 1209 window_tree_host_->Hide(); |
| 1157 window_->SetVisible(false); | 1210 window_->SetVisible(false); |
| 1158 GetNativeWindow()->Hide(); | 1211 GetNativeWindow()->Hide(); |
| 1159 } | 1212 } |
| 1160 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); | 1213 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); |
| 1161 } | 1214 } |
| 1162 | 1215 |
| 1163 } // namespace views | 1216 } // namespace views |
| OLD | NEW |