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

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

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . Created 3 years, 9 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/common/devtools/ash_devtools_css_agent.h" 5 #include "ash/common/devtools/ash_devtools_css_agent.h"
6 6
7 #include "ash/common/wm_window.h" 7 #include "ash/common/wm_window.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::OnUIElementBoundsChanged(UIElement* ui_element) {
167 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWindow(window)); 167 InvalidateStyleSheet(ui_element->GetNodeId());
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 } 168 }
177 169
178 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> 170 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
179 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { 171 AshDevToolsCSSAgent::GetStylesForNode(int node_id) {
180 gfx::Rect bounds; 172 gfx::Rect bounds;
181 bool visible = false; 173 bool visible = false;
182 return GetPropertiesForNodeId(node_id, &bounds, &visible) 174 return GetPropertiesForNodeId(node_id, &bounds, &visible)
183 ? BuildCSSStyle(node_id, bounds, visible) 175 ? BuildCSSStyle(node_id, bounds, visible)
184 : nullptr; 176 : nullptr;
185 } 177 }
186 178
187 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { 179 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) {
188 // 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).
189 frontend()->styleSheetChanged(base::IntToString(node_id)); 181 frontend()->styleSheetChanged(base::IntToString(node_id));
190 } 182 }
191 183
192 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, 184 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id,
193 gfx::Rect* bounds, 185 gfx::Rect* bounds,
194 bool* visible) { 186 bool* visible) {
195 WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); 187 UIElement* ui_element = UIElement::GetUIElementByNodeId(node_id);
196 if (window) { 188 if (ui_element->GetBounds(bounds) && ui_element->GetVisible(visible))
197 *bounds = window->GetBounds();
198 *visible = window->IsVisible();
199 return true; 189 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; 190 return false;
214 } 191 }
215 192
216 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, 193 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id,
217 const gfx::Rect& bounds, 194 const gfx::Rect& bounds,
218 bool visible) { 195 bool visible) {
219 WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); 196 UIElement* ui_element = UIElement::GetUIElementByNodeId(node_id);
220 if (window) { 197 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; 198 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; 199 return false;
249 } 200 }
250 201
251 } // namespace devtools 202 } // namespace devtools
252 } // namespace ash 203 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698