Commit 27761e38 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Change default display for new windows without parent or context

Make views::Widget::InitParams::context optional. This cuts some
dependencies between //chrome/browser/ui and //ash, which we need to
do for go/mustash.

Change the default display for windows that supply neither parent nor
context to the "root window for new windows" (i.e. the display where
the user last activated a window). The old behavior was to always use
the primary display. The new behavior is consistent with mash.

Fix a couple cases where windows were defaulting to the primary
display when they should have been using the display for new windows
(e.g. task manager when all browsers are closed).

Bug: 826569
Test: covered by tests
Change-Id: I4571c3c7066b4247559d43e7b1192ef8411f8919
Reviewed-on: https://chromium-review.googlesource.com/988732
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547515}
parent 24a92352
......@@ -103,10 +103,9 @@ PinDialogManager::RequestPinResponse PinDialogManager::ShowPinDialog(
attempts_left, callback, this);
gfx::NativeWindow parent = GetBrowserParentWindow();
gfx::NativeWindow context =
parent ? nullptr : ash::Shell::GetPrimaryRootWindow();
active_window_ = views::DialogDelegate::CreateDialogWidget(active_pin_dialog_,
context, parent);
// If there is no parent, falls back to the root window for new windows.
active_window_ = views::DialogDelegate::CreateDialogWidget(
active_pin_dialog_, /*context=*/ nullptr, parent);
active_window_->Show();
return SUCCESS;
......
......@@ -72,8 +72,10 @@ IdleActionWarningDialogView::IdleActionWarningDialogView(
UpdateLabel();
views::DialogDelegate::CreateDialogWidget(
this, ash::Shell::GetPrimaryRootWindow(), NULL)->Show();
// Shown on the root window for new windows.
views::DialogDelegate::CreateDialogWidget(this, nullptr /* context */,
nullptr /* parent */)
->Show();
update_timer_.Start(
FROM_HERE,
......
......@@ -75,18 +75,11 @@ ChromeViewsDelegate::GetOpacityForInitParams(
views::NativeWidget* ChromeViewsDelegate::CreateNativeWidget(
views::Widget::InitParams* params,
views::internal::NativeWidgetDelegate* delegate) {
// When we are doing straight chromeos builds, we still need to handle the
// toplevel window case.
// There may be a few remaining widgets in Chrome OS that are not top level,
// but have neither a context nor a parent. Provide a fallback context so
// users don't crash. Developers will hit the DCHECK and should provide a
// context.
if (params->context)
params->context = params->context->GetRootWindow();
DCHECK(params->parent || params->context || !params->child)
<< "Please provide a parent or context for this widget.";
if (!params->parent && !params->context)
params->context = ash::Shell::GetPrimaryRootWindow();
// Classic ash requires a parent or a context that it can use to look up a
// root window to find a WindowParentingClient. Mash handles window parenting
// inside ash, see ash::CreateAndParentTopLevelWindow().
if (!ash_util::IsRunningInMash() && !params->parent && !params->context)
params->context = ash::Shell::GetRootWindowForNewWindows();
// By returning null Widget creates the default NativeWidget implementation,
// which for chromeos is NativeWidgetAura.
......
......@@ -8,15 +8,17 @@
// This file is only instantiated in classic ash/mus. It is never used in mash.
// See native_browser_frame_factory_chromeos.cc switches on GetAshConfig().
#include "ash/public/cpp/window_properties.h" // mash-ok
#include "ash/public/cpp/window_state_type.h" // mash-ok
#include "ash/shell.h" // mash-ok
#include "ash/wm/window_properties.h" // mash-ok
#include "ash/wm/window_state.h" // mash-ok
#include "ash/wm/window_state_delegate.h" // mash-ok
#include "ash/wm/window_util.h" // mash-ok
#include "ash/public/cpp/config.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/cpp/window_state_type.h"
#include "ash/shell.h" // mash-ok
#include "ash/wm/window_properties.h" // mash-ok
#include "ash/wm/window_state.h" // mash-ok
#include "ash/wm/window_state_delegate.h" // mash-ok
#include "ash/wm/window_util.h" // mash-ok
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
......@@ -61,6 +63,7 @@ BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame,
BrowserView* browser_view)
: views::NativeWidgetAura(browser_frame),
browser_view_(browser_view) {
DCHECK_NE(chromeos::GetAshConfig(), ash::Config::MASH);
GetNativeWindow()->SetName("BrowserFrameAsh");
Browser* browser = browser_view->browser();
ash::wm::WindowState* window_state =
......
......@@ -12,7 +12,8 @@
class BrowserFrame;
class BrowserView;
// BrowserFrameAsh provides the frame for Chrome browser windows on Chrome OS.
// BrowserFrameAsh provides the frame for Chrome browser windows on Chrome OS
// under classic ash.
class BrowserFrameAsh : public views::NativeWidgetAura,
public NativeBrowserFrame {
public:
......
......@@ -20,11 +20,13 @@
#include "ui/views/mus/window_manager_frame_values.h"
#if defined(OS_CHROMEOS)
#include "ash/public/cpp/config.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/cpp/window_state_type.h"
#include "ash/public/interfaces/window_properties.mojom.h"
#include "ash/public/interfaces/window_style.mojom.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#endif
......@@ -32,7 +34,12 @@ BrowserFrameMus::BrowserFrameMus(BrowserFrame* browser_frame,
BrowserView* browser_view)
: views::DesktopNativeWidgetAura(browser_frame),
browser_frame_(browser_frame),
browser_view_(browser_view) {}
browser_view_(browser_view) {
#if defined(OS_CHROMEOS)
// Not used with Mus on Chrome OS.
DCHECK_EQ(chromeos::GetAshConfig(), ash::Config::MASH);
#endif
}
BrowserFrameMus::~BrowserFrameMus() {}
......
......@@ -30,7 +30,13 @@
#endif
#if defined(OS_CHROMEOS)
#include "ash/shell.h"
#include "ash/shell.h" // mash-ok
#include "chrome/browser/chromeos/ash_config.h"
#include "mojo/public/cpp/bindings/type_converter.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#endif
namespace {
......@@ -184,8 +190,14 @@ gfx::NativeViewId ScreenCaptureNotificationUIViews::OnStarted(
// TODO(sergeyu): The notification bar must be shown on the monitor that's
// being captured. Make sure it's always the case. Currently we always capture
// the primary monitor.
if (ash::Shell::HasInstance())
if (chromeos::GetAshConfig() != ash::Config::MASH) {
params.context = ash::Shell::GetPrimaryRootWindow();
} else {
const display::Display primary_display =
display::Screen::GetScreen()->GetPrimaryDisplay();
params.mus_properties[ui::mojom::WindowManager::kDisplayId_InitProperty] =
mojo::ConvertTo<std::vector<uint8_t>>(primary_display.id());
}
#endif
widget->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
......
......@@ -34,12 +34,9 @@
#include "ui/views/window/dialog_client_view.h"
#if defined(OS_CHROMEOS)
// gn check complains on Linux Ozone.
#include "ash/public/cpp/shelf_item.h" // nogncheck
#include "ash/public/cpp/window_properties.h" // nogncheck
#include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/resources/grit/ash_resources.h"
#include "ash/wm/window_util.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
......@@ -75,13 +72,10 @@ task_manager::TaskManagerTableModel* TaskManagerView::Show(Browser* browser) {
g_task_manager_view = new TaskManagerView();
// On Chrome OS, pressing Search-Esc when there are no open browser windows
// will open the task manager on the root window for new windows.
gfx::NativeWindow context =
browser ? browser->window()->GetNativeWindow() : nullptr;
#if defined(OS_CHROMEOS)
if (!ash_util::IsRunningInMash() && !context)
context = ash::wm::GetActiveWindow();
#endif
DialogDelegate::CreateDialogWidget(g_task_manager_view, context, nullptr);
g_task_manager_view->InitAlwaysOnTopState();
......
......@@ -51,6 +51,8 @@ class FocusManagerEventHandler;
class TooltipManagerAura;
class WindowReorderer;
// DesktopNativeWidgetAura handles top-level widgets on Windows, Linux, and
// Chrome OS with mash.
class VIEWS_EXPORT DesktopNativeWidgetAura
: public internal::NativeWidgetPrivate,
public aura::WindowDelegate,
......
......@@ -147,7 +147,6 @@ void NativeWidgetAura::SetShadowElevationFromInitParams(
// NativeWidgetAura, internal::NativeWidgetPrivate implementation:
void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
// Aura needs to know which desktop (Ash or regular) will manage this widget.
// See Widget::InitParams::context for details.
DCHECK(params.parent || params.context);
......
......@@ -276,8 +276,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// hierarchy this widget should be placed. (This is separate from |parent|;
// if you pass a RootWindow to |parent|, your window will be parented to
// |parent|. If you pass a RootWindow to |context|, we ask that RootWindow
// where it wants your window placed.) NULL is not allowed if you are using
// aura.
// where it wants your window placed.) Nullptr is not allowed on Windows and
// Linux. Nullptr is allowed on Chrome OS, which will place the window on
// the default desktop for new windows.
gfx::NativeWindow context;
// If true, forces the window to be shown in the taskbar, even for window
// types that do not appear in the taskbar by default (popup and bubble).
......
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