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" |
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/display/display.h" | 16 #include "ui/display/display.h" |
17 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 #include "ui/views/widget/widget_observer.h" | 20 #include "ui/views/widget/widget_observer.h" |
21 #include "ui/views/window/dialog_delegate.h" | 21 #include "ui/views/window/dialog_delegate.h" |
22 | 22 |
23 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
24 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" | 24 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" |
25 #endif | 25 #endif |
26 | 26 |
| 27 #if defined(USE_AURA) |
| 28 #include "ui/aura/window.h" |
| 29 #include "ui/compositor/dip_util.h" |
| 30 #endif |
| 31 |
27 using web_modal::ModalDialogHost; | 32 using web_modal::ModalDialogHost; |
28 using web_modal::ModalDialogHostObserver; | 33 using web_modal::ModalDialogHostObserver; |
29 | 34 |
30 namespace constrained_window { | 35 namespace constrained_window { |
31 namespace { | 36 namespace { |
32 | 37 |
33 ConstrainedWindowViewsClient* constrained_window_views_client = nullptr; | 38 ConstrainedWindowViewsClient* constrained_window_views_client = nullptr; |
34 | 39 |
35 // The name of a key to store on the window handle to associate | 40 // The name of a key to store on the window handle to associate |
36 // WidgetModalDialogHostObserverViews with the Widget. | 41 // WidgetModalDialogHostObserverViews with the Widget. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const display::Display display = | 124 const display::Display display = |
120 display::Screen::GetScreen()->GetDisplayNearestView( | 125 display::Screen::GetScreen()->GetDisplayNearestView( |
121 dialog_host->GetHostView()); | 126 dialog_host->GetHostView()); |
122 const gfx::Rect work_area = display.work_area(); | 127 const gfx::Rect work_area = display.work_area(); |
123 if (!work_area.Contains(display_rect)) | 128 if (!work_area.Contains(display_rect)) |
124 display_rect.AdjustToFit(work_area); | 129 display_rect.AdjustToFit(work_area); |
125 position = display_rect.origin(); | 130 position = display_rect.origin(); |
126 } | 131 } |
127 | 132 |
128 widget->SetBounds(gfx::Rect(position, size)); | 133 widget->SetBounds(gfx::Rect(position, size)); |
| 134 |
| 135 #if defined(USE_AURA) |
| 136 if (!widget->is_top_level()) { |
| 137 // Toplevel windows are automatiacally snapped, but CHILD windows |
| 138 // may not. If it's not toplevel, snap the widget's layer to pixel |
| 139 // based on the parent toplevel window, which should be snapped. |
| 140 gfx::NativeView window = widget->GetNativeView(); |
| 141 views::Widget* toplevel = |
| 142 views::Widget::GetTopLevelWidgetForNativeView(window->parent()); |
| 143 ui::SnapLayerToPhysicalPixelBoundary(toplevel->GetLayer(), |
| 144 widget->GetLayer()); |
| 145 } |
| 146 #endif |
129 } | 147 } |
130 | 148 |
131 } // namespace | 149 } // namespace |
132 | 150 |
133 // static | 151 // static |
134 void SetConstrainedWindowViewsClient( | 152 void SetConstrainedWindowViewsClient( |
135 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { | 153 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { |
136 delete constrained_window_views_client; | 154 delete constrained_window_views_client; |
137 constrained_window_views_client = new_client.release(); | 155 constrained_window_views_client = new_client.release(); |
138 } | 156 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 DCHECK_EQ(parent_view, host->GetHostView()); | 258 DCHECK_EQ(parent_view, host->GetHostView()); |
241 ModalDialogHostObserver* dialog_host_observer = | 259 ModalDialogHostObserver* dialog_host_observer = |
242 new WidgetModalDialogHostObserverViews( | 260 new WidgetModalDialogHostObserverViews( |
243 host, widget, kWidgetModalDialogHostObserverViewsKey); | 261 host, widget, kWidgetModalDialogHostObserverViewsKey); |
244 dialog_host_observer->OnPositionRequiresUpdate(); | 262 dialog_host_observer->OnPositionRequiresUpdate(); |
245 } | 263 } |
246 return widget; | 264 return widget; |
247 } | 265 } |
248 | 266 |
249 } // namespace constrained window | 267 } // namespace constrained window |
OLD | NEW |