OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/devtools/ash_devtools_css_agent.h" | 5 #include "ash/devtools/ash_devtools_css_agent.h" |
6 | 6 |
7 #include "ash/wm_window.h" | |
8 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "ui/aura/window.h" |
10 | 10 |
11 namespace ash { | 11 namespace ash { |
12 namespace devtools { | 12 namespace devtools { |
13 | 13 |
14 namespace { | 14 namespace { |
15 using namespace ui::devtools::protocol; | 15 using namespace ui::devtools::protocol; |
16 | 16 |
17 const char kHeight[] = "height"; | 17 const char kHeight[] = "height"; |
18 const char kWidth[] = "width"; | 18 const char kWidth[] = "width"; |
19 const char kX[] = "x"; | 19 const char kX[] = "x"; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible)); | 157 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible)); |
158 | 158 |
159 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible)) | 159 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible)) |
160 return NodeNotFoundError(node_id); | 160 return NodeNotFoundError(node_id); |
161 } | 161 } |
162 *result = std::move(updated_styles); | 162 *result = std::move(updated_styles); |
163 return ui::devtools::protocol::Response::OK(); | 163 return ui::devtools::protocol::Response::OK(); |
164 } | 164 } |
165 | 165 |
166 void AshDevToolsCSSAgent::OnWindowBoundsChanged(WmWindow* window) { | 166 void AshDevToolsCSSAgent::OnWindowBoundsChanged(aura::Window* window) { |
167 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWindow(window)); | 167 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWindow(window)); |
168 } | 168 } |
169 | 169 |
170 void AshDevToolsCSSAgent::OnWidgetBoundsChanged(views::Widget* widget) { | 170 void AshDevToolsCSSAgent::OnWidgetBoundsChanged(views::Widget* widget) { |
171 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWidget(widget)); | 171 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWidget(widget)); |
172 } | 172 } |
173 | 173 |
174 void AshDevToolsCSSAgent::OnViewBoundsChanged(views::View* view) { | 174 void AshDevToolsCSSAgent::OnViewBoundsChanged(views::View* view) { |
175 InvalidateStyleSheet(dom_agent_->GetNodeIdFromView(view)); | 175 InvalidateStyleSheet(dom_agent_->GetNodeIdFromView(view)); |
176 } | 176 } |
177 | 177 |
178 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> | 178 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> |
179 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { | 179 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { |
180 gfx::Rect bounds; | 180 gfx::Rect bounds; |
181 bool visible = false; | 181 bool visible = false; |
182 return GetPropertiesForNodeId(node_id, &bounds, &visible) | 182 return GetPropertiesForNodeId(node_id, &bounds, &visible) |
183 ? BuildCSSStyle(node_id, bounds, visible) | 183 ? BuildCSSStyle(node_id, bounds, visible) |
184 : nullptr; | 184 : nullptr; |
185 } | 185 } |
186 | 186 |
187 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { | 187 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { |
188 // The stylesheetId for each node is equivalent to its node_id (as a string). | 188 // The stylesheetId for each node is equivalent to its node_id (as a string). |
189 frontend()->styleSheetChanged(base::IntToString(node_id)); | 189 frontend()->styleSheetChanged(base::IntToString(node_id)); |
190 } | 190 } |
191 | 191 |
192 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, | 192 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, |
193 gfx::Rect* bounds, | 193 gfx::Rect* bounds, |
194 bool* visible) { | 194 bool* visible) { |
195 WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); | 195 aura::Window* window = dom_agent_->GetWindowFromNodeId(node_id); |
196 if (window) { | 196 if (window) { |
197 *bounds = window->GetBounds(); | 197 *bounds = window->bounds(); |
198 *visible = window->IsVisible(); | 198 *visible = window->IsVisible(); |
199 return true; | 199 return true; |
200 } | 200 } |
201 views::Widget* widget = dom_agent_->GetWidgetFromNodeId(node_id); | 201 views::Widget* widget = dom_agent_->GetWidgetFromNodeId(node_id); |
202 if (widget) { | 202 if (widget) { |
203 *bounds = widget->GetRestoredBounds(); | 203 *bounds = widget->GetRestoredBounds(); |
204 *visible = widget->IsVisible(); | 204 *visible = widget->IsVisible(); |
205 return true; | 205 return true; |
206 } | 206 } |
207 views::View* view = dom_agent_->GetViewFromNodeId(node_id); | 207 views::View* view = dom_agent_->GetViewFromNodeId(node_id); |
208 if (view) { | 208 if (view) { |
209 *bounds = view->bounds(); | 209 *bounds = view->bounds(); |
210 *visible = view->visible(); | 210 *visible = view->visible(); |
211 return true; | 211 return true; |
212 } | 212 } |
213 return false; | 213 return false; |
214 } | 214 } |
215 | 215 |
216 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, | 216 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, |
217 const gfx::Rect& bounds, | 217 const gfx::Rect& bounds, |
218 bool visible) { | 218 bool visible) { |
219 WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); | 219 aura::Window* window = dom_agent_->GetWindowFromNodeId(node_id); |
220 if (window) { | 220 if (window) { |
221 window->SetBounds(bounds); | 221 window->SetBounds(bounds); |
222 if (visible != window->IsVisible()) { | 222 if (visible != window->IsVisible()) { |
223 if (visible) | 223 if (visible) |
224 window->Show(); | 224 window->Show(); |
225 else | 225 else |
226 window->Hide(); | 226 window->Hide(); |
227 } | 227 } |
228 return true; | 228 return true; |
229 } | 229 } |
(...skipping 13 matching lines...) Expand all Loading... |
243 view->SetBoundsRect(bounds); | 243 view->SetBoundsRect(bounds); |
244 if (visible != view->visible()) | 244 if (visible != view->visible()) |
245 view->SetVisible(visible); | 245 view->SetVisible(visible); |
246 return true; | 246 return true; |
247 } | 247 } |
248 return false; | 248 return false; |
249 } | 249 } |
250 | 250 |
251 } // namespace devtools | 251 } // namespace devtools |
252 } // namespace ash | 252 } // namespace ash |
OLD | NEW |