OLD | NEW |
---|---|
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 Loading... | |
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 DCHECK(enabled()); |
lpique
2016/01/28 20:48:32
Should this be a precondition check inside CreateS
reveman
2016/01/28 21:35:19
Good idea. Done.
| |
93 | |
94 if (!widget_) | |
95 CreateShellSurfaceWidget(); | |
96 | |
122 widget_->Maximize(); | 97 widget_->Maximize(); |
123 | 98 |
124 if (!configure_callback_.is_null()) | 99 if (!configure_callback_.is_null()) |
125 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); | 100 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); |
126 } | 101 } |
127 | 102 |
128 void ShellSurface::SetFullscreen(bool fullscreen) { | 103 void ShellSurface::SetFullscreen(bool fullscreen) { |
129 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen); | 104 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen); |
130 | 105 |
131 DCHECK(widget_); | 106 DCHECK(enabled()); |
107 | |
108 if (!widget_) | |
109 CreateShellSurfaceWidget(); | |
110 | |
132 widget_->SetFullscreen(fullscreen); | 111 widget_->SetFullscreen(fullscreen); |
133 | 112 |
134 if (!configure_callback_.is_null()) | 113 if (!configure_callback_.is_null()) |
135 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); | 114 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); |
136 } | 115 } |
137 | 116 |
138 void ShellSurface::SetTitle(const base::string16& title) { | 117 void ShellSurface::SetTitle(const base::string16& title) { |
139 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", | 118 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
140 base::UTF16ToUTF8(title)); | 119 base::UTF16ToUTF8(title)); |
141 | 120 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 new base::trace_event::TracedValue; | 174 new base::trace_event::TracedValue; |
196 value->SetString("title", base::UTF16ToUTF8(title_)); | 175 value->SetString("title", base::UTF16ToUTF8(title_)); |
197 value->SetString("application_id", application_id_); | 176 value->SetString("application_id", application_id_); |
198 return value; | 177 return value; |
199 } | 178 } |
200 | 179 |
201 //////////////////////////////////////////////////////////////////////////////// | 180 //////////////////////////////////////////////////////////////////////////////// |
202 // SurfaceDelegate overrides: | 181 // SurfaceDelegate overrides: |
203 | 182 |
204 void ShellSurface::OnSurfaceCommit() { | 183 void ShellSurface::OnSurfaceCommit() { |
184 if (enabled() && !widget_) | |
185 CreateShellSurfaceWidget(); | |
186 | |
205 surface_->CommitSurfaceHierarchy(); | 187 surface_->CommitSurfaceHierarchy(); |
188 | |
206 if (widget_) { | 189 if (widget_) { |
207 // Update surface bounds and widget size. | 190 // Update surface bounds and widget size. |
208 gfx::Point origin; | 191 gfx::Point origin; |
209 views::View::ConvertPointToWidget(this, &origin); | 192 views::View::ConvertPointToWidget(this, &origin); |
210 surface_->SetBounds(gfx::Rect(origin - geometry_.OffsetFromOrigin(), | 193 surface_->SetBounds(gfx::Rect(origin - geometry_.OffsetFromOrigin(), |
211 surface_->layer()->size())); | 194 surface_->layer()->size())); |
212 widget_->SetSize(widget_->non_client_view()->GetPreferredSize()); | 195 widget_->SetSize(widget_->non_client_view()->GetPreferredSize()); |
213 | 196 |
214 // Show widget if not already visible. | 197 // Show widget if not already visible. |
215 if (!widget_->IsClosed() && !widget_->IsVisible()) | 198 if (!widget_->IsClosed() && !widget_->IsVisible()) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
264 // views::Views overrides: | 247 // views::Views overrides: |
265 | 248 |
266 gfx::Size ShellSurface::GetPreferredSize() const { | 249 gfx::Size ShellSurface::GetPreferredSize() const { |
267 if (!geometry_.IsEmpty()) | 250 if (!geometry_.IsEmpty()) |
268 return geometry_.size(); | 251 return geometry_.size(); |
269 | 252 |
270 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); | 253 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); |
271 } | 254 } |
272 | 255 |
256 //////////////////////////////////////////////////////////////////////////////// | |
257 // ShellSurface, private: | |
258 | |
259 void ShellSurface::CreateShellSurfaceWidget() { | |
260 DCHECK(!widget_); | |
261 | |
lpique
2016/01/28 20:48:32
Was dropping the TRACE_EVENT intentional?
reveman
2016/01/28 21:35:19
Yes, I've been limiting TRACE_EVENT statements to
| |
262 views::Widget::InitParams params; | |
263 params.type = views::Widget::InitParams::TYPE_WINDOW; | |
264 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
265 params.delegate = this; | |
266 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; | |
267 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
268 params.show_state = ui::SHOW_STATE_NORMAL; | |
269 params.parent = ash::Shell::GetContainer( | |
270 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); | |
271 widget_.reset(new ShellSurfaceWidget(this)); | |
272 widget_->Init(params); | |
273 widget_->GetNativeWindow()->set_owned_by_parent(false); | |
274 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | |
275 widget_->GetNativeWindow()->AddChild(surface_); | |
276 SetApplicationId(widget_->GetNativeWindow(), &application_id_); | |
277 | |
278 // The position of a top-level shell surface is managed by Ash. | |
279 ash::wm::GetWindowState(widget_->GetNativeWindow()) | |
280 ->set_window_position_managed(true); | |
281 } | |
282 | |
273 } // namespace exo | 283 } // namespace exo |
OLD | NEW |