OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/widget/widget.h" | 5 #include "views/widget/widget.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "ui/base/l10n/l10n_font_util.h" | 10 #include "ui/base/l10n/l10n_font_util.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/compositor/compositor.h" | 12 #include "ui/gfx/compositor/compositor.h" |
13 #include "ui/gfx/compositor/layer.h" | 13 #include "ui/gfx/compositor/layer.h" |
| 14 #include "ui/gfx/screen.h" |
14 #include "views/controls/menu/menu_controller.h" | 15 #include "views/controls/menu/menu_controller.h" |
15 #include "views/focus/focus_manager.h" | 16 #include "views/focus/focus_manager.h" |
16 #include "views/focus/focus_manager_factory.h" | 17 #include "views/focus/focus_manager_factory.h" |
17 #include "views/focus/view_storage.h" | 18 #include "views/focus/view_storage.h" |
18 #include "views/focus/widget_focus_manager.h" | 19 #include "views/focus/widget_focus_manager.h" |
19 #include "views/ime/input_method.h" | 20 #include "views/ime/input_method.h" |
20 #include "views/views_delegate.h" | 21 #include "views/views_delegate.h" |
21 #include "views/widget/default_theme_provider.h" | 22 #include "views/widget/default_theme_provider.h" |
22 #include "views/widget/native_widget_private.h" | 23 #include "views/widget/native_widget_private.h" |
23 #include "views/widget/root_view.h" | 24 #include "views/widget/root_view.h" |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 423 } |
423 | 424 |
424 void Widget::SetBounds(const gfx::Rect& bounds) { | 425 void Widget::SetBounds(const gfx::Rect& bounds) { |
425 native_widget_->SetBounds(bounds); | 426 native_widget_->SetBounds(bounds); |
426 } | 427 } |
427 | 428 |
428 void Widget::SetSize(const gfx::Size& size) { | 429 void Widget::SetSize(const gfx::Size& size) { |
429 native_widget_->SetSize(size); | 430 native_widget_->SetSize(size); |
430 } | 431 } |
431 | 432 |
432 void Widget::SetBoundsConstrained(const gfx::Rect& bounds, | 433 void Widget::SetBoundsConstrained(const gfx::Rect& bounds) { |
433 Widget* other_widget) { | 434 gfx::Rect work_area = |
434 native_widget_->SetBoundsConstrained(bounds, other_widget); | 435 gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin()); |
| 436 if (work_area.IsEmpty()) { |
| 437 SetBounds(bounds); |
| 438 } else { |
| 439 // Inset the work area slightly. |
| 440 work_area.Inset(10, 10, 10, 10); |
| 441 SetBounds(work_area.AdjustToFit(bounds)); |
| 442 } |
435 } | 443 } |
436 | 444 |
437 void Widget::MoveAboveWidget(Widget* widget) { | 445 void Widget::MoveAboveWidget(Widget* widget) { |
438 native_widget_->MoveAbove(widget->GetNativeView()); | 446 native_widget_->MoveAbove(widget->GetNativeView()); |
439 } | 447 } |
440 | 448 |
441 void Widget::MoveAbove(gfx::NativeView native_view) { | 449 void Widget::MoveAbove(gfx::NativeView native_view) { |
442 native_widget_->MoveAbove(native_view); | 450 native_widget_->MoveAbove(native_view); |
443 } | 451 } |
444 | 452 |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 } else { | 1154 } else { |
1147 SetBounds(saved_bounds); | 1155 SetBounds(saved_bounds); |
1148 } | 1156 } |
1149 } else { | 1157 } else { |
1150 if (bounds.IsEmpty()) { | 1158 if (bounds.IsEmpty()) { |
1151 // No initial bounds supplied, so size the window to its content and | 1159 // No initial bounds supplied, so size the window to its content and |
1152 // center over its parent. | 1160 // center over its parent. |
1153 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); | 1161 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); |
1154 } else { | 1162 } else { |
1155 // Use the supplied initial bounds. | 1163 // Use the supplied initial bounds. |
1156 SetBoundsConstrained(bounds, NULL); | 1164 SetBoundsConstrained(bounds); |
1157 } | 1165 } |
1158 } | 1166 } |
1159 } | 1167 } |
1160 | 1168 |
1161 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, | 1169 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, |
1162 ui::WindowShowState* show_state) { | 1170 ui::WindowShowState* show_state) { |
1163 // First we obtain the window's saved show-style and store it. We need to do | 1171 // First we obtain the window's saved show-style and store it. We need to do |
1164 // this here, rather than in Show() because by the time Show() is called, | 1172 // this here, rather than in Show() because by the time Show() is called, |
1165 // the window's size will have been reset (below) and the saved maximized | 1173 // the window's size will have been reset (below) and the saved maximized |
1166 // state will have been lost. Sadly there's no way to tell on Windows when | 1174 // state will have been lost. Sadly there's no way to tell on Windows when |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1207 |
1200 //////////////////////////////////////////////////////////////////////////////// | 1208 //////////////////////////////////////////////////////////////////////////////// |
1201 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1209 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1202 | 1210 |
1203 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1211 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1204 return this; | 1212 return this; |
1205 } | 1213 } |
1206 | 1214 |
1207 } // namespace internal | 1215 } // namespace internal |
1208 } // namespace views | 1216 } // namespace views |
OLD | NEW |