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

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: Refactor show_state checks 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
312 mus::mojom::ShowState show_state() { return show_state_; }
313
309 // mus::WindowObserver: 314 // mus::WindowObserver:
310 void OnWindowVisibilityChanging(mus::Window* window) override { 315 void OnWindowVisibilityChanging(mus::Window* window) override {
311 native_widget_mus_->OnMusWindowVisibilityChanging(window); 316 native_widget_mus_->OnMusWindowVisibilityChanging(window);
312 } 317 }
313 void OnWindowVisibilityChanged(mus::Window* window) override { 318 void OnWindowVisibilityChanged(mus::Window* window) override {
314 native_widget_mus_->OnMusWindowVisibilityChanged(window); 319 native_widget_mus_->OnMusWindowVisibilityChanged(window);
315 } 320 }
316 void OnWindowBoundsChanged(mus::Window* window, 321 void OnWindowBoundsChanged(mus::Window* window,
317 const gfx::Rect& old_bounds, 322 const gfx::Rect& old_bounds,
318 const gfx::Rect& new_bounds) override { 323 const gfx::Rect& new_bounds) override {
319 platform_window_delegate()->OnBoundsChanged(new_bounds); 324 platform_window_delegate()->OnBoundsChanged(new_bounds);
320 } 325 }
326 void OnWindowSharedPropertyChanged(
327 mus::Window* window,
328 const std::string& name,
329 const std::vector<uint8_t>* old_data,
330 const std::vector<uint8_t>* new_data) override {
331 if (name != mus::mojom::WindowManager::kShowState_Property)
332 return;
333 mus::mojom::ShowState show_state =
334 static_cast<mus::mojom::ShowState>(window->GetSharedProperty<int32_t>(
335 mus::mojom::WindowManager::kShowState_Property));
336 if (show_state == show_state_)
337 return;
338 show_state_ = show_state;
339 ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN;
340 switch (show_state_) {
341 case mus::mojom::ShowState::MINIMIZED:
342 state = ui::PLATFORM_WINDOW_STATE_MINIMIZED;
343 break;
344 case mus::mojom::ShowState::MAXIMIZED:
345 state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED;
346 break;
347 case mus::mojom::ShowState::DEFAULT:
348 case mus::mojom::ShowState::INACTIVE:
349 case mus::mojom::ShowState::NORMAL:
350 case mus::mojom::ShowState::DOCKED:
351 // TODO(sky): support docked.
352 state = ui::PLATFORM_WINDOW_STATE_NORMAL;
353 break;
354 case mus::mojom::ShowState::FULLSCREEN:
355 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN;
356 break;
357 }
358 platform_window_delegate()->OnWindowStateChanged(state);
359 }
321 360
322 private: 361 private:
323 mus::Window* mus_window() { return native_widget_mus_->window(); } 362 mus::Window* mus_window() { return native_widget_mus_->window(); }
324 WindowTreeHostMus* window_tree_host() { 363 WindowTreeHostMus* window_tree_host() {
325 return native_widget_mus_->window_tree_host(); 364 return native_widget_mus_->window_tree_host();
326 } 365 }
327 ui::PlatformWindowDelegate* platform_window_delegate() { 366 ui::PlatformWindowDelegate* platform_window_delegate() {
328 return static_cast<ui::PlatformWindowDelegate*>( 367 return native_widget_mus_->window_tree_host();
329 native_widget_mus_->window_tree_host());
330 } 368 }
331 369
332 NativeWidgetMus* native_widget_mus_; 370 NativeWidgetMus* native_widget_mus_;
371 mus::mojom::ShowState show_state_;
333 372
334 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver); 373 DISALLOW_COPY_AND_ASSIGN(MusWindowObserver);
335 }; 374 };
336 375
337 //////////////////////////////////////////////////////////////////////////////// 376 ////////////////////////////////////////////////////////////////////////////////
338 // NativeWidgetMus, public: 377 // NativeWidgetMus, public:
339 378
340 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, 379 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate,
341 shell::Connector* connector, 380 shell::Connector* connector,
342 mus::Window* window, 381 mus::Window* window,
343 mus::mojom::SurfaceType surface_type) 382 mus::mojom::SurfaceType surface_type)
344 : window_(window), 383 : window_(window),
345 native_widget_delegate_(delegate), 384 native_widget_delegate_(delegate),
346 surface_type_(surface_type), 385 surface_type_(surface_type),
347 show_state_before_fullscreen_(ui::PLATFORM_WINDOW_STATE_UNKNOWN), 386 show_state_before_fullscreen_(mus::mojom::ShowState::DEFAULT),
348 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 387 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
349 content_(new aura::Window(this)), 388 content_(new aura::Window(this)),
350 close_widget_factory_(this) { 389 close_widget_factory_(this) {
351 mus_window_observer_.reset(new MusWindowObserver(this)); 390 mus_window_observer_.reset(new MusWindowObserver(this));
352 391
353 // TODO(fsamuel): Figure out lifetime of |window_|. 392 // TODO(fsamuel): Figure out lifetime of |window_|.
354 aura::SetMusWindow(content_, window_); 393 aura::SetMusWindow(content_, window_);
355 394
356 window->SetLocalProperty(kNativeWidgetMusKey, this); 395 window->SetLocalProperty(kNativeWidgetMusKey, this);
357 // WindowTreeHost creates the compositor using the ContextFactory from 396 // WindowTreeHost creates the compositor using the ContextFactory from
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 bool NativeWidgetMus::IsAlwaysOnTop() const { 888 bool NativeWidgetMus::IsAlwaysOnTop() const {
850 // NOTIMPLEMENTED(); 889 // NOTIMPLEMENTED();
851 return false; 890 return false;
852 } 891 }
853 892
854 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) { 893 void NativeWidgetMus::SetVisibleOnAllWorkspaces(bool always_visible) {
855 // NOTIMPLEMENTED(); 894 // NOTIMPLEMENTED();
856 } 895 }
857 896
858 void NativeWidgetMus::Maximize() { 897 void NativeWidgetMus::Maximize() {
859 if (window_tree_host_) 898 SetShowState(mus::mojom::ShowState::MAXIMIZED);
860 window_tree_host_->platform_window()->Maximize();
861 } 899 }
862 900
863 void NativeWidgetMus::Minimize() { 901 void NativeWidgetMus::Minimize() {
864 if (window_tree_host_) 902 SetShowState(mus::mojom::ShowState::MINIMIZED);
865 window_tree_host_->platform_window()->Minimize();
866 } 903 }
867 904
868 bool NativeWidgetMus::IsMaximized() const { 905 bool NativeWidgetMus::IsMaximized() const {
869 return window_tree_host_ && 906 return mus_window_observer_ &&
870 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MAXIMIZED; 907 mus_window_observer_->show_state() == mus::mojom::ShowState::MAXIMIZED;
871 } 908 }
872 909
873 bool NativeWidgetMus::IsMinimized() const { 910 bool NativeWidgetMus::IsMinimized() const {
874 return window_tree_host_ && 911 return mus_window_observer_ &&
875 window_tree_host_->show_state() == ui::PLATFORM_WINDOW_STATE_MINIMIZED; 912 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED;
876 } 913 }
877 914
878 void NativeWidgetMus::Restore() { 915 void NativeWidgetMus::Restore() {
879 if (window_tree_host_) 916 SetShowState(mus::mojom::ShowState::NORMAL);
880 window_tree_host_->platform_window()->Restore();
881 } 917 }
882 918
883 void NativeWidgetMus::SetFullscreen(bool fullscreen) { 919 void NativeWidgetMus::SetFullscreen(bool fullscreen) {
884 if (!window_tree_host_ || IsFullscreen() == fullscreen) 920 if (!window_tree_host_ || IsFullscreen() == fullscreen)
885 return; 921 return;
886 if (fullscreen) { 922 if (fullscreen) {
887 show_state_before_fullscreen_ = window_tree_host_->show_state(); 923 show_state_before_fullscreen_ = mus_window_observer_->show_state();
888 window_tree_host_->platform_window()->ToggleFullscreen(); 924 window_tree_host_->platform_window()->ToggleFullscreen();
889 } else { 925 } else {
890 switch (show_state_before_fullscreen_) { 926 switch (show_state_before_fullscreen_) {
891 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED: 927 case mus::mojom::ShowState::MAXIMIZED:
892 Maximize(); 928 Maximize();
893 break; 929 break;
894 case ui::PLATFORM_WINDOW_STATE_MINIMIZED: 930 case mus::mojom::ShowState::MINIMIZED:
895 Minimize(); 931 Minimize();
896 break; 932 break;
897 case ui::PLATFORM_WINDOW_STATE_UNKNOWN: 933 case mus::mojom::ShowState::DEFAULT:
898 case ui::PLATFORM_WINDOW_STATE_NORMAL: 934 case mus::mojom::ShowState::NORMAL:
899 case ui::PLATFORM_WINDOW_STATE_FULLSCREEN: 935 case mus::mojom::ShowState::INACTIVE:
936 case mus::mojom::ShowState::FULLSCREEN:
937 case mus::mojom::ShowState::DOCKED:
900 // TODO(sad): This may not be sufficient. 938 // TODO(sad): This may not be sufficient.
901 Restore(); 939 Restore();
902 break; 940 break;
903 } 941 }
904 } 942 }
905 } 943 }
906 944
907 bool NativeWidgetMus::IsFullscreen() const { 945 bool NativeWidgetMus::IsFullscreen() const {
908 return window_tree_host_ && 946 return mus_window_observer_ &&
909 window_tree_host_->show_state() == 947 mus_window_observer_->show_state() == mus::mojom::ShowState::FULLSCREEN;
910 ui::PLATFORM_WINDOW_STATE_FULLSCREEN;
911 } 948 }
912 949
913 void NativeWidgetMus::SetOpacity(unsigned char opacity) { 950 void NativeWidgetMus::SetOpacity(unsigned char opacity) {
914 if (window_) 951 if (window_)
915 window_->SetOpacity(opacity / 255.0); 952 window_->SetOpacity(opacity / 255.0);
916 } 953 }
917 954
918 void NativeWidgetMus::FlashFrame(bool flash_frame) { 955 void NativeWidgetMus::FlashFrame(bool flash_frame) {
919 // NOTIMPLEMENTED(); 956 // NOTIMPLEMENTED();
920 } 957 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1126 }
1090 1127
1091 bool NativeWidgetMus::HasHitTestMask() const { 1128 bool NativeWidgetMus::HasHitTestMask() const {
1092 return native_widget_delegate_->HasHitTestMask(); 1129 return native_widget_delegate_->HasHitTestMask();
1093 } 1130 }
1094 1131
1095 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const { 1132 void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const {
1096 native_widget_delegate_->GetHitTestMask(mask); 1133 native_widget_delegate_->GetHitTestMask(mask);
1097 } 1134 }
1098 1135
1136 void NativeWidgetMus::SetShowState(mus::mojom::ShowState show_state) {
1137 if (!window_)
1138 return;
1139 window_->SetSharedProperty<int32_t>(
1140 mus::mojom::WindowManager::kShowState_Property,
1141 static_cast<int32_t>(show_state));
1142 }
1143
1099 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) { 1144 void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) {
1100 if (event->is_char()) { 1145 if (event->is_char()) {
1101 // If a ui::InputMethod object is attached to the root window, character 1146 // 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. 1147 // 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 1148 // If such object is not attached, character events might be sent (e.g. on
1104 // Windows). In this case, we just skip these. 1149 // Windows). In this case, we just skip these.
1105 return; 1150 return;
1106 } 1151 }
1107 // Renderer may send a key event back to us if the key event wasn't handled, 1152 // 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. 1153 // and the window may be invisible by that time.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 GetNativeWindow()->Show(); 1199 GetNativeWindow()->Show();
1155 } else { 1200 } else {
1156 window_tree_host_->Hide(); 1201 window_tree_host_->Hide();
1157 window_->SetVisible(false); 1202 window_->SetVisible(false);
1158 GetNativeWindow()->Hide(); 1203 GetNativeWindow()->Hide();
1159 } 1204 }
1160 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); 1205 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible());
1161 } 1206 }
1162 1207
1163 } // namespace views 1208 } // 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