Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: components/constrained_window/constrained_window_views.cc

Issue 2172363002: Created min size for print preview dialog and modified to allow the Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mac build error Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 15fad72bf5bac3f6b9882971a16bc56e439901e4..e47b495f1c2b7e82ad81755baac5b781e45a1527 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,11 @@
#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"
+#endif
+
#if defined(OS_MACOSX)
#import "components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.h"
#endif
@@ -111,6 +119,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 +156,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);
}
@@ -179,6 +207,25 @@ views::Widget* ShowWebModalDialogWithOverlayViews(
}
#endif
+views::Widget* ShowTopLevelWebModalDialogViews(
+ 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.
+ content::WebContents* web_contents =
+ guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
+ gfx::NativeWindow parent = web_contents->GetTopLevelNativeWindow();
+ gfx::NativeView parent_view =
+ parent ? constrained_window_views_client->GetDialogHostView(parent)
+ : nullptr;
+ views::Widget* widget =
+ views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view);
+ ShowTopLevelModalDialog(widget->GetNativeWindow(), web_contents, target);
+ return widget;
+}
+
views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
content::WebContents* web_contents) {
DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType());
@@ -225,4 +272,4 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
return widget;
}
-} // namespace constrained window
+} // namespace constrained_window

Powered by Google App Engine
This is Rietveld 408576698