| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 views::Widget* const widget_; | 47 views::Widget* const widget_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(CustomFrameView); | 49 DISALLOW_COPY_AND_ASSIGN(CustomFrameView); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class ShellSurfaceWidget : public views::Widget { | 52 class ShellSurfaceWidget : public views::Widget { |
| 53 public: | 53 public: |
| 54 explicit ShellSurfaceWidget(ShellSurface* shell_surface) | 54 explicit ShellSurfaceWidget(ShellSurface* shell_surface) |
| 55 : shell_surface_(shell_surface) {} | 55 : shell_surface_(shell_surface) {} |
| 56 | 56 |
| 57 static views::Widget::InitParams CreateInitParams( | |
| 58 views::WidgetDelegate* delegate) { | |
| 59 views::Widget::InitParams params; | |
| 60 params.type = views::Widget::InitParams::TYPE_WINDOW; | |
| 61 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 62 params.delegate = delegate; | |
| 63 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; | |
| 64 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 65 params.show_state = ui::SHOW_STATE_NORMAL; | |
| 66 params.parent = | |
| 67 ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), | |
| 68 ash::kShellWindowId_DefaultContainer); | |
| 69 return params; | |
| 70 } | |
| 71 | |
| 72 // Overridden from views::Widget | 57 // Overridden from views::Widget |
| 73 void Close() override { shell_surface_->Close(); } | 58 void Close() override { shell_surface_->Close(); } |
| 74 | 59 |
| 75 private: | 60 private: |
| 76 ShellSurface* const shell_surface_; | 61 ShellSurface* const shell_surface_; |
| 77 | 62 |
| 78 DISALLOW_COPY_AND_ASSIGN(ShellSurfaceWidget); | 63 DISALLOW_COPY_AND_ASSIGN(ShellSurfaceWidget); |
| 79 }; | 64 }; |
| 80 | 65 |
| 81 } // namespace | 66 } // namespace |
| (...skipping 12 matching lines...) Expand all Loading... |
| 94 | 79 |
| 95 ShellSurface::~ShellSurface() { | 80 ShellSurface::~ShellSurface() { |
| 96 if (surface_) { | 81 if (surface_) { |
| 97 surface_->SetSurfaceDelegate(nullptr); | 82 surface_->SetSurfaceDelegate(nullptr); |
| 98 surface_->RemoveSurfaceObserver(this); | 83 surface_->RemoveSurfaceObserver(this); |
| 99 } | 84 } |
| 100 if (widget_) | 85 if (widget_) |
| 101 widget_->CloseNow(); | 86 widget_->CloseNow(); |
| 102 } | 87 } |
| 103 | 88 |
| 104 void ShellSurface::SetToplevel() { | 89 void ShellSurface::Init() { |
| 105 TRACE_EVENT0("exo", "ShellSurface::SetToplevel"); | 90 TRACE_EVENT0("exo", "ShellSurface::Init"); |
| 106 | 91 |
| 107 if (widget_) { | 92 if (widget_) { |
| 108 DLOG(WARNING) << "Shell surface already mapped"; | 93 DLOG(WARNING) << "Shell surface already initialized"; |
| 109 return; | 94 return; |
| 110 } | 95 } |
| 111 | 96 |
| 112 views::Widget::InitParams params = ShellSurfaceWidget::CreateInitParams(this); | 97 views::Widget::InitParams params; |
| 113 params.bounds = gfx::Rect(gfx::Size(1, 1)); | 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); |
| 114 widget_.reset(new ShellSurfaceWidget(this)); | 106 widget_.reset(new ShellSurfaceWidget(this)); |
| 115 widget_->Init(params); | 107 widget_->Init(params); |
| 116 widget_->GetNativeWindow()->set_owned_by_parent(false); | 108 widget_->GetNativeWindow()->set_owned_by_parent(false); |
| 117 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | 109 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
| 118 widget_->GetNativeWindow()->AddChild(surface_); | 110 widget_->GetNativeWindow()->AddChild(surface_); |
| 119 SetApplicationId(widget_->GetNativeWindow(), &application_id_); | 111 SetApplicationId(widget_->GetNativeWindow(), &application_id_); |
| 120 | 112 |
| 121 // The position of a standard top level shell surface is managed by Ash. | 113 // The position of a top-level shell surface is managed by Ash. |
| 122 ash::wm::GetWindowState(widget_->GetNativeWindow()) | 114 ash::wm::GetWindowState(widget_->GetNativeWindow()) |
| 123 ->set_window_position_managed(true); | 115 ->set_window_position_managed(true); |
| 124 } | 116 } |
| 125 | 117 |
| 126 void ShellSurface::SetMaximized() { | 118 void ShellSurface::Maximize() { |
| 127 TRACE_EVENT0("exo", "ShellSurface::SetMaximized"); | 119 TRACE_EVENT0("exo", "ShellSurface::Maximize"); |
| 128 | 120 |
| 129 if (widget_) { | 121 DCHECK(widget_); |
| 130 DLOG(WARNING) << "Shell surface already mapped"; | 122 widget_->Maximize(); |
| 131 return; | |
| 132 } | |
| 133 | 123 |
| 134 views::Widget::InitParams params = ShellSurfaceWidget::CreateInitParams(this); | 124 if (!configure_callback_.is_null()) |
| 135 params.show_state = ui::SHOW_STATE_MAXIMIZED; | 125 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); |
| 136 widget_.reset(new ShellSurfaceWidget(this)); | |
| 137 widget_->Init(params); | |
| 138 widget_->GetNativeWindow()->set_owned_by_parent(false); | |
| 139 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | |
| 140 widget_->GetNativeWindow()->AddChild(surface_); | |
| 141 SetApplicationId(widget_->GetNativeWindow(), &application_id_); | |
| 142 } | 126 } |
| 143 | 127 |
| 144 void ShellSurface::SetFullscreen() { | 128 void ShellSurface::SetFullscreen(bool fullscreen) { |
| 145 TRACE_EVENT0("exo", "ShellSurface::SetFullscreen"); | 129 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen); |
| 146 | 130 |
| 147 if (widget_) { | 131 DCHECK(widget_); |
| 148 DLOG(WARNING) << "Shell surface already mapped"; | 132 widget_->SetFullscreen(fullscreen); |
| 149 return; | |
| 150 } | |
| 151 | 133 |
| 152 views::Widget::InitParams params = ShellSurfaceWidget::CreateInitParams(this); | 134 if (!configure_callback_.is_null()) |
| 153 params.show_state = ui::SHOW_STATE_FULLSCREEN; | 135 configure_callback_.Run(widget_->GetWindowBoundsInScreen().size()); |
| 154 widget_.reset(new ShellSurfaceWidget(this)); | |
| 155 widget_->Init(params); | |
| 156 widget_->GetNativeWindow()->set_owned_by_parent(false); | |
| 157 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | |
| 158 widget_->GetNativeWindow()->AddChild(surface_); | |
| 159 SetApplicationId(widget_->GetNativeWindow(), &application_id_); | |
| 160 } | 136 } |
| 161 | 137 |
| 162 void ShellSurface::SetTitle(const base::string16& title) { | 138 void ShellSurface::SetTitle(const base::string16& title) { |
| 163 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", | 139 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
| 164 base::UTF16ToUTF8(title)); | 140 base::UTF16ToUTF8(title)); |
| 165 | 141 |
| 166 title_ = title; | 142 title_ = title; |
| 167 if (widget_) | 143 if (widget_) |
| 168 widget_->UpdateWindowTitle(); | 144 widget_->UpdateWindowTitle(); |
| 169 } | 145 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // views::Views overrides: | 264 // views::Views overrides: |
| 289 | 265 |
| 290 gfx::Size ShellSurface::GetPreferredSize() const { | 266 gfx::Size ShellSurface::GetPreferredSize() const { |
| 291 if (!geometry_.IsEmpty()) | 267 if (!geometry_.IsEmpty()) |
| 292 return geometry_.size(); | 268 return geometry_.size(); |
| 293 | 269 |
| 294 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); | 270 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); |
| 295 } | 271 } |
| 296 | 272 |
| 297 } // namespace exo | 273 } // namespace exo |
| OLD | NEW |