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

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

Issue 1645043003: exo: Improve window placement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.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/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_state.h" 9 #include "ash/wm/window_state.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 ShellSurface::~ShellSurface() { 80 ShellSurface::~ShellSurface() {
81 if (surface_) { 81 if (surface_) {
82 surface_->SetSurfaceDelegate(nullptr); 82 surface_->SetSurfaceDelegate(nullptr);
83 surface_->RemoveSurfaceObserver(this); 83 surface_->RemoveSurfaceObserver(this);
84 } 84 }
85 if (widget_) 85 if (widget_)
86 widget_->CloseNow(); 86 widget_->CloseNow();
87 } 87 }
88 88
89 void ShellSurface::Init() {
90 TRACE_EVENT0("exo", "ShellSurface::Init");
91
92 if (widget_) {
93 DLOG(WARNING) << "Shell surface already initialized";
94 return;
95 }
96
97 views::Widget::InitParams params;
98 params.type = views::Widget::InitParams::TYPE_WINDOW;
99 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
100 params.delegate = this;
101 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
102 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
103 params.show_state = ui::SHOW_STATE_NORMAL;
104 params.parent = ash::Shell::GetContainer(
105 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
106 widget_.reset(new ShellSurfaceWidget(this));
107 widget_->Init(params);
108 widget_->GetNativeWindow()->set_owned_by_parent(false);
109 widget_->GetNativeWindow()->SetName("ExoShellSurface");
110 widget_->GetNativeWindow()->AddChild(surface_);
111 SetApplicationId(widget_->GetNativeWindow(), &application_id_);
112
113 // The position of a top-level shell surface is managed by Ash.
114 ash::wm::GetWindowState(widget_->GetNativeWindow())
115 ->set_window_position_managed(true);
116 }
117
118 void ShellSurface::Maximize() { 89 void ShellSurface::Maximize() {
119 TRACE_EVENT0("exo", "ShellSurface::Maximize"); 90 TRACE_EVENT0("exo", "ShellSurface::Maximize");
120 91
121 DCHECK(widget_); 92 if (!widget_)
93 CreateShellSurfaceWidget();
94
122 widget_->Maximize(); 95 widget_->Maximize();
123 96
124 if (!configure_callback_.is_null()) 97 if (!configure_callback_.is_null())
125 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); 98 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size());
126 } 99 }
127 100
128 void ShellSurface::SetFullscreen(bool fullscreen) { 101 void ShellSurface::SetFullscreen(bool fullscreen) {
129 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen); 102 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen);
130 103
131 DCHECK(widget_); 104 if (!widget_)
105 CreateShellSurfaceWidget();
106
132 widget_->SetFullscreen(fullscreen); 107 widget_->SetFullscreen(fullscreen);
133 108
134 if (!configure_callback_.is_null()) 109 if (!configure_callback_.is_null())
135 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); 110 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size());
136 } 111 }
137 112
138 void ShellSurface::SetTitle(const base::string16& title) { 113 void ShellSurface::SetTitle(const base::string16& title) {
139 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", 114 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title",
140 base::UTF16ToUTF8(title)); 115 base::UTF16ToUTF8(title));
141 116
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 new base::trace_event::TracedValue; 170 new base::trace_event::TracedValue;
196 value->SetString("title", base::UTF16ToUTF8(title_)); 171 value->SetString("title", base::UTF16ToUTF8(title_));
197 value->SetString("application_id", application_id_); 172 value->SetString("application_id", application_id_);
198 return value; 173 return value;
199 } 174 }
200 175
201 //////////////////////////////////////////////////////////////////////////////// 176 ////////////////////////////////////////////////////////////////////////////////
202 // SurfaceDelegate overrides: 177 // SurfaceDelegate overrides:
203 178
204 void ShellSurface::OnSurfaceCommit() { 179 void ShellSurface::OnSurfaceCommit() {
180 if (enabled() && !widget_)
181 CreateShellSurfaceWidget();
182
205 surface_->CommitSurfaceHierarchy(); 183 surface_->CommitSurfaceHierarchy();
184
206 if (widget_) { 185 if (widget_) {
207 // Update surface bounds and widget size. 186 // Update surface bounds and widget size.
208 gfx::Point origin; 187 gfx::Point origin;
209 views::View::ConvertPointToWidget(this, &origin); 188 views::View::ConvertPointToWidget(this, &origin);
210 surface_->SetBounds(gfx::Rect(origin - geometry_.OffsetFromOrigin(), 189 surface_->SetBounds(gfx::Rect(origin - geometry_.OffsetFromOrigin(),
211 surface_->layer()->size())); 190 surface_->layer()->size()));
212 widget_->SetSize(widget_->non_client_view()->GetPreferredSize()); 191 widget_->SetSize(widget_->non_client_view()->GetPreferredSize());
213 192
214 // Show widget if not already visible. 193 // Show widget if not already visible.
215 if (!widget_->IsClosed() && !widget_->IsVisible()) 194 if (!widget_->IsClosed() && !widget_->IsVisible())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 //////////////////////////////////////////////////////////////////////////////// 242 ////////////////////////////////////////////////////////////////////////////////
264 // views::Views overrides: 243 // views::Views overrides:
265 244
266 gfx::Size ShellSurface::GetPreferredSize() const { 245 gfx::Size ShellSurface::GetPreferredSize() const {
267 if (!geometry_.IsEmpty()) 246 if (!geometry_.IsEmpty())
268 return geometry_.size(); 247 return geometry_.size();
269 248
270 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); 249 return surface_ ? surface_->GetPreferredSize() : gfx::Size();
271 } 250 }
272 251
252 ////////////////////////////////////////////////////////////////////////////////
253 // ShellSurface, private:
254
255 void ShellSurface::CreateShellSurfaceWidget() {
256 DCHECK(enabled());
257 DCHECK(!widget_);
258
259 views::Widget::InitParams params;
260 params.type = views::Widget::InitParams::TYPE_WINDOW;
261 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
262 params.delegate = this;
263 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
264 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
265 params.show_state = ui::SHOW_STATE_NORMAL;
266 params.parent = ash::Shell::GetContainer(
267 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
268 widget_.reset(new ShellSurfaceWidget(this));
269 widget_->Init(params);
270 widget_->GetNativeWindow()->set_owned_by_parent(false);
271 widget_->GetNativeWindow()->SetName("ExoShellSurface");
272 widget_->GetNativeWindow()->AddChild(surface_);
273 SetApplicationId(widget_->GetNativeWindow(), &application_id_);
274
275 // The position of a top-level shell surface is managed by Ash.
276 ash::wm::GetWindowState(widget_->GetNativeWindow())
277 ->set_window_position_managed(true);
278 }
279
273 } // namespace exo 280 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698