Chromium Code Reviews| 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 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 gfx::Point position = dialog_host->GetDialogPosition(size); | 86 gfx::Point position = dialog_host->GetDialogPosition(size); |
| 87 views::Border* border = widget->non_client_view()->frame_view()->border(); | 87 views::Border* border = widget->non_client_view()->frame_view()->border(); |
| 88 // Border may be null during widget initialization. | 88 // Border may be null during widget initialization. |
| 89 if (border) { | 89 if (border) { |
| 90 // Align the first row of pixels inside the border. This is the apparent | 90 // Align the first row of pixels inside the border. This is the apparent |
| 91 // top of the dialog. | 91 // top of the dialog. |
| 92 position.set_y(position.y() - border->GetInsets().top()); | 92 position.set_y(position.y() - border->GetInsets().top()); |
| 93 } | 93 } |
| 94 | |
| 95 if (widget->is_top_level()) { | 94 if (widget->is_top_level()) { |
| 96 position += | 95 if (!widget->IsModalTypeChild()) |
| 96 position += | |
| 97 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())-> | 97 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())-> |
| 98 GetClientAreaBoundsInScreen().OffsetFromOrigin(); | 98 GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
| 99 | |
| 100 if (widget->IsModalTypeChild()) { | |
|
Mike Wittman
2016/07/26 17:27:35
nit: if else
rbpotter
2016/07/26 21:48:19
Acknowledged.
| |
| 101 gfx::Rect bound = | |
| 102 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())-> | |
| 103 GetClientAreaBoundsInScreen(); | |
| 104 if (bound.width() - border->GetInsets().left() < size.width()) { | |
| 105 position.set_x(position.x() + (size.width()-bound.width())/2 + | |
| 106 border->GetInsets().left()); | |
| 107 } | |
| 108 } | |
| 99 } | 109 } |
| 100 | |
| 101 widget->SetBounds(gfx::Rect(position, size)); | 110 widget->SetBounds(gfx::Rect(position, size)); |
| 102 } | 111 } |
| 103 | 112 |
| 104 } // namespace | 113 } // namespace |
| 105 | 114 |
| 106 // static | 115 // static |
| 107 void SetConstrainedWindowViewsClient( | 116 void SetConstrainedWindowViewsClient( |
| 108 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { | 117 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { |
| 109 delete constrained_window_views_client; | 118 delete constrained_window_views_client; |
| 110 constrained_window_views_client = new_client.release(); | 119 constrained_window_views_client = new_client.release(); |
| 111 } | 120 } |
| 112 | 121 |
| 113 void UpdateWebContentsModalDialogPosition( | 122 void UpdateWebContentsModalDialogPosition( |
| 114 views::Widget* widget, | 123 views::Widget* widget, |
| 115 web_modal::WebContentsModalDialogHost* dialog_host) { | 124 web_modal::WebContentsModalDialogHost* dialog_host) { |
| 116 gfx::Size size = widget->GetRootView()->GetPreferredSize(); | 125 gfx::Size size = widget->GetRootView()->GetPreferredSize(); |
| 117 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); | 126 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); |
| 118 // Enlarge the max size by the top border, as the dialog will be shifted | 127 // Enlarge the max size by the top border, as the dialog will be shifted |
| 119 // outside the area specified by the dialog host by this amount later. | 128 // outside the area specified by the dialog host by this amount later. |
| 120 views::Border* border = | 129 views::Border* border = |
| 121 widget->non_client_view()->frame_view()->border(); | 130 widget->non_client_view()->frame_view()->border(); |
| 122 // Border may be null during widget initialization. | 131 // Border may be null during widget initialization. |
| 123 if (border) | 132 if (border) |
| 124 max_size.Enlarge(0, border->GetInsets().top()); | 133 max_size.Enlarge(0, border->GetInsets().top()); |
| 125 size.SetToMin(max_size); | 134 if (!widget->is_top_level()) |
| 135 size.SetToMin(max_size); | |
| 126 UpdateModalDialogPosition(widget, dialog_host, size); | 136 UpdateModalDialogPosition(widget, dialog_host, size); |
| 127 } | 137 } |
| 128 | 138 |
| 129 void UpdateWidgetModalDialogPosition(views::Widget* widget, | 139 void UpdateWidgetModalDialogPosition(views::Widget* widget, |
| 130 web_modal::ModalDialogHost* dialog_host) { | 140 web_modal::ModalDialogHost* dialog_host) { |
| 131 UpdateModalDialogPosition(widget, dialog_host, | 141 UpdateModalDialogPosition(widget, dialog_host, |
| 132 widget->GetRootView()->GetPreferredSize()); | 142 widget->GetRootView()->GetPreferredSize()); |
| 133 } | 143 } |
| 134 | 144 |
| 135 views::Widget* ShowWebModalDialogViews( | 145 views::Widget* ShowWebModalDialogViews( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 DCHECK_EQ(parent_view, host->GetHostView()); | 196 DCHECK_EQ(parent_view, host->GetHostView()); |
| 187 ModalDialogHostObserver* dialog_host_observer = | 197 ModalDialogHostObserver* dialog_host_observer = |
| 188 new WidgetModalDialogHostObserverViews( | 198 new WidgetModalDialogHostObserverViews( |
| 189 host, widget, kWidgetModalDialogHostObserverViewsKey); | 199 host, widget, kWidgetModalDialogHostObserverViewsKey); |
| 190 dialog_host_observer->OnPositionRequiresUpdate(); | 200 dialog_host_observer->OnPositionRequiresUpdate(); |
| 191 } | 201 } |
| 192 return widget; | 202 return widget; |
| 193 } | 203 } |
| 194 | 204 |
| 195 } // namespace constrained window | 205 } // namespace constrained window |
| OLD | NEW |