| Index: components/constrained_window/constrained_window_views.cc
|
| diff --git a/components/constrained_window/constrained_window_views.cc b/components/constrained_window/constrained_window_views.cc
|
| index 3ed86ce06852a9da707d5868000e19a7103a8b7d..f9341214bfa683d7f98c9e5cc3e570768b7e76a6 100644
|
| --- a/components/constrained_window/constrained_window_views.cc
|
| +++ b/components/constrained_window/constrained_window_views.cc
|
| @@ -5,6 +5,9 @@
|
| #include "components/constrained_window/constrained_window_views.h"
|
|
|
| #include <algorithm>
|
| +#if defined(OS_MACOSX)
|
| +#include <utility>
|
| +#endif
|
|
|
| #include "base/macros.h"
|
| #include "build/build_config.h"
|
| @@ -18,6 +21,12 @@
|
| #include "ui/views/widget/widget_observer.h"
|
| #include "ui/views/window/dialog_delegate.h"
|
|
|
| +#if defined(USE_AURA)
|
| +#include "ui/aura/window.h"
|
| +#include "ui/wm/core/window_modality_controller.h"
|
| +#include "ui/wm/core/window_util.h"
|
| +#endif
|
| +
|
| #if defined(OS_MACOSX)
|
| #import "components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.h"
|
| #endif
|
| @@ -111,6 +120,19 @@ void UpdateModalDialogPosition(views::Widget* widget,
|
| if (widget->is_top_level())
|
| position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin();
|
|
|
| +#if defined(USE_AURA)
|
| + // Prevents widgets that extend outside the parent window from having their
|
| + // horizontal position centered on the center of the parent window. Instead,
|
| + // positions top left corner in parent top left corner so widget extends
|
| + // below and to the right of the parent window.
|
| + if (widget->GetNativeWindowProperty(wm::kAllowTransientParentEventsKey)) {
|
| + gfx::Rect bound = dialog_host->GetHostView()->GetBoundsInScreen();
|
| + if (bound.width() - border->GetInsets().left() < size.width()) {
|
| + position.set_x(position.x() + (size.width() - bound.width()) / 2 +
|
| + border->GetInsets().left());
|
| + }
|
| + }
|
| +#endif
|
| widget->SetBounds(gfx::Rect(position, size));
|
| }
|
|
|
| @@ -135,7 +157,14 @@ void UpdateWebContentsModalDialogPosition(
|
| // Border may be null during widget initialization.
|
| if (border)
|
| max_size.Enlarge(0, border->GetInsets().top());
|
| - size.SetToMin(max_size);
|
| +#if defined(USE_AURA)
|
| + bool has_independent_bounds =
|
| + !!(widget->GetNativeWindowProperty(wm::kAllowTransientParentEventsKey));
|
| +#else
|
| + bool has_independent_bounds = false;
|
| +#endif
|
| + if (!has_independent_bounds)
|
| + size.SetToMin(max_size);
|
| UpdateModalDialogPosition(widget, dialog_host, size);
|
| }
|
|
|
| @@ -154,13 +183,39 @@ content::WebContents* GetTopLevelWebContents(
|
| views::Widget* ShowWebModalDialogViews(
|
| views::WidgetDelegate* dialog,
|
| content::WebContents* initiator_web_contents) {
|
| + LOG(ERROR) << "2 arg show modal dialog";
|
| + return ShowWebModalDialogViews(dialog, initiator_web_contents, nullptr);
|
| +}
|
| +
|
| +views::Widget* ShowWebModalDialogViews(
|
| + views::WidgetDelegate* dialog,
|
| + content::WebContents* initiator_web_contents,
|
| + ui::AcceleratorTarget* target) {
|
| DCHECK(constrained_window_views_client);
|
| // For embedded WebContents, use the embedder's WebContents for constrained
|
| // window.
|
| +
|
| + LOG(ERROR) << "3 arg show modal dialog, target = " << target;
|
| content::WebContents* web_contents =
|
| GetTopLevelWebContents(initiator_web_contents);
|
| - views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
|
| - ShowModalDialog(widget->GetNativeWindow(), web_contents);
|
| + views::Widget* widget = nullptr;
|
| + if (dialog->GetModalType() == ui::MODAL_TYPE_CHILD) {
|
| + widget = CreateWebModalDialogViews(dialog, web_contents);
|
| + ShowModalDialog(widget->GetNativeWindow(), web_contents);
|
| + } else {
|
| + // This is a top level dialog with child modal dialog behavior.
|
| +#if defined(OS_WIN)
|
| + gfx::NativeView parent_view = nullptr;
|
| +#else
|
| + gfx::NativeWindow parent = web_contents->GetTopLevelNativeWindow();
|
| + gfx::NativeView parent_view =
|
| + parent ? constrained_window_views_client->GetDialogHostView(parent)
|
| + : nullptr;
|
| +#endif
|
| + widget = views::DialogDelegate::CreateDialogWidget(
|
| + dialog, nullptr, parent_view);
|
| + ShowTopLevelModalDialog(widget->GetNativeWindow(), web_contents, target);
|
| + }
|
| return widget;
|
| }
|
|
|
| @@ -232,4 +287,4 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
|
| return widget;
|
| }
|
|
|
| -} // namespace constrained window
|
| +} // namespace constrained_window
|
|
|