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

Unified Diff: ash/common/devtools/ash_devtools_css_agent.cc

Issue 2526103002: Add live updates for AshDevToolsCSSAgent (Closed)
Patch Set: Override enable/disable methods to attach/detach observer to DOMAgent Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/devtools/ash_devtools_css_agent.h ('k') | ash/common/devtools/ash_devtools_dom_agent.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/devtools/ash_devtools_css_agent.cc
diff --git a/ash/common/devtools/ash_devtools_css_agent.cc b/ash/common/devtools/ash_devtools_css_agent.cc
index ac41162ca2fdb5ce4e0b2bae39ec7289da7a40df..aebfb21763dc9ef264594363dead046a5d08a875 100644
--- a/ash/common/devtools/ash_devtools_css_agent.cc
+++ b/ash/common/devtools/ash_devtools_css_agent.cc
@@ -30,67 +30,80 @@ std::unique_ptr<Array<CSS::CSSProperty>> BuildBoundsCSSPropertyArray(
return cssProperties;
}
-std::unique_ptr<CSS::CSSStyle> BuildCSSStyle(
- std::unique_ptr<Array<CSS::CSSProperty>> cssProperties) {
+std::unique_ptr<CSS::CSSStyle> BuildCSSStyle(int node_id,
+ const gfx::Rect& bounds) {
return CSS::CSSStyle::create()
- .setCssProperties(std::move(cssProperties))
+ .setCssProperties(BuildBoundsCSSPropertyArray(bounds))
.setShorthandEntries(Array<std::string>::create())
.build();
}
-std::unique_ptr<CSS::CSSStyle> BuildCSSStyleForBounds(const gfx::Rect& bounds) {
- return BuildCSSStyle(BuildBoundsCSSPropertyArray(bounds));
-}
+} // namespace
-std::unique_ptr<CSS::CSSStyle> BuildStyles(WmWindow* window) {
- return BuildCSSStyleForBounds(window->GetBounds());
+AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent)
+ : dom_agent_(dom_agent) {
+ DCHECK(dom_agent_);
}
-std::unique_ptr<CSS::CSSStyle> BuildStyles(views::Widget* widget) {
- return BuildCSSStyleForBounds(widget->GetWindowBoundsInScreen());
+AshDevToolsCSSAgent::~AshDevToolsCSSAgent() {
+ disable();
}
-std::unique_ptr<CSS::CSSStyle> BuildStyles(views::View* view) {
- return BuildCSSStyleForBounds(view->bounds());
+ui::devtools::protocol::Response AshDevToolsCSSAgent::enable() {
+ dom_agent_->AddObserver(this);
+ return ui::devtools::protocol::Response::OK();
}
-} // namespace
-
-AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent)
- : dom_agent_(dom_agent) {
- DCHECK(dom_agent_);
+ui::devtools::protocol::Response AshDevToolsCSSAgent::disable() {
+ dom_agent_->RemoveObserver(this);
+ return ui::devtools::protocol::Response::OK();
}
-AshDevToolsCSSAgent::~AshDevToolsCSSAgent() {}
-
ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode(
int node_id,
ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>*
- inlineStyle) {
- *inlineStyle = GetStylesForNode(node_id);
- if (!inlineStyle) {
+ inline_style) {
+ *inline_style = GetStylesForNode(node_id);
+ if (!inline_style) {
return ui::devtools::protocol::Response::Error(
"Node with that id not found");
}
return ui::devtools::protocol::Response::OK();
}
+void AshDevToolsCSSAgent::OnWindowBoundsChanged(WmWindow* window) {
+ InvalidateStyleSheet(dom_agent_->GetNodeIdFromWindow(window));
+}
+
+void AshDevToolsCSSAgent::OnWidgetBoundsChanged(views::Widget* widget) {
+ InvalidateStyleSheet(dom_agent_->GetNodeIdFromWidget(widget));
+}
+
+void AshDevToolsCSSAgent::OnViewBoundsChanged(views::View* view) {
+ InvalidateStyleSheet(dom_agent_->GetNodeIdFromView(view));
+}
+
std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
AshDevToolsCSSAgent::GetStylesForNode(int node_id) {
WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id);
if (window)
- return BuildStyles(window);
+ return BuildCSSStyle(node_id, window->GetBounds());
views::Widget* widget = dom_agent_->GetWidgetFromNodeId(node_id);
if (widget)
- return BuildStyles(widget);
+ return BuildCSSStyle(node_id, widget->GetWindowBoundsInScreen());
views::View* view = dom_agent_->GetViewFromNodeId(node_id);
if (view)
- return BuildStyles(view);
+ return BuildCSSStyle(node_id, view->bounds());
return nullptr;
}
+void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) {
+ // The stylesheetId for each node is equivalent to its node_id (as a string).
+ frontend()->styleSheetChanged(base::IntToString(node_id));
+}
+
} // namespace devtools
} // namespace ash
« no previous file with comments | « ash/common/devtools/ash_devtools_css_agent.h ('k') | ash/common/devtools/ash_devtools_dom_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698