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

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

Issue 2242283002: Add an adapter layer (WMHelper) between exo and ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build errors. Created 4 years, 4 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 | « components/exo/shell_surface.h ('k') | components/exo/touch.cc » ('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 "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
9 #include "ash/common/wm/window_resizer.h" 9 #include "ash/common/wm/window_resizer.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
11 #include "ash/common/wm/window_state_delegate.h" 11 #include "ash/common/wm/window_state_delegate.h"
12 #include "ash/shell.h"
13 #include "ash/wm/window_state_aura.h" 12 #include "ash/wm/window_state_aura.h"
14 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/macros.h" 15 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
18 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
19 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
20 #include "base/trace_event/trace_event_argument.h" 19 #include "base/trace_event/trace_event_argument.h"
21 #include "components/exo/surface.h" 20 #include "components/exo/surface.h"
22 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/client/cursor_client.h"
23 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
24 #include "ui/aura/window_event_dispatcher.h" 24 #include "ui/aura/window_event_dispatcher.h"
25 #include "ui/aura/window_property.h" 25 #include "ui/aura/window_property.h"
26 #include "ui/aura/window_targeter.h" 26 #include "ui/aura/window_targeter.h"
27 #include "ui/aura/window_tree_host.h" 27 #include "ui/aura/window_tree_host.h"
28 #include "ui/base/accelerators/accelerator.h" 28 #include "ui/base/accelerators/accelerator.h"
29 #include "ui/gfx/path.h" 29 #include "ui/gfx/path.h"
30 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_observer.h" 31 #include "ui/views/widget/widget_observer.h"
32 #include "ui/wm/core/coordinate_conversion.h" 32 #include "ui/wm/core/coordinate_conversion.h"
33 #include "ui/wm/core/shadow.h" 33 #include "ui/wm/core/shadow.h"
34 #include "ui/wm/core/shadow_controller.h" 34 #include "ui/wm/core/shadow_controller.h"
35 #include "ui/wm/core/shadow_types.h" 35 #include "ui/wm/core/shadow_types.h"
36 #include "ui/wm/core/window_util.h" 36 #include "ui/wm/core/window_util.h"
37 #include "ui/wm/public/activation_client.h"
38 37
39 DECLARE_WINDOW_PROPERTY_TYPE(std::string*) 38 DECLARE_WINDOW_PROPERTY_TYPE(std::string*)
40 39
41 namespace exo { 40 namespace exo {
42 namespace { 41 namespace {
43 42
44 // This is a struct for accelerator keys used to close ShellSurfaces. 43 // This is a struct for accelerator keys used to close ShellSurfaces.
45 const struct Accelerator { 44 const struct Accelerator {
46 ui::KeyboardCode keycode; 45 ui::KeyboardCode keycode;
47 int modifiers; 46 int modifiers;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 ShellSurface* parent, 246 ShellSurface* parent,
248 const gfx::Rect& initial_bounds, 247 const gfx::Rect& initial_bounds,
249 bool activatable, 248 bool activatable,
250 int container) 249 int container)
251 : widget_(nullptr), 250 : widget_(nullptr),
252 surface_(surface), 251 surface_(surface),
253 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr), 252 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr),
254 initial_bounds_(initial_bounds), 253 initial_bounds_(initial_bounds),
255 activatable_(activatable), 254 activatable_(activatable),
256 container_(container) { 255 container_(container) {
257 ash::Shell::GetInstance()->activation_client()->AddObserver(this); 256 WMHelper::GetInstance()->AddActivationObserver(this);
258 surface_->SetSurfaceDelegate(this); 257 surface_->SetSurfaceDelegate(this);
259 surface_->AddSurfaceObserver(this); 258 surface_->AddSurfaceObserver(this);
260 surface_->window()->Show(); 259 surface_->window()->Show();
261 set_owned_by_client(); 260 set_owned_by_client();
262 if (parent_) 261 if (parent_)
263 parent_->AddObserver(this); 262 parent_->AddObserver(this);
264 } 263 }
265 264
266 ShellSurface::ShellSurface(Surface* surface) 265 ShellSurface::ShellSurface(Surface* surface)
267 : ShellSurface(surface, 266 : ShellSurface(surface,
268 nullptr, 267 nullptr,
269 gfx::Rect(), 268 gfx::Rect(),
270 true, 269 true,
271 ash::kShellWindowId_DefaultContainer) {} 270 ash::kShellWindowId_DefaultContainer) {}
272 271
273 ShellSurface::~ShellSurface() { 272 ShellSurface::~ShellSurface() {
274 DCHECK(!scoped_configure_); 273 DCHECK(!scoped_configure_);
275 if (resizer_) 274 if (resizer_)
276 EndDrag(false /* revert */); 275 EndDrag(false /* revert */);
277 if (widget_) { 276 if (widget_) {
278 ash::wm::GetWindowState(widget_->GetNativeWindow())->RemoveObserver(this); 277 ash::wm::GetWindowState(widget_->GetNativeWindow())->RemoveObserver(this);
279 widget_->GetNativeWindow()->RemoveObserver(this); 278 widget_->GetNativeWindow()->RemoveObserver(this);
280 if (widget_->IsVisible()) 279 if (widget_->IsVisible())
281 widget_->Hide(); 280 widget_->Hide();
282 widget_->CloseNow(); 281 widget_->CloseNow();
283 } 282 }
284 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); 283 WMHelper::GetInstance()->RemoveActivationObserver(this);
285 if (parent_) 284 if (parent_)
286 parent_->RemoveObserver(this); 285 parent_->RemoveObserver(this);
287 if (surface_) { 286 if (surface_) {
288 if (scale_ != 1.0) 287 if (scale_ != 1.0)
289 surface_->window()->SetTransform(gfx::Transform()); 288 surface_->window()->SetTransform(gfx::Transform());
290 surface_->SetSurfaceDelegate(nullptr); 289 surface_->SetSurfaceDelegate(nullptr);
291 surface_->RemoveSurfaceObserver(this); 290 surface_->RemoveSurfaceObserver(this);
292 } 291 }
293 } 292 }
294 293
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 if (window == parent_) { 788 if (window == parent_) {
790 parent_ = nullptr; 789 parent_ = nullptr;
791 // Disable shell surface in case parent is destroyed before shell surface 790 // Disable shell surface in case parent is destroyed before shell surface
792 // widget has been created. 791 // widget has been created.
793 SetEnabled(false); 792 SetEnabled(false);
794 } 793 }
795 window->RemoveObserver(this); 794 window->RemoveObserver(this);
796 } 795 }
797 796
798 //////////////////////////////////////////////////////////////////////////////// 797 ////////////////////////////////////////////////////////////////////////////////
799 // aura::client::ActivationChangeObserver overrides: 798 // WMHelper::ActivationObserver overrides:
800 799
801 void ShellSurface::OnWindowActivated( 800 void ShellSurface::OnWindowActivated(
802 aura::client::ActivationChangeObserver::ActivationReason reason,
803 aura::Window* gained_active, 801 aura::Window* gained_active,
804 aura::Window* lost_active) { 802 aura::Window* lost_active) {
805 if (!widget_) 803 if (!widget_)
806 return; 804 return;
807 805
808 if (gained_active == widget_->GetNativeWindow() || 806 if (gained_active == widget_->GetNativeWindow() ||
809 lost_active == widget_->GetNativeWindow()) { 807 lost_active == widget_->GetNativeWindow()) {
810 DCHECK(activatable_); 808 DCHECK(activatable_);
811 Configure(); 809 Configure();
812 } 810 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 DCHECK(!widget_); 897 DCHECK(!widget_);
900 898
901 views::Widget::InitParams params; 899 views::Widget::InitParams params;
902 params.type = views::Widget::InitParams::TYPE_WINDOW; 900 params.type = views::Widget::InitParams::TYPE_WINDOW;
903 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; 901 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
904 params.delegate = this; 902 params.delegate = this;
905 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; 903 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
906 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 904 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
907 params.show_state = show_state; 905 params.show_state = show_state;
908 // Make shell surface a transient child if |parent_| has been set. 906 // Make shell surface a transient child if |parent_| has been set.
909 params.parent = parent_ ? parent_ : 907 params.parent =
910 ash::Shell::GetContainer(ash::Shell::GetTargetRootWindow(), container_); 908 parent_ ? parent_ : WMHelper::GetInstance()->GetContainer(container_);
911 params.bounds = initial_bounds_; 909 params.bounds = initial_bounds_;
912 bool activatable = activatable_; 910 bool activatable = activatable_;
913 // ShellSurfaces in system modal container are only activatable if input 911 // ShellSurfaces in system modal container are only activatable if input
914 // region is non-empty. See OnCommitSurface() for more details. 912 // region is non-empty. See OnCommitSurface() for more details.
915 if (container_ == ash::kShellWindowId_SystemModalContainer) 913 if (container_ == ash::kShellWindowId_SystemModalContainer)
916 activatable &= !surface_->GetHitTestBounds().IsEmpty(); 914 activatable &= !surface_->GetHitTestBounds().IsEmpty();
917 params.activatable = activatable ? views::Widget::InitParams::ACTIVATABLE_YES 915 params.activatable = activatable ? views::Widget::InitParams::ACTIVATABLE_YES
918 : views::Widget::InitParams::ACTIVATABLE_NO; 916 : views::Widget::InitParams::ACTIVATABLE_NO;
919 917
920 // Note: NativeWidget owns this widget. 918 // Note: NativeWidget owns this widget.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 if (!resizer_) 1061 if (!resizer_)
1064 return; 1062 return;
1065 1063
1066 // Apply pending origin offsets and resize direction before starting a new 1064 // Apply pending origin offsets and resize direction before starting a new
1067 // resize operation. These can still be pending if the client has acknowledged 1065 // resize operation. These can still be pending if the client has acknowledged
1068 // the configure request but not yet called Commit(). 1066 // the configure request but not yet called Commit().
1069 origin_ += pending_origin_offset_; 1067 origin_ += pending_origin_offset_;
1070 pending_origin_offset_ = gfx::Vector2d(); 1068 pending_origin_offset_ = gfx::Vector2d();
1071 resize_component_ = pending_resize_component_; 1069 resize_component_ = pending_resize_component_;
1072 1070
1073 ash::Shell::GetInstance()->AddPreTargetHandler(this); 1071 WMHelper::GetInstance()->AddPreTargetHandler(this);
1074 widget_->GetNativeWindow()->SetCapture(); 1072 widget_->GetNativeWindow()->SetCapture();
1075 1073
1076 // Notify client that resizing state has changed. 1074 // Notify client that resizing state has changed.
1077 if (IsResizing()) 1075 if (IsResizing())
1078 Configure(); 1076 Configure();
1079 } 1077 }
1080 1078
1081 void ShellSurface::EndDrag(bool revert) { 1079 void ShellSurface::EndDrag(bool revert) {
1082 DCHECK(widget_); 1080 DCHECK(widget_);
1083 DCHECK(resizer_); 1081 DCHECK(resizer_);
1084 1082
1085 bool was_resizing = IsResizing(); 1083 bool was_resizing = IsResizing();
1086 1084
1087 if (revert) 1085 if (revert)
1088 resizer_->RevertDrag(); 1086 resizer_->RevertDrag();
1089 else 1087 else
1090 resizer_->CompleteDrag(); 1088 resizer_->CompleteDrag();
1091 1089
1092 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 1090 WMHelper::GetInstance()->RemovePreTargetHandler(this);
1093 widget_->GetNativeWindow()->ReleaseCapture(); 1091 widget_->GetNativeWindow()->ReleaseCapture();
1094 resizer_.reset(); 1092 resizer_.reset();
1095 1093
1096 // Notify client that resizing state has changed. 1094 // Notify client that resizing state has changed.
1097 if (was_resizing) 1095 if (was_resizing)
1098 Configure(); 1096 Configure();
1099 1097
1100 UpdateWidgetBounds(); 1098 UpdateWidgetBounds();
1101 } 1099 }
1102 1100
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 shadow_overlay_->layer()->Add(shadow->layer()); 1240 shadow_overlay_->layer()->Add(shadow->layer());
1243 window->AddChild(shadow_overlay_); 1241 window->AddChild(shadow_overlay_);
1244 shadow_overlay_->Show(); 1242 shadow_overlay_->Show();
1245 } 1243 }
1246 shadow_overlay_->SetBounds(shadow_bounds); 1244 shadow_overlay_->SetBounds(shadow_bounds);
1247 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1245 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1248 } 1246 }
1249 } 1247 }
1250 1248
1251 } // namespace exo 1249 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/touch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698