Commit 600525ba authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Revert "Set tooltip widget bounds after the tooltip text colors are set"

This reverts commit crrev.com/c/2181825 in order to fix a tooltip bug
on certain multi-mon setups on Windows. This is not an automatic revert
because subsequent changes required a bit of editing to undo the change.

Manual testing shows that this fixes the multi-mon variable-DPI
tooltip issue, but regresses bug 1053938.

Bug: 1108833, 1053938
Change-Id: I39b9a013ad82c79b2e3cb263e380ad9f3e65554a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380252
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803949}
parent fe40545d
......@@ -209,7 +209,7 @@ gfx::Rect TooltipAura::GetTooltipBounds(const gfx::Point& mouse_pos,
return tooltip_rect;
}
void TooltipAura::CreateTooltipWidget() {
void TooltipAura::CreateTooltipWidget(const gfx::Rect& bounds) {
DCHECK(!widget_);
DCHECK(tooltip_window_);
widget_ = new TooltipWidget;
......@@ -221,6 +221,7 @@ void TooltipAura::CreateTooltipWidget() {
DCHECK(params.context);
params.z_order = ui::ZOrderLevel::kFloatingUIElement;
params.accept_events = false;
params.bounds = bounds;
if (CanUseTranslucentTooltipWidget())
params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;
params.shadow_type = views::Widget::InitParams::ShadowType::kNone;
......@@ -228,7 +229,6 @@ void TooltipAura::CreateTooltipWidget() {
// which just amount to overkill for this UI.
params.force_software_compositing = true;
widget_->Init(std::move(params));
widget_->SetTooltipView(std::make_unique<TooltipView>());
}
void TooltipAura::DestroyWidget() {
......@@ -251,15 +251,21 @@ void TooltipAura::SetText(aura::Window* window,
tooltip_window_ = window;
if (!widget_) {
CreateTooltipWidget();
auto new_tooltip_view = std::make_unique<TooltipView>();
new_tooltip_view->SetMaxWidth(GetMaxWidth(location));
new_tooltip_view->SetText(tooltip_text);
CreateTooltipWidget(
GetTooltipBounds(location, new_tooltip_view->GetPreferredSize()));
widget_->SetTooltipView(std::move(new_tooltip_view));
widget_->AddObserver(this);
} else {
TooltipView* old_tooltip_view = widget_->GetTooltipView();
old_tooltip_view->SetMaxWidth(GetMaxWidth(location));
old_tooltip_view->SetText(tooltip_text);
widget_->SetBounds(
GetTooltipBounds(location, old_tooltip_view->GetPreferredSize()));
}
TooltipView* tooltip_view = widget_->GetTooltipView();
tooltip_view->SetMaxWidth(GetMaxWidth(location));
tooltip_view->SetText(tooltip_text);
ui::NativeTheme* native_theme = widget_->GetNativeTheme();
auto background_color =
native_theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
......@@ -273,19 +279,9 @@ void TooltipAura::SetText(aura::Window* window,
if (!CanUseTranslucentTooltipWidget())
foreground_color =
color_utils::GetResultingPaintColor(foreground_color, background_color);
TooltipView* tooltip_view = widget_->GetTooltipView();
tooltip_view->SetBackgroundColor(background_color, foreground_color);
tooltip_view->SetForegroundColor(foreground_color);
// Calculate the tooltip preferred size after all tooltip attributes are
// updated - tooltip updates (for example setting text color) may invalidate
// the tooltip render text layout, which would make layout run just done to
// calculate the tooltip string size get immendiately disregarded.
// This also addresses https://crbug.com/2181825 (after color update,
// GetPreferredSize() will generate fresh render text layout, even if the
// actual tooltip text hasn't changed).
const gfx::Rect adjusted_bounds =
GetTooltipBounds(location, tooltip_view->GetPreferredSize());
widget_->SetBounds(adjusted_bounds);
}
void TooltipAura::Show() {
......
......@@ -48,7 +48,7 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
const gfx::Size& tooltip_size);
// Sets |widget_| to a new instance of TooltipWidget.
void CreateTooltipWidget();
void CreateTooltipWidget(const gfx::Rect& bounds);
// Destroys |widget_|.
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