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

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

Issue 1967543002: Move ShowState-related code from PlatformWindowMus to NativeWidgetMus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review comments from sadrul Created 4 years, 7 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/platform_window_mus.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/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
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 native_widget_mus_->window_tree_host();
329 native_widget_mus_->window_tree_host());
330 } 366 }
331 367
332 NativeWidgetMus* native_widget_mus_; 368 NativeWidgetMus* native_widget_mus_;
369 mus::mojom::ShowState show_state_;
333 370
334 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver); 371 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver);
335 }; 372 };
336 373
337 //////////////////////////////////////////////////////////////////////////////// 374 ////////////////////////////////////////////////////////////////////////////////
338 // NativeWidgetMus, public: 375 // NativeWidgetMus, public:
339 376
340 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, 377 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate,
341 shell::Connector* connector, 378 shell::Connector* connector,
342 mus::Window* window, 379 mus::Window* window,
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 bool NativeWidgetMus::IsAlwaysOnTop() const { 886 bool NativeWidgetMus::IsAlwaysOnTop() const {
850 // NOTIMPLEMENTED(); 887 // NOTIMPLEMENTED();
851 return false; 888 return false;
852 } 889 }
853 890
854 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) { 891 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) {
855 // NOTIMPLEMENTED(); 892 // NOTIMPLEMENTED();
856 } 893 }
857 894
858 void NativeWidgetMus::Maximize() { 895 void NativeWidgetMus::Maximize() {
859 if (window_tree_host_) 896 SetShowState(mus::mojom::ShowState::MAXIMIZED);
860 window_tree_host_->platform_window()->Maximize();
861 } 897 }
862 898
863 void NativeWidgetMus::Minimize() { 899 void NativeWidgetMus::Minimize() {
864 if (window_tree_host_) 900 SetShowState(mus::mojom::ShowState::MINIMIZED);
865 window_tree_host_->platform_window()->Minimize();
866 } 901 }
867 902
868 bool NativeWidgetMus::IsMaximized() const { 903 bool NativeWidgetMus::IsMaximized() const {
869 return window_tree_host_ && 904 return mus_window_observer_ &&
870 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MAXIMIZED; 905 mus_window_observer_->show_state() == ui::PLATFORM_WINDOW_STATE_MAXIMIZED;
871 } 906 }
872 907
873 bool NativeWidgetMus::IsMinimized() const { 908 bool NativeWidgetMus::IsMinimized() const {
874 return window_tree_host_ && 909 return mus_window_observer_ &&
875 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MINIMIZED; 910 mus_window_observer_->show_state() == ui::PLATFORM_WINDOW_STATE_MINIMIZED;
sadrul 2016/05/11 14:18:20 Make sure to add show_state() accessor to the obse
Mark Dittmer 2016/05/11 15:12:55 Done.
876 } 911 }
877 912
878 void NativeWidgetMus::Restore() { 913 void NativeWidgetMus::Restore() {
879 if (window_tree_host_) 914 SetShowState(mus::mojom::ShowState::NORMAL);
880 window_tree_host_->platform_window()->Restore();
881 } 915 }
882 916
883 void NativeWidgetMus::SetFullscreen(bool fullscreen) { 917 void NativeWidgetMus::SetFullscreen(bool fullscreen) {
884 if (!window_tree_host_ || IsFullscreen() == fullscreen) 918 if (!window_tree_host_ || IsFullscreen() == fullscreen)
885 return; 919 return;
886 if (fullscreen) { 920 if (fullscreen) {
887 show_state_before_fullscreen_ = window_tree_host_->show_state(); 921 show_state_before_fullscreen_ = window_tree_host_->show_state();
sadrul 2016/05/11 14:18:20 Get rid of WindowTreeHostMus::show_state
Mark Dittmer 2016/05/11 15:12:55 Done.
888 window_tree_host_->platform_window()->ToggleFullscreen(); 922 window_tree_host_->platform_window()->ToggleFullscreen();
889 } else { 923 } else {
890 switch (show_state_before_fullscreen_) { 924 switch (show_state_before_fullscreen_) {
891 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED: 925 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED:
892 Maximize(); 926 Maximize();
893 break; 927 break;
894 case ui::PLATFORM_WINDOW_STATE_MINIMIZED: 928 case ui::PLATFORM_WINDOW_STATE_MINIMIZED:
895 Minimize(); 929 Minimize();
896 break; 930 break;
897 case ui::PLATFORM_WINDOW_STATE_UNKNOWN: 931 case ui::PLATFORM_WINDOW_STATE_UNKNOWN:
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1123 }
1090 1124
1091 bool NativeWidgetMus::HasHitTestMask() const { 1125 bool NativeWidgetMus::HasHitTestMask() const {
1092 return native_widget_delegate_->HasHitTestMask(); 1126 return native_widget_delegate_->HasHitTestMask();
1093 } 1127 }
1094 1128
1095 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const { 1129 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const {
1096 native_widget_delegate_->GetHitTestMask(mask); 1130 native_widget_delegate_->GetHitTestMask(mask);
1097 } 1131 }
1098 1132
1133 void NativeWidgetMus::SetShowState(mus::mojom::ShowState show_state) {
1134 if (!window_)
1135 return;
1136 window_->SetSharedProperty<int32_t>(
1137 mus::mojom::WindowManager::kShowState_Property,
1138 static_cast<int32_t>(show_state));
1139 }
1140
1099 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) { 1141 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) {
1100 if (event->is_char()) { 1142 if (event->is_char()) {
1101 // If a ui::InputMethod object is attached to the root window, character 1143 // 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. 1144 // 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 1145 // If such object is not attached, character events might be sent (e.g. on
1104 // Windows). In this case, we just skip these. 1146 // Windows). In this case, we just skip these.
1105 return; 1147 return;
1106 } 1148 }
1107 // Renderer may send a key event back to us if the key event wasn't handled, 1149 // 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. 1150 // and the window may be invisible by that time.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 GetNativeWindow()->Show(); 1196 GetNativeWindow()->Show();
1155 } else { 1197 } else {
1156 window_tree_host_->Hide(); 1198 window_tree_host_->Hide();
1157 window_->SetVisible(false); 1199 window_->SetVisible(false);
1158 GetNativeWindow()->Hide(); 1200 GetNativeWindow()->Hide();
1159 } 1201 }
1160 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); 1202 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible());
1161 } 1203 }
1162 1204
1163 } // namespace views 1205 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/platform_window_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698