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 "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 }; | 45 }; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
50 // ShellSurface, public: | 50 // ShellSurface, public: |
51 | 51 |
52 ShellSurface::ShellSurface(Surface* surface) | 52 ShellSurface::ShellSurface(Surface* surface) |
53 : surface_(surface), show_state_(ui::SHOW_STATE_END) { | 53 : surface_(surface), show_state_(ui::SHOW_STATE_END) { |
54 surface_->SetSurfaceDelegate(this); | 54 surface_->SetSurfaceDelegate(this); |
| 55 surface_->AddSurfaceObserver(this); |
55 } | 56 } |
56 | 57 |
57 ShellSurface::~ShellSurface() { | 58 ShellSurface::~ShellSurface() { |
58 if (surface_) | 59 if (surface_) { |
59 surface_->SetSurfaceDelegate(nullptr); | 60 surface_->SetSurfaceDelegate(nullptr); |
| 61 surface_->RemoveSurfaceObserver(this); |
| 62 } |
60 if (widget_) | 63 if (widget_) |
61 widget_->CloseNow(); | 64 widget_->CloseNow(); |
62 } | 65 } |
63 | 66 |
64 void ShellSurface::Show() { | 67 void ShellSurface::Show() { |
65 TRACE_EVENT0("exo", "ShellSurface::Show"); | 68 TRACE_EVENT0("exo", "ShellSurface::Show"); |
66 | 69 |
67 if (!widget_ && show_state_ == ui::SHOW_STATE_END) | 70 if (!widget_ && show_state_ == ui::SHOW_STATE_END) |
68 show_state_ = ui::SHOW_STATE_DEFAULT; | 71 show_state_ = ui::SHOW_STATE_DEFAULT; |
69 } | 72 } |
(...skipping 29 matching lines...) Expand all Loading... |
99 const { | 102 const { |
100 scoped_refptr<base::trace_event::TracedValue> value = | 103 scoped_refptr<base::trace_event::TracedValue> value = |
101 new base::trace_event::TracedValue; | 104 new base::trace_event::TracedValue; |
102 value->SetString("title", base::UTF16ToUTF8(title_)); | 105 value->SetString("title", base::UTF16ToUTF8(title_)); |
103 return value; | 106 return value; |
104 } | 107 } |
105 | 108 |
106 //////////////////////////////////////////////////////////////////////////////// | 109 //////////////////////////////////////////////////////////////////////////////// |
107 // SurfaceDelegate overrides: | 110 // SurfaceDelegate overrides: |
108 | 111 |
109 void ShellSurface::OnSurfaceDestroying() { | |
110 surface_ = nullptr; | |
111 } | |
112 | |
113 void ShellSurface::OnSurfaceCommit() { | 112 void ShellSurface::OnSurfaceCommit() { |
114 if (widget_ || show_state_ == ui::SHOW_STATE_END) | 113 if (widget_ || show_state_ == ui::SHOW_STATE_END) { |
| 114 surface_->CommitSurfaceHierarchy(); |
115 return; | 115 return; |
| 116 } |
116 | 117 |
117 views::Widget::InitParams params; | 118 views::Widget::InitParams params; |
118 params.type = views::Widget::InitParams::TYPE_WINDOW; | 119 params.type = views::Widget::InitParams::TYPE_WINDOW; |
119 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 120 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
120 params.delegate = this; | 121 params.delegate = this; |
121 params.shadow_type = show_state_ == ui::SHOW_STATE_NORMAL | 122 params.shadow_type = show_state_ == ui::SHOW_STATE_NORMAL |
122 ? views::Widget::InitParams::SHADOW_TYPE_DROP | 123 ? views::Widget::InitParams::SHADOW_TYPE_DROP |
123 : views::Widget::InitParams::SHADOW_TYPE_NONE; | 124 : views::Widget::InitParams::SHADOW_TYPE_NONE; |
124 params.opacity = show_state_ == ui::SHOW_STATE_NORMAL | 125 params.opacity = show_state_ == ui::SHOW_STATE_NORMAL |
125 ? views::Widget::InitParams::OPAQUE_WINDOW | 126 ? views::Widget::InitParams::OPAQUE_WINDOW |
126 : views::Widget::InitParams::TRANSLUCENT_WINDOW; | 127 : views::Widget::InitParams::TRANSLUCENT_WINDOW; |
127 params.show_state = show_state_; | 128 params.show_state = show_state_; |
128 params.parent = ash::Shell::GetContainer( | 129 params.parent = ash::Shell::GetContainer( |
129 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); | 130 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); |
130 widget_.reset(new views::Widget); | 131 widget_.reset(new views::Widget); |
131 widget_->Init(params); | 132 widget_->Init(params); |
132 widget_->GetNativeWindow()->set_owned_by_parent(false); | 133 widget_->GetNativeWindow()->set_owned_by_parent(false); |
133 widget_->GetNativeView()->SetName("ShellSurface"); | 134 widget_->GetNativeView()->SetName("ShellSurface"); |
| 135 |
| 136 surface_->CommitSurfaceHierarchy(); |
| 137 surface_->SetVisible(true); |
| 138 surface_->SetEnabled(true); |
| 139 |
134 widget_->Show(); | 140 widget_->Show(); |
135 } | 141 } |
136 | 142 |
| 143 bool ShellSurface::IsSurfaceSynchronized() const { |
| 144 // A shell surface is always desynchronized. |
| 145 return false; |
| 146 } |
| 147 |
| 148 //////////////////////////////////////////////////////////////////////////////// |
| 149 // SurfaceObserver overrides: |
| 150 |
| 151 void ShellSurface::OnSurfaceDestroying(Surface* surface) { |
| 152 surface->RemoveSurfaceObserver(this); |
| 153 surface_ = nullptr; |
| 154 } |
| 155 |
137 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
138 // views::WidgetDelegate overrides: | 157 // views::WidgetDelegate overrides: |
139 | 158 |
140 base::string16 ShellSurface::GetWindowTitle() const { | 159 base::string16 ShellSurface::GetWindowTitle() const { |
141 return title_; | 160 return title_; |
142 } | 161 } |
143 | 162 |
144 views::Widget* ShellSurface::GetWidget() { | 163 views::Widget* ShellSurface::GetWidget() { |
145 return widget_.get(); | 164 return widget_.get(); |
146 } | 165 } |
147 | 166 |
148 const views::Widget* ShellSurface::GetWidget() const { | 167 const views::Widget* ShellSurface::GetWidget() const { |
149 return widget_.get(); | 168 return widget_.get(); |
150 } | 169 } |
151 | 170 |
152 views::View* ShellSurface::GetContentsView() { | 171 views::View* ShellSurface::GetContentsView() { |
153 return surface_; | 172 return surface_; |
154 } | 173 } |
155 | 174 |
156 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView( | 175 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView( |
157 views::Widget* widget) { | 176 views::Widget* widget) { |
158 // Default show state is borderless and requires a custom frame view as the | 177 // Default show state is borderless and requires a custom frame view as the |
159 // default one does not support this. | 178 // default one does not support this. |
160 return show_state_ != ui::SHOW_STATE_NORMAL ? new CustomFrameView(widget) | 179 return show_state_ != ui::SHOW_STATE_NORMAL ? new CustomFrameView(widget) |
161 : nullptr; | 180 : nullptr; |
162 } | 181 } |
163 | 182 |
164 } // namespace exo | 183 } // namespace exo |
OLD | NEW |