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

Side by Side Diff: ash/devtools/ash_devtools_css_agent.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: nits 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 "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 {
13 14
14 namespace { 15 namespace {
15 using namespace ui::devtools::protocol; 16 using namespace ui::devtools::protocol;
16 17
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->GetBounds(bounds) && ui_element->GetVisible(visible))
197 *bounds = window->bounds();
198 *visible = window->IsVisible();
199 return true; 190 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;
212 }
213 return false; 191 return false;
214 } 192 }
215 193
216 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, 194 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id,
217 const gfx::Rect& bounds, 195 const gfx::Rect& bounds,
218 bool visible) { 196 bool visible) {
219 aura::Window* window = dom_agent_->GetWindowFromNodeId(node_id); 197 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id);
220 if (window) { 198 if (ui_element->SetBounds(bounds) && ui_element->SetVisible(visible))
221 window->SetBounds(bounds);
222 if (visible != window->IsVisible()) {
223 if (visible)
224 window->Show();
225 else
226 window->Hide();
227 }
228 return true; 199 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;
247 }
248 return false; 200 return false;
249 } 201 }
250 202
251 } // namespace devtools 203 } // namespace devtools
252 } // namespace ash 204 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698