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

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

Issue 2899503002: Revert of Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: 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
« no previous file with comments | « ash/devtools/ash_devtools_css_agent.h ('k') | ash/devtools/ash_devtools_dom_agent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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"
10 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
11 10
12 namespace ash { 11 namespace ash {
13 namespace devtools { 12 namespace devtools {
13
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AshDevToolsCSSAgent::OnWindowBoundsChanged(aura::Window* window) {
168 InvalidateStyleSheet(node_id); 167 InvalidateStyleSheet(dom_agent_->GetNodeIdFromWindow(window));
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));
169 } 176 }
170 177
171 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> 178 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
172 AshDevToolsCSSAgent::GetStylesForNode(int node_id) { 179 AshDevToolsCSSAgent::GetStylesForNode(int node_id) {
173 gfx::Rect bounds; 180 gfx::Rect bounds;
174 bool visible = false; 181 bool visible = false;
175 return GetPropertiesForNodeId(node_id, &bounds, &visible) 182 return GetPropertiesForNodeId(node_id, &bounds, &visible)
176 ? BuildCSSStyle(node_id, bounds, visible) 183 ? BuildCSSStyle(node_id, bounds, visible)
177 : nullptr; 184 : nullptr;
178 } 185 }
179 186
180 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { 187 void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) {
181 // The stylesheetId for each node is equivalent to its node_id (as a string). 188 // The stylesheetId for each node is equivalent to its node_id (as a string).
182 frontend()->styleSheetChanged(base::IntToString(node_id)); 189 frontend()->styleSheetChanged(base::IntToString(node_id));
183 } 190 }
184 191
185 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id, 192 bool AshDevToolsCSSAgent::GetPropertiesForNodeId(int node_id,
186 gfx::Rect* bounds, 193 gfx::Rect* bounds,
187 bool* visible) { 194 bool* visible) {
188 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 195 aura::Window* window = dom_agent_->GetWindowFromNodeId(node_id);
189 if (ui_element) { 196 if (window) {
190 ui_element->GetBounds(bounds); 197 *bounds = window->bounds();
191 ui_element->GetVisible(visible); 198 *visible = window->IsVisible();
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();
192 return true; 211 return true;
193 } 212 }
194 return false; 213 return false;
195 } 214 }
196 215
197 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id, 216 bool AshDevToolsCSSAgent::SetPropertiesForNodeId(int node_id,
198 const gfx::Rect& bounds, 217 const gfx::Rect& bounds,
199 bool visible) { 218 bool visible) {
200 UIElement* ui_element = dom_agent_->GetElementFromNodeId(node_id); 219 aura::Window* window = dom_agent_->GetWindowFromNodeId(node_id);
201 if (ui_element) { 220 if (window) {
202 ui_element->SetBounds(bounds); 221 window->SetBounds(bounds);
203 ui_element->SetVisible(visible); 222 if (visible != window->IsVisible()) {
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);
204 return true; 246 return true;
205 } 247 }
206 return false; 248 return false;
207 } 249 }
208 250
209 } // namespace devtools 251 } // namespace devtools
210 } // namespace ash 252 } // namespace ash
OLDNEW
« no previous file with comments | « ash/devtools/ash_devtools_css_agent.h ('k') | ash/devtools/ash_devtools_dom_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698