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

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: Change to CrOS only. 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 bool* independent_bounds = NULL;
105 #if defined(USE_AURA)
106 independent_bounds = static_cast<bool*>(
107 widget->GetNativeWindowProperty(wm::kHasIndependentBoundsKey));
108 #endif
109 if (independent_bounds && *independent_bounds) {
110 gfx::Rect bound =
111 views::Widget::GetWidgetForNativeView(dialog_host->GetHostView())
112 ->GetClientAreaBoundsInScreen();
113 if (bound.width() - border->GetInsets().left() < size.width()) {
Mike Wittman 2016/08/12 22:51:34 comment what this logic is doing
rbpotter 2016/08/15 18:03:45 Done.
114 position.set_x(position.x() + (size.width() - bound.width()) / 2 +
115 border->GetInsets().left());
116 }
117 }
99 } 118 }
100 119
101 widget->SetBounds(gfx::Rect(position, size)); 120 widget->SetBounds(gfx::Rect(position, size));
102 } 121 }
103 122
104 } // namespace 123 } // namespace
105 124
106 // static 125 // static
107 void SetConstrainedWindowViewsClient( 126 void SetConstrainedWindowViewsClient(
108 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { 127 std::unique_ptr<ConstrainedWindowViewsClient> new_client) {
109 delete constrained_window_views_client; 128 delete constrained_window_views_client;
110 constrained_window_views_client = new_client.release(); 129 constrained_window_views_client = new_client.release();
111 } 130 }
112 131
113 void UpdateWebContentsModalDialogPosition( 132 void UpdateWebContentsModalDialogPosition(
114 views::Widget* widget, 133 views::Widget* widget,
115 web_modal::WebContentsModalDialogHost* dialog_host) { 134 web_modal::WebContentsModalDialogHost* dialog_host) {
116 gfx::Size size = widget->GetRootView()->GetPreferredSize(); 135 gfx::Size size = widget->GetRootView()->GetPreferredSize();
117 gfx::Size max_size = dialog_host->GetMaximumDialogSize(); 136 gfx::Size max_size = dialog_host->GetMaximumDialogSize();
118 // Enlarge the max size by the top border, as the dialog will be shifted 137 // 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. 138 // outside the area specified by the dialog host by this amount later.
120 views::Border* border = 139 views::Border* border =
121 widget->non_client_view()->frame_view()->border(); 140 widget->non_client_view()->frame_view()->border();
122 // Border may be null during widget initialization. 141 // Border may be null during widget initialization.
123 if (border) 142 if (border)
124 max_size.Enlarge(0, border->GetInsets().top()); 143 max_size.Enlarge(0, border->GetInsets().top());
125 size.SetToMin(max_size); 144 bool* independent_bounds = NULL;
145 #if defined(USE_AURA)
146 independent_bounds = static_cast<bool*>(
147 widget->GetNativeWindowProperty(wm::kHasIndependentBoundsKey));
148 #endif
149 if (!(independent_bounds && *independent_bounds)) {
150 size.SetToMin(max_size);
151 }
126 UpdateModalDialogPosition(widget, dialog_host, size); 152 UpdateModalDialogPosition(widget, dialog_host, size);
127 } 153 }
128 154
129 void UpdateWidgetModalDialogPosition(views::Widget* widget, 155 void UpdateWidgetModalDialogPosition(views::Widget* widget,
130 web_modal::ModalDialogHost* dialog_host) { 156 web_modal::ModalDialogHost* dialog_host) {
131 UpdateModalDialogPosition(widget, dialog_host, 157 UpdateModalDialogPosition(widget, dialog_host,
132 widget->GetRootView()->GetPreferredSize()); 158 widget->GetRootView()->GetPreferredSize());
133 } 159 }
134 160
135 views::Widget* ShowWebModalDialogViews( 161 views::Widget* ShowWebModalDialogViews(
136 views::WidgetDelegate* dialog, 162 views::WidgetDelegate* dialog,
137 content::WebContents* initiator_web_contents) { 163 content::WebContents* initiator_web_contents) {
138 DCHECK(constrained_window_views_client); 164 DCHECK(constrained_window_views_client);
139 // For embedded WebContents, use the embedder's WebContents for constrained 165 // For embedded WebContents, use the embedder's WebContents for constrained
140 // window. 166 // window.
141 content::WebContents* web_contents = 167 content::WebContents* web_contents =
142 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents); 168 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
143 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents); 169 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
144 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 170 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
145 ->ShowModalDialog(widget->GetNativeWindow()); 171 ->ShowModalDialog(widget->GetNativeWindow());
146 return widget; 172 return widget;
147 } 173 }
148 174
175 views::Widget* ShowNonClippedWebModalDialogViews(
176 views::WidgetDelegate* dialog,
177 content::WebContents* initiator_web_contents) {
178 DCHECK(constrained_window_views_client);
179 // For embedded WebContents, use the embedder's WebContents for constrained
180 // window.
181 content::WebContents* web_contents =
182 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
183 views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
184 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
185 ->ShowNonClippedModalDialog(widget->GetNativeWindow());
186 return widget;
187 }
188
149 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog, 189 views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
150 content::WebContents* web_contents) { 190 content::WebContents* web_contents) {
151 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); 191 DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType());
152 return views::DialogDelegate::CreateDialogWidget( 192 return views::DialogDelegate::CreateDialogWidget(
153 dialog, nullptr, 193 dialog, nullptr,
154 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) 194 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
155 ->delegate() 195 ->delegate()
156 ->GetWebContentsModalDialogHost() 196 ->GetWebContentsModalDialogHost()
157 ->GetHostView()); 197 ->GetHostView());
158 } 198 }
(...skipping 26 matching lines...) Expand all
185 if (host) { 225 if (host) {
186 DCHECK_EQ(parent_view, host->GetHostView()); 226 DCHECK_EQ(parent_view, host->GetHostView());
187 ModalDialogHostObserver* dialog_host_observer = 227 ModalDialogHostObserver* dialog_host_observer =
188 new WidgetModalDialogHostObserverViews( 228 new WidgetModalDialogHostObserverViews(
189 host, widget, kWidgetModalDialogHostObserverViewsKey); 229 host, widget, kWidgetModalDialogHostObserverViewsKey);
190 dialog_host_observer->OnPositionRequiresUpdate(); 230 dialog_host_observer->OnPositionRequiresUpdate();
191 } 231 }
192 return widget; 232 return widget;
193 } 233 }
194 234
195 } // namespace constrained window 235 } // namespace constrained_window
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698