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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "components/exo/surface.h" | 14 #include "components/exo/surface.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_property.h" |
16 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
| 20 DECLARE_WINDOW_PROPERTY_TYPE(std::string*) |
| 21 |
19 namespace exo { | 22 namespace exo { |
20 namespace { | 23 namespace { |
21 | 24 |
22 class CustomFrameView : public views::NonClientFrameView { | 25 class CustomFrameView : public views::NonClientFrameView { |
23 public: | 26 public: |
24 explicit CustomFrameView(views::Widget* widget) : widget_(widget) {} | 27 explicit CustomFrameView(views::Widget* widget) : widget_(widget) {} |
25 ~CustomFrameView() override {} | 28 ~CustomFrameView() override {} |
26 | 29 |
27 // Overridden from views::NonClientFrameView: | 30 // Overridden from views::NonClientFrameView: |
28 gfx::Rect GetBoundsForClientView() const override { return bounds(); } | 31 gfx::Rect GetBoundsForClientView() const override { return bounds(); } |
(...skipping 28 matching lines...) Expand all Loading... |
57 params.parent = ash::Shell::GetContainer( | 60 params.parent = ash::Shell::GetContainer( |
58 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); | 61 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); |
59 return params; | 62 return params; |
60 } | 63 } |
61 | 64 |
62 } // namespace | 65 } // namespace |
63 | 66 |
64 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
65 // ShellSurface, public: | 68 // ShellSurface, public: |
66 | 69 |
| 70 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(std::string*, kApplicationIdKey, nullptr) |
| 71 |
67 ShellSurface::ShellSurface(Surface* surface) : surface_(surface) { | 72 ShellSurface::ShellSurface(Surface* surface) : surface_(surface) { |
68 surface_->SetSurfaceDelegate(this); | 73 surface_->SetSurfaceDelegate(this); |
69 surface_->AddSurfaceObserver(this); | 74 surface_->AddSurfaceObserver(this); |
70 surface_->Show(); | 75 surface_->Show(); |
71 set_owned_by_client(); | 76 set_owned_by_client(); |
72 } | 77 } |
73 | 78 |
74 ShellSurface::~ShellSurface() { | 79 ShellSurface::~ShellSurface() { |
75 if (surface_) { | 80 if (surface_) { |
76 surface_->SetSurfaceDelegate(nullptr); | 81 surface_->SetSurfaceDelegate(nullptr); |
(...skipping 11 matching lines...) Expand all Loading... |
88 return; | 93 return; |
89 } | 94 } |
90 | 95 |
91 views::Widget::InitParams params = CreateWidgetInitParams(this); | 96 views::Widget::InitParams params = CreateWidgetInitParams(this); |
92 params.bounds = gfx::Rect(gfx::Size(1, 1)); | 97 params.bounds = gfx::Rect(gfx::Size(1, 1)); |
93 widget_.reset(new views::Widget); | 98 widget_.reset(new views::Widget); |
94 widget_->Init(params); | 99 widget_->Init(params); |
95 widget_->GetNativeWindow()->set_owned_by_parent(false); | 100 widget_->GetNativeWindow()->set_owned_by_parent(false); |
96 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | 101 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
97 widget_->GetNativeWindow()->AddChild(surface_); | 102 widget_->GetNativeWindow()->AddChild(surface_); |
| 103 SetApplicationId(widget_->GetNativeWindow(), &application_id_); |
98 | 104 |
99 // The position of a standard top level shell surface is managed by Ash. | 105 // The position of a standard top level shell surface is managed by Ash. |
100 ash::wm::GetWindowState(widget_->GetNativeWindow()) | 106 ash::wm::GetWindowState(widget_->GetNativeWindow()) |
101 ->set_window_position_managed(true); | 107 ->set_window_position_managed(true); |
102 } | 108 } |
103 | 109 |
104 void ShellSurface::SetMaximized() { | 110 void ShellSurface::SetMaximized() { |
105 TRACE_EVENT0("exo", "ShellSurface::SetMaximized"); | 111 TRACE_EVENT0("exo", "ShellSurface::SetMaximized"); |
106 | 112 |
107 if (widget_) { | 113 if (widget_) { |
108 DLOG(WARNING) << "Shell surface already mapped"; | 114 DLOG(WARNING) << "Shell surface already mapped"; |
109 return; | 115 return; |
110 } | 116 } |
111 | 117 |
112 views::Widget::InitParams params = CreateWidgetInitParams(this); | 118 views::Widget::InitParams params = CreateWidgetInitParams(this); |
113 params.show_state = ui::SHOW_STATE_MAXIMIZED; | 119 params.show_state = ui::SHOW_STATE_MAXIMIZED; |
114 widget_.reset(new views::Widget); | 120 widget_.reset(new views::Widget); |
115 widget_->Init(params); | 121 widget_->Init(params); |
116 widget_->GetNativeWindow()->set_owned_by_parent(false); | 122 widget_->GetNativeWindow()->set_owned_by_parent(false); |
117 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | 123 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
118 widget_->GetNativeWindow()->AddChild(surface_); | 124 widget_->GetNativeWindow()->AddChild(surface_); |
| 125 SetApplicationId(widget_->GetNativeWindow(), &application_id_); |
119 } | 126 } |
120 | 127 |
121 void ShellSurface::SetFullscreen() { | 128 void ShellSurface::SetFullscreen() { |
122 TRACE_EVENT0("exo", "ShellSurface::SetFullscreen"); | 129 TRACE_EVENT0("exo", "ShellSurface::SetFullscreen"); |
123 | 130 |
124 if (widget_) { | 131 if (widget_) { |
125 DLOG(WARNING) << "Shell surface already mapped"; | 132 DLOG(WARNING) << "Shell surface already mapped"; |
126 return; | 133 return; |
127 } | 134 } |
128 | 135 |
129 views::Widget::InitParams params = CreateWidgetInitParams(this); | 136 views::Widget::InitParams params = CreateWidgetInitParams(this); |
130 params.show_state = ui::SHOW_STATE_FULLSCREEN; | 137 params.show_state = ui::SHOW_STATE_FULLSCREEN; |
131 widget_.reset(new views::Widget); | 138 widget_.reset(new views::Widget); |
132 widget_->Init(params); | 139 widget_->Init(params); |
133 widget_->GetNativeWindow()->set_owned_by_parent(false); | 140 widget_->GetNativeWindow()->set_owned_by_parent(false); |
134 widget_->GetNativeWindow()->SetName("ExoShellSurface"); | 141 widget_->GetNativeWindow()->SetName("ExoShellSurface"); |
135 widget_->GetNativeWindow()->AddChild(surface_); | 142 widget_->GetNativeWindow()->AddChild(surface_); |
| 143 SetApplicationId(widget_->GetNativeWindow(), &application_id_); |
136 } | 144 } |
137 | 145 |
138 void ShellSurface::SetTitle(const base::string16& title) { | 146 void ShellSurface::SetTitle(const base::string16& title) { |
139 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", | 147 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
140 base::UTF16ToUTF8(title)); | 148 base::UTF16ToUTF8(title)); |
141 | 149 |
142 title_ = title; | 150 title_ = title; |
143 if (widget_) | 151 if (widget_) |
144 widget_->UpdateWindowTitle(); | 152 widget_->UpdateWindowTitle(); |
145 } | 153 } |
146 | 154 |
| 155 // static |
| 156 void ShellSurface::SetApplicationId(aura::Window* window, |
| 157 std::string* application_id) { |
| 158 window->SetProperty(kApplicationIdKey, application_id); |
| 159 } |
| 160 |
| 161 // static |
| 162 const std::string ShellSurface::GetApplicationId(aura::Window* window) { |
| 163 std::string* string_ptr = window->GetProperty(kApplicationIdKey); |
| 164 return string_ptr ? *string_ptr : std::string(); |
| 165 } |
| 166 |
| 167 void ShellSurface::SetApplicationId(const std::string& application_id) { |
| 168 TRACE_EVENT1("exo", "ShellSurface::SetApplicationId", "application_id", |
| 169 application_id); |
| 170 |
| 171 application_id_ = application_id; |
| 172 } |
| 173 |
147 void ShellSurface::Move() { | 174 void ShellSurface::Move() { |
148 TRACE_EVENT0("exo", "ShellSurface::Move"); | 175 TRACE_EVENT0("exo", "ShellSurface::Move"); |
149 | 176 |
150 if (widget_) { | 177 if (widget_) { |
151 widget_->RunMoveLoop(gfx::Vector2d(), views::Widget::MOVE_LOOP_SOURCE_MOUSE, | 178 widget_->RunMoveLoop(gfx::Vector2d(), views::Widget::MOVE_LOOP_SOURCE_MOUSE, |
152 views::Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE); | 179 views::Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE); |
153 } | 180 } |
154 } | 181 } |
155 | 182 |
156 scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() | 183 scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() |
157 const { | 184 const { |
158 scoped_refptr<base::trace_event::TracedValue> value = | 185 scoped_refptr<base::trace_event::TracedValue> value = |
159 new base::trace_event::TracedValue; | 186 new base::trace_event::TracedValue; |
160 value->SetString("title", base::UTF16ToUTF8(title_)); | 187 value->SetString("title", base::UTF16ToUTF8(title_)); |
| 188 value->SetString("application_id", application_id_); |
161 return value; | 189 return value; |
162 } | 190 } |
163 | 191 |
164 //////////////////////////////////////////////////////////////////////////////// | 192 //////////////////////////////////////////////////////////////////////////////// |
165 // SurfaceDelegate overrides: | 193 // SurfaceDelegate overrides: |
166 | 194 |
167 void ShellSurface::OnSurfaceCommit() { | 195 void ShellSurface::OnSurfaceCommit() { |
168 surface_->CommitSurfaceHierarchy(); | 196 surface_->CommitSurfaceHierarchy(); |
169 if (widget_) { | 197 if (widget_) { |
170 // Update surface bounds and widget size. | 198 // Update surface bounds and widget size. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 245 } |
218 | 246 |
219 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
220 // views::Views overrides: | 248 // views::Views overrides: |
221 | 249 |
222 gfx::Size ShellSurface::GetPreferredSize() const { | 250 gfx::Size ShellSurface::GetPreferredSize() const { |
223 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); | 251 return surface_ ? surface_->GetPreferredSize() : gfx::Size(); |
224 } | 252 } |
225 | 253 |
226 } // namespace exo | 254 } // namespace exo |
OLD | NEW |