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

Side by Side Diff: components/exo/shell_surface.cc

Issue 2688483003: exo: Refactor ShellSurface and WaylandRemoteShell (Closed)
Patch Set: Address nits Created 3 years, 10 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 "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/frame/custom_frame_view_ash.h" 9 #include "ash/common/frame/custom_frame_view_ash.h"
10 #include "ash/common/shelf/wm_shelf.h" 10 #include "ash/common/shelf/wm_shelf.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 328 }
329 } 329 }
330 330
331 //////////////////////////////////////////////////////////////////////////////// 331 ////////////////////////////////////////////////////////////////////////////////
332 // ShellSurface, public: 332 // ShellSurface, public:
333 333
334 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) 334 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr)
335 335
336 ShellSurface::ShellSurface(Surface* surface, 336 ShellSurface::ShellSurface(Surface* surface,
337 ShellSurface* parent, 337 ShellSurface* parent,
338 const gfx::Rect& initial_bounds, 338 BoundsMode bounds_mode,
339 const gfx::Point& origin,
339 bool activatable, 340 bool activatable,
340 bool can_minimize, 341 bool can_minimize,
341 int container) 342 int container)
342 : widget_(nullptr), 343 : widget_(nullptr),
343 surface_(surface), 344 surface_(surface),
344 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr), 345 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr),
345 initial_bounds_(initial_bounds), 346 bounds_mode_(bounds_mode),
347 origin_(origin),
346 activatable_(activatable), 348 activatable_(activatable),
347 can_minimize_(can_minimize), 349 can_minimize_(can_minimize),
348 container_(container) { 350 container_(container) {
349 WMHelper::GetInstance()->AddActivationObserver(this); 351 WMHelper::GetInstance()->AddActivationObserver(this);
350 surface_->SetSurfaceDelegate(this); 352 surface_->SetSurfaceDelegate(this);
351 surface_->AddSurfaceObserver(this); 353 surface_->AddSurfaceObserver(this);
352 surface_->window()->Show(); 354 surface_->window()->Show();
353 set_owned_by_client(); 355 set_owned_by_client();
354 if (parent_) 356 if (parent_)
355 parent_->AddObserver(this); 357 parent_->AddObserver(this);
356 } 358 }
357 359
358 ShellSurface::ShellSurface(Surface* surface) 360 ShellSurface::ShellSurface(Surface* surface)
359 : ShellSurface(surface, 361 : ShellSurface(surface,
360 nullptr, 362 nullptr,
361 gfx::Rect(), 363 BoundsMode::SHELL,
364 gfx::Point(),
362 true, 365 true,
363 true, 366 true,
364 ash::kShellWindowId_DefaultContainer) {} 367 ash::kShellWindowId_DefaultContainer) {}
365 368
366 ShellSurface::~ShellSurface() { 369 ShellSurface::~ShellSurface() {
367 DCHECK(!scoped_configure_); 370 DCHECK(!scoped_configure_);
368 if (resizer_) 371 if (resizer_)
369 EndDrag(false /* revert */); 372 EndDrag(false /* revert */);
370 if (widget_) { 373 if (widget_) {
371 ash::wm::GetWindowState(widget_->GetNativeWindow())->RemoveObserver(this); 374 ash::wm::GetWindowState(widget_->GetNativeWindow())->RemoveObserver(this);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 void ShellSurface::SetApplicationId(const std::string& application_id) { 560 void ShellSurface::SetApplicationId(const std::string& application_id) {
558 // Store the value in |application_id_| in case the window does not exist yet. 561 // Store the value in |application_id_| in case the window does not exist yet.
559 application_id_ = application_id; 562 application_id_ = application_id;
560 if (widget_ && widget_->GetNativeWindow()) 563 if (widget_ && widget_->GetNativeWindow())
561 SetApplicationId(widget_->GetNativeWindow(), application_id); 564 SetApplicationId(widget_->GetNativeWindow(), application_id);
562 } 565 }
563 566
564 void ShellSurface::Move() { 567 void ShellSurface::Move() {
565 TRACE_EVENT0("exo", "ShellSurface::Move"); 568 TRACE_EVENT0("exo", "ShellSurface::Move");
566 569
567 if (widget_ && !widget_->movement_disabled()) 570 if (!widget_)
568 AttemptToStartDrag(HTCAPTION); 571 return;
572
573 switch (bounds_mode_) {
574 case BoundsMode::SHELL:
575 AttemptToStartDrag(HTCAPTION);
576 return;
577 case BoundsMode::CLIENT:
578 case BoundsMode::FIXED:
579 break;
reveman 2017/02/10 02:10:53 return;
Dominik Laskowski 2017/02/10 03:05:18 Done.
580 }
581
582 NOTREACHED();
569 } 583 }
570 584
571 void ShellSurface::Resize(int component) { 585 void ShellSurface::Resize(int component) {
572 TRACE_EVENT1("exo", "ShellSurface::Resize", "component", component); 586 TRACE_EVENT1("exo", "ShellSurface::Resize", "component", component);
573 587
574 if (widget_ && !widget_->movement_disabled()) 588 if (!widget_)
575 AttemptToStartDrag(component); 589 return;
590
591 switch (bounds_mode_) {
592 case BoundsMode::SHELL:
593 AttemptToStartDrag(component);
594 return;
595 case BoundsMode::CLIENT:
596 case BoundsMode::FIXED:
597 break;
reveman 2017/02/10 02:10:53 return;
Dominik Laskowski 2017/02/10 03:05:18 Done.
598 }
599
600 NOTREACHED();
576 } 601 }
577 602
578 void ShellSurface::Close() { 603 void ShellSurface::Close() {
579 if (!close_callback_.is_null()) 604 if (!close_callback_.is_null())
580 close_callback_.Run(); 605 close_callback_.Run();
581 } 606 }
582 607
583 void ShellSurface::SetGeometry(const gfx::Rect& geometry) { 608 void ShellSurface::SetGeometry(const gfx::Rect& geometry) {
584 TRACE_EVENT1("exo", "ShellSurface::SetGeometry", "geometry", 609 TRACE_EVENT1("exo", "ShellSurface::SetGeometry", "geometry",
585 geometry.ToString()); 610 geometry.ToString());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 667
643 void ShellSurface::SetTopInset(int height) { 668 void ShellSurface::SetTopInset(int height) {
644 TRACE_EVENT1("exo", "ShellSurface::SetTopInset", "height", height); 669 TRACE_EVENT1("exo", "ShellSurface::SetTopInset", "height", height);
645 670
646 pending_top_inset_height_ = height; 671 pending_top_inset_height_ = height;
647 } 672 }
648 673
649 void ShellSurface::SetOrigin(const gfx::Point& origin) { 674 void ShellSurface::SetOrigin(const gfx::Point& origin) {
650 TRACE_EVENT1("exo", "ShellSurface::SetOrigin", "origin", origin.ToString()); 675 TRACE_EVENT1("exo", "ShellSurface::SetOrigin", "origin", origin.ToString());
651 676
652 initial_bounds_ = gfx::Rect(origin, gfx::Size(1, 1)); 677 origin_ = origin;
653 } 678 }
654 679
655 void ShellSurface::SetActivatable(bool activatable) { 680 void ShellSurface::SetActivatable(bool activatable) {
656 TRACE_EVENT1("exo", "ShellSurface::SetActivatable", "activatable", 681 TRACE_EVENT1("exo", "ShellSurface::SetActivatable", "activatable",
657 activatable); 682 activatable);
658 683
659 activatable_ = activatable; 684 activatable_ = activatable;
660 } 685 }
661 686
662 void ShellSurface::SetContainer(int container) { 687 void ShellSurface::SetContainer(int container) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 if (enabled() && !widget_) { 722 if (enabled() && !widget_) {
698 // Defer widget creation until surface contains some contents. 723 // Defer widget creation until surface contains some contents.
699 if (surface_->content_size().IsEmpty()) 724 if (surface_->content_size().IsEmpty())
700 Configure(); 725 Configure();
701 else 726 else
702 CreateShellSurfaceWidget(ui::SHOW_STATE_NORMAL); 727 CreateShellSurfaceWidget(ui::SHOW_STATE_NORMAL);
703 } 728 }
704 729
705 // Apply the accumulated pending origin offset to reflect acknowledged 730 // Apply the accumulated pending origin offset to reflect acknowledged
706 // configure requests. 731 // configure requests.
707 origin_ += pending_origin_offset_; 732 origin_offset_ += pending_origin_offset_;
708 pending_origin_offset_ = gfx::Vector2d(); 733 pending_origin_offset_ = gfx::Vector2d();
709 734
710 // Update resize direction to reflect acknowledged configure requests. 735 // Update resize direction to reflect acknowledged configure requests.
711 resize_component_ = pending_resize_component_; 736 resize_component_ = pending_resize_component_;
712 737
713 if (widget_) { 738 if (widget_) {
714 // Apply new window geometry. 739 // Apply new window geometry.
715 geometry_ = pending_geometry_; 740 geometry_ = pending_geometry_;
716 741
717 UpdateWidgetBounds(); 742 UpdateWidgetBounds();
(...skipping 18 matching lines...) Expand all
736 if (activatable != CanActivate()) { 761 if (activatable != CanActivate()) {
737 set_can_activate(activatable); 762 set_can_activate(activatable);
738 // Activate or deactivate window if activation state changed. 763 // Activate or deactivate window if activation state changed.
739 if (activatable) 764 if (activatable)
740 wm::ActivateWindow(widget_->GetNativeWindow()); 765 wm::ActivateWindow(widget_->GetNativeWindow());
741 else if (widget_->IsActive()) 766 else if (widget_->IsActive())
742 wm::DeactivateWindow(widget_->GetNativeWindow()); 767 wm::DeactivateWindow(widget_->GetNativeWindow());
743 } 768 }
744 } 769 }
745 770
746 gfx::Rect client_view_bounds = 771 UpdateSurfaceBounds();
747 widget_->non_client_view()->frame_view()->GetBoundsForClientView();
748
749 // Update surface bounds.
750 surface_->window()->SetBounds(
751 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(),
752 surface_->window()->layer()->size()));
753 772
754 // Update surface scale. 773 // Update surface scale.
755 if (pending_scale_ != scale_) { 774 if (pending_scale_ != scale_) {
756 gfx::Transform transform; 775 gfx::Transform transform;
757 DCHECK_NE(pending_scale_, 0.0); 776 DCHECK_NE(pending_scale_, 0.0);
758 transform.Scale(1.0 / pending_scale_, 1.0 / pending_scale_); 777 transform.Scale(1.0 / pending_scale_, 1.0 / pending_scale_);
759 surface_->window()->SetTransform(transform); 778 surface_->window()->SetTransform(transform);
760 scale_ = pending_scale_; 779 scale_ = pending_scale_;
761 } 780 }
762 781
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // destroyed callback may destroy the ShellSurface instance. This call needs 818 // destroyed callback may destroy the ShellSurface instance. This call needs
800 // to be last so that the instance can be destroyed. 819 // to be last so that the instance can be destroyed.
801 if (!surface_destroyed_callback_.is_null()) 820 if (!surface_destroyed_callback_.is_null())
802 surface_destroyed_callback_.Run(); 821 surface_destroyed_callback_.Run();
803 } 822 }
804 823
805 //////////////////////////////////////////////////////////////////////////////// 824 ////////////////////////////////////////////////////////////////////////////////
806 // views::WidgetDelegate overrides: 825 // views::WidgetDelegate overrides:
807 826
808 bool ShellSurface::CanResize() const { 827 bool ShellSurface::CanResize() const {
809 return initial_bounds_.IsEmpty(); 828 return bounds_mode_ == BoundsMode::SHELL;
810 } 829 }
811 830
812 bool ShellSurface::CanMaximize() const { 831 bool ShellSurface::CanMaximize() const {
813 // Shell surfaces in system modal container cannot be maximized. 832 // Shell surfaces in system modal container cannot be maximized.
814 if (container_ == ash::kShellWindowId_SystemModalContainer) 833 if (container_ == ash::kShellWindowId_SystemModalContainer)
815 return false; 834 return false;
816 835
817 // Non-transient shell surfaces can be maximized. 836 // Non-transient shell surfaces can be maximized.
818 return !parent_; 837 return !parent_;
819 } 838 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // Re-enable animations if they were disabled in pre state change handler. 944 // Re-enable animations if they were disabled in pre state change handler.
926 scoped_animations_disabled_.reset(); 945 scoped_animations_disabled_.reset();
927 } 946 }
928 947
929 //////////////////////////////////////////////////////////////////////////////// 948 ////////////////////////////////////////////////////////////////////////////////
930 // aura::WindowObserver overrides: 949 // aura::WindowObserver overrides:
931 950
932 void ShellSurface::OnWindowBoundsChanged(aura::Window* window, 951 void ShellSurface::OnWindowBoundsChanged(aura::Window* window,
933 const gfx::Rect& old_bounds, 952 const gfx::Rect& old_bounds,
934 const gfx::Rect& new_bounds) { 953 const gfx::Rect& new_bounds) {
935 if (!widget_ || !surface_ || ignore_window_bounds_changes_) 954 if (bounds_mode_ == BoundsMode::CLIENT || !widget_ || !surface_ ||
reveman 2017/02/10 02:10:53 why is this needed?
Dominik Laskowski 2017/02/10 03:05:18 Oops, this belongs to the dependent CL. Removed.
955 ignore_window_bounds_changes_)
936 return; 956 return;
937 957
938 if (window == widget_->GetNativeWindow()) { 958 if (window == widget_->GetNativeWindow()) {
939 if (new_bounds.size() == old_bounds.size()) 959 if (new_bounds.size() == old_bounds.size())
940 return; 960 return;
941 961
942 // If size changed then give the client a chance to produce new contents 962 // If size changed then give the client a chance to produce new contents
943 // before origin on screen is changed by adding offset to the next configure 963 // before origin on screen is changed. Retain the old origin by reverting
944 // request and offset |origin_| by the same distance. 964 // the origin delta until the next configure is acknowledged.
945 gfx::Vector2d origin_offset = new_bounds.origin() - old_bounds.origin(); 965 gfx::Vector2d delta = new_bounds.origin() - old_bounds.origin();
946 pending_origin_config_offset_ += origin_offset; 966 origin_offset_ -= delta;
947 origin_ -= origin_offset; 967 pending_origin_offset_accumulator_ += delta;
948 968
949 gfx::Rect client_view_bounds = 969 UpdateSurfaceBounds();
950 widget_->non_client_view()->frame_view()->GetBoundsForClientView();
951
952 // Update surface bounds.
953 surface_->window()->SetBounds(
954 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(),
955 surface_->window()->layer()->size()));
956 970
957 // The shadow size may be updated to match the widget. Change it back 971 // The shadow size may be updated to match the widget. Change it back
958 // to the shadow content size. 972 // to the shadow content size.
959 // TODO(oshima): When the arc window reiszing is enabled, we may want to 973 // TODO(oshima): When the arc window reiszing is enabled, we may want to
960 // implement shadow management here instead of using shadow controller. 974 // implement shadow management here instead of using shadow controller.
961 UpdateShadow(); 975 UpdateShadow();
962 976
963 Configure(); 977 Configure();
964 } 978 }
965 } 979 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 views::Widget::InitParams params; 1101 views::Widget::InitParams params;
1088 params.type = views::Widget::InitParams::TYPE_WINDOW; 1102 params.type = views::Widget::InitParams::TYPE_WINDOW;
1089 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; 1103 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
1090 params.delegate = this; 1104 params.delegate = this;
1091 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; 1105 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
1092 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 1106 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
1093 params.show_state = show_state; 1107 params.show_state = show_state;
1094 // Make shell surface a transient child if |parent_| has been set. 1108 // Make shell surface a transient child if |parent_| has been set.
1095 params.parent = 1109 params.parent =
1096 parent_ ? parent_ : WMHelper::GetInstance()->GetContainer(container_); 1110 parent_ ? parent_ : WMHelper::GetInstance()->GetContainer(container_);
1097 params.bounds = initial_bounds_; 1111 params.bounds = gfx::Rect(origin_, gfx::Size());
1098 bool activatable = activatable_; 1112 bool activatable = activatable_;
1099 // ShellSurfaces in system modal container are only activatable if input 1113 // ShellSurfaces in system modal container are only activatable if input
1100 // region is non-empty. See OnCommitSurface() for more details. 1114 // region is non-empty. See OnCommitSurface() for more details.
1101 if (container_ == ash::kShellWindowId_SystemModalContainer) 1115 if (container_ == ash::kShellWindowId_SystemModalContainer)
1102 activatable &= !surface_->GetHitTestBounds().IsEmpty(); 1116 activatable &= !surface_->GetHitTestBounds().IsEmpty();
1103 params.activatable = activatable ? views::Widget::InitParams::ACTIVATABLE_YES 1117 params.activatable = activatable ? views::Widget::InitParams::ACTIVATABLE_YES
1104 : views::Widget::InitParams::ACTIVATABLE_NO; 1118 : views::Widget::InitParams::ACTIVATABLE_NO;
1105 1119
1106 // Note: NativeWidget owns this widget. 1120 // Note: NativeWidget owns this widget.
1107 widget_ = new ShellSurfaceWidget(this); 1121 widget_ = new ShellSurfaceWidget(this);
1108 widget_->Init(params); 1122 widget_->Init(params);
1109 1123
1110 aura::Window* window = widget_->GetNativeWindow(); 1124 aura::Window* window = widget_->GetNativeWindow();
1111 window->SetName("ExoShellSurface"); 1125 window->SetName("ExoShellSurface");
1112 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, 1126 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey,
1113 false); 1127 false);
1114 window->AddChild(surface_->window()); 1128 window->AddChild(surface_->window());
1115 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); 1129 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_)));
1116 SetApplicationId(window, application_id_); 1130 SetApplicationId(window, application_id_);
1117 SetMainSurface(window, surface_); 1131 SetMainSurface(window, surface_);
1118 1132
1119 // Start tracking changes to window bounds and window state. 1133 // Start tracking changes to window bounds and window state.
1120 window->AddObserver(this); 1134 window->AddObserver(this);
1121 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); 1135 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window);
1122 window_state->AddObserver(this); 1136 window_state->AddObserver(this);
1123 1137
1124 // Absolete positioned shell surfaces may request the bounds that does not 1138 // Allow the client to request bounds that do not fill the entire work area
1125 // fill the entire work area / display in maximized / fullscreen state. 1139 // when maximized, or the entire display when fullscreen.
1126 // Allow such clients to update the bounds in these states. 1140 window_state->set_allow_set_bounds_in_maximized(
1127 if (!initial_bounds_.IsEmpty()) 1141 bounds_mode_ == BoundsMode::CLIENT);
1128 window_state->set_allow_set_bounds_in_maximized(true);
1129 1142
1130 // Notify client of initial state if different than normal. 1143 // Notify client of initial state if different than normal.
1131 if (window_state->GetStateType() != ash::wm::WINDOW_STATE_TYPE_NORMAL && 1144 if (window_state->GetStateType() != ash::wm::WINDOW_STATE_TYPE_NORMAL &&
1132 !state_changed_callback_.is_null()) { 1145 !state_changed_callback_.is_null()) {
1133 state_changed_callback_.Run(ash::wm::WINDOW_STATE_TYPE_NORMAL, 1146 state_changed_callback_.Run(ash::wm::WINDOW_STATE_TYPE_NORMAL,
1134 window_state->GetStateType()); 1147 window_state->GetStateType());
1135 } 1148 }
1136 1149
1137 // Disable movement if initial bounds were specified. 1150 // Disable movement if bounds are controlled by the client or fixed.
1138 widget_->set_movement_disabled(!initial_bounds_.IsEmpty()); 1151 bool movement_disabled = bounds_mode_ != BoundsMode::SHELL;
1139 window_state->set_ignore_keyboard_bounds_change(!initial_bounds_.IsEmpty()); 1152 widget_->set_movement_disabled(movement_disabled);
1153 window_state->set_ignore_keyboard_bounds_change(movement_disabled);
1140 1154
1141 // AutoHide shelf in fullscreen state. 1155 // AutoHide shelf in fullscreen state.
1142 window_state->set_hide_shelf_when_fullscreen(false); 1156 window_state->set_hide_shelf_when_fullscreen(false);
1143 1157
1144 // Fade visibility animations for non-activatable windows. 1158 // Fade visibility animations for non-activatable windows.
1145 if (!activatable_) { 1159 if (!activatable_) {
1146 wm::SetWindowVisibilityAnimationType( 1160 wm::SetWindowVisibilityAnimationType(
1147 window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 1161 window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
1148 } 1162 }
1149 1163
(...skipping 12 matching lines...) Expand all
1162 pending_show_widget_ = true; 1176 pending_show_widget_ = true;
1163 } 1177 }
1164 1178
1165 void ShellSurface::Configure() { 1179 void ShellSurface::Configure() {
1166 // Delay configure callback if |scoped_configure_| is set. 1180 // Delay configure callback if |scoped_configure_| is set.
1167 if (scoped_configure_) { 1181 if (scoped_configure_) {
1168 scoped_configure_->set_needs_configure(); 1182 scoped_configure_->set_needs_configure();
1169 return; 1183 return;
1170 } 1184 }
1171 1185
1172 gfx::Vector2d origin_offset = pending_origin_config_offset_; 1186 gfx::Vector2d origin_offset = pending_origin_offset_accumulator_;
1173 pending_origin_config_offset_ = gfx::Vector2d(); 1187 pending_origin_offset_accumulator_ = gfx::Vector2d();
1174 1188
1175 int resize_component = HTCAPTION; 1189 int resize_component = HTCAPTION;
1176 if (widget_) { 1190 if (widget_) {
1177 ash::wm::WindowState* window_state = 1191 ash::wm::WindowState* window_state =
1178 ash::wm::GetWindowState(widget_->GetNativeWindow()); 1192 ash::wm::GetWindowState(widget_->GetNativeWindow());
1179 1193
1180 // If surface is being resized, save the resize direction. 1194 // If surface is being resized, save the resize direction.
1181 if (window_state->is_dragged()) 1195 if (window_state->is_dragged())
1182 resize_component = window_state->drag_details()->window_component; 1196 resize_component = window_state->drag_details()->window_component;
1183 } 1197 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1281
1268 resizer_ = ash::CreateWindowResizer( 1282 resizer_ = ash::CreateWindowResizer(
1269 ash::WmWindow::Get(widget_->GetNativeWindow()), drag_location, component, 1283 ash::WmWindow::Get(widget_->GetNativeWindow()), drag_location, component,
1270 aura::client::WINDOW_MOVE_SOURCE_MOUSE); 1284 aura::client::WINDOW_MOVE_SOURCE_MOUSE);
1271 if (!resizer_) 1285 if (!resizer_)
1272 return; 1286 return;
1273 1287
1274 // Apply pending origin offsets and resize direction before starting a new 1288 // Apply pending origin offsets and resize direction before starting a new
1275 // resize operation. These can still be pending if the client has acknowledged 1289 // resize operation. These can still be pending if the client has acknowledged
1276 // the configure request but not yet called Commit(). 1290 // the configure request but not yet called Commit().
1277 origin_ += pending_origin_offset_; 1291 origin_offset_ += pending_origin_offset_;
1278 pending_origin_offset_ = gfx::Vector2d(); 1292 pending_origin_offset_ = gfx::Vector2d();
1279 resize_component_ = pending_resize_component_; 1293 resize_component_ = pending_resize_component_;
1280 1294
1281 WMHelper::GetInstance()->AddPreTargetHandler(this); 1295 WMHelper::GetInstance()->AddPreTargetHandler(this);
1282 widget_->GetNativeWindow()->SetCapture(); 1296 widget_->GetNativeWindow()->SetCapture();
1283 1297
1284 // Notify client that resizing state has changed. 1298 // Notify client that resizing state has changed.
1285 if (IsResizing()) 1299 if (IsResizing())
1286 Configure(); 1300 Configure();
1287 } 1301 }
1288 1302
1289 void ShellSurface::EndDrag(bool revert) { 1303 void ShellSurface::EndDrag(bool revert) {
1290 DCHECK(widget_); 1304 DCHECK(widget_);
1291 DCHECK(resizer_); 1305 DCHECK(resizer_);
1292 1306
1293 bool was_resizing = IsResizing(); 1307 switch (bounds_mode_) {
reveman 2017/02/10 02:10:53 is this switch statement needed? what happens if y
Dominik Laskowski 2017/02/10 03:05:18 Not necessary but simplifies the diff of the depen
reveman 2017/02/10 05:51:54 Let's save switch statement until needed. That mak
Dominik Laskowski 2017/02/10 18:47:16 Done.
1308 case BoundsMode::SHELL: {
1309 bool was_resizing = IsResizing();
1294 1310
1295 if (revert) 1311 if (revert)
1296 resizer_->RevertDrag(); 1312 resizer_->RevertDrag();
1297 else 1313 else
1298 resizer_->CompleteDrag(); 1314 resizer_->CompleteDrag();
1299 1315
1300 WMHelper::GetInstance()->RemovePreTargetHandler(this); 1316 WMHelper::GetInstance()->RemovePreTargetHandler(this);
1301 widget_->GetNativeWindow()->ReleaseCapture(); 1317 widget_->GetNativeWindow()->ReleaseCapture();
1302 resizer_.reset(); 1318 resizer_.reset();
1303 1319
1304 // Notify client that resizing state has changed. 1320 // Notify client that resizing state has changed.
1305 if (was_resizing) 1321 if (was_resizing)
1306 Configure(); 1322 Configure();
1307 1323
1308 UpdateWidgetBounds(); 1324 UpdateWidgetBounds();
1325 return;
1326 }
1327 case BoundsMode::CLIENT:
1328 case BoundsMode::FIXED:
1329 break;
1330 }
1331
1332 NOTREACHED();
1309 } 1333 }
1310 1334
1311 bool ShellSurface::IsResizing() const { 1335 bool ShellSurface::IsResizing() const {
1312 ash::wm::WindowState* window_state = 1336 ash::wm::WindowState* window_state =
1313 ash::wm::GetWindowState(widget_->GetNativeWindow()); 1337 ash::wm::GetWindowState(widget_->GetNativeWindow());
1314 if (!window_state->is_dragged()) 1338 if (!window_state->is_dragged())
1315 return false; 1339 return false;
1316 1340
1317 return window_state->drag_details()->bounds_change & 1341 return window_state->drag_details()->bounds_change &
1318 ash::WindowResizer::kBoundsChange_Resizes; 1342 ash::WindowResizer::kBoundsChange_Resizes;
1319 } 1343 }
1320 1344
1321 gfx::Rect ShellSurface::GetVisibleBounds() const { 1345 gfx::Rect ShellSurface::GetVisibleBounds() const {
1322 // Use |geometry_| if set, otherwise use the visual bounds of the surface. 1346 // Use |geometry_| if set, otherwise use the visual bounds of the surface.
1323 return geometry_.IsEmpty() ? gfx::Rect(surface_->window()->layer()->size()) 1347 return geometry_.IsEmpty() ? gfx::Rect(surface_->window()->layer()->size())
1324 : geometry_; 1348 : geometry_;
1325 } 1349 }
1326 1350
1327 gfx::Point ShellSurface::GetSurfaceOrigin() const { 1351 gfx::Point ShellSurface::GetSurfaceOrigin() const {
1328 // If initial bounds were specified then surface origin is always relative 1352 // For client-positioned shell surfaces, the surface origin corresponds to the
1329 // to those bounds. 1353 // widget position relative to the origin specified by the client. Since the
1330 if (!initial_bounds_.IsEmpty()) { 1354 // surface is positioned relative to the widget, negate this vector to align
1331 gfx::Point origin = widget_->GetNativeWindow()->bounds().origin(); 1355 // the surface with the widget.
1332 wm::ConvertPointToScreen(widget_->GetNativeWindow()->parent(), &origin); 1356 if (bounds_mode_ != BoundsMode::SHELL) {
1333 return initial_bounds_.origin() - origin.OffsetFromOrigin(); 1357 gfx::Point position = widget_->GetNativeWindow()->bounds().origin();
1358 wm::ConvertPointToScreen(widget_->GetNativeWindow()->parent(), &position);
1359 return origin_ - position.OffsetFromOrigin();
1334 } 1360 }
1335 1361
1336 gfx::Rect visible_bounds = GetVisibleBounds(); 1362 gfx::Rect visible_bounds = GetVisibleBounds();
1337 gfx::Rect client_bounds = 1363 gfx::Rect client_bounds =
1338 widget_->non_client_view()->frame_view()->GetBoundsForClientView(); 1364 widget_->non_client_view()->frame_view()->GetBoundsForClientView();
1339 switch (resize_component_) { 1365 switch (resize_component_) {
1340 case HTCAPTION: 1366 case HTCAPTION:
1341 return origin_ - visible_bounds.OffsetFromOrigin(); 1367 return gfx::Point() + origin_offset_ - visible_bounds.OffsetFromOrigin();
1342 case HTBOTTOM: 1368 case HTBOTTOM:
1343 case HTRIGHT: 1369 case HTRIGHT:
1344 case HTBOTTOMRIGHT: 1370 case HTBOTTOMRIGHT:
1345 return gfx::Point() - visible_bounds.OffsetFromOrigin(); 1371 return gfx::Point() - visible_bounds.OffsetFromOrigin();
1346 case HTTOP: 1372 case HTTOP:
1347 case HTTOPRIGHT: 1373 case HTTOPRIGHT:
1348 return gfx::Point(0, client_bounds.height() - visible_bounds.height()) - 1374 return gfx::Point(0, client_bounds.height() - visible_bounds.height()) -
1349 visible_bounds.OffsetFromOrigin(); 1375 visible_bounds.OffsetFromOrigin();
1350 break;
1351 case HTLEFT: 1376 case HTLEFT:
1352 case HTBOTTOMLEFT: 1377 case HTBOTTOMLEFT:
1353 return gfx::Point(client_bounds.width() - visible_bounds.width(), 0) - 1378 return gfx::Point(client_bounds.width() - visible_bounds.width(), 0) -
1354 visible_bounds.OffsetFromOrigin(); 1379 visible_bounds.OffsetFromOrigin();
1355 case HTTOPLEFT: 1380 case HTTOPLEFT:
1356 return gfx::Point(client_bounds.width() - visible_bounds.width(), 1381 return gfx::Point(client_bounds.width() - visible_bounds.width(),
1357 client_bounds.height() - visible_bounds.height()) - 1382 client_bounds.height() - visible_bounds.height()) -
1358 visible_bounds.OffsetFromOrigin(); 1383 visible_bounds.OffsetFromOrigin();
1359 default: 1384 default:
1360 NOTREACHED(); 1385 NOTREACHED();
1361 return gfx::Point(); 1386 return gfx::Point();
1362 } 1387 }
1363 } 1388 }
1364 1389
1365 void ShellSurface::UpdateWidgetBounds() { 1390 void ShellSurface::UpdateWidgetBounds() {
1366 DCHECK(widget_); 1391 DCHECK(widget_);
1367 1392
1368 // Return early if the shell is currently managing the bounds of the widget. 1393 // Return early if the shell is currently managing the bounds of the widget.
1369 // 1) When a window is either maximized/fullscreen/pinned, and the bounds 1394 if (bounds_mode_ == BoundsMode::SHELL) {
reveman 2017/02/10 02:10:53 why is this check needed? should we return early i
Dominik Laskowski 2017/02/10 03:05:18 It replaces the allow_set_bounds_in_maximized chec
reveman 2017/02/10 05:51:53 Let's not make the assumption that IsResizing can
Dominik Laskowski 2017/02/10 18:47:16 Reverted.
1370 // isn't controlled by a client. 1395 // 1) When a window is either maximized/fullscreen/pinned.
1371 ash::wm::WindowState* window_state = 1396 ash::wm::WindowState* window_state =
1372 ash::wm::GetWindowState(widget_->GetNativeWindow()); 1397 ash::wm::GetWindowState(widget_->GetNativeWindow());
1373 if (window_state->IsMaximizedOrFullscreenOrPinned() && 1398 if (window_state->IsMaximizedOrFullscreenOrPinned())
1374 !window_state->allow_set_bounds_in_maximized()) { 1399 return;
1375 return; 1400
1401 // 2) When a window is being dragged.
1402 if (IsResizing())
1403 return;
1376 } 1404 }
1377 1405
1378 // 2) When a window is being dragged.
1379 if (IsResizing())
1380 return;
1381
1382 // Return early if there is pending configure requests. 1406 // Return early if there is pending configure requests.
1383 if (!pending_configs_.empty() || scoped_configure_) 1407 if (!pending_configs_.empty() || scoped_configure_)
1384 return; 1408 return;
1385 1409
1386 gfx::Rect visible_bounds = GetVisibleBounds(); 1410 gfx::Rect visible_bounds = GetVisibleBounds();
1387 gfx::Rect new_widget_bounds = 1411 gfx::Rect new_widget_bounds =
1388 widget_->non_client_view()->GetWindowBoundsForClientBounds( 1412 widget_->non_client_view()->GetWindowBoundsForClientBounds(
1389 visible_bounds); 1413 visible_bounds);
1390 1414
1391 // Avoid changing widget origin unless initial bounds were specified and 1415 switch (bounds_mode_) {
1392 // widget origin is always relative to it. 1416 case BoundsMode::CLIENT:
1393 if (initial_bounds_.IsEmpty()) { 1417 case BoundsMode::FIXED:
1394 new_widget_bounds.set_origin(widget_->GetWindowBoundsInScreen().origin()); 1418 // Position is relative to the origin.
1395 } else { 1419 new_widget_bounds += origin_.OffsetFromOrigin();
1396 new_widget_bounds.set_origin(initial_bounds_.origin() + 1420 break;
1397 visible_bounds.OffsetFromOrigin()); 1421 case BoundsMode::SHELL:
1398 } 1422 // Update widget origin using the surface origin if the current location
1399 1423 // of surface is being anchored to one side of the widget as a result of a
1400 // Update widget origin using the surface origin if the current location of 1424 // resize operation.
1401 // surface is being anchored to one side of the widget as a result of a 1425 if (resize_component_ != HTCAPTION) {
1402 // resize operation. 1426 gfx::Point widget_origin =
1403 if (resize_component_ != HTCAPTION) { 1427 GetSurfaceOrigin() + visible_bounds.OffsetFromOrigin();
1404 gfx::Point new_widget_origin = 1428 wm::ConvertPointToScreen(widget_->GetNativeWindow(), &widget_origin);
1405 GetSurfaceOrigin() + visible_bounds.OffsetFromOrigin(); 1429 new_widget_bounds.set_origin(widget_origin);
1406 wm::ConvertPointToScreen(widget_->GetNativeWindow(), &new_widget_origin); 1430 } else {
1407 new_widget_bounds.set_origin(new_widget_origin); 1431 // Preserve widget position.
1432 new_widget_bounds.set_origin(
1433 widget_->GetWindowBoundsInScreen().origin());
1434 }
1435 break;
1408 } 1436 }
1409 1437
1410 // Set |ignore_window_bounds_changes_| as this change to window bounds 1438 // Set |ignore_window_bounds_changes_| as this change to window bounds
1411 // should not result in a configure request. 1439 // should not result in a configure request.
1412 DCHECK(!ignore_window_bounds_changes_); 1440 DCHECK(!ignore_window_bounds_changes_);
1413 ignore_window_bounds_changes_ = true; 1441 ignore_window_bounds_changes_ = true;
1414 if (widget_->GetWindowBoundsInScreen() != new_widget_bounds) 1442 if (widget_->GetWindowBoundsInScreen() != new_widget_bounds)
1415 widget_->SetBounds(new_widget_bounds); 1443 widget_->SetBounds(new_widget_bounds);
1416 ignore_window_bounds_changes_ = false; 1444 ignore_window_bounds_changes_ = false;
1445 }
1417 1446
1447 void ShellSurface::UpdateSurfaceBounds() {
1418 gfx::Rect client_view_bounds = 1448 gfx::Rect client_view_bounds =
1419 widget_->non_client_view()->frame_view()->GetBoundsForClientView(); 1449 widget_->non_client_view()->frame_view()->GetBoundsForClientView();
1420 1450
1421 // A change to the widget size requires surface bounds to be re-adjusted.
1422 surface_->window()->SetBounds( 1451 surface_->window()->SetBounds(
1423 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(), 1452 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(),
1424 surface_->window()->layer()->size())); 1453 surface_->window()->layer()->size()));
1425 } 1454 }
1426 1455
1427 void ShellSurface::UpdateShadow() { 1456 void ShellSurface::UpdateShadow() {
1428 if (!widget_) 1457 if (!widget_)
1429 return; 1458 return;
1430 aura::Window* window = widget_->GetNativeWindow(); 1459 aura::Window* window = widget_->GetNativeWindow();
1431 if (!shadow_enabled_) { 1460 if (!shadow_enabled_) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 // small style shadow for them. 1579 // small style shadow for them.
1551 if (!activatable_) 1580 if (!activatable_)
1552 shadow->SetElevation(wm::ShadowElevation::SMALL); 1581 shadow->SetElevation(wm::ShadowElevation::SMALL);
1553 // We don't have rounded corners unless frame is enabled. 1582 // We don't have rounded corners unless frame is enabled.
1554 if (!frame_enabled_) 1583 if (!frame_enabled_)
1555 shadow->SetRoundedCornerRadius(0); 1584 shadow->SetRoundedCornerRadius(0);
1556 } 1585 }
1557 } 1586 }
1558 1587
1559 } // namespace exo 1588 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698