Commit 490c27ba authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Deliver bounds information to CreateTooltipWidget

When 'CreateTooltipWidget' creates 'Widget' for tooltip and
initializes it, it needs its bounds at InitParams. If it
doesn't have the bounds information, some platform widgets
get crashed and DesktopWindowTreeHostX11 keeps
|sanitized_params| to avoid this case.

This patch delivers the bounds for the tooltip widget and
adds DCHECK to find what causes the empty bounds.

Bug: 849585
Change-Id: I3de067a917e4343bab642c3a1b13434b6cfaeee0
Reviewed-on: https://chromium-review.googlesource.com/1086820Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#582426}
parent 4c172804
...@@ -164,6 +164,8 @@ void X11WindowBase::Close() { ...@@ -164,6 +164,8 @@ void X11WindowBase::Close() {
} }
void X11WindowBase::SetBounds(const gfx::Rect& bounds) { void X11WindowBase::SetBounds(const gfx::Rect& bounds) {
DCHECK(!bounds.size().IsEmpty());
if (xwindow_ != x11::None) { if (xwindow_ != x11::None) {
XWindowChanges changes = {0}; XWindowChanges changes = {0};
unsigned value_mask = 0; unsigned value_mask = 0;
......
...@@ -42,7 +42,8 @@ bool CanUseTranslucentTooltipWidget() { ...@@ -42,7 +42,8 @@ bool CanUseTranslucentTooltipWidget() {
} }
// Creates a widget of type TYPE_TOOLTIP // Creates a widget of type TYPE_TOOLTIP
views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { views::Widget* CreateTooltipWidget(aura::Window* tooltip_window,
const gfx::Rect& bounds) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params; views::Widget::InitParams params;
// For aura, since we set the type to TYPE_TOOLTIP, the widget will get // For aura, since we set the type to TYPE_TOOLTIP, the widget will get
...@@ -52,6 +53,7 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { ...@@ -52,6 +53,7 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) {
DCHECK(params.context); DCHECK(params.context);
params.keep_on_top = true; params.keep_on_top = true;
params.accept_events = false; params.accept_events = false;
params.bounds = bounds;
if (CanUseTranslucentTooltipWidget()) if (CanUseTranslucentTooltipWidget())
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
...@@ -166,8 +168,8 @@ gfx::RenderText* TooltipAura::GetRenderTextForTest() { ...@@ -166,8 +168,8 @@ gfx::RenderText* TooltipAura::GetRenderTextForTest() {
return tooltip_view_->render_text_for_test(); return tooltip_view_->render_text_for_test();
} }
void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos, gfx::Rect TooltipAura::GetTooltipBounds(const gfx::Point& mouse_pos,
const gfx::Size& tooltip_size) { const gfx::Size& tooltip_size) {
gfx::Rect tooltip_rect(mouse_pos, tooltip_size); gfx::Rect tooltip_rect(mouse_pos, tooltip_size);
tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
display::Screen* screen = display::Screen::GetScreen(); display::Screen* screen = display::Screen::GetScreen();
...@@ -186,7 +188,7 @@ void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos, ...@@ -186,7 +188,7 @@ void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
tooltip_rect.set_y(mouse_pos.y() - tooltip_size.height()); tooltip_rect.set_y(mouse_pos.y() - tooltip_size.height());
tooltip_rect.AdjustToFit(display_bounds); tooltip_rect.AdjustToFit(display_bounds);
widget_->SetBounds(tooltip_rect); return tooltip_rect;
} }
void TooltipAura::DestroyWidget() { void TooltipAura::DestroyWidget() {
...@@ -210,14 +212,17 @@ void TooltipAura::SetText(aura::Window* window, ...@@ -210,14 +212,17 @@ void TooltipAura::SetText(aura::Window* window,
tooltip_view_->SetMaxWidth(GetMaxWidth(location)); tooltip_view_->SetMaxWidth(GetMaxWidth(location));
tooltip_view_->SetText(tooltip_text); tooltip_view_->SetText(tooltip_text);
const gfx::Rect adjusted_bounds =
GetTooltipBounds(location, tooltip_view_->GetPreferredSize());
if (!widget_) { if (!widget_) {
widget_ = CreateTooltipWidget(tooltip_window_); widget_ = CreateTooltipWidget(tooltip_window_, adjusted_bounds);
widget_->SetContentsView(tooltip_view_.get()); widget_->SetContentsView(tooltip_view_.get());
widget_->AddObserver(this); widget_->AddObserver(this);
} else {
widget_->SetBounds(adjusted_bounds);
} }
SetTooltipBounds(location, tooltip_view_->GetPreferredSize());
ui::NativeTheme* native_theme = widget_->GetNativeTheme(); ui::NativeTheme* native_theme = widget_->GetNativeTheme();
tooltip_view_->SetBackgroundColor(native_theme->GetSystemColor( tooltip_view_->SetBackgroundColor(native_theme->GetSystemColor(
ui::NativeTheme::kColorId_TooltipBackground)); ui::NativeTheme::kColorId_TooltipBackground));
......
...@@ -38,9 +38,9 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver { ...@@ -38,9 +38,9 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
gfx::RenderText* GetRenderTextForTest(); gfx::RenderText* GetRenderTextForTest();
// Adjusts the bounds given by the arguments to fit inside the desktop // Adjusts the bounds given by the arguments to fit inside the desktop
// and applies the adjusted bounds to the label_. // and returns the adjusted bounds.
void SetTooltipBounds(const gfx::Point& mouse_pos, gfx::Rect GetTooltipBounds(const gfx::Point& mouse_pos,
const gfx::Size& tooltip_size); const gfx::Size& tooltip_size);
// Destroys |widget_|. // Destroys |widget_|.
void DestroyWidget(); void DestroyWidget();
......
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