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

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: Various fixes 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 #if defined(USE_AURA)
22 #include "ui/wm/core/window_modality_controller.h"
23 #endif
24
21 using web_modal::ModalDialogHost; 25 using web_modal::ModalDialogHost;
22 using web_modal::ModalDialogHostObserver; 26 using web_modal::ModalDialogHostObserver;
23 27
24 namespace constrained_window { 28 namespace constrained_window {
25 namespace { 29 namespace {
26 30
27 ConstrainedWindowViewsClient* constrained_window_views_client = NULL; 31 ConstrainedWindowViewsClient* constrained_window_views_client = NULL;
28 32
29 // The name of a key to store on the window handle to associate 33 // The name of a key to store on the window handle to associate
30 // WidgetModalDialogHostObserverViews with the Widget. 34 // WidgetModalDialogHostObserverViews with the Widget.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (border) { 93 if (border) {
90 // 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
91 // top of the dialog. 95 // top of the dialog.
92 position.set_y(position.y() - border->GetInsets().top()); 96 position.set_y(position.y() - border->GetInsets().top());
93 } 97 }
94 98
95 if (widget->is_top_level()) { 99 if (widget->is_top_level()) {
96 position += 100 position +=
97 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())-> 101 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())->
98 GetClientAreaBoundsInScreen().OffsetFromOrigin(); 102 GetClientAreaBoundsInScreen().OffsetFromOrigin();
103 } else {
104 void* independent_bounds = NULL;
Mike Wittman 2016/08/15 19:36:37 Enclosing all this in the preprocessor conditional
rbpotter 2016/08/15 21:32:54 Done.
105 #if defined(USE_AURA)
106 independent_bounds =
107 widget->GetNativeWindowProperty(wm::kHasIndependentBoundsKey);
108 #endif
109
110 // Prevents widgets that extend outside the parent window from having their
111 // horizontal position cetnered on the center of the parent window.
112 // Instead, positions top left corner in parent top left corner so widget
113 // extends below and to the right of the parent window.
114 if (independent_bounds) {
115 gfx::Rect bound =
116 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())
117 ->GetClientAreaBoundsInScreen();
118 if (bound.width() - border->GetInsets().left() < size.width()) {
119 position.set_x(position.x() + (size.width() - bound.width()) / 2 +
120 border->GetInsets().left());
121 }
122 }
99 } 123 }
100 124
101 widget->SetBounds(gfx::Rect(position, size)); 125 widget->SetBounds(gfx::Rect(position, size));
102 } 126 }
103 127
104 } // namespace 128 } // namespace
105 129
106 // static 130 // static
107 void SetConstrainedWindowViewsClient( 131 void SetConstrainedWindowViewsClient(
108 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { 132 std::unique_ptr<ConstrainedWindowViewsClient> new_client) {
109 delete constrained_window_views_client; 133 delete constrained_window_views_client;
110 constrained_window_views_client = new_client.release(); 134 constrained_window_views_client = new_client.release();
111 } 135 }
112 136
113 void UpdateWebContentsModalDialogPosition( 137 void UpdateWebContentsModalDialogPosition(
114 views::Widget* widget, 138 views::Widget* widget,
115 web_modal::WebContentsModalDialogHost* dialog_host) { 139 web_modal::WebContentsModalDialogHost* dialog_host) {
116 gfx::Size size = widget->GetRootView()->GetPreferredSize(); 140 gfx::Size size = widget->GetRootView()->GetPreferredSize();
117 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); 141 gfx::Size max_size = dialog_host->GetMaximumDialogSize();
118 // Enlarge the max size by the top border, as the dialog will be shifted 142 // 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. 143 // outside the area specified by the dialog host by this amount later.
120 views::Border* border = 144 views::Border* border =
121 widget->non_client_view()->frame_view()->border(); 145 widget->non_client_view()->frame_view()->border();
122 // Border may be null during widget initialization. 146 // Border may be null during widget initialization.
123 if (border) 147 if (border)
124 max_size.Enlarge(0, border->GetInsets().top()); 148 max_size.Enlarge(0, border->GetInsets().top());
125 size.SetToMin(max_size); 149 void* independent_bounds = NULL;
Mike Wittman 2016/08/15 19:36:37 This variable is clearer as a bool, and set separa
rbpotter 2016/08/15 21:32:54 Done.
150 #if defined(USE_AURA)
151 independent_bounds =
152 widget->GetNativeWindowProperty(wm::kHasIndependentBoundsKey);
153 #endif
154 if (!independent_bounds) {
155 size.SetToMin(max_size);
156 }
126 UpdateModalDialogPosition(widget, dialog_host, size); 157 UpdateModalDialogPosition(widget, dialog_host, size);
127 } 158 }
128 159
129 void UpdateWidgetModalDialogPosition(views::Widget* widget, 160 void UpdateWidgetModalDialogPosition(views::Widget* widget,
130 web_modal::ModalDialogHost* dialog_host) { 161 web_modal::ModalDialogHost* dialog_host) {
131 UpdateModalDialogPosition(widget, dialog_host, 162 UpdateModalDialogPosition(widget, dialog_host,
132 widget->GetRootView()->GetPreferredSize()); 163 widget->GetRootView()->GetPreferredSize());
133 } 164 }
134 165
135 views::Widget* ShowWebModalDialogViews( 166 views::Widget* ShowWebModalDialogViews(
136 views::WidgetDelegate* dialog, 167 views::WidgetDelegate* dialog,
137 content::WebContents* initiator_web_contents) { 168 content::WebContents* initiator_web_contents) {
138 DCHECK(constrained_window_views_client); 169 DCHECK(constrained_window_views_client);
139 // For embedded WebContents, use the embedder's WebContents for constrained 170 // For embedded WebContents, use the embedder's WebContents for constrained
140 // window. 171 // window.
141 content::WebContents* web_contents = 172 content::WebContents* web_contents =
142 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents); 173 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
143 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents); 174 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
144 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 175 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
145 ->ShowModalDialog(widget->GetNativeWindow()); 176 ->ShowModalDialog(widget->GetNativeWindow());
146 return widget; 177 return widget;
147 } 178 }
148 179
180 views::Widget* ShowNonClippedWebModalDialogViews(
181 views::WidgetDelegate* dialog,
182 content::WebContents* initiator_web_contents) {
183 DCHECK(constrained_window_views_client);
184 // For embedded WebContents, use the embedder's WebContents for constrained
185 // window.
186 content::WebContents* web_contents =
187 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
188 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
189 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
190 ->ShowNonClippedModalDialog(widget->GetNativeWindow());
191 return widget;
192 }
193
149 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, 194 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
150 content::WebContents* web_contents) { 195 content::WebContents* web_contents) {
151 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); 196 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType());
152 return views::DialogDelegate::CreateDialogWidget( 197 return views::DialogDelegate::CreateDialogWidget(
153 dialog, nullptr, 198 dialog, nullptr,
154 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 199 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
155 ->delegate() 200 ->delegate()
156 ->GetWebContentsModalDialogHost() 201 ->GetWebContentsModalDialogHost()
157 ->GetHostView()); 202 ->GetHostView());
158 } 203 }
(...skipping 26 matching lines...) Expand all
185 if (host) { 230 if (host) {
186 DCHECK_EQ(parent_view, host->GetHostView()); 231 DCHECK_EQ(parent_view, host->GetHostView());
187 ModalDialogHostObserver* dialog_host_observer = 232 ModalDialogHostObserver* dialog_host_observer =
188 new WidgetModalDialogHostObserverViews( 233 new WidgetModalDialogHostObserverViews(
189 host, widget, kWidgetModalDialogHostObserverViewsKey); 234 host, widget, kWidgetModalDialogHostObserverViewsKey);
190 dialog_host_observer->OnPositionRequiresUpdate(); 235 dialog_host_observer->OnPositionRequiresUpdate();
191 } 236 }
192 return widget; 237 return widget;
193 } 238 }
194 239
195 } // namespace constrained window 240 } // namespace constrained_window
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698