| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/constrained_window/constrained_window_views.h" | 5 #include "components/constrained_window/constrained_window_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #if defined(OS_MACOSX) |
| 9 #include <utility> |
| 10 #endif |
| 8 | 11 |
| 9 #include "base/macros.h" | 12 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 11 #include "components/constrained_window/constrained_window_views_client.h" | 14 #include "components/constrained_window/constrained_window_views_client.h" |
| 12 #include "components/guest_view/browser/guest_view_base.h" | 15 #include "components/guest_view/browser/guest_view_base.h" |
| 13 #include "components/web_modal/web_contents_modal_dialog_host.h" | 16 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 17 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 18 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 16 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 17 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_observer.h" | 21 #include "ui/views/widget/widget_observer.h" |
| 19 #include "ui/views/window/dialog_delegate.h" | 22 #include "ui/views/window/dialog_delegate.h" |
| 20 | 23 |
| 24 #if defined(USE_AURA) |
| 25 #include "ui/aura/window.h" |
| 26 #include "ui/wm/core/window_modality_controller.h" |
| 27 #include "ui/wm/core/window_util.h" |
| 28 #endif |
| 29 |
| 21 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
| 22 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" | 31 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" |
| 23 #endif | 32 #endif |
| 24 | 33 |
| 25 using web_modal::ModalDialogHost; | 34 using web_modal::ModalDialogHost; |
| 26 using web_modal::ModalDialogHostObserver; | 35 using web_modal::ModalDialogHostObserver; |
| 27 | 36 |
| 28 namespace constrained_window { | 37 namespace constrained_window { |
| 29 namespace { | 38 namespace { |
| 30 | 39 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Border may be null during widget initialization. | 113 // Border may be null during widget initialization. |
| 105 if (border) { | 114 if (border) { |
| 106 // Align the first row of pixels inside the border. This is the apparent | 115 // Align the first row of pixels inside the border. This is the apparent |
| 107 // top of the dialog. | 116 // top of the dialog. |
| 108 position.set_y(position.y() - border->GetInsets().top()); | 117 position.set_y(position.y() - border->GetInsets().top()); |
| 109 } | 118 } |
| 110 | 119 |
| 111 if (widget->is_top_level()) | 120 if (widget->is_top_level()) |
| 112 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); | 121 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
| 113 | 122 |
| 123 #if defined(USE_AURA) |
| 124 // Prevents widgets that extend outside the parent window from having their |
| 125 // horizontal position centered on the center of the parent window. Instead, |
| 126 // positions top left corner in parent top left corner so widget extends |
| 127 // below and to the right of the parent window. |
| 128 if (widget->GetNativeWindowProperty(wm::kAllowTransientParentEventsKey)) { |
| 129 gfx::Rect bound = dialog_host->GetHostView()->GetBoundsInScreen(); |
| 130 if (bound.width() - border->GetInsets().left() < size.width()) { |
| 131 position.set_x(position.x() + (size.width() - bound.width()) / 2 + |
| 132 border->GetInsets().left()); |
| 133 } |
| 134 } |
| 135 #endif |
| 114 widget->SetBounds(gfx::Rect(position, size)); | 136 widget->SetBounds(gfx::Rect(position, size)); |
| 115 } | 137 } |
| 116 | 138 |
| 117 } // namespace | 139 } // namespace |
| 118 | 140 |
| 119 // static | 141 // static |
| 120 void SetConstrainedWindowViewsClient( | 142 void SetConstrainedWindowViewsClient( |
| 121 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { | 143 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { |
| 122 delete constrained_window_views_client; | 144 delete constrained_window_views_client; |
| 123 constrained_window_views_client = new_client.release(); | 145 constrained_window_views_client = new_client.release(); |
| 124 } | 146 } |
| 125 | 147 |
| 126 void UpdateWebContentsModalDialogPosition( | 148 void UpdateWebContentsModalDialogPosition( |
| 127 views::Widget* widget, | 149 views::Widget* widget, |
| 128 web_modal::WebContentsModalDialogHost* dialog_host) { | 150 web_modal::WebContentsModalDialogHost* dialog_host) { |
| 129 gfx::Size size = widget->GetRootView()->GetPreferredSize(); | 151 gfx::Size size = widget->GetRootView()->GetPreferredSize(); |
| 130 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); | 152 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); |
| 131 // Enlarge the max size by the top border, as the dialog will be shifted | 153 // Enlarge the max size by the top border, as the dialog will be shifted |
| 132 // outside the area specified by the dialog host by this amount later. | 154 // outside the area specified by the dialog host by this amount later. |
| 133 views::Border* border = | 155 views::Border* border = |
| 134 widget->non_client_view()->frame_view()->border(); | 156 widget->non_client_view()->frame_view()->border(); |
| 135 // Border may be null during widget initialization. | 157 // Border may be null during widget initialization. |
| 136 if (border) | 158 if (border) |
| 137 max_size.Enlarge(0, border->GetInsets().top()); | 159 max_size.Enlarge(0, border->GetInsets().top()); |
| 138 size.SetToMin(max_size); | 160 #if defined(USE_AURA) |
| 161 bool has_independent_bounds = |
| 162 !!(widget->GetNativeWindowProperty(wm::kAllowTransientParentEventsKey)); |
| 163 #else |
| 164 bool has_independent_bounds = false; |
| 165 #endif |
| 166 if (!has_independent_bounds) |
| 167 size.SetToMin(max_size); |
| 139 UpdateModalDialogPosition(widget, dialog_host, size); | 168 UpdateModalDialogPosition(widget, dialog_host, size); |
| 140 } | 169 } |
| 141 | 170 |
| 142 void UpdateWidgetModalDialogPosition(views::Widget* widget, | 171 void UpdateWidgetModalDialogPosition(views::Widget* widget, |
| 143 web_modal::ModalDialogHost* dialog_host) { | 172 web_modal::ModalDialogHost* dialog_host) { |
| 144 UpdateModalDialogPosition(widget, dialog_host, | 173 UpdateModalDialogPosition(widget, dialog_host, |
| 145 widget->GetRootView()->GetPreferredSize()); | 174 widget->GetRootView()->GetPreferredSize()); |
| 146 } | 175 } |
| 147 | 176 |
| 148 content::WebContents* GetTopLevelWebContents( | 177 content::WebContents* GetTopLevelWebContents( |
| 149 content::WebContents* initiator_web_contents) { | 178 content::WebContents* initiator_web_contents) { |
| 150 return guest_view::GuestViewBase::GetTopLevelWebContents( | 179 return guest_view::GuestViewBase::GetTopLevelWebContents( |
| 151 initiator_web_contents); | 180 initiator_web_contents); |
| 152 } | 181 } |
| 153 | 182 |
| 154 views::Widget* ShowWebModalDialogViews( | 183 views::Widget* ShowWebModalDialogViews( |
| 155 views::WidgetDelegate* dialog, | 184 views::WidgetDelegate* dialog, |
| 156 content::WebContents* initiator_web_contents) { | 185 content::WebContents* initiator_web_contents) { |
| 186 LOG(ERROR) << "2 arg show modal dialog"; |
| 187 return ShowWebModalDialogViews(dialog, initiator_web_contents, nullptr); |
| 188 } |
| 189 |
| 190 views::Widget* ShowWebModalDialogViews( |
| 191 views::WidgetDelegate* dialog, |
| 192 content::WebContents* initiator_web_contents, |
| 193 ui::AcceleratorTarget* target) { |
| 157 DCHECK(constrained_window_views_client); | 194 DCHECK(constrained_window_views_client); |
| 158 // For embedded WebContents, use the embedder's WebContents for constrained | 195 // For embedded WebContents, use the embedder's WebContents for constrained |
| 159 // window. | 196 // window. |
| 197 |
| 198 LOG(ERROR) << "3 arg show modal dialog, target = " << target; |
| 160 content::WebContents* web_contents = | 199 content::WebContents* web_contents = |
| 161 GetTopLevelWebContents(initiator_web_contents); | 200 GetTopLevelWebContents(initiator_web_contents); |
| 162 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents); | 201 views::Widget* widget = nullptr; |
| 163 ShowModalDialog(widget->GetNativeWindow(), web_contents); | 202 if (dialog->GetModalType() == ui::MODAL_TYPE_CHILD) { |
| 203 widget = CreateWebModalDialogViews(dialog, web_contents); |
| 204 ShowModalDialog(widget->GetNativeWindow(), web_contents); |
| 205 } else { |
| 206 // This is a top level dialog with child modal dialog behavior. |
| 207 #if defined(OS_WIN) |
| 208 gfx::NativeView parent_view = nullptr; |
| 209 #else |
| 210 gfx::NativeWindow parent = web_contents->GetTopLevelNativeWindow(); |
| 211 gfx::NativeView parent_view = |
| 212 parent ? constrained_window_views_client->GetDialogHostView(parent) |
| 213 : nullptr; |
| 214 #endif |
| 215 widget = views::DialogDelegate::CreateDialogWidget( |
| 216 dialog, nullptr, parent_view); |
| 217 ShowTopLevelModalDialog(widget->GetNativeWindow(), web_contents, target); |
| 218 } |
| 164 return widget; | 219 return widget; |
| 165 } | 220 } |
| 166 | 221 |
| 167 #if defined(OS_MACOSX) | 222 #if defined(OS_MACOSX) |
| 168 views::Widget* ShowWebModalDialogWithOverlayViews( | 223 views::Widget* ShowWebModalDialogWithOverlayViews( |
| 169 views::WidgetDelegate* dialog, | 224 views::WidgetDelegate* dialog, |
| 170 content::WebContents* initiator_web_contents) { | 225 content::WebContents* initiator_web_contents) { |
| 171 DCHECK(constrained_window_views_client); | 226 DCHECK(constrained_window_views_client); |
| 172 // For embedded WebContents, use the embedder's WebContents for constrained | 227 // For embedded WebContents, use the embedder's WebContents for constrained |
| 173 // window. | 228 // window. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (host) { | 280 if (host) { |
| 226 DCHECK_EQ(parent_view, host->GetHostView()); | 281 DCHECK_EQ(parent_view, host->GetHostView()); |
| 227 ModalDialogHostObserver* dialog_host_observer = | 282 ModalDialogHostObserver* dialog_host_observer = |
| 228 new WidgetModalDialogHostObserverViews( | 283 new WidgetModalDialogHostObserverViews( |
| 229 host, widget, kWidgetModalDialogHostObserverViewsKey); | 284 host, widget, kWidgetModalDialogHostObserverViewsKey); |
| 230 dialog_host_observer->OnPositionRequiresUpdate(); | 285 dialog_host_observer->OnPositionRequiresUpdate(); |
| 231 } | 286 } |
| 232 return widget; | 287 return widget; |
| 233 } | 288 } |
| 234 | 289 |
| 235 } // namespace constrained window | 290 } // namespace constrained_window |
| OLD | NEW |