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