Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: components/ui_devtools/views/ui_devtools_css_agent.cc

Issue 2899783002: Move DevTools out of ash and turn it to a component. (Closed)
Patch Set: NON_EXPORTED_BASE base class Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/ui_devtools/views/ui_devtools_css_agent.h"
6 6
7 #include "ash/devtools/ui_element.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 "components/ui_devtools/views/ui_element.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
11 11
12 namespace ash { 12 namespace ui {
13 namespace devtools { 13 namespace devtools {
14 namespace { 14 namespace {
15 15
16 using namespace ui::devtools::protocol; 16 using namespace ui::devtools::protocol;
17 17
18 const char kHeight[] = "height"; 18 const char kHeight[] = "height";
19 const char kWidth[] = "width"; 19 const char kWidth[] = "width";
20 const char kX[] = "x"; 20 const char kX[] = "x";
21 const char kY[] = "y"; 21 const char kY[] = "y";
22 const char kVisibility[] = "visibility"; 22 const char kVisibility[] = "visibility";
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 else if (property == kVisibility) 93 else if (property == kVisibility)
94 *visible = std::max(0, value) == 1; 94 *visible = std::max(0, value) == 1;
95 else 95 else
96 return Response::Error("Unsupported property=" + property); 96 return Response::Error("Unsupported property=" + property);
97 } 97 }
98 return Response::OK(); 98 return Response::OK();
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent) 103 UIDevToolsCSSAgent::UIDevToolsCSSAgent(UIDevToolsDOMAgent* dom_agent)
104 : dom_agent_(dom_agent) { 104 : dom_agent_(dom_agent) {
105 DCHECK(dom_agent_); 105 DCHECK(dom_agent_);
106 } 106 }
107 107
108 AshDevToolsCSSAgent::~AshDevToolsCSSAgent() { 108 UIDevToolsCSSAgent::~UIDevToolsCSSAgent() {
109 disable(); 109 disable();
110 } 110 }
111 111
112 ui::devtools::protocol::Response AshDevToolsCSSAgent::enable() { 112 ui::devtools::protocol::Response UIDevToolsCSSAgent::enable() {
113 dom_agent_->AddObserver(this); 113 dom_agent_->AddObserver(this);
114 return ui::devtools::protocol::Response::OK(); 114 return ui::devtools::protocol::Response::OK();
115 } 115 }
116 116
117 ui::devtools::protocol::Response AshDevToolsCSSAgent::disable() { 117 ui::devtools::protocol::Response UIDevToolsCSSAgent::disable() {
118 dom_agent_->RemoveObserver(this); 118 dom_agent_->RemoveObserver(this);
119 return ui::devtools::protocol::Response::OK(); 119 return ui::devtools::protocol::Response::OK();
120 } 120 }
121 121
122 ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode( 122 ui::devtools::protocol::Response UIDevToolsCSSAgent::getMatchedStylesForNode(
123 int node_id, 123 int node_id,
124 ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>* 124 ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>*
125 inline_style) { 125 inline_style) {
126 *inline_style = GetStylesForNode(node_id); 126 *inline_style = GetStylesForNode(node_id);
127 if (!inline_style) 127 if (!inline_style)
128 return NodeNotFoundError(node_id); 128 return NodeNotFoundError(node_id);
129 return ui::devtools::protocol::Response::OK(); 129 return ui::devtools::protocol::Response::OK();
130 } 130 }
131 131
132 ui::devtools::protocol::Response AshDevToolsCSSAgent::setStyleTexts( 132 ui::devtools::protocol::Response UIDevToolsCSSAgent::setStyleTexts(
133 std::unique_ptr<ui::devtools::protocol::Array< 133 std::unique_ptr<ui::devtools::protocol::Array<
134 ui::devtools::protocol::CSS::StyleDeclarationEdit>> edits, 134 ui::devtools::protocol::CSS::StyleDeclarationEdit>> edits,
135 std::unique_ptr< 135 std::unique_ptr<
136 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>* 136 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>*
137 result) { 137 result) {
138 std::unique_ptr< 138 std::unique_ptr<
139 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>> 139 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>
140 updated_styles = ui::devtools::protocol::Array< 140 updated_styles = ui::devtools::protocol::Array<
141 ui::devtools::protocol::CSS::CSSStyle>::create(); 141 ui::devtools::protocol::CSS::CSSStyle>::create();
142 for (size_t i = 0; i < edits->length(); i++) { 142 for (size_t i = 0; i < edits->length(); i++) {
(...skipping 14 matching lines...) Expand all
157 157
158 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible)); 158 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible));
159 159
160 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible)) 160 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible))
161 return NodeNotFoundError(node_id); 161 return NodeNotFoundError(node_id);
162 } 162 }
163 *result = std::move(updated_styles); 163 *result = std::move(updated_styles);
164 return ui::devtools::protocol::Response::OK(); 164 return ui::devtools::protocol::Response::OK();
165 } 165 }
166 166
167 void AshDevToolsCSSAgent::OnNodeBoundsChanged(int node_id) { 167 void UIDevToolsCSSAgent::OnNodeBoundsChanged(int node_id) {
168 InvalidateStyleSheet(node_id); 168 InvalidateStyleSheet(node_id);
169 } 169 }
170 170
171 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> 171 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
172 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { 172 UIDevToolsCSSAgent::GetStylesForNode(int node_id) {
173 gfx::Rect bounds; 173 gfx::Rect bounds;
174 bool visible = false; 174 bool visible = false;
175 return GetPropertiesForNodeId(node_id, &bounds, &visible) 175 return GetPropertiesForNodeId(node_id, &bounds, &visible)
176 ? BuildCSSStyle(node_id, bounds, visible) 176 ? BuildCSSStyle(node_id, bounds, visible)
177 : nullptr; 177 : nullptr;
178 } 178 }
179 179
180 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { 180 void UIDevToolsCSSAgent::InvalidateStyleSheet(int node_id) {
181 // 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).
182 frontend()->styleSheetChanged(base::IntToString(node_id)); 182 frontend()->styleSheetChanged(base::IntToString(node_id));
183 } 183 }
184 184
185 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, 185 bool UIDevToolsCSSAgent::GetPropertiesForNodeId(int node_id,
186 gfx::Rect* bounds, 186 gfx::Rect* bounds,
187 bool* visible) { 187 bool* visible) {
188 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 188 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id);
189 if (ui_element) { 189 if (ui_element) {
190 ui_element->GetBounds(bounds); 190 ui_element->GetBounds(bounds);
191 ui_element->GetVisible(visible); 191 ui_element->GetVisible(visible);
192 return true; 192 return true;
193 } 193 }
194 return false; 194 return false;
195 } 195 }
196 196
197 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, 197 bool UIDevToolsCSSAgent::SetPropertiesForNodeId(int node_id,
198 const gfx::Rect& bounds, 198 const gfx::Rect& bounds,
199 bool visible) { 199 bool visible) {
200 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 200 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id);
201 if (ui_element) { 201 if (ui_element) {
202 ui_element->SetBounds(bounds); 202 ui_element->SetBounds(bounds);
203 ui_element->SetVisible(visible); 203 ui_element->SetVisible(visible);
204 return true; 204 return true;
205 } 205 }
206 return false; 206 return false;
207 } 207 }
208 208
209 } // namespace devtools 209 } // namespace devtools
210 } // namespace ash 210 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698