0

Remove lacros tooltip code from //ui/views

Lacros is deprecated. Remove tooltip code from //ui/views and
also remove tests from test files.

1) Remove code under IS_CHROMEOS_LACROS including call sites and
impls.
2) Remove *_lacros.cc/.h files.
3) Clean up fwd decl and includes (like unnecessary fwd decls while
using objects by value, etc).
4) Remove helper calls (getters/setters) added for tooltip code for
lacros.
5) Remove redundant functions like "UseServerSideTooltip" that has
never been used.

Bug: 374073840, 373971535
Change-Id: Id76c1ffa3827422addba0bad9f241630d8e4e781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5961738
Reviewed-by: Peter Boström <pbos@chromium.org>
Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1374491}
This commit is contained in:
Maksim Sisov
2024-10-28 07:29:41 +00:00
committed by Chromium LUCI CQ
parent b928b027ff
commit e7dc3e39af
21 changed files with 19 additions and 621 deletions

@ -37,51 +37,6 @@ using content::WebContents;
using views::corewm::TooltipController;
using views::corewm::test::TooltipControllerTestHelper;
#if BUILDFLAG(IS_CHROMEOS_LACROS)
class TooltipMonitor : public wm::TooltipObserver {
public:
TooltipMonitor() = default;
TooltipMonitor(const TooltipMonitor&) = delete;
TooltipMonitor& operator=(const TooltipMonitor&) = delete;
~TooltipMonitor() override = default;
bool IsWidgetActive() const { return is_tooltip_active_; }
void WaitUntilTooltipShown() {
if (!is_tooltip_active_) {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
}
void WaitUntilTooltipClosed() {
if (is_tooltip_active_) {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
}
void OnTooltipShown(aura::Window* window,
const std::u16string& text,
const gfx::Rect& bounds) override {
is_tooltip_active_ = true;
if (run_loop_ && run_loop_->running()) {
run_loop_->Quit();
}
}
void OnTooltipHidden(aura::Window* window) override {
is_tooltip_active_ = false;
if (run_loop_ && run_loop_->running()) {
run_loop_->Quit();
}
}
private:
bool is_tooltip_active_ = false;
std::unique_ptr<base::RunLoop> run_loop_;
};
#else
using views::corewm::TooltipAura;
class TooltipMonitor {
@ -138,7 +93,6 @@ class TooltipMonitor {
std::unique_ptr<views::AnyWidgetObserver> observer_;
std::unique_ptr<base::RunLoop> run_loop_;
}; // class TooltipMonitor
#endif // BUILDFLAG(IS_CHROMEOS_LACROS)
// Browser tests for tooltips on platforms that use TooltipAura to display the
// tooltip.
@ -156,9 +110,6 @@ class TooltipBrowserTest : public InProcessBrowserTest {
event_generator_ = std::make_unique<ui::test::EventGenerator>(root_window);
helper_ = std::make_unique<TooltipControllerTestHelper>(root_window);
tooltip_monitor_ = std::make_unique<TooltipMonitor>();
#if BUILDFLAG(IS_CHROMEOS_LACROS)
helper()->AddObserver(tooltip_monitor_.get());
#endif
}
content::WebContents* web_contents() { return web_contents_; }
@ -235,11 +186,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
gfx::Point position = WebContentPositionToScreenCoordinate(10, 10);
event_generator()->MoveMouseTo(position);
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Sends mouse move event to Ash as well to make server side tooltip work.
EXPECT_TRUE(ui_controls::SendMouseMove(
position.x(), position.y(), browser()->window()->GetNativeWindow()));
#endif
tooltip_monitor()->WaitUntilTooltipShown();
EXPECT_TRUE(helper()->IsTooltipVisible());
EXPECT_EQ(expected_text, helper()->GetTooltipText());
@ -250,8 +196,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
// https://crbug.com/1212403. Flaky on linux-chromeos-rel and other linux bots.
// TODO(elkurin): Keyboard triggered tooltip needs command line switch on server
// side while Lacros cannot set Ash flag.
#define MAYBE_ShowTooltipFromWebContentWithKeyboard \
DISABLED_ShowTooltipFromWebContentWithKeyboard
#else
@ -275,8 +219,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
// https://crbug.com/1212403. Flaky on linux-chromeos-rel.
// https://crbug.com/1241736. Flaky on Win.
// TODO(elkurin): Keyboard triggered tooltip needs command line switch on server
// side while Lacros cannot set Ash flag.
IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
DISABLED_ShowTooltipFromIFrameWithKeyboard) {
// There are two tooltips in this file: one above the iframe and one inside
@ -335,11 +277,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
// First, trigger the tooltip from the cursor.
gfx::Point position = WebContentPositionToScreenCoordinate(10, 10);
event_generator()->MoveMouseTo(position);
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Sends mouse move event to Ash as well to make server side tooltip work.
EXPECT_TRUE(ui_controls::SendMouseMove(
position.x(), position.y(), browser()->window()->GetNativeWindow()));
#endif
tooltip_monitor()->WaitUntilTooltipShown();
EXPECT_TRUE(helper()->IsTooltipVisible());
EXPECT_EQ(expected_text, helper()->GetTooltipText());
@ -355,8 +292,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
// https://crbug.com/1212403. Flaky on linux-chromeos-rel.
// https://crbug.com/1241736. Flaky on Win.
// TODO(elkurin): Keyboard triggered tooltip needs command line switch on server
// side while Lacros cannot set Ash flag.
#define MAYBE_HideTooltipOnKeyPressTriggeredByKeyboard \
DISABLED_HideTooltipOnKeyPressTriggeredByKeyboard
#else
@ -385,8 +320,6 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest,
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
// https://crbug.com/1212403. Flaky on linux-chromeos-rel, windows, linux.
// TODO(elkurin): Keyboard triggered tooltip needs command line switch on server
// side while Lacros cannot set Ash flag.
#define MAYBE_ScriptFocusHidesKeyboardTriggeredTooltip \
DISABLED_ScriptFocusHidesKeyboardTriggeredTooltip
#else
@ -447,22 +380,13 @@ IN_PROC_BROWSER_TEST_F(TooltipBrowserTest, ResetTooltipOnClosingWindow) {
// Trigger the tooltip from the cursor.
gfx::Point position = WebContentPositionToScreenCoordinate(10, 10);
event_generator()->MoveMouseTo(position);
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Sends mouse move event to Ash as well to make server side tooltip work.
EXPECT_TRUE(ui_controls::SendMouseMove(
position.x(), position.y(), browser()->window()->GetNativeWindow()));
#endif
tooltip_monitor()->WaitUntilTooltipShown();
EXPECT_TRUE(helper()->IsTooltipVisible());
// Tooltip should be hidden on closing window.
chrome::CloseWindow(browser());
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
// Verify tooltip is closed.
// This is skipped on Lacros since tooltip_controller is destructed before
// receiving OnTooltipHiddenOnServer.
tooltip_monitor()->WaitUntilTooltipClosed();
#endif
// Make sure Chrome won't crash during window destruction.
ui_test_utils::WaitForBrowserToClose();

@ -786,6 +786,7 @@ component("views") {
"accessibility/ax_window_obj_wrapper.h",
"controls/native/native_view_host_aura.h",
"corewm/tooltip.h",
"corewm/tooltip_aura.h",
"corewm/tooltip_controller.h",
"corewm/tooltip_state_manager.h",
"corewm/tooltip_view_aura.h",
@ -814,6 +815,7 @@ component("views") {
"controls/menu/menu_pre_target_handler_aura.cc",
"controls/menu/menu_pre_target_handler_aura.h",
"controls/native/native_view_host_aura.cc",
"corewm/tooltip_aura.cc",
"corewm/tooltip_controller.cc",
"corewm/tooltip_state_manager.cc",
"corewm/tooltip_view_aura.cc",
@ -832,13 +834,6 @@ component("views") {
if (!is_chromeos_ash) {
sources += [ "accessibility/widget_ax_tree_id_map.cc" ]
}
if (is_chromeos_lacros) {
public += [ "corewm/tooltip_lacros.h" ]
sources += [ "corewm/tooltip_lacros.cc" ]
} else {
public += [ "corewm/tooltip_aura.h" ]
sources += [ "corewm/tooltip_aura.cc" ]
}
deps += [
"//ui/aura",
"//ui/base/cursor/mojom:cursor_type_shared",

@ -28,10 +28,6 @@ specific_include_rules = {
"+ui/views/painter.h",
],
"tooltip_lacros.cc": [
"+ui/views/widget/desktop_aura/desktop_window_tree_host_lacros.h",
],
"desktop_capture_controller_unittest.cc": [
"+ui/views/test/native_widget_factory.h",
"+ui/views/test/widget_test.h",

@ -14,13 +14,8 @@ namespace aura {
class Window;
}
namespace base {
class TimeDelta;
}
namespace gfx {
class Point;
class Rect;
} // namespace gfx
namespace wm {
@ -54,18 +49,6 @@ class VIEWS_EXPORT Tooltip {
const gfx::Point& position,
const TooltipTrigger trigger) = 0;
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Sets show/hide delay. Only used for Lacros.
virtual void SetDelay(const base::TimeDelta& show_delay,
const base::TimeDelta& hide_delay) {}
// Called when tooltip is shown/hidden on server.
// Only used by Lacros.
virtual void OnTooltipShownOnServer(const std::u16string& text,
const gfx::Rect& bounds) {}
virtual void OnTooltipHiddenOnServer() {}
#endif // BUILDFLAG(IS_CHROMEOS_LACROS)
// Shows the tooltip at the specified location (in screen coordinates).
virtual void Show() = 0;
@ -74,11 +57,6 @@ class VIEWS_EXPORT Tooltip {
// Is the tooltip visible?
virtual bool IsVisible() = 0;
protected:
// Max visual tooltip width. If a tooltip is greater than this width, it will
// be wrapped.
static constexpr int kTooltipMaxWidth = 800;
};
} // namespace views::corewm

@ -33,11 +33,13 @@
namespace {
// Max visual tooltip width. If a tooltip is greater than this width, it will
// be wrapped.
static constexpr int kTooltipMaxWidth = 800;
// TODO(varkha): Update if native widget can be transparent on Linux.
bool CanUseTranslucentTooltipWidget() {
// TODO(crbug.com/40118868): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) || BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
return false;
#else
return true;
@ -57,7 +59,8 @@ TooltipAura::TooltipAura()
TooltipAura::TooltipAura(
const TooltipAura::TooltipViewFactory& tooltip_view_factory)
: tooltip_view_factory_(tooltip_view_factory) {}
: tooltip_view_factory_(tooltip_view_factory),
max_width_(kTooltipMaxWidth) {}
TooltipAura::~TooltipAura() {
DestroyWidget();

@ -105,7 +105,7 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
// showing.
raw_ptr<aura::Window> tooltip_window_ = nullptr;
int max_width_ = kTooltipMaxWidth;
int max_width_;
// Observes tooltip state change.
base::ObserverList<wm::TooltipObserver> observers_;

@ -10,7 +10,6 @@
#include <utility>
#include <vector>
#include "base/time/time.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/cursor_client.h"
@ -22,9 +21,7 @@
#include "ui/compositor/layer_type.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/views/corewm/tooltip_state_manager.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/wm/public/activation_client.h"
@ -389,18 +386,6 @@ void TooltipController::SetShowTooltipDelay(aura::Window* target,
show_tooltip_delay_map_[target] = delay;
}
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void TooltipController::OnTooltipShownOnServer(aura::Window* window,
const std::u16string& text,
const gfx::Rect& bounds) {
state_manager_->OnTooltipShownOnServer(window, text, bounds);
}
void TooltipController::OnTooltipHiddenOnServer() {
state_manager_->OnTooltipHiddenOnServer();
}
#endif // BUILDFLAG(IS_CHROMEOS_LACROS)
////////////////////////////////////////////////////////////////////////////////
// TooltipController private:

@ -11,11 +11,12 @@
#include <string_view>
#include "base/memory/raw_ptr.h"
#include "build/chromeos_buildflags.h"
#include "base/time/time.h"
#include "ui/aura/client/cursor_client_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/views_export.h"
#include "ui/wm/public/activation_change_observer.h"
@ -25,12 +26,7 @@ namespace aura {
class Window;
}
namespace base {
class TimeDelta;
}
namespace gfx {
class Point;
class Rect;
} // namespace gfx
@ -110,15 +106,6 @@ class VIEWS_EXPORT TooltipController
// Sets show tooltip delay for `target` window.
void SetShowTooltipDelay(aura::Window* target, base::TimeDelta delay);
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Called when tooltip is shown/hidden on server.
// This is only used for Lacros whose tooltip is handled on server-side.
void OnTooltipShownOnServer(aura::Window* window,
const std::u16string& text,
const gfx::Rect& bounds);
void OnTooltipHiddenOnServer();
#endif // BUILDFLA(IS_CHROMEOS_LACROS)
private:
friend class test::TooltipControllerTestHelper;

@ -29,14 +29,6 @@ TooltipControllerTestHelper::~TooltipControllerTestHelper() {
}
}
bool TooltipControllerTestHelper::UseServerSideTooltip() {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
return true;
#else
return false;
#endif
}
const std::u16string& TooltipControllerTestHelper::GetTooltipText() {
return state_manager()->tooltip_text();
}
@ -69,15 +61,6 @@ void TooltipControllerTestHelper::FireHideTooltipTimer() {
state_manager()->HideAndReset();
}
void TooltipControllerTestHelper::AddObserver(wm::TooltipObserver* observer) {
controller_->AddObserver(observer);
}
void TooltipControllerTestHelper::RemoveObserver(
wm::TooltipObserver* observer) {
controller_->RemoveObserver(observer);
}
bool TooltipControllerTestHelper::IsWillShowTooltipTimerRunning() {
return state_manager()->IsWillShowTooltipTimerRunningForTesting();
}

@ -26,10 +26,6 @@ namespace base {
class TimeDelta;
}
namespace wm {
class TooltipObserver;
}
namespace views::corewm::test {
// TooltipControllerTestHelper provides access to TooltipControllers private
@ -54,11 +50,6 @@ class TooltipControllerTestHelper : public aura::WindowObserver {
return controller_->state_manager_.get();
}
// Returns true if server side tooltip is enabled. The server side means
// tooltip is handled on ash (server) and lacros is the client.
// Always returns false except for Lacros.
bool UseServerSideTooltip();
// These are mostly cover methods for TooltipController private methods.
const std::u16string& GetTooltipText();
aura::Window* GetTooltipParentWindow();
@ -68,8 +59,6 @@ class TooltipControllerTestHelper : public aura::WindowObserver {
void HideAndReset();
void UpdateIfRequired(TooltipTrigger trigger);
void FireHideTooltipTimer();
void AddObserver(wm::TooltipObserver* observer);
void RemoveObserver(wm::TooltipObserver* observer);
bool IsWillShowTooltipTimerRunning();
bool IsWillHideTooltipTimerRunning();
bool IsTooltipVisible();

@ -53,65 +53,6 @@
namespace views::corewm::test {
namespace {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
class TestTooltipLacros : public Tooltip {
public:
TestTooltipLacros() = default;
TestTooltipLacros(const TestTooltipLacros&) = delete;
TestTooltipLacros& operator=(const TestTooltipLacros&) = delete;
~TestTooltipLacros() override {
state_manager_ = nullptr;
}
void AddObserver(wm::TooltipObserver* observer) override {}
void RemoveObserver(wm::TooltipObserver* observer) override {}
const std::u16string& tooltip_text() const { return tooltip_text_; }
// Tooltip:
int GetMaxWidth(const gfx::Point& location) const override { return 100; }
void Update(aura::Window* window,
const std::u16string& tooltip_text,
const gfx::Point& position,
const TooltipTrigger trigger) override {
tooltip_parent_ = window;
tooltip_text_ = tooltip_text;
anchor_point_ = position + window->GetBoundsInScreen().OffsetFromOrigin();
trigger_ = trigger;
}
void Show() override {
is_visible_ = true;
DCHECK(state_manager_);
state_manager_->OnTooltipShownOnServer(tooltip_parent_, tooltip_text_,
gfx::Rect());
}
void Hide() override {
is_visible_ = false;
tooltip_parent_ = nullptr;
DCHECK(state_manager_);
state_manager_->OnTooltipHiddenOnServer();
}
bool IsVisible() override { return is_visible_; }
void SetStateManager(TooltipStateManager* state_manager) {
state_manager_ = state_manager;
}
const gfx::Point& anchor_point() { return anchor_point_; }
TooltipTrigger trigger() { return trigger_; }
private:
bool is_visible_ = false;
raw_ptr<aura::Window> tooltip_parent_ = nullptr;
raw_ptr<TooltipStateManager> state_manager_ = nullptr; // not owned.
std::u16string tooltip_text_;
gfx::Point anchor_point_;
TooltipTrigger trigger_;
};
#endif
std::unique_ptr<views::Widget> CreateWidget(aura::Window* root) {
auto widget = std::make_unique<views::Widget>();
views::Widget::InitParams params(Widget::InitParams::CLIENT_OWNS_WIDGET);
@ -160,26 +101,8 @@ class TooltipControllerTest : public ViewsTestBase {
view_ = new TooltipTestView;
widget_->GetContentsView()->AddChildView(view_.get());
view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds());
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Use TestTooltip instead of TooltipLacros to avoid using server side
// impl since it requires ui_controls which only works in
// interactive_ui_tests.
tooltip_ = new TestTooltipLacros();
controller_ = std::make_unique<TooltipController>(
std::unique_ptr<views::corewm::Tooltip>(tooltip_),
/*activation_client=*/nullptr);
widget_->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler(
controller_.get());
// Set tooltip client after creating widget since tooltip controller is
// constructed and overriden inside CreateWidget() for Lacros.
SetTooltipClient(widget_->GetNativeWindow()->GetRootWindow(),
controller_.get());
#endif
helper_ = std::make_unique<TooltipControllerTestHelper>(
widget_->GetNativeWindow()->GetRootWindow());
#if BUILDFLAG(IS_CHROMEOS_LACROS)
tooltip_->SetStateManager(helper_->state_manager());
#endif
generator_ = std::make_unique<ui::test::EventGenerator>(GetRootWindow());
}
@ -187,8 +110,7 @@ class TooltipControllerTest : public ViewsTestBase {
// Reset the tooltip in case tests end with a visible tooltip.
helper_->state_manager()->HideAndReset();
#if !BUILDFLAG(ENABLE_DESKTOP_AURA) || BUILDFLAG(IS_WIN) || \
BUILDFLAG(IS_CHROMEOS_LACROS)
#if !BUILDFLAG(ENABLE_DESKTOP_AURA) || BUILDFLAG(IS_WIN)
aura::Window* root_window = GetContext();
if (root_window) {
root_window->RemovePreTargetHandler(controller_.get());
@ -201,9 +123,6 @@ class TooltipControllerTest : public ViewsTestBase {
generator_.reset();
helper_.reset();
view_ = nullptr;
#if BUILDFLAG(IS_CHROMEOS_LACROS)
widget_->CloseNow();
#endif
widget_.reset();
ViewsTestBase::TearDown();
}
@ -244,8 +163,6 @@ class TooltipControllerTest : public ViewsTestBase {
protected:
#if !BUILDFLAG(ENABLE_DESKTOP_AURA) || BUILDFLAG(IS_WIN)
raw_ptr<TooltipAura> tooltip_; // not owned.
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
raw_ptr<TestTooltipLacros> tooltip_; // not owned.
#endif
private:
@ -526,17 +443,7 @@ TEST_F(TooltipControllerTest, DontShowEmptyTooltips) {
EXPECT_FALSE(helper_->IsTooltipVisible());
}
// Disabled on Lacros since TooltipLacros does not have tooltip timer on client
// side so cannot be tested on unittest.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TooltipUpdateWhenTooltipDeferTimerIsRunning \
DISABLED_TooltipUpdateWhenTooltipDeferTimerIsRunning
#else
#define MAYBE_TooltipUpdateWhenTooltipDeferTimerIsRunning \
TooltipUpdateWhenTooltipDeferTimerIsRunning
#endif
TEST_F(TooltipControllerTest,
MAYBE_TooltipUpdateWhenTooltipDeferTimerIsRunning) {
TEST_F(TooltipControllerTest, TooltipUpdateWhenTooltipDeferTimerIsRunning) {
view_->set_tooltip_text(u"Tooltip Text for view 1");
EXPECT_EQ(std::u16string(), helper_->GetTooltipText());
EXPECT_EQ(nullptr, helper_->GetTooltipParentWindow());
@ -580,24 +487,18 @@ TEST_F(TooltipControllerTest, TooltipHidesOnKeyPressAndStaysHiddenUntilChange) {
EXPECT_TRUE(helper_->IsTooltipVisible());
EXPECT_EQ(helper_->state_manager()->tooltip_trigger(),
TooltipTrigger::kCursor);
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_TRUE(helper_->IsWillHideTooltipTimerRunning());
#endif
generator_->PressKey(ui::VKEY_1, 0);
EXPECT_FALSE(helper_->IsTooltipVisible());
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_FALSE(helper_->IsWillHideTooltipTimerRunning());
#endif
// Moving the mouse inside |view1| should not change the state of the tooltip
// or the timers.
for (int i = 0; i < 49; i++) {
generator_->MoveMouseBy(1, 0);
EXPECT_FALSE(helper_->IsTooltipVisible());
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_FALSE(helper_->IsWillHideTooltipTimerRunning());
#endif
EXPECT_EQ(window, GetRootWindow()->GetEventHandlerForPoint(
generator_->current_screen_location()));
std::u16string expected_tooltip = u"Tooltip Text for view 1";
@ -612,9 +513,7 @@ TEST_F(TooltipControllerTest, TooltipHidesOnKeyPressAndStaysHiddenUntilChange) {
EXPECT_TRUE(helper_->IsTooltipVisible());
EXPECT_EQ(helper_->state_manager()->tooltip_trigger(),
TooltipTrigger::kCursor);
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_TRUE(helper_->IsWillHideTooltipTimerRunning());
#endif
std::u16string expected_tooltip = u"Tooltip Text for view 2";
EXPECT_EQ(expected_tooltip, wm::GetTooltipText(window));
EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
@ -653,24 +552,18 @@ TEST_F(TooltipControllerTest, TooltipHidesOnTimeoutAndStaysHiddenUntilChange) {
EXPECT_TRUE(helper_->IsTooltipVisible());
EXPECT_EQ(helper_->state_manager()->tooltip_trigger(),
TooltipTrigger::kCursor);
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_TRUE(helper_->IsWillHideTooltipTimerRunning());
#endif
helper_->FireHideTooltipTimer();
EXPECT_FALSE(helper_->IsTooltipVisible());
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_FALSE(helper_->IsWillHideTooltipTimerRunning());
#endif
// Moving the mouse inside |view1| should not change the state of the tooltip
// or the timers.
for (int i = 0; i < 49; ++i) {
generator_->MoveMouseBy(1, 0);
EXPECT_FALSE(helper_->IsTooltipVisible());
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_FALSE(helper_->IsWillHideTooltipTimerRunning());
#endif
EXPECT_EQ(window, GetRootWindow()->GetEventHandlerForPoint(
generator_->current_screen_location()));
std::u16string expected_tooltip = u"Tooltip Text for view 1";
@ -685,9 +578,7 @@ TEST_F(TooltipControllerTest, TooltipHidesOnTimeoutAndStaysHiddenUntilChange) {
EXPECT_TRUE(helper_->IsTooltipVisible());
EXPECT_EQ(helper_->state_manager()->tooltip_trigger(),
TooltipTrigger::kCursor);
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
EXPECT_TRUE(helper_->IsWillHideTooltipTimerRunning());
#endif
std::u16string expected_tooltip = u"Tooltip Text for view 2";
EXPECT_EQ(expected_tooltip, wm::GetTooltipText(window));
EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
@ -855,8 +746,7 @@ TEST_F(TooltipControllerTest, DISABLED_CloseOnCaptureLost) {
// Disabled on Linux as X11ScreenOzone::GetAcceleratedWidgetAtScreenPoint
// and WaylandScreen::GetAcceleratedWidgetAtScreenPoint don't consider z-order.
// Disabled on Windows due to failing bots. http://crbug.com/604479
// Disabled on Lacros due to crash and flakiness.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_Capture DISABLED_Capture
#else
#define MAYBE_Capture Capture
@ -962,18 +852,9 @@ TEST_F(TooltipControllerTest, ShowTooltipOnTooltipTextUpdate) {
EXPECT_EQ(nullptr, helper_->GetTooltipParentWindow());
}
// Disabled on Lacros since TooltipLacros does not have tooltip timer on client
// side so cannot be tested on unittest.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TooltipPositionUpdatedWhenTimerRunning \
DISABLED_TooltipPositionUpdatedWhenTimerRunning
#else
#define MAYBE_TooltipPositionUpdatedWhenTimerRunning \
TooltipPositionUpdatedWhenTimerRunning
#endif
// This test validates that the TooltipController correctly triggers a position
// update for a tooltip that is about to be shown.
TEST_F(TooltipControllerTest, MAYBE_TooltipPositionUpdatedWhenTimerRunning) {
TEST_F(TooltipControllerTest, TooltipPositionUpdatedWhenTimerRunning) {
EXPECT_EQ(nullptr, helper_->state_manager()->tooltip_parent_window());
EXPECT_EQ(std::u16string(), helper_->state_manager()->tooltip_text());
@ -1058,9 +939,6 @@ TEST_F(TooltipControllerTest, TooltipHiddenWhenWindowDeactivated) {
namespace {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
using TestTooltip = TestTooltipLacros;
#else
class TestTooltip : public Tooltip {
public:
TestTooltip() = default;
@ -1097,7 +975,6 @@ class TestTooltip : public Tooltip {
gfx::Point anchor_point_;
TooltipTrigger trigger_;
};
#endif
} // namespace
@ -1120,9 +997,6 @@ class TooltipControllerTest2 : public aura::test::AuraTestBase {
root_window()->AddPreTargetHandler(controller_.get());
SetTooltipClient(root_window(), controller_.get());
helper_ = std::make_unique<TooltipControllerTestHelper>(root_window());
#if BUILDFLAG(IS_CHROMEOS_LACROS)
test_tooltip_->SetStateManager(helper_->state_manager());
#endif
generator_ = std::make_unique<ui::test::EventGenerator>(root_window());
}
@ -1221,9 +1095,6 @@ class TooltipControllerTest3 : public ViewsTestBase {
GetRootWindow()->AddPreTargetHandler(controller_.get());
SetTooltipClient(GetRootWindow(), controller_.get());
helper_ = std::make_unique<TooltipControllerTestHelper>(GetRootWindow());
#if BUILDFLAG(IS_CHROMEOS_LACROS)
test_tooltip_->SetStateManager(helper_->state_manager());
#endif
}
void TearDown() override {
@ -1402,15 +1273,7 @@ TEST_F(TooltipStateManagerTest, ShowAndHideTooltip) {
EXPECT_FALSE(helper_->IsTooltipVisible());
}
// Disabled on Lacros since TooltipLacros cannot handle tooltip with delay on
// client side properly. To test with delay, it needs to use Ash server with
// ui_controls in interactive_ui_tests.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_ShowTooltipWithDelay DISABLED_ShowTooltipWithDelay
#else
#define MAYBE_ShowTooltipWithDelay ShowTooltipWithDelay
#endif
TEST_F(TooltipStateManagerTest, MAYBE_ShowTooltipWithDelay) {
TEST_F(TooltipStateManagerTest, ShowTooltipWithDelay) {
EXPECT_EQ(nullptr, helper_->state_manager()->tooltip_parent_window());
EXPECT_EQ(std::u16string(), helper_->state_manager()->tooltip_text());
@ -1449,19 +1312,11 @@ TEST_F(TooltipStateManagerTest, MAYBE_ShowTooltipWithDelay) {
helper_->SkipTooltipShowDelay(true);
}
// Disabled on Lacros since TooltipLacros cannot handle tooltip with delay on
// client side properly. To test with delay, it needs to use Ash server with
// ui_controls in interactive_ui_tests.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_UpdatePositionIfNeeded DISABLED_UpdatePositionIfNeeded
#else
#define MAYBE_UpdatePositionIfNeeded UpdatePositionIfNeeded
#endif
// This test ensures that we can update the position of the tooltip after the
// |will_show_tooltip_timer_| has been started. This is needed because the
// cursor might still move between the moment Show is called and the timer
// fires.
TEST_F(TooltipStateManagerTest, MAYBE_UpdatePositionIfNeeded) {
TEST_F(TooltipStateManagerTest, UpdatePositionIfNeeded) {
EXPECT_EQ(nullptr, helper_->state_manager()->tooltip_parent_window());
EXPECT_EQ(std::u16string(), helper_->state_manager()->tooltip_text());

@ -1,123 +0,0 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/corewm/tooltip_lacros.h"
#include <algorithm>
#include "ui/aura/window.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/platform_window/platform_window.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_lacros.h"
#include "ui/wm/public/tooltip_observer.h"
namespace views::corewm {
namespace {
ui::PlatformWindowTooltipTrigger ToPlatformWindowTooltipTrigger(
TooltipTrigger trigger) {
switch (trigger) {
case TooltipTrigger::kCursor:
return ui::PlatformWindowTooltipTrigger::kCursor;
case TooltipTrigger::kKeyboard:
return ui::PlatformWindowTooltipTrigger::kKeyboard;
}
}
} // namespace
const char TooltipLacros::kWidgetName[] = "TooltipLacros";
TooltipLacros::TooltipLacros() = default;
TooltipLacros::~TooltipLacros() {
// Hide tooltip before destructing.
Hide();
}
void TooltipLacros::AddObserver(wm::TooltipObserver* observer) {
observers_.AddObserver(observer);
}
void TooltipLacros::RemoveObserver(wm::TooltipObserver* observer) {
observers_.RemoveObserver(observer);
}
void TooltipLacros::OnTooltipShownOnServer(const std::u16string& text,
const gfx::Rect& bounds) {
is_visible_ = true;
observers_.Notify(&wm::TooltipObserver::OnTooltipShown, parent_window_, text,
bounds);
}
void TooltipLacros::OnTooltipHiddenOnServer() {
is_visible_ = false;
observers_.Notify(&wm::TooltipObserver::OnTooltipHidden, parent_window_);
}
int TooltipLacros::GetMaxWidth(const gfx::Point& location) const {
display::Screen* screen = display::Screen::GetScreen();
gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds());
return std::min(kTooltipMaxWidth, (display_bounds.width() + 1) / 2);
}
void TooltipLacros::Update(aura::Window* parent_window,
const std::u16string& text,
const gfx::Point& position,
const TooltipTrigger trigger) {
DCHECK(parent_window);
parent_window_ = parent_window;
text_ = text;
position_ = position;
// Add the distance between `parent_window` and its toplevel window to
// `position_` since Ash-side server will use this position as relative to
// wayland toplevel window.
// TODO(crbug.com/40246673): Use WaylandWindow instead of ToplevelWindow/Popup
// when it's supported on ozone.
aura::Window::ConvertPointToTarget(
parent_window_, parent_window_->GetRootWindow(), &position_);
trigger_ = trigger;
}
void TooltipLacros::SetDelay(const base::TimeDelta& show_delay,
const base::TimeDelta& hide_delay) {
show_delay_ = show_delay;
hide_delay_ = hide_delay;
}
void TooltipLacros::Show() {
DCHECK(parent_window_);
auto* host =
views::DesktopWindowTreeHostLacros::From(parent_window_->GetHost());
auto* platform_window = host ? host->platform_window() : nullptr;
DCHECK(platform_window);
platform_window->ShowTooltip(text_, position_,
ToPlatformWindowTooltipTrigger(trigger_),
show_delay_, hide_delay_);
}
void TooltipLacros::Hide() {
if (!parent_window_) {
return;
}
auto* host =
views::DesktopWindowTreeHostLacros::From(parent_window_->GetHost());
auto* platform_window = host ? host->platform_window() : nullptr;
// `platform_window` may be null for testing.
if (platform_window) {
platform_window->HideTooltip();
}
parent_window_ = nullptr;
}
bool TooltipLacros::IsVisible() {
return is_visible_;
}
} // namespace views::corewm

@ -1,87 +0,0 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_COREWM_TOOLTIP_LACROS_H_
#define UI_VIEWS_COREWM_TOOLTIP_LACROS_H_
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/views_export.h"
namespace aura {
class Window;
}
namespace gfx {
class Rect;
}
namespace wm {
class TooltipObserver;
}
namespace views::corewm {
namespace test {
class TooltipLacrosForTesting;
}
// Implementation of Tooltip on Lacros using server side tooltip.
// TooltipLacros requests Ash to show/hide tooltip and Ash creates tooltip
// widget on server side and notifies Lacros of the tooltip visibility, position
// and the actual text to be shown.
//
// This is only used when Ash supports server side tooltip. If not, fallbacks to
// TooltipAura.
class VIEWS_EXPORT TooltipLacros : public Tooltip {
public:
static const char kWidgetName[];
TooltipLacros();
TooltipLacros(const TooltipLacros&) = delete;
TooltipLacros& operator=(const TooltipLacros&) = delete;
~TooltipLacros() override;
// Tooltip:
void AddObserver(wm::TooltipObserver* observer) override;
void RemoveObserver(wm::TooltipObserver* observer) override;
void OnTooltipShownOnServer(const std::u16string& text,
const gfx::Rect& boudns) override;
void OnTooltipHiddenOnServer() override;
private:
friend class test::TooltipLacrosForTesting;
// Tooltip:
int GetMaxWidth(const gfx::Point& location) const override;
void Update(aura::Window* parent_window,
const std::u16string& text,
const gfx::Point& position,
const TooltipTrigger trigger) override;
void SetDelay(const base::TimeDelta& show_delay,
const base::TimeDelta& hide_delay) override;
void Show() override;
void Hide() override;
bool IsVisible() override;
// True if tooltip is visible.
bool is_visible_ = false;
raw_ptr<aura::Window, DanglingUntriaged> parent_window_ = nullptr;
std::u16string text_;
gfx::Point position_;
TooltipTrigger trigger_;
base::TimeDelta show_delay_;
base::TimeDelta hide_delay_;
// Observes tooltip state change.
base::ObserverList<wm::TooltipObserver> observers_;
};
} // namespace views::corewm
#endif // UI_VIEWS_COREWM_TOOLTIP_LACROS_H_

@ -13,9 +13,7 @@
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/text_elider.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/wm/public/tooltip_client.h"
#include "ui/wm/public/tooltip_observer.h"
@ -107,22 +105,6 @@ void TooltipStateManager::UpdatePositionIfNeeded(const gfx::Point& position,
position_ = position;
}
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void TooltipStateManager::OnTooltipShownOnServer(aura::Window* window,
const std::u16string& text,
const gfx::Rect& bounds) {
tooltip_id_ = wm::GetTooltipId(window);
tooltip_parent_window_ = window;
tooltip_->OnTooltipShownOnServer(text, bounds);
}
void TooltipStateManager::OnTooltipHiddenOnServer() {
tooltip_id_ = nullptr;
tooltip_parent_window_ = nullptr;
tooltip_->OnTooltipHiddenOnServer();
}
#endif // BUILDFLAG(IS_CHROMEOS_LACROS)
void TooltipStateManager::ShowNow(const std::u16string& trimmed_text,
const base::TimeDelta hide_delay) {
if (!tooltip_parent_window_)
@ -146,14 +128,6 @@ void TooltipStateManager::StartWillShowTooltipTimer(
const std::u16string& trimmed_text,
const base::TimeDelta show_delay,
const base::TimeDelta hide_delay) {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Send `show_delay` and `hide_delay` together and delegate the timer
// handling on Ash side.
tooltip_->Update(tooltip_parent_window_, trimmed_text, position_,
tooltip_trigger_);
tooltip_->SetDelay(show_delay, hide_delay);
tooltip_->Show();
#else
if (!show_delay.is_zero()) {
// Start will show tooltip timer is show_delay is non-zero.
will_show_tooltip_timer_.Start(
@ -168,7 +142,6 @@ void TooltipStateManager::StartWillShowTooltipTimer(
// timer to fire before continuing for non-Lacros platforms.
ShowNow(trimmed_text, hide_delay);
}
#endif // BUILDFLAG(IS_CHROMEOS_LACROS)
}
} // namespace views::corewm

@ -21,10 +21,6 @@ namespace aura {
class Window;
}
namespace gfx {
class Rect;
}
namespace wm {
class TooltipObserver;
}
@ -83,15 +79,6 @@ class VIEWS_EXPORT TooltipStateManager {
void UpdatePositionIfNeeded(const gfx::Point& position,
TooltipTrigger trigger);
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Called when tooltip is shown/hidden on server.
// Only used by Lacros.
void OnTooltipShownOnServer(aura::Window* window,
const std::u16string& text,
const gfx::Rect& bounds);
void OnTooltipHiddenOnServer();
#endif
private:
friend class test::TooltipControllerTestHelper;
@ -132,8 +119,6 @@ class VIEWS_EXPORT TooltipStateManager {
// Two timers for the tooltip: one to hide an on-screen tooltip after a delay,
// and one to display the tooltip when the timer fires.
// Timers are always not running on Lacros using server side tooltip since
// they are handled on Ash side.
base::OneShotTimer will_hide_tooltip_timer_;
base::OneShotTimer will_show_tooltip_timer_;

@ -426,11 +426,6 @@ void DesktopNativeWidgetAura::NotifyAccessibilityEvent(
GetWidget()->GetRootView()->NotifyAccessibilityEvent(event_type, true);
}
views::corewm::TooltipController*
DesktopNativeWidgetAura::tooltip_controller() {
return tooltip_controller_.get();
}
void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
if (!native_widget_delegate_ ||
!native_widget_delegate_->ShouldHandleNativeWidgetActivationChanged(

@ -99,8 +99,6 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
aura::Window* content_window() { return content_window_; }
views::corewm::TooltipController* tooltip_controller();
Widget::InitParams::Type widget_type() const { return widget_type_; }
// Ensures that the correct window is activated/deactivated based on whether

@ -201,21 +201,6 @@ void DesktopWindowTreeHostLacros::OnOverviewModeChanged(bool in_overview) {
UpdateWindowHints();
}
void DesktopWindowTreeHostLacros::OnTooltipShownOnServer(
const std::u16string& text,
const gfx::Rect& bounds) {
if (tooltip_controller()) {
tooltip_controller()->OnTooltipShownOnServer(GetContentWindow(), text,
bounds);
}
}
void DesktopWindowTreeHostLacros::OnTooltipHiddenOnServer() {
if (tooltip_controller()) {
tooltip_controller()->OnTooltipHiddenOnServer();
}
}
void DesktopWindowTreeHostLacros::OnBoundsChanged(const BoundsChange& change) {
// DesktopWindowTreeHostPlatform::OnBoundsChanged() may result in |this| being
// deleted. As an extra safety guard, keep track of `this` with a weak

@ -67,9 +67,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostLacros
void OnFullscreenTypeChanged(ui::PlatformFullscreenType old_type,
ui::PlatformFullscreenType new_type) override;
void OnOverviewModeChanged(bool in_overview) override;
void OnTooltipShownOnServer(const std::u16string& text,
const gfx::Rect& bounds) override;
void OnTooltipHiddenOnServer() override;
void OnBoundsChanged(const BoundsChange& change) override;
// DesktopWindowTreeHostPlatform overrides:

@ -39,6 +39,7 @@
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h"
#include "ui/platform_window/wm/wm_move_loop_handler.h"
#include "ui/views/corewm/tooltip_aura.h"
#include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
@ -53,12 +54,6 @@
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_linux.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "ui/views/corewm/tooltip_lacros.h"
#else
#include "ui/views/corewm/tooltip_aura.h"
#endif
DEFINE_UI_CLASS_PROPERTY_TYPE(views::DesktopWindowTreeHostPlatform*)
namespace views {
@ -348,11 +343,7 @@ void DesktopWindowTreeHostPlatform::OnActiveWindowChanged(bool active) {
std::unique_ptr<corewm::Tooltip>
DesktopWindowTreeHostPlatform::CreateTooltip() {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
return std::make_unique<corewm::TooltipLacros>();
#else
return std::make_unique<corewm::TooltipAura>();
#endif
}
std::unique_ptr<aura::client::DragDropClient>
@ -1104,11 +1095,6 @@ const Widget* DesktopWindowTreeHostPlatform::GetWidget() const {
: nullptr;
}
views::corewm::TooltipController*
DesktopWindowTreeHostPlatform::tooltip_controller() {
return desktop_native_widget_aura_->tooltip_controller();
}
void DesktopWindowTreeHostPlatform::ScheduleRelayout() {
if (!native_widget_delegate_) {
return;

@ -30,10 +30,6 @@ class PaintContext;
namespace views {
namespace corewm {
class TooltipController;
}
class VIEWS_EXPORT DesktopWindowTreeHostPlatform
: public aura::WindowTreeHostPlatform,
public DesktopWindowTreeHost,
@ -213,8 +209,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
Widget* GetWidget();
const Widget* GetWidget() const;
views::corewm::TooltipController* tooltip_controller();
void ScheduleRelayout();
private: