diff options
Diffstat (limited to 'views/window')
-rw-r--r-- | views/window/dialog_client_view.cc | 56 | ||||
-rw-r--r-- | views/window/dialog_client_view.h | 14 | ||||
-rw-r--r-- | views/window/dialog_delegate.h | 2 |
3 files changed, 54 insertions, 18 deletions
diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index b25c6bc..7ea51f1 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -112,7 +112,8 @@ DialogClientView::DialogClientView(Window* owner, View* contents_view) extra_view_(NULL), accepted_(false), listening_to_focus_(false), - saved_focus_manager_(NULL) { + saved_focus_manager_(NULL), + bottom_view_(NULL) { InitClass(); } @@ -237,6 +238,16 @@ void DialogClientView::CancelWindow() { Close(); } +void DialogClientView::SetBottomView(View* bottom_view) { + if (bottom_view_) { + RemoveChildView(bottom_view_); + delete bottom_view_; + } + bottom_view_ = bottom_view; + if (bottom_view_) + AddChildView(bottom_view_); +} + /////////////////////////////////////////////////////////////////////////////// // DialogClientView, View overrides: @@ -304,6 +315,13 @@ void DialogClientView::PaintChildren(gfx::Canvas* canvas) { void DialogClientView::Layout() { if (has_dialog_buttons()) LayoutDialogButtons(); + if (bottom_view_) { + gfx::Rect bounds = GetLocalBounds(false); + gfx::Size pref = bottom_view_->GetPreferredSize(); + bottom_view_->SetBounds(bounds.x(), + bounds.bottom() - pref.height() - kButtonVEdgeMargin, + bounds.width(), pref.height()); + } LayoutContentsView(); } @@ -357,6 +375,10 @@ gfx::Size DialogClientView::GetPreferredSize() { prefsize.set_width(std::max(prefsize.width(), width)); } } + if (bottom_view_) { + gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); + prefsize.Enlarge(0, bottom_pref.height() + kButtonVEdgeMargin); + } prefsize.Enlarge(0, button_height); return prefsize; } @@ -437,14 +459,19 @@ int DialogClientView::GetButtonsHeight() const { } void DialogClientView::LayoutDialogButtons() { + gfx::Rect lb = GetLocalBounds(false); gfx::Rect extra_bounds; + int bottom_y = lb.bottom() - kButtonVEdgeMargin; + if (bottom_view_) { + gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); + bottom_y -= bottom_pref.height() + kButtonVEdgeMargin + kButtonVEdgeMargin; + } if (cancel_button_) { gfx::Size ps = cancel_button_->GetPreferredSize(); - gfx::Rect lb = GetLocalBounds(false); int button_width = std::max( GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_CANCEL), ps.width()); int button_x = lb.right() - button_width - kButtonHEdgeMargin; - int button_y = lb.bottom() - ps.height() - kButtonVEdgeMargin; + int button_y = bottom_y - ps.height(); cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); // The extra view bounds are dependent on this button. extra_bounds.set_width(std::max(0, cancel_button_->x())); @@ -452,14 +479,13 @@ void DialogClientView::LayoutDialogButtons() { } if (ok_button_) { gfx::Size ps = ok_button_->GetPreferredSize(); - gfx::Rect lb = GetLocalBounds(false); int button_width = std::max( GetButtonWidth(MessageBoxFlags::DIALOGBUTTON_OK), ps.width()); int ok_button_right = lb.right() - kButtonHEdgeMargin; if (cancel_button_) ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; int button_x = ok_button_right - button_width; - int button_y = lb.bottom() - ps.height() - kButtonVEdgeMargin; + int button_y = bottom_y - ps.height(); ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, ps.height()); // The extra view bounds are dependent on this button. @@ -468,7 +494,6 @@ void DialogClientView::LayoutDialogButtons() { } if (extra_view_) { gfx::Size ps = extra_view_->GetPreferredSize(); - gfx::Rect lb = GetLocalBounds(false); extra_bounds.set_x(lb.x() + kButtonHEdgeMargin); extra_bounds.set_height(ps.height()); extra_view_->SetBounds(extra_bounds); @@ -497,16 +522,6 @@ DialogDelegate* DialogClientView::GetDialogDelegate() const { return dd; } -// static -void DialogClientView::InitClass() { - static bool initialized = false; - if (!initialized) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); - initialized = true; - } -} - void DialogClientView::Close() { window()->Close(); GetDialogDelegate()->OnClose(); @@ -534,5 +549,14 @@ void DialogClientView::UpdateFocusListener() { } } +// static +void DialogClientView::InitClass() { + static bool initialized = false; + if (!initialized) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); + initialized = true; + } +} } // namespace views diff --git a/views/window/dialog_client_view.h b/views/window/dialog_client_view.h index d7a5fb2..e23e346 100644 --- a/views/window/dialog_client_view.h +++ b/views/window/dialog_client_view.h @@ -25,6 +25,9 @@ class Window; // embedded contents view to provide extra UI to be shown in the row of // buttons. // +// DialogClientView also provides the ability to set an arbitrary view that is +// positioned beneath the buttons. +// class DialogClientView : public ClientView, public ButtonListener, public FocusChangeListener { @@ -50,6 +53,11 @@ class DialogClientView : public ClientView, NativeButton* ok_button() const { return ok_button_; } NativeButton* cancel_button() const { return cancel_button_; } + // Sets the view that is positioned along the bottom of the buttons. The + // bottom view is positioned beneath the buttons at the full width of the + // dialog. If there is an existing bottom view it is removed and deleted. + void SetBottomView(View* bottom_view); + // Overridden from View: virtual void NativeViewHierarchyChanged(bool attached, gfx::NativeView native_view, @@ -106,6 +114,8 @@ class DialogClientView : public ClientView, // Updates focus listener. void UpdateFocusListener(); + static void InitClass(); + // The dialog buttons. NativeButton* ok_button_; NativeButton* cancel_button_; @@ -128,8 +138,10 @@ class DialogClientView : public ClientView, // When ancestor gets changed focus manager gets changed as well. FocusManager* saved_focus_manager_; + // View positioned along the bottom, beneath the buttons. + View* bottom_view_; + // Static resource initialization - static void InitClass(); static gfx::Font* dialog_button_font_; DISALLOW_COPY_AND_ASSIGN(DialogClientView); diff --git a/views/window/dialog_delegate.h b/views/window/dialog_delegate.h index 0d66956..19c2a89 100644 --- a/views/window/dialog_delegate.h +++ b/views/window/dialog_delegate.h @@ -104,7 +104,7 @@ class DialogDelegate : public WindowDelegate { virtual ClientView* CreateClientView(Window* window); // Called when the window has been closed. - virtual void OnClose() {}; + virtual void OnClose() {} // A helper for accessing the DialogClientView object contained by this // delegate's Window. |