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

Side by Side Diff: components/constrained_window/constrained_window_views.cc

Issue 2551773002: MacViews: Exploring removal of window-modal sheets.
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 DISALLOW_COPY_AND_ASSIGN(WidgetModalDialogHostObserverViews); 80 DISALLOW_COPY_AND_ASSIGN(WidgetModalDialogHostObserverViews);
81 }; 81 };
82 82
83 void UpdateModalDialogPosition(views::Widget* widget, 83 void UpdateModalDialogPosition(views::Widget* widget,
84 web_modal::ModalDialogHost* dialog_host, 84 web_modal::ModalDialogHost* dialog_host,
85 const gfx::Size& size) { 85 const gfx::Size& size) {
86 // Do not forcibly update the dialog widget position if it is being dragged. 86 // Do not forcibly update the dialog widget position if it is being dragged.
87 if (widget->HasCapture()) 87 if (widget->HasCapture())
88 return; 88 return;
89 89
90 views::Widget* host_widget =
91 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView());
92
93 // If the host view is not backed by a Views::Widget, just update the widget
94 // size. This can happen on MacViews under the Cocoa browser where the window
95 // modal dialogs are displayed as sheets, and their position is managed by a
96 // ConstrainedWindowSheetController instance.
97 if (!host_widget) {
98 widget->SetSize(size);
99 return;
100 }
101
102 gfx::Point position = dialog_host->GetDialogPosition(size); 90 gfx::Point position = dialog_host->GetDialogPosition(size);
103 views::Border* border = widget->non_client_view()->frame_view()->border(); 91 views::Border* border = widget->non_client_view()->frame_view()->border();
104 // Border may be null during widget initialization. 92 // Border may be null during widget initialization.
105 if (border) { 93 if (border) {
106 // Align the first row of pixels inside the border. This is the apparent 94 // Align the first row of pixels inside the border. This is the apparent
107 // top of the dialog. 95 // top of the dialog.
108 position.set_y(position.y() - border->GetInsets().top()); 96 position.set_y(position.y() - border->GetInsets().top());
109 } 97 }
110 98
111 if (widget->is_top_level()) 99 if (widget->is_top_level())
112 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); 100 position += dialog_host->GetHostPosition().OffsetFromOrigin();
113 101
114 widget->SetBounds(gfx::Rect(position, size)); 102 widget->SetBounds(gfx::Rect(position, size));
115 } 103 }
116 104
117 } // namespace 105 } // namespace
118 106
119 // static 107 // static
120 void SetConstrainedWindowViewsClient( 108 void SetConstrainedWindowViewsClient(
121 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { 109 std::unique_ptr<ConstrainedWindowViewsClient> new_client) {
122 delete constrained_window_views_client; 110 delete constrained_window_views_client;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 DCHECK_NE(ui::MODAL_TYPE_NONE, dialog->GetModalType()); 190 DCHECK_NE(ui::MODAL_TYPE_NONE, dialog->GetModalType());
203 DCHECK(!parent || constrained_window_views_client); 191 DCHECK(!parent || constrained_window_views_client);
204 192
205 gfx::NativeView parent_view = 193 gfx::NativeView parent_view =
206 parent ? constrained_window_views_client->GetDialogHostView(parent) 194 parent ? constrained_window_views_client->GetDialogHostView(parent)
207 : nullptr; 195 : nullptr;
208 views::Widget* widget = 196 views::Widget* widget =
209 views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view); 197 views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view);
210 198
211 bool requires_positioning = dialog->ShouldUseCustomFrame(); 199 bool requires_positioning = dialog->ShouldUseCustomFrame();
212
213 #if defined(OS_MACOSX)
214 // On Mac, window modal dialogs are displayed as sheets, so their position is
215 // managed by the parent window.
216 requires_positioning = false;
217 #endif
218
219 if (!requires_positioning) 200 if (!requires_positioning)
220 return widget; 201 return widget;
221 202
222 ModalDialogHost* host = 203 ModalDialogHost* host =
223 parent ? constrained_window_views_client->GetModalDialogHost(parent) 204 parent ? constrained_window_views_client->GetModalDialogHost(parent)
224 : nullptr; 205 : nullptr;
225 if (host) { 206 if (host) {
207 #if !defined(OS_MACOSX)
208 // On Mac, the host view for tab-modal dialogs may differ from the host view
209 // for window-modal dialogs. There is only one ModalDialogHost per window,
210 // designed for tab-modal dialogs, but suitable for positioning window-
211 // modal dialogs as well.
212 // On other platforms, the gfx::NativeView should match.
226 DCHECK_EQ(parent_view, host->GetHostView()); 213 DCHECK_EQ(parent_view, host->GetHostView());
214 #endif
227 ModalDialogHostObserver* dialog_host_observer = 215 ModalDialogHostObserver* dialog_host_observer =
228 new WidgetModalDialogHostObserverViews( 216 new WidgetModalDialogHostObserverViews(
229 host, widget, kWidgetModalDialogHostObserverViewsKey); 217 host, widget, kWidgetModalDialogHostObserverViewsKey);
230 dialog_host_observer->OnPositionRequiresUpdate(); 218 dialog_host_observer->OnPositionRequiresUpdate();
231 } 219 }
232 return widget; 220 return widget;
233 } 221 }
234 222
235 } // namespace constrained window 223 } // namespace constrained window
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698