diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-05 00:44:13 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-05 00:44:13 +0000 |
commit | deacc1e3067cf667bd1653a5ca0aedd6d5f74e6d (patch) | |
tree | c65e580d1c09499f2a5cda285daab4650d02a0e8 /ui | |
parent | 9c2fd4b882fd801e607d48befc8b4cac50865393 (diff) | |
download | chromium_src-deacc1e3067cf667bd1653a5ca0aedd6d5f74e6d.zip chromium_src-deacc1e3067cf667bd1653a5ca0aedd6d5f74e6d.tar.gz chromium_src-deacc1e3067cf667bd1653a5ca0aedd6d5f74e6d.tar.bz2 |
views: add a "footnote view" to DialogClientView.
This will be used for the Terms of Service banner in AutofillDialogViews.
BUG=170511
Review URL: https://codereview.chromium.org/12047102
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180585 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/window/dialog_client_view.cc | 44 | ||||
-rw-r--r-- | ui/views/window/dialog_client_view.h | 11 | ||||
-rw-r--r-- | ui/views/window/dialog_delegate.cc | 4 | ||||
-rw-r--r-- | ui/views/window/dialog_delegate.h | 5 |
4 files changed, 61 insertions, 3 deletions
diff --git a/ui/views/window/dialog_client_view.cc b/ui/views/window/dialog_client_view.cc index df2c83b..ba16988 100644 --- a/ui/views/window/dialog_client_view.cc +++ b/ui/views/window/dialog_client_view.cc @@ -119,6 +119,7 @@ DialogClientView::DialogClientView(Widget* owner, View* contents_view) cancel_button_(NULL), default_button_(NULL), extra_view_(NULL), + footnote_view_(NULL), size_extra_view_height_to_buttons_(false), notified_delegate_(false), listening_to_focus_(false), @@ -222,9 +223,8 @@ void DialogClientView::UpdateDialogButtons() { if (buttons & ui::DIALOG_BUTTON_OK) UpdateButtonHelper(ok_button_, dd, ui::DIALOG_BUTTON_OK); - if (buttons & ui::DIALOG_BUTTON_CANCEL) { + if (buttons & ui::DIALOG_BUTTON_CANCEL) UpdateButtonHelper(cancel_button_, dd, ui::DIALOG_BUTTON_CANCEL); - } LayoutDialogButtons(); SchedulePaint(); @@ -318,6 +318,10 @@ void DialogClientView::PaintChildren(gfx::Canvas* canvas) { void DialogClientView::Layout() { if (has_dialog_buttons()) LayoutDialogButtons(); + + if (footnote_view_) + LayoutFootnoteView(); + LayoutContentsView(); } @@ -335,6 +339,7 @@ void DialogClientView::ViewHierarchyChanged(bool is_add, View* parent, // The "extra view" must be created and installed after the contents view // has been inserted into the view hierarchy. CreateExtraView(); + CreateFootnoteView(); UpdateDialogButtons(); Layout(); } @@ -365,6 +370,13 @@ gfx::Size DialogClientView::GetPreferredSize() { } } prefsize.Enlarge(0, button_height); + + if (footnote_view_) { + gfx::Size footnote_size = footnote_view_->GetPreferredSize(); + prefsize.Enlarge(0, footnote_size.height()); + prefsize.set_width(std::max(prefsize.width(), footnote_size.width())); + } + return prefsize; } @@ -481,10 +493,17 @@ int DialogClientView::GetDialogButtonsAreaHeight() const { style_params_.button_vedge_margin; } +int DialogClientView::GetFootnoteViewHeight() const { + return footnote_view_ ? footnote_view_->GetPreferredSize().height() : 0; +} + void DialogClientView::LayoutDialogButtons() { gfx::Rect lb = GetContentsBounds(); gfx::Rect extra_bounds; int bottom_y = lb.bottom() - style_params_.button_vedge_margin; + if (footnote_view_) + bottom_y -= footnote_view_->GetPreferredSize().height(); + int button_height = GetButtonsHeight(); if (cancel_button_) { gfx::Size ps = cancel_button_->GetPreferredSize(); @@ -521,11 +540,21 @@ void DialogClientView::LayoutDialogButtons() { void DialogClientView::LayoutContentsView() { gfx::Rect lb = GetContentsBounds(); - lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); + lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight() - + GetFootnoteViewHeight())); contents_view()->SetBoundsRect(lb); contents_view()->Layout(); } +void DialogClientView::LayoutFootnoteView() { + int height = GetFootnoteViewHeight(); + gfx::Rect bounds = GetContentsBounds(); + bounds.set_y(bounds.height() - height); + bounds.set_height(height); + footnote_view_->SetBoundsRect(bounds); + footnote_view_->Layout(); +} + void DialogClientView::CreateExtraView() { View* extra_view = GetDialogDelegate()->GetExtraView(); if (extra_view && !extra_view_) { @@ -537,6 +566,15 @@ void DialogClientView::CreateExtraView() { } } +void DialogClientView::CreateFootnoteView() { + if (footnote_view_) + return; + + footnote_view_ = GetDialogDelegate()->GetFootnoteView(); + if (footnote_view_) + AddChildView(footnote_view_); +} + DialogDelegate* DialogClientView::GetDialogDelegate() const { return GetWidget()->widget_delegate()->AsDialogDelegate(); } diff --git a/ui/views/window/dialog_client_view.h b/ui/views/window/dialog_client_view.h index 6550819..c8136d4 100644 --- a/ui/views/window/dialog_client_view.h +++ b/ui/views/window/dialog_client_view.h @@ -119,9 +119,14 @@ class VIEWS_EXPORT DialogClientView : public ClientView, // and the spacing between bottom of buttons to end of the dialog. int GetDialogButtonsAreaHeight() const; + // Returns the preferred height of |footnote_view_|, or 0 if that view is + // NULL. + int GetFootnoteViewHeight() const; + // Position and size various sub-views. void LayoutDialogButtons(); void LayoutContentsView(); + void LayoutFootnoteView(); // Makes the specified button the default button. void SetDefaultButton(TextButton* button); @@ -131,6 +136,9 @@ class VIEWS_EXPORT DialogClientView : public ClientView, // Create and add the extra view, if supplied by the delegate. void CreateExtraView(); + // Creates and adds the footnote view, if supplied by the delegate. + void CreateFootnoteView(); + // Returns the DialogDelegate for the window. DialogDelegate* GetDialogDelegate() const; @@ -153,6 +161,9 @@ class VIEWS_EXPORT DialogClientView : public ClientView, // The button-level extra view, NULL unless the dialog delegate supplies one. View* extra_view_; + // The view that resides beneath the dialog buttons, or NULL. + View* footnote_view_; + // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for // details on this. bool size_extra_view_height_to_buttons_; diff --git a/ui/views/window/dialog_delegate.cc b/ui/views/window/dialog_delegate.cc index d9b0517..80606fc 100644 --- a/ui/views/window/dialog_delegate.cc +++ b/ui/views/window/dialog_delegate.cc @@ -92,6 +92,10 @@ bool DialogDelegate::GetSizeExtraViewHeightToButtons() { return false; } +View* DialogDelegate::GetFootnoteView() { + return NULL; +} + bool DialogDelegate::Cancel() { return true; } diff --git a/ui/views/window/dialog_delegate.h b/ui/views/window/dialog_delegate.h index 174648b..a039e8f 100644 --- a/ui/views/window/dialog_delegate.h +++ b/ui/views/window/dialog_delegate.h @@ -74,6 +74,11 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { // max(extra_view preferred height, buttons preferred height). virtual bool GetSizeExtraViewHeightToButtons(); + // Like GetExtraView, this function can be overridden to display an auxiliary + // view in the dialog. This view will be placed beneath the dialog buttons and + // will extend all the way from the left to the right of the dialog. + virtual View* GetFootnoteView(); + // For Dialog boxes, if there is a "Cancel" button or no dialog button at all, // this is called when the user presses the "Cancel" button or the Close // button on the window or in the system menu, or presses the Esc key. |