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

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

Issue 2486543003: Add CSS agent for various window/widget/view attributes in devtools (Closed)
Patch Set: Add CSS agent for various window/widget/view attributes in devtools 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
new file mode 100644
index 0000000000000000000000000000000000000000..177a5ab7748b0931dc38b702fbc4bb2a49d36250
--- /dev/null
+++ b/ash/common/devtools/ash_devtools_css_agent.cc
@@ -0,0 +1,112 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/common/devtools/ash_devtools_css_agent.h"
+
+#include "ash/common/wm_window.h"
+
+namespace ash {
+namespace devtools {
+
+namespace {
+using namespace ui::devtools::protocol;
+
+std::unique_ptr<CSS::CSSProperty> BuildCSSProperty(const std::string& name,
+ int value) {
+ return CSS::CSSProperty::create()
+ .setName(name)
+ .setValue(base::IntToString(value))
+ .build();
+}
+
+std::unique_ptr<CSS::ShorthandEntry> BuildShorthandEntry(
+ const std::string& name,
+ int value) {
+ return CSS::ShorthandEntry::create()
+ .setName(name)
+ .setValue(base::IntToString(value))
+ .build();
+}
+
+std::unique_ptr<Array<CSS::CSSProperty>> BuildBoundsCSSPropertyArray(
+ const gfx::Rect& bounds) {
+ std::unique_ptr<Array<CSS::CSSProperty>> cssProperties =
sadrul 2016/11/10 20:34:14 You can use auto here if you want.
Sarmad Hashmi 2016/11/15 17:02:02 Done.
+ Array<CSS::CSSProperty>::create();
+ cssProperties->addItem(BuildCSSProperty("height", bounds.height()));
+ cssProperties->addItem(BuildCSSProperty("width", bounds.width()));
sadrul 2016/11/10 20:34:14 Add "x" and "y" too?
Sarmad Hashmi 2016/11/15 17:02:02 Done.
+ return cssProperties;
+}
+
+std::unique_ptr<Array<CSS::ShorthandEntry>> BuildBoundsShorthandEntryArray(
+ const gfx::Rect& bounds) {
+ std::unique_ptr<Array<CSS::ShorthandEntry>> shorthandEntries =
sadrul 2016/11/10 20:34:14 ditto
Sarmad Hashmi 2016/11/15 17:02:02 Removed this.
+ Array<CSS::ShorthandEntry>::create();
+ shorthandEntries->addItem(BuildShorthandEntry("height", bounds.height()));
+ shorthandEntries->addItem(BuildShorthandEntry("width", bounds.width()));
+ return shorthandEntries;
+}
+
+std::unique_ptr<CSS::CSSStyle> BuildCSSStyle(
+ std::unique_ptr<Array<CSS::CSSProperty>> cssProperties,
+ std::unique_ptr<Array<CSS::ShorthandEntry>> shorthandEntries) {
+ return CSS::CSSStyle::create()
+ .setCssProperties(std::move(cssProperties))
+ .setShorthandEntries(std::move(shorthandEntries))
+ .build();
+}
+
+std::unique_ptr<CSS::CSSStyle> BuildCSSStyleForBounds(const gfx::Rect& bounds) {
+ return BuildCSSStyle(BuildBoundsCSSPropertyArray(bounds),
+ BuildBoundsShorthandEntryArray(bounds));
sadrul 2016/11/10 20:34:14 What is the 'shorthand entry' list?
Sarmad Hashmi 2016/11/15 17:02:02 Frontend requires us to pass this. I took out Shor
+}
+
+std::unique_ptr<CSS::CSSStyle> BuildStyles(WmWindow* window) {
+ return BuildCSSStyleForBounds(window->GetBounds());
+}
+
+std::unique_ptr<CSS::CSSStyle> BuildStyles(views::Widget* widget) {
+ return BuildCSSStyleForBounds(widget->GetWindowBoundsInScreen());
+}
+
+std::unique_ptr<CSS::CSSStyle> BuildStyles(views::View* view) {
+ return BuildCSSStyleForBounds(view->bounds());
+}
+
+} // namespace
+
+AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent)
+ : dom_agent_(dom_agent) {
+ DCHECK(dom_agent_);
+}
+
+AshDevToolsCSSAgent::~AshDevToolsCSSAgent() {}
+
+ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode(
+ int nodeId,
+ ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>*
+ inlineStyle) {
+ *inlineStyle = GetStylesForNode(nodeId);
+ return ui::devtools::protocol::Response::OK();
+}
+
+std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle>
+AshDevToolsCSSAgent::GetStylesForNode(int nodeId) {
+ WmWindow* window = dom_agent_->GetWindowFromNodeId(nodeId);
+ if (window)
+ return BuildStyles(window);
+
+ views::Widget* widget = dom_agent_->GetWidgetFromNodeId(nodeId);
+ if (widget)
+ return BuildStyles(widget);
+
+ views::View* view = dom_agent_->GetViewFromNodeId(nodeId);
+ if (view)
+ return BuildStyles(view);
+
+ NOTREACHED();
+ return nullptr;
+}
+
+} // 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