Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/devtools/ash_devtools_css_agent.h" | |
| 6 | |
| 7 #include "ash/common/wm_window.h" | |
| 8 | |
| 9 namespace ash { | |
| 10 namespace devtools { | |
| 11 | |
| 12 namespace { | |
| 13 using namespace ui::devtools::protocol; | |
| 14 | |
| 15 std::unique_ptr<CSS::CSSProperty> BuildCSSProperty(const std::string& name, | |
| 16 int value) { | |
| 17 return CSS::CSSProperty::create() | |
| 18 .setName(name) | |
| 19 .setValue(base::IntToString(value)) | |
| 20 .build(); | |
| 21 } | |
| 22 | |
| 23 std::unique_ptr<CSS::ShorthandEntry> BuildShorthandEntry( | |
| 24 const std::string& name, | |
| 25 int value) { | |
| 26 return CSS::ShorthandEntry::create() | |
| 27 .setName(name) | |
| 28 .setValue(base::IntToString(value)) | |
| 29 .build(); | |
| 30 } | |
| 31 | |
| 32 std::unique_ptr<Array<CSS::CSSProperty>> BuildBoundsCSSPropertyArray( | |
| 33 const gfx::Rect& bounds) { | |
| 34 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.
| |
| 35 Array<CSS::CSSProperty>::create(); | |
| 36 cssProperties->addItem(BuildCSSProperty("height", bounds.height())); | |
| 37 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.
| |
| 38 return cssProperties; | |
| 39 } | |
| 40 | |
| 41 std::unique_ptr<Array<CSS::ShorthandEntry>> BuildBoundsShorthandEntryArray( | |
| 42 const gfx::Rect& bounds) { | |
| 43 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.
| |
| 44 Array<CSS::ShorthandEntry>::create(); | |
| 45 shorthandEntries->addItem(BuildShorthandEntry("height", bounds.height())); | |
| 46 shorthandEntries->addItem(BuildShorthandEntry("width", bounds.width())); | |
| 47 return shorthandEntries; | |
| 48 } | |
| 49 | |
| 50 std::unique_ptr<CSS::CSSStyle> BuildCSSStyle( | |
| 51 std::unique_ptr<Array<CSS::CSSProperty>> cssProperties, | |
| 52 std::unique_ptr<Array<CSS::ShorthandEntry>> shorthandEntries) { | |
| 53 return CSS::CSSStyle::create() | |
| 54 .setCssProperties(std::move(cssProperties)) | |
| 55 .setShorthandEntries(std::move(shorthandEntries)) | |
| 56 .build(); | |
| 57 } | |
| 58 | |
| 59 std::unique_ptr<CSS::CSSStyle> BuildCSSStyleForBounds(const gfx::Rect& bounds) { | |
| 60 return BuildCSSStyle(BuildBoundsCSSPropertyArray(bounds), | |
| 61 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
| |
| 62 } | |
| 63 | |
| 64 std::unique_ptr<CSS::CSSStyle> BuildStyles(WmWindow* window) { | |
| 65 return BuildCSSStyleForBounds(window->GetBounds()); | |
| 66 } | |
| 67 | |
| 68 std::unique_ptr<CSS::CSSStyle> BuildStyles(views::Widget* widget) { | |
| 69 return BuildCSSStyleForBounds(widget->GetWindowBoundsInScreen()); | |
| 70 } | |
| 71 | |
| 72 std::unique_ptr<CSS::CSSStyle> BuildStyles(views::View* view) { | |
| 73 return BuildCSSStyleForBounds(view->bounds()); | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent) | |
| 79 : dom_agent_(dom_agent) { | |
| 80 DCHECK(dom_agent_); | |
| 81 } | |
| 82 | |
| 83 AshDevToolsCSSAgent::~AshDevToolsCSSAgent() {} | |
| 84 | |
| 85 ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode( | |
| 86 int nodeId, | |
| 87 ui::devtools::protocol::Maybe<ui::devtools::protocol::CSS::CSSStyle>* | |
| 88 inlineStyle) { | |
| 89 *inlineStyle = GetStylesForNode(nodeId); | |
| 90 return ui::devtools::protocol::Response::OK(); | |
| 91 } | |
| 92 | |
| 93 std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> | |
| 94 AshDevToolsCSSAgent::GetStylesForNode(int nodeId) { | |
| 95 WmWindow* window = dom_agent_->GetWindowFromNodeId(nodeId); | |
| 96 if (window) | |
| 97 return BuildStyles(window); | |
| 98 | |
| 99 views::Widget* widget = dom_agent_->GetWidgetFromNodeId(nodeId); | |
| 100 if (widget) | |
| 101 return BuildStyles(widget); | |
| 102 | |
| 103 views::View* view = dom_agent_->GetViewFromNodeId(nodeId); | |
| 104 if (view) | |
| 105 return BuildStyles(view); | |
| 106 | |
| 107 NOTREACHED(); | |
| 108 return nullptr; | |
| 109 } | |
| 110 | |
| 111 } // namespace devtools | |
| 112 } // namespace ash | |
| OLD | NEW |