| Index: views/widget/widget.cc
|
| ===================================================================
|
| --- views/widget/widget.cc (revision 88397)
|
| +++ views/widget/widget.cc (working copy)
|
| @@ -7,6 +7,8 @@
|
| #include "base/logging.h"
|
| #include "base/message_loop.h"
|
| #include "base/utf_string_conversions.h"
|
| +#include "ui/base/l10n/l10n_font_util.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/compositor/compositor.h"
|
| #include "views/focus/view_storage.h"
|
| #include "views/ime/input_method.h"
|
| @@ -98,7 +100,9 @@
|
| is_secondary_widget_(true),
|
| frame_type_(FRAME_TYPE_DEFAULT),
|
| disable_inactive_rendering_(false),
|
| - widget_closed_(false) {
|
| + widget_closed_(false),
|
| + saved_maximized_state_(false),
|
| + minimum_size_(100, 100) {
|
| }
|
|
|
| Widget::~Widget() {
|
| @@ -125,6 +129,25 @@
|
| return native_widget ? native_widget->GetWidget() : NULL;
|
| }
|
|
|
| +// static
|
| +int Widget::GetLocalizedContentsWidth(int col_resource_id) {
|
| + return ui::GetLocalizedContentsWidthForFont(col_resource_id,
|
| + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
|
| +}
|
| +
|
| +// static
|
| +int Widget::GetLocalizedContentsHeight(int row_resource_id) {
|
| + return ui::GetLocalizedContentsHeightForFont(row_resource_id,
|
| + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
|
| +}
|
| +
|
| +// static
|
| +gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
|
| + int row_resource_id) {
|
| + return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
|
| + GetLocalizedContentsHeight(row_resource_id));
|
| +}
|
| +
|
| void Widget::Init(const InitParams& params) {
|
| widget_delegate_ =
|
| params.delegate ? params.delegate : new DefaultWidgetDelegate;
|
| @@ -284,7 +307,17 @@
|
| }
|
|
|
| void Widget::Show() {
|
| - native_widget_->Show();
|
| + if (non_client_view_) {
|
| + native_widget_->ShowNativeWidget(
|
| + saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
|
| + : NativeWidget::SHOW_RESTORED);
|
| + // |saved_maximized_state_| only applies the first time the window is shown.
|
| + // If we don't reset the value the window will be shown maximized every time
|
| + // it is subsequently shown after being hidden.
|
| + saved_maximized_state_ = false;
|
| + } else {
|
| + native_widget_->Show();
|
| + }
|
| }
|
|
|
| void Widget::Hide() {
|
| @@ -524,6 +557,14 @@
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // Widget, NativeWidgetDelegate implementation:
|
|
|
| +bool Widget::IsModal() const {
|
| + return widget_delegate_->IsModal();
|
| +}
|
| +
|
| +bool Widget::IsDialogBox() const {
|
| + return !!widget_delegate_->AsDialogDelegate();
|
| +}
|
| +
|
| bool Widget::CanActivate() const {
|
| return widget_delegate_->CanActivate();
|
| }
|
| @@ -558,7 +599,7 @@
|
| focused_view);
|
| }
|
|
|
| -void Widget::OnNativeWidgetCreated() {
|
| +void Widget::OnNativeWidgetCreated(const gfx::Rect& create_bounds) {
|
| if (GetTopLevelWidget() == this) {
|
| // Only the top level Widget in a native widget hierarchy has a focus
|
| // manager.
|
| @@ -570,6 +611,12 @@
|
| widget_delegate_->GetAccessibleWindowRole());
|
| native_widget_->SetAccessibleState(
|
| widget_delegate_->GetAccessibleWindowState());
|
| +
|
| + if (widget_delegate_->IsModal())
|
| + native_widget_->BecomeModal();
|
| +
|
| + UpdateWindowTitle();
|
| + SetInitialBounds(create_bounds);
|
| }
|
|
|
| void Widget::OnNativeWidgetDestroying() {
|
| @@ -779,6 +826,55 @@
|
| widget_delegate_->SaveWindowPlacement(bounds, maximized);
|
| }
|
|
|
| +void Widget::SetInitialBounds(const gfx::Rect& bounds) {
|
| + if (!non_client_view_)
|
| + return;
|
|
|
| + // First we obtain the window's saved show-style and store it. We need to do
|
| + // this here, rather than in Show() because by the time Show() is called,
|
| + // the window's size will have been reset (below) and the saved maximized
|
| + // state will have been lost. Sadly there's no way to tell on Windows when
|
| + // a window is restored from maximized state, so we can't more accurately
|
| + // track maximized state independently of sizing information.
|
| + widget_delegate_->GetSavedMaximizedState(
|
| + &saved_maximized_state_);
|
|
|
| + // Restore the window's placement from the controller.
|
| + gfx::Rect saved_bounds = bounds;
|
| + if (widget_delegate_->GetSavedWindowBounds(&saved_bounds)) {
|
| + if (!widget_delegate_->ShouldRestoreWindowSize()) {
|
| + saved_bounds.set_size(non_client_view_->GetPreferredSize());
|
| + } else {
|
| + // Make sure the bounds are at least the minimum size.
|
| + if (saved_bounds.width() < minimum_size_.width()) {
|
| + saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
|
| + saved_bounds.right() + minimum_size_.width() -
|
| + saved_bounds.width(),
|
| + saved_bounds.bottom());
|
| + }
|
| +
|
| + if (saved_bounds.height() < minimum_size_.height()) {
|
| + saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
|
| + saved_bounds.right(),
|
| + saved_bounds.bottom() + minimum_size_.height() -
|
| + saved_bounds.height());
|
| + }
|
| + }
|
| +
|
| + // Widget's SetBounds method does not further modify the bounds that are
|
| + // passed to it.
|
| + SetBounds(saved_bounds);
|
| + } else {
|
| + if (bounds.IsEmpty()) {
|
| + // No initial bounds supplied, so size the window to its content and
|
| + // center over its parent.
|
| + native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
|
| + } else {
|
| + // Use the supplied initial bounds.
|
| + SetBoundsConstrained(bounds, NULL);
|
| + }
|
| + }
|
| +}
|
| +
|
| +
|
| } // namespace views
|
|
|