| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
| 65 // ShellSurface, public: | 65 // ShellSurface, public: |
| 66 | 66 |
| 67 ShellSurface::ShellSurface(Surface* surface) : surface_(surface) { | 67 ShellSurface::ShellSurface(Surface* surface) : surface_(surface) { |
| 68 surface_->SetSurfaceDelegate(this); | 68 surface_->SetSurfaceDelegate(this); |
| 69 surface_->AddSurfaceObserver(this); | 69 surface_->AddSurfaceObserver(this); |
| 70 surface_->SetVisible(true); | 70 surface_->Show(); |
| 71 surface_->SetEnabled(true); | 71 set_owned_by_client(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 ShellSurface::~ShellSurface() { | 74 ShellSurface::~ShellSurface() { |
| 75 if (surface_) { | 75 if (surface_) { |
| 76 surface_->SetSurfaceDelegate(nullptr); | 76 surface_->SetSurfaceDelegate(nullptr); |
| 77 surface_->RemoveSurfaceObserver(this); | 77 surface_->RemoveSurfaceObserver(this); |
| 78 } | 78 } |
| 79 if (widget_) | 79 if (widget_) |
| 80 widget_->CloseNow(); | 80 widget_->CloseNow(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ShellSurface::SetToplevel() { | 83 void ShellSurface::SetToplevel() { |
| 84 TRACE_EVENT0("exo", "ShellSurface::SetToplevel"); | 84 TRACE_EVENT0("exo", "ShellSurface::SetToplevel"); |
| 85 | 85 |
| 86 if (widget_) { | 86 if (widget_) { |
| 87 DLOG(WARNING) << "Shell surface already mapped"; | 87 DLOG(WARNING) << "Shell surface already mapped"; |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 views::Widget::InitParams params = CreateWidgetInitParams(this); | 91 views::Widget::InitParams params = CreateWidgetInitParams(this); |
| 92 params.bounds = gfx::Rect(gfx::Size(1, 1)); | 92 params.bounds = gfx::Rect(gfx::Size(1, 1)); |
| 93 widget_.reset(new views::Widget); | 93 widget_.reset(new views::Widget); |
| 94 widget_->Init(params); | 94 widget_->Init(params); |
| 95 widget_->GetNativeWindow()->set_owned_by_parent(false); | 95 widget_->GetNativeWindow()->set_owned_by_parent(false); |
| 96 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
| 97 widget_->GetNativeWindow()->AddChild(surface_); |
| 96 | 98 |
| 97 // The position of a standard top level shell surface is managed by Ash. | 99 // The position of a standard top level shell surface is managed by Ash. |
| 98 ash::wm::GetWindowState(widget_->GetNativeWindow()) | 100 ash::wm::GetWindowState(widget_->GetNativeWindow()) |
| 99 ->set_window_position_managed(true); | 101 ->set_window_position_managed(true); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void ShellSurface::SetMaximized() { | 104 void ShellSurface::SetMaximized() { |
| 103 TRACE_EVENT0("exo", "ShellSurface::SetMaximized"); | 105 TRACE_EVENT0("exo", "ShellSurface::SetMaximized"); |
| 104 | 106 |
| 105 if (widget_) { | 107 if (widget_) { |
| 106 DLOG(WARNING) << "Shell surface already mapped"; | 108 DLOG(WARNING) << "Shell surface already mapped"; |
| 107 return; | 109 return; |
| 108 } | 110 } |
| 109 | 111 |
| 110 views::Widget::InitParams params = CreateWidgetInitParams(this); | 112 views::Widget::InitParams params = CreateWidgetInitParams(this); |
| 111 params.show_state = ui::SHOW_STATE_MAXIMIZED; | 113 params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 112 widget_.reset(new views::Widget); | 114 widget_.reset(new views::Widget); |
| 113 widget_->Init(params); | 115 widget_->Init(params); |
| 114 widget_->GetNativeWindow()->set_owned_by_parent(false); | 116 widget_->GetNativeWindow()->set_owned_by_parent(false); |
| 117 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
| 118 widget_->GetNativeWindow()->AddChild(surface_); |
| 115 } | 119 } |
| 116 | 120 |
| 117 void ShellSurface::SetFullscreen() { | 121 void ShellSurface::SetFullscreen() { |
| 118 TRACE_EVENT0("exo", "ShellSurface::SetFullscreen"); | 122 TRACE_EVENT0("exo", "ShellSurface::SetFullscreen"); |
| 119 | 123 |
| 120 if (widget_) { | 124 if (widget_) { |
| 121 DLOG(WARNING) << "Shell surface already mapped"; | 125 DLOG(WARNING) << "Shell surface already mapped"; |
| 122 return; | 126 return; |
| 123 } | 127 } |
| 124 | 128 |
| 125 views::Widget::InitParams params = CreateWidgetInitParams(this); | 129 views::Widget::InitParams params = CreateWidgetInitParams(this); |
| 126 params.show_state = ui::SHOW_STATE_FULLSCREEN; | 130 params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 127 widget_.reset(new views::Widget); | 131 widget_.reset(new views::Widget); |
| 128 widget_->Init(params); | 132 widget_->Init(params); |
| 129 widget_->GetNativeWindow()->set_owned_by_parent(false); | 133 widget_->GetNativeWindow()->set_owned_by_parent(false); |
| 134 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
| 135 widget_->GetNativeWindow()->AddChild(surface_); |
| 130 } | 136 } |
| 131 | 137 |
| 132 void ShellSurface::SetTitle(const base::string16& title) { | 138 void ShellSurface::SetTitle(const base::string16& title) { |
| 133 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", | 139 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
| 134 base::UTF16ToUTF8(title)); | 140 base::UTF16ToUTF8(title)); |
| 135 | 141 |
| 136 title_ = title; | 142 title_ = title; |
| 137 if (widget_) | 143 if (widget_) |
| 138 widget_->UpdateWindowTitle(); | 144 widget_->UpdateWindowTitle(); |
| 139 } | 145 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 value->SetString("title", base::UTF16ToUTF8(title_)); | 160 value->SetString("title", base::UTF16ToUTF8(title_)); |
| 155 return value; | 161 return value; |
| 156 } | 162 } |
| 157 | 163 |
| 158 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
| 159 // SurfaceDelegate overrides: | 165 // SurfaceDelegate overrides: |
| 160 | 166 |
| 161 void ShellSurface::OnSurfaceCommit() { | 167 void ShellSurface::OnSurfaceCommit() { |
| 162 surface_->CommitSurfaceHierarchy(); | 168 surface_->CommitSurfaceHierarchy(); |
| 163 if (widget_) { | 169 if (widget_) { |
| 170 // Update surface bounds and widget size. |
| 171 gfx::Point origin; |
| 172 views::View::ConvertPointToWidget(this, &origin); |
| 173 surface_->SetBounds(gfx::Rect(origin, surface_->layer()->size())); |
| 164 widget_->SetSize(widget_->non_client_view()->GetPreferredSize()); | 174 widget_->SetSize(widget_->non_client_view()->GetPreferredSize()); |
| 165 | 175 |
| 166 // Show widget if not already visible. | 176 // Show widget if not already visible. |
| 167 if (!widget_->GetNativeWindow()->TargetVisibility()) | 177 if (!widget_->IsClosed() && !widget_->IsVisible()) |
| 168 widget_->Show(); | 178 widget_->Show(); |
| 169 } | 179 } |
| 170 } | 180 } |
| 171 | 181 |
| 172 bool ShellSurface::IsSurfaceSynchronized() const { | 182 bool ShellSurface::IsSurfaceSynchronized() const { |
| 173 // A shell surface is always desynchronized. | 183 // A shell surface is always desynchronized. |
| 174 return false; | 184 return false; |
| 175 } | 185 } |
| 176 | 186 |
| 177 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 13 matching lines...) Expand all Loading... |
| 191 | 201 |
| 192 views::Widget* ShellSurface::GetWidget() { | 202 views::Widget* ShellSurface::GetWidget() { |
| 193 return widget_.get(); | 203 return widget_.get(); |
| 194 } | 204 } |
| 195 | 205 |
| 196 const views::Widget* ShellSurface::GetWidget() const { | 206 const views::Widget* ShellSurface::GetWidget() const { |
| 197 return widget_.get(); | 207 return widget_.get(); |
| 198 } | 208 } |
| 199 | 209 |
| 200 views::View* ShellSurface::GetContentsView() { | 210 views::View* ShellSurface::GetContentsView() { |
| 201 return surface_; | 211 return this; |
| 202 } | 212 } |
| 203 | 213 |
| 204 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView( | 214 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView( |
| 205 views::Widget* widget) { | 215 views::Widget* widget) { |
| 206 return new CustomFrameView(widget); | 216 return new CustomFrameView(widget); |
| 207 } | 217 } |
| 208 | 218 |
| 219 //////////////////////////////////////////////////////////////////////////////// |
| 220 // views::Views overrides: |
| 221 |
| 222 gfx::Size ShellSurface::GetPreferredSize() const { |
| 223 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); |
| 224 } |
| 225 |
| 209 } // namespace exo | 226 } // namespace exo |
| OLD | NEW |