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

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

Issue 2852733002: Duplicate -Move DevTools out of ash and turn it to a component. (Closed)
Patch Set: move unittest to ui/views Created 3 years, 7 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/devtools/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/devtools/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
16 using namespace ui::devtools::protocol; 15 using namespace ui::devtools::protocol;
17 16
18 const char kHeight[] = "height"; 17 const char kHeight[] = "height";
19 const char kWidth[] = "width"; 18 const char kWidth[] = "width";
20 const char kX[] = "x"; 19 const char kX[] = "x";
21 const char kY[] = "y"; 20 const char kY[] = "y";
22 const char kVisibility[] = "visibility"; 21 const char kVisibility[] = "visibility";
23 22
24 std::unique_ptr<CSS::SourceRange> BuildDefaultSourceRange() { 23 std::unique_ptr<CSS::SourceRange> BuildDefaultSourceRange() {
25 // These tell the frontend where in the stylesheet a certain style 24 // These tell the frontend where in the stylesheet a certain style
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 else if (property == kVisibility) 92 else if (property == kVisibility)
94 *visible = std::max(0, value) == 1; 93 *visible = std::max(0, value) == 1;
95 else 94 else
96 return Response::Error("Unsupported property=" + property); 95 return Response::Error("Unsupported property=" + property);
97 } 96 }
98 return Response::OK(); 97 return Response::OK();
99 } 98 }
100 99
101 } // namespace 100 } // namespace
102 101
103 AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent) 102 UIDevToolsCSSAgent::UIDevToolsCSSAgent(UIDevToolsDOMAgent* dom_agent)
104 : dom_agent_(dom_agent) { 103 : dom_agent_(dom_agent) {
105 DCHECK(dom_agent_); 104 DCHECK(dom_agent_);
106 } 105 }
107 106
108 AshDevToolsCSSAgent::~AshDevToolsCSSAgent() { 107 UIDevToolsCSSAgent::~UIDevToolsCSSAgent() {
109 disable(); 108 disable();
110 } 109 }
111 110
112 ui::devtools::protocol::Response AshDevToolsCSSAgent::enable() { 111 ui::devtools::protocol::Response UIDevToolsCSSAgent::enable() {
113 dom_agent_->AddObserver(this); 112 dom_agent_->AddObserver(this);
114 return ui::devtools::protocol::Response::OK(); 113 return ui::devtools::protocol::Response::OK();
115 } 114 }
116 115
117 ui::devtools::protocol::Response AshDevToolsCSSAgent::disable() { 116 ui::devtools::protocol::Response UIDevToolsCSSAgent::disable() {
118 dom_agent_->RemoveObserver(this); 117 dom_agent_->RemoveObserver(this);
119 return ui::devtools::protocol::Response::OK(); 118 return ui::devtools::protocol::Response::OK();
120 } 119 }
121 120
122 ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode( 121 ui::devtools::protocol::Response UIDevToolsCSSAgent::getMatchedStylesForNode(
123 int node_id, 122 int node_id,
124 ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>* 123 ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>*
125 inline_style) { 124 inline_style) {
126 *inline_style = GetStylesForNode(node_id); 125 *inline_style = GetStylesForNode(node_id);
127 if (!inline_style) 126 if (!inline_style)
128 return NodeNotFoundError(node_id); 127 return NodeNotFoundError(node_id);
129 return ui::devtools::protocol::Response::OK(); 128 return ui::devtools::protocol::Response::OK();
130 } 129 }
131 130
132 ui::devtools::protocol::Response AshDevToolsCSSAgent::setStyleTexts( 131 ui::devtools::protocol::Response UIDevToolsCSSAgent::setStyleTexts(
133 std::unique_ptr<ui::devtools::protocol::Array< 132 std::unique_ptr<ui::devtools::protocol::Array<
134 ui::devtools::protocol::CSS::StyleDeclarationEdit>> edits, 133 ui::devtools::protocol::CSS::StyleDeclarationEdit>> edits,
135 std::unique_ptr< 134 std::unique_ptr<
136 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>* 135 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>*
137 result) { 136 result) {
138 std::unique_ptr< 137 std::unique_ptr<
139 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>> 138 ui::devtools::protocol::Array<ui::devtools::protocol::CSS::CSSStyle>>
140 updated_styles = ui::devtools::protocol::Array< 139 updated_styles = ui::devtools::protocol::Array<
141 ui::devtools::protocol::CSS::CSSStyle>::create(); 140 ui::devtools::protocol::CSS::CSSStyle>::create();
142 for (size_t i = 0; i < edits->length(); i++) { 141 for (size_t i = 0; i < edits->length(); i++) {
(...skipping 14 matching lines...) Expand all
157 156
158 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible)); 157 updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible));
159 158
160 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible)) 159 if (!SetPropertiesForNodeId(node_id, updated_bounds, visible))
161 return NodeNotFoundError(node_id); 160 return NodeNotFoundError(node_id);
162 } 161 }
163 *result = std::move(updated_styles); 162 *result = std::move(updated_styles);
164 return ui::devtools::protocol::Response::OK(); 163 return ui::devtools::protocol::Response::OK();
165 } 164 }
166 165
167 void AshDevToolsCSSAgent::OnNodeBoundsChanged(int node_id) { 166 void UIDevToolsCSSAgent::OnNodeBoundsChanged(int node_id) {
168 InvalidateStyleSheet(node_id); 167 InvalidateStyleSheet(node_id);
169 } 168 }
170 169
171 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> 170 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
172 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { 171 UIDevToolsCSSAgent::GetStylesForNode(int node_id) {
173 gfx::Rect bounds; 172 gfx::Rect bounds;
174 bool visible = false; 173 bool visible = false;
175 return GetPropertiesForNodeId(node_id, &bounds, &visible) 174 return GetPropertiesForNodeId(node_id, &bounds, &visible)
176 ? BuildCSSStyle(node_id, bounds, visible) 175 ? BuildCSSStyle(node_id, bounds, visible)
177 : nullptr; 176 : nullptr;
178 } 177 }
179 178
180 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { 179 void UIDevToolsCSSAgent::InvalidateStyleSheet(int node_id) {
181 // The stylesheetId for each node is equivalent to its node_id (as a string). 180 // The stylesheetId for each node is equivalent to its node_id (as a string).
182 frontend()->styleSheetChanged(base::IntToString(node_id)); 181 frontend()->styleSheetChanged(base::IntToString(node_id));
183 } 182 }
184 183
185 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, 184 bool UIDevToolsCSSAgent::GetPropertiesForNodeId(int node_id,
186 gfx::Rect* bounds, 185 gfx::Rect* bounds,
187 bool* visible) { 186 bool* visible) {
188 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 187 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id);
189 if (ui_element) { 188 if (ui_element) {
190 ui_element->GetBounds(bounds); 189 ui_element->GetBounds(bounds);
191 ui_element->GetVisible(visible); 190 ui_element->GetVisible(visible);
192 return true; 191 return true;
193 } 192 }
194 return false; 193 return false;
195 } 194 }
196 195
197 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, 196 bool UIDevToolsCSSAgent::SetPropertiesForNodeId(int node_id,
198 const gfx::Rect& bounds, 197 const gfx::Rect& bounds,
199 bool visible) { 198 bool visible) {
200 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 199 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id);
201 if (ui_element) { 200 if (ui_element) {
202 ui_element->SetBounds(bounds); 201 ui_element->SetBounds(bounds);
203 ui_element->SetVisible(visible); 202 ui_element->SetVisible(visible);
204 return true; 203 return true;
205 } 204 }
206 return false; 205 return false;
207 } 206 }
208 207
209 } // namespace devtools 208 } // namespace devtools
210 } // namespace ash 209 } // namespace ui
OLDNEW
« no previous file with comments | « components/ui_devtools/devtools/ui_devtools_css_agent.h ('k') | components/ui_devtools/devtools/ui_devtools_dom_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698