Commit 7d421c49 authored by Wei Li's avatar Wei Li Committed by Commit Bot

UIDevTools: Don't highlight empty elements

When an empty element is hovered, do not show a tiny highlighted
square. There is no need to highlight in this case. However, for
invisible non-empty element, we still show its bound for information.

BUG=898998

Change-Id: I8d5569710c427011dac90ec5ef9bc4dbc63eadd4
Reviewed-on: https://chromium-review.googlesource.com/c/1309413
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604945}
parent f6fcb2b6
...@@ -503,16 +503,18 @@ Response OverlayAgentAura::HighlightNode(int node_id, bool show_size) { ...@@ -503,16 +503,18 @@ Response OverlayAgentAura::HighlightNode(int node_id, bool show_size) {
highlight_rect_config_ = HighlightRectsConfiguration::NO_DRAW; highlight_rect_config_ = HighlightRectsConfiguration::NO_DRAW;
show_size_on_canvas_ = show_size; show_size_on_canvas_ = show_size;
UpdateHighlight(element->GetNodeWindowAndBounds()); layer_for_highlighting_->SetVisible(
UpdateHighlight(element->GetNodeWindowAndBounds()));
if (!layer_for_highlighting_->visible())
layer_for_highlighting_->SetVisible(true);
return Response::OK(); return Response::OK();
} }
void OverlayAgentAura::UpdateHighlight( bool OverlayAgentAura::UpdateHighlight(
const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds) { const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds) {
if (window_and_bounds.second.IsEmpty()) {
hovered_rect_.SetRect(0, 0, 0, 0);
return false;
}
gfx::NativeWindow root = window_and_bounds.first->GetRootWindow(); gfx::NativeWindow root = window_and_bounds.first->GetRootWindow();
layer_for_highlighting_->SetBounds(root->bounds()); layer_for_highlighting_->SetBounds(root->bounds());
layer_for_highlighting_->SchedulePaint(root->bounds()); layer_for_highlighting_->SchedulePaint(root->bounds());
...@@ -528,6 +530,7 @@ void OverlayAgentAura::UpdateHighlight( ...@@ -528,6 +530,7 @@ void OverlayAgentAura::UpdateHighlight(
gfx::Point origin = hovered_rect_.origin(); gfx::Point origin = hovered_rect_.origin();
screen_position_client->ConvertPointFromScreen(root, &origin); screen_position_client->ConvertPointFromScreen(root, &origin);
hovered_rect_.set_origin(origin); hovered_rect_.set_origin(origin);
return true;
} }
void OverlayAgentAura::OnMouseEvent(ui::MouseEvent* event) { void OverlayAgentAura::OnMouseEvent(ui::MouseEvent* event) {
......
...@@ -67,9 +67,11 @@ class OverlayAgentAura : public OverlayAgent, ...@@ -67,9 +67,11 @@ class OverlayAgentAura : public OverlayAgent,
FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWidget); FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWidget);
#if defined(USE_AURA) #if defined(USE_AURA)
FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWindow); FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWindow);
FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightEmptyOrInvisibleWindow);
#endif #endif
protocol::Response HighlightNode(int node_id, bool show_size = false); protocol::Response HighlightNode(int node_id, bool show_size = false);
void UpdateHighlight( // Returns true when there is any visible element to highlight.
bool UpdateHighlight(
const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds); const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_bounds);
// Shows the distances between the nodes identified by |pinned_id| and // Shows the distances between the nodes identified by |pinned_id| and
......
...@@ -92,6 +92,16 @@ class OverlayAgentTest : public views::ViewsTestBase { ...@@ -92,6 +92,16 @@ class OverlayAgentTest : public views::ViewsTestBase {
node_id)); node_id));
} }
std::unique_ptr<aura::Window> CreateWindowElement(const gfx::Rect& bounds) {
std::unique_ptr<aura::Window> window = std::make_unique<aura::Window>(
nullptr, aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_NOT_DRAWN);
window->SetBounds(bounds);
GetContext()->AddChild(window.get());
window->Show();
return window;
}
std::unique_ptr<views::Widget> CreateWidget() { std::unique_ptr<views::Widget> CreateWidget() {
auto widget = std::make_unique<views::Widget>(); auto widget = std::make_unique<views::Widget>();
views::Widget::InitParams params; views::Widget::InitParams params;
...@@ -333,12 +343,7 @@ TEST_F(OverlayAgentTest, HighlightWindow) { ...@@ -333,12 +343,7 @@ TEST_F(OverlayAgentTest, HighlightWindow) {
dom_agent()->getDocument(&root); dom_agent()->getDocument(&root);
std::unique_ptr<aura::Window> window = std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr, aura::client::WINDOW_TYPE_NORMAL); CreateWindowElement(gfx::Rect(0, 0, 20, 20));
window->Init(ui::LAYER_NOT_DRAWN);
window->SetBounds(gfx::Rect());
GetContext()->AddChild(window.get());
window->Show();
int window_id = int window_id =
dom_agent() dom_agent()
->element_root() ->element_root()
...@@ -355,6 +360,38 @@ TEST_F(OverlayAgentTest, HighlightWindow) { ...@@ -355,6 +360,38 @@ TEST_F(OverlayAgentTest, HighlightWindow) {
overlay_agent()->hideHighlight(); overlay_agent()->hideHighlight();
EXPECT_FALSE(highlightingLayer->visible()); EXPECT_FALSE(highlightingLayer->visible());
} }
TEST_F(OverlayAgentTest, HighlightEmptyOrInvisibleWindow) {
std::unique_ptr<protocol::DOM::Node> root;
dom_agent()->getDocument(&root);
std::unique_ptr<aura::Window> window = CreateWindowElement(gfx::Rect());
int window_id =
dom_agent()
->element_root()
->FindUIElementIdForBackendElement<aura::Window>(window.get());
DCHECK_NE(window_id, 0);
overlay_agent()->highlightNode(nullptr, window_id);
ui::Layer* highlightingLayer = overlay_agent()->layer_for_highlighting();
DCHECK(highlightingLayer);
// Highlight doesn't show for empty element.
EXPECT_FALSE(highlightingLayer->parent());
EXPECT_FALSE(highlightingLayer->visible());
// Make the window non-empty, the highlight shows up.
window->SetBounds(gfx::Rect(10, 10, 50, 50));
overlay_agent()->highlightNode(nullptr, window_id);
EXPECT_EQ(highlightingLayer->parent(), GetContext()->layer());
EXPECT_TRUE(highlightingLayer->visible());
// Make the window invisible, the highlight still shows.
window->Hide();
overlay_agent()->highlightNode(nullptr, window_id);
EXPECT_EQ(highlightingLayer->parent(), GetContext()->layer());
EXPECT_TRUE(highlightingLayer->visible());
}
#endif #endif
TEST_F(OverlayAgentTest, HighlightWidget) { TEST_F(OverlayAgentTest, HighlightWidget) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment