Commit a4d4b817 authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Improve window parenting for select file dialogs

Select file dialogs are implemented in ash-chrome via
SelectFileDialogExtension, which requires an aura::Window owning window
for the dialog.

Use the currently active (frontmost) window, which will usually be the
spawning Lacros window. Verify that it's still a ShellSurface, just in
case window activation has changed between when the user initiated the
file picker and ash-chrome has received the mojo message.

This isn't quite right -- in theory a non-active window could spawn a
file picker -- but it's better than a modal file picker that blocks
the whole desktop.

Bug: 1090587
Test: multiple lacros windows can have their own file picker children
Change-Id: I582cd534e49228f3da5ab67e5ad99812f1a48432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303681Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789719}
parent f58a1ad1
......@@ -6,6 +6,7 @@ specific_include_rules = {
"select_file_crosapi\.cc": [
# For window parenting.
"+ash/shell.h",
"+ash/wm/desks/desks_util.h",
# For Chrome OS-specific file manager parameters.
"+chrome/browser/ui/views/select_file_dialog_extension.h",
],
......
......@@ -9,14 +9,17 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/desks/desks_util.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/numerics/ranges.h"
#include "chrome/browser/ui/views/select_file_dialog_extension.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "components/exo/shell_surface_util.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_policy.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "ui/wm/public/activation_client.h"
#include "url/gurl.h"
namespace {
......@@ -54,6 +57,20 @@ ui::SelectFileDialog::FileTypeInfo::AllowedPaths GetUiAllowedPaths(
}
}
// TODO(https://crbug.com/1090587): Parent to the ShellSurface that spawned
// the dialog. For now, parent to the active window, which in practice should be
// the spawning window.
aura::Window* GetOwnerWindow() {
aura::Window* root = ash::Shell::GetRootWindowForNewWindows();
aura::Window* active = ::wm::GetActivationClient(root)->GetActiveWindow();
// Check that the active window is still a ShellSurface window.
if (active && exo::GetShellSurfaceBaseForWindow(active))
return active;
// Fallback to the active virtual desk.
return ash::Shell::GetContainer(root,
ash::desks_util::GetActiveDeskContainerId());
}
// Manages a single open/save dialog. There may be multiple dialogs showing at
// the same time. Deletes itself when the dialog is closed.
class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {
......@@ -67,11 +84,7 @@ class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {
SelectFileDialogExtension::Create(this, /*policy=*/nullptr);
SelectFileDialogExtension::Owner owner;
// TODO(https://crbug.com/1090587): Parent to the ShellSurface that spawned
// the dialog. For now, just put it on the default desktop.
owner.window = ash::Shell::GetContainer(
ash::Shell::GetRootWindowForNewWindows(),
ash::kShellWindowId_DefaultContainerDeprecated);
owner.window = GetOwnerWindow();
// TODO(https://crbug.com/1090587): Replace with ID from Wayland client.
owner.lacros_window_id = g_next_window_id++;
......
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