Chromium Code Reviews| 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 bd13af21dc77bb6c9e5a8d017b276ecfcc3be5a0..8a3e2a89a96ac1066d3ac43fbd00c24efdd505fc 100644 |
| --- a/ash/common/devtools/ash_devtools_css_agent.cc |
| +++ b/ash/common/devtools/ash_devtools_css_agent.cc |
| @@ -19,6 +19,7 @@ const char kHeight[] = "height"; |
| const char kWidth[] = "width"; |
| const char kX[] = "x"; |
| const char kY[] = "y"; |
| +const char kVisibility[] = "visibility"; |
| std::unique_ptr<CSS::SourceRange> BuildDefaultSourceRange() { |
| // These tell the frontend where in the stylesheet a certain style |
| @@ -42,49 +43,29 @@ std::unique_ptr<CSS::CSSProperty> BuildCSSProperty(const std::string& name, |
| .build(); |
| } |
| -std::unique_ptr<Array<CSS::CSSProperty>> BuildBoundsCSSPropertyArray( |
| - const gfx::Rect& bounds) { |
| +std::unique_ptr<Array<CSS::CSSProperty>> BuildCSSPropertyArray( |
| + const gfx::Rect& bounds, |
| + const bool& visible) { |
|
varkha
2017/03/08 15:23:59
Here and below. No need to pass simple types by re
thanhph
2017/03/09 16:30:58
Done.
|
| auto cssProperties = Array<CSS::CSSProperty>::create(); |
| cssProperties->addItem(BuildCSSProperty(kHeight, bounds.height())); |
| cssProperties->addItem(BuildCSSProperty(kWidth, bounds.width())); |
| cssProperties->addItem(BuildCSSProperty(kX, bounds.x())); |
| cssProperties->addItem(BuildCSSProperty(kY, bounds.y())); |
| + cssProperties->addItem(BuildCSSProperty(kVisibility, visible)); |
| return cssProperties; |
| } |
| std::unique_ptr<CSS::CSSStyle> BuildCSSStyle(int node_id, |
| - const gfx::Rect& bounds) { |
| + const gfx::Rect& bounds, |
| + const bool& visible) { |
| return CSS::CSSStyle::create() |
| .setRange(BuildDefaultSourceRange()) |
| .setStyleSheetId(base::IntToString(node_id)) |
| - .setCssProperties(BuildBoundsCSSPropertyArray(bounds)) |
| + .setCssProperties(BuildCSSPropertyArray(bounds, visible)) |
| .setShorthandEntries(Array<std::string>::create()) |
| .build(); |
| } |
| -Response ParseBounds(const std::string& style_text, gfx::Rect& bounds) { |
| - std::vector<std::string> tokens = base::SplitString( |
| - style_text, ":;", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| - for (size_t i = 0; i < tokens.size() - 1; i += 2) { |
| - const std::string& property = tokens.at(i); |
| - int value; |
| - if (!base::StringToInt(tokens.at(i + 1), &value)) |
| - return Response::Error("Unable to parse value for property=" + property); |
| - |
| - if (property == kHeight) |
| - bounds.set_height(std::max(0, value)); |
| - else if (property == kWidth) |
| - bounds.set_width(std::max(0, value)); |
| - else if (property == kX) |
| - bounds.set_x(value); |
| - else if (property == kY) |
| - bounds.set_y(value); |
| - else |
| - return Response::Error("Unsupported property=" + property); |
| - } |
| - return Response::OK(); |
| -} |
| - |
| } // namespace |
| AshDevToolsCSSAgent::AshDevToolsCSSAgent(AshDevToolsDOMAgent* dom_agent) |
| @@ -113,7 +94,7 @@ ui::devtools::protocol::Response AshDevToolsCSSAgent::getMatchedStylesForNode( |
| *inline_style = GetStylesForNode(node_id); |
| if (!inline_style) { |
| return ui::devtools::protocol::Response::Error( |
| - "Node with that id not found"); |
| + "No node id " + std::to_string(node_id) + " found"); |
|
varkha
2017/03/08 15:23:59
Maybe format as "Node with id=<node_id> not found"
sadrul
2017/03/08 15:38:59
+1 re utility method to generate the error message
thanhph
2017/03/09 16:30:58
Done, thanks! A helper function is added in anon n
|
| } |
| return ui::devtools::protocol::Response::OK(); |
| } |
| @@ -135,23 +116,23 @@ ui::devtools::protocol::Response AshDevToolsCSSAgent::setStyleTexts( |
| return ui::devtools::protocol::Response::Error("Invalid node id"); |
| gfx::Rect updated_bounds; |
| - if (!GetBoundsForNodeId(node_id, &updated_bounds)) { |
| + bool visible; |
| + if (!GetNodeIdProperties(node_id, &updated_bounds, &visible)) { |
| return ui::devtools::protocol::Response::Error( |
| - "No node found with that id"); |
| + "No node id " + std::to_string(node_id) + " found"); |
| } |
| - |
| ui::devtools::protocol::Response response( |
| - ParseBounds(edit->getText(), updated_bounds)); |
| + ParseProperties(edit->getText(), &updated_bounds, &visible)); |
| if (!response.isSuccess()) |
| return response; |
| - updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds)); |
| - if (!UpdateBounds(node_id, updated_bounds)) { |
| + updated_styles->addItem(BuildCSSStyle(node_id, updated_bounds, visible)); |
| + |
| + if (!UpdateObjectProperties(node_id, updated_bounds, visible)) { |
| return ui::devtools::protocol::Response::Error( |
| - "No node found with that id"); |
| + "No node id " + std::to_string(node_id) + " found"); |
| } |
| } |
| - |
| *result = std::move(updated_styles); |
| return ui::devtools::protocol::Response::OK(); |
| } |
| @@ -171,8 +152,10 @@ void AshDevToolsCSSAgent::OnViewBoundsChanged(views::View* view) { |
| std::unique_ptr<ui::devtools::protocol::CSS::CSSStyle> |
| AshDevToolsCSSAgent::GetStylesForNode(int node_id) { |
| gfx::Rect bounds; |
| - return GetBoundsForNodeId(node_id, &bounds) ? BuildCSSStyle(node_id, bounds) |
| - : nullptr; |
| + bool visible; |
| + return GetNodeIdProperties(node_id, &bounds, &visible) |
| + ? BuildCSSStyle(node_id, bounds, visible) |
| + : nullptr; |
| } |
| void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { |
| @@ -180,49 +163,91 @@ void AshDevToolsCSSAgent::InvalidateStyleSheet(int node_id) { |
| frontend()->styleSheetChanged(base::IntToString(node_id)); |
| } |
| -bool AshDevToolsCSSAgent::GetBoundsForNodeId(int node_id, gfx::Rect* bounds) { |
| +bool AshDevToolsCSSAgent::GetNodeIdProperties(int node_id, |
| + gfx::Rect* bounds, |
| + bool* visible) { |
| WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); |
| if (window) { |
| *bounds = window->GetBounds(); |
| + *visible = window->IsVisible(); |
| return true; |
| } |
| - |
| views::Widget* widget = dom_agent_->GetWidgetFromNodeId(node_id); |
| if (widget) { |
| *bounds = widget->GetRestoredBounds(); |
| + *visible = widget->IsVisible(); |
| return true; |
| } |
| - |
| views::View* view = dom_agent_->GetViewFromNodeId(node_id); |
| if (view) { |
| *bounds = view->bounds(); |
| + *visible = view->visible(); |
| return true; |
| } |
| - |
| return false; |
| } |
| -bool AshDevToolsCSSAgent::UpdateBounds(int node_id, const gfx::Rect& bounds) { |
| +bool AshDevToolsCSSAgent::UpdateObjectProperties(int node_id, |
| + const gfx::Rect& bounds, |
| + const bool& visible) { |
| WmWindow* window = dom_agent_->GetWindowFromNodeId(node_id); |
| if (window) { |
| window->SetBounds(bounds); |
| + if (visible != window->IsVisible()) { |
| + if (visible) |
| + window->Show(); |
| + else |
| + window->Hide(); |
| + } |
| return true; |
| } |
| - |
| views::Widget* widget = dom_agent_->GetWidgetFromNodeId(node_id); |
| if (widget) { |
| widget->SetBounds(bounds); |
| + if (visible != widget->IsVisible()) { |
| + if (visible) |
| + widget->Show(); |
| + else |
| + widget->Hide(); |
| + } |
| return true; |
| } |
| - |
| views::View* view = dom_agent_->GetViewFromNodeId(node_id); |
| if (view) { |
| view->SetBoundsRect(bounds); |
| + if (visible != view->visible()) |
| + view->SetVisible(visible); |
| return true; |
| } |
| - |
| return false; |
| } |
| +Response AshDevToolsCSSAgent::ParseProperties(const std::string& style_text, |
| + gfx::Rect* bounds, |
| + bool* visible) { |
| + std::vector<std::string> tokens = base::SplitString( |
| + style_text, ":;", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| + for (size_t i = 0; i < tokens.size() - 1; i += 2) { |
| + const std::string& property = tokens.at(i); |
| + int value; |
| + if (!base::StringToInt(tokens.at(i + 1), &value)) |
| + return Response::Error("Unable to parse value for property=" + property); |
| + |
| + if (property == kHeight) |
| + bounds->set_height(std::max(0, value)); |
| + else if (property == kWidth) |
| + bounds->set_width(std::max(0, value)); |
| + else if (property == kX) |
| + bounds->set_x(value); |
| + else if (property == kY) |
| + bounds->set_y(value); |
| + else if (property == kVisibility) |
| + *visible = std::max(0, value) == 1; |
| + else |
| + return Response::Error("Unsupported property=" + property); |
| + } |
| + return Response::OK(); |
| +} |
| + |
| } // namespace devtools |
| } // namespace ash |