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

Side by Side 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: Track independent bounds as native window property not member of widget class Created 4 years, 4 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 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"
11 #include "components/constrained_window/constrained_window_views_client.h" 11 #include "components/constrained_window/constrained_window_views_client.h"
12 #include "components/guest_view/browser/guest_view_base.h" 12 #include "components/guest_view/browser/guest_view_base.h"
13 #include "components/web_modal/web_contents_modal_dialog_host.h" 13 #include "components/web_modal/web_contents_modal_dialog_host.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" 14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
16 #include "ui/views/border.h" 16 #include "ui/views/border.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_observer.h" 18 #include "ui/views/widget/widget_observer.h"
19 #include "ui/views/window/dialog_delegate.h" 19 #include "ui/views/window/dialog_delegate.h"
20 20
21 using web_modal::ModalDialogHost; 21 using web_modal::ModalDialogHost;
22 using web_modal::ModalDialogHostObserver; 22 using web_modal::ModalDialogHostObserver;
23 23
24 namespace constrained_window { 24 namespace constrained_window {
25
26 const char kHasIndependentBoundsKey[] = "__INDEPENDENT_BOUNDS__";
Mike Wittman 2016/08/05 16:03:46 If I understood Scott correctly in the off-review
rbpotter 2016/08/12 16:36:07 Done.
27
25 namespace { 28 namespace {
26 29
27 ConstrainedWindowViewsClient* constrained_window_views_client = NULL; 30 ConstrainedWindowViewsClient* constrained_window_views_client = NULL;
28 31
29 // The name of a key to store on the window handle to associate 32 // The name of a key to store on the window handle to associate
30 // WidgetModalDialogHostObserverViews with the Widget. 33 // WidgetModalDialogHostObserverViews with the Widget.
31 const char* const kWidgetModalDialogHostObserverViewsKey = 34 const char* const kWidgetModalDialogHostObserverViewsKey =
32 "__WIDGET_MODAL_DIALOG_HOST_OBSERVER_VIEWS__"; 35 "__WIDGET_MODAL_DIALOG_HOST_OBSERVER_VIEWS__";
33 36
34 // Applies positioning changes from the ModalDialogHost to the Widget. 37 // Applies positioning changes from the ModalDialogHost to the Widget.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return; 87 return;
85 88
86 gfx::Point position = dialog_host->GetDialogPosition(size); 89 gfx::Point position = dialog_host->GetDialogPosition(size);
87 views::Border* border = widget->non_client_view()->frame_view()->border(); 90 views::Border* border = widget->non_client_view()->frame_view()->border();
88 // Border may be null during widget initialization. 91 // Border may be null during widget initialization.
89 if (border) { 92 if (border) {
90 // Align the first row of pixels inside the border. This is the apparent 93 // Align the first row of pixels inside the border. This is the apparent
91 // top of the dialog. 94 // top of the dialog.
92 position.set_y(position.y() - border->GetInsets().top()); 95 position.set_y(position.y() - border->GetInsets().top());
93 } 96 }
94
95 if (widget->is_top_level()) { 97 if (widget->is_top_level()) {
96 position += 98 position +=
97 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())-> 99 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())->
98 GetClientAreaBoundsInScreen().OffsetFromOrigin(); 100 GetClientAreaBoundsInScreen().OffsetFromOrigin();
101 } else {
102 bool * independent_bounds = NULL;
103 independent_bounds = reinterpret_cast<bool*>(
Mike Wittman 2016/08/05 16:03:46 static_cast<> is preferred when casting from void*
rbpotter 2016/08/12 16:36:07 Done.
104 widget->GetNativeWindowProperty(kHasIndependentBoundsKey));
105 if (independent_bounds && *independent_bounds) {
106 gfx::Rect bound =
107 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())->
108 GetClientAreaBoundsInScreen();
109 if (bound.width() - border->GetInsets().left() < size.width()) {
110 position.set_x(position.x() + (size.width()-bound.width())/2 +
111 border->GetInsets().left());
112 }
113 }
99 } 114 }
100
101 widget->SetBounds(gfx::Rect(position, size)); 115 widget->SetBounds(gfx::Rect(position, size));
102 } 116 }
103 117
104 } // namespace 118 } // namespace
105 119
106 // static 120 // static
107 void SetConstrainedWindowViewsClient( 121 void SetConstrainedWindowViewsClient(
108 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { 122 std::unique_ptr<ConstrainedWindowViewsClient> new_client) {
109 delete constrained_window_views_client; 123 delete constrained_window_views_client;
110 constrained_window_views_client = new_client.release(); 124 constrained_window_views_client = new_client.release();
111 } 125 }
112 126
113 void UpdateWebContentsModalDialogPosition( 127 void UpdateWebContentsModalDialogPosition(
114 views::Widget* widget, 128 views::Widget* widget,
115 web_modal::WebContentsModalDialogHost* dialog_host) { 129 web_modal::WebContentsModalDialogHost* dialog_host) {
116 gfx::Size size = widget->GetRootView()->GetPreferredSize(); 130 gfx::Size size = widget->GetRootView()->GetPreferredSize();
117 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); 131 gfx::Size max_size = dialog_host->GetMaximumDialogSize();
118 // Enlarge the max size by the top border, as the dialog will be shifted 132 // 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. 133 // outside the area specified by the dialog host by this amount later.
120 views::Border* border = 134 views::Border* border =
121 widget->non_client_view()->frame_view()->border(); 135 widget->non_client_view()->frame_view()->border();
122 // Border may be null during widget initialization. 136 // Border may be null during widget initialization.
123 if (border) 137 if (border)
124 max_size.Enlarge(0, border->GetInsets().top()); 138 max_size.Enlarge(0, border->GetInsets().top());
125 size.SetToMin(max_size); 139 bool * independent_bounds = NULL;
140 independent_bounds = reinterpret_cast<bool*>(
141 widget->GetNativeWindowProperty(kHasIndependentBoundsKey));
142 if (!(independent_bounds && *independent_bounds)) {
143 size.SetToMin(max_size);
144 }
126 UpdateModalDialogPosition(widget, dialog_host, size); 145 UpdateModalDialogPosition(widget, dialog_host, size);
127 } 146 }
128 147
129 void UpdateWidgetModalDialogPosition(views::Widget* widget, 148 void UpdateWidgetModalDialogPosition(views::Widget* widget,
130 web_modal::ModalDialogHost* dialog_host) { 149 web_modal::ModalDialogHost* dialog_host) {
131 UpdateModalDialogPosition(widget, dialog_host, 150 UpdateModalDialogPosition(widget, dialog_host,
132 widget->GetRootView()->GetPreferredSize()); 151 widget->GetRootView()->GetPreferredSize());
133 } 152 }
134 153
135 views::Widget* ShowWebModalDialogViews( 154 views::Widget* ShowWebModalDialogViews(
136 views::WidgetDelegate* dialog, 155 views::WidgetDelegate* dialog,
137 content::WebContents* initiator_web_contents) { 156 content::WebContents* initiator_web_contents) {
138 DCHECK(constrained_window_views_client); 157 DCHECK(constrained_window_views_client);
139 // For embedded WebContents, use the embedder's WebContents for constrained 158 // For embedded WebContents, use the embedder's WebContents for constrained
140 // window. 159 // window.
141 content::WebContents* web_contents = 160 content::WebContents* web_contents =
142 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents); 161 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
143 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents); 162 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
144 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 163 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
145 ->ShowModalDialog(widget->GetNativeWindow()); 164 ->ShowModalDialog(widget->GetNativeWindow(), NULL, NULL);
146 return widget; 165 return widget;
147 } 166 }
148 167
168 views::Widget* ShowWebModalDialogWithIndBoundsViews(
169 views::WidgetDelegate* dialog,
170 content::WebContents* initiator_web_contents,
171 bool * independent_bounds) {
172 DCHECK(constrained_window_views_client);
173 // For embedded WebContents, use the embedder's WebContents for constrained
174 // window.
175 content::WebContents* web_contents =
176 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
177 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
178 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
179 ->ShowModalDialog(widget->GetNativeWindow(), independent_bounds,
180 kHasIndependentBoundsKey);
181 return widget;
182 }
183
149 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, 184 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
150 content::WebContents* web_contents) { 185 content::WebContents* web_contents) {
151 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); 186 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType());
152 return views::DialogDelegate::CreateDialogWidget( 187 return views::DialogDelegate::CreateDialogWidget(
153 dialog, nullptr, 188 dialog, nullptr,
154 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 189 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
155 ->delegate() 190 ->delegate()
156 ->GetWebContentsModalDialogHost() 191 ->GetWebContentsModalDialogHost()
157 ->GetHostView()); 192 ->GetHostView());
158 } 193 }
(...skipping 27 matching lines...) Expand all
186 DCHECK_EQ(parent_view, host->GetHostView()); 221 DCHECK_EQ(parent_view, host->GetHostView());
187 ModalDialogHostObserver* dialog_host_observer = 222 ModalDialogHostObserver* dialog_host_observer =
188 new WidgetModalDialogHostObserverViews( 223 new WidgetModalDialogHostObserverViews(
189 host, widget, kWidgetModalDialogHostObserverViewsKey); 224 host, widget, kWidgetModalDialogHostObserverViewsKey);
190 dialog_host_observer->OnPositionRequiresUpdate(); 225 dialog_host_observer->OnPositionRequiresUpdate();
191 } 226 }
192 return widget; 227 return widget;
193 } 228 }
194 229
195 } // namespace constrained window 230 } // namespace constrained window
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698