diff options
22 files changed, 332 insertions, 769 deletions
diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc index 22569628..49d460b 100644 --- a/chrome/browser/chromeos/options/network_config_view.cc +++ b/chrome/browser/chromeos/options/network_config_view.cc @@ -30,7 +30,6 @@ #include "ui/gfx/rect.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/controls/image_view.h" -#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" @@ -74,9 +73,9 @@ namespace chromeos { const int ChildNetworkConfigView::kInputFieldMinWidth = 270; NetworkConfigView::NetworkConfigView(Network* network) - : delegate_(NULL), - advanced_button_(NULL), - advanced_button_container_(NULL) { + : child_config_view_(NULL), + delegate_(NULL), + advanced_button_(NULL) { DCHECK(GetActiveDialog() == NULL); SetActiveDialog(this); if (network->type() == TYPE_WIFI) { @@ -90,24 +89,24 @@ NetworkConfigView::NetworkConfigView(Network* network) new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); } else { NOTREACHED(); - child_config_view_ = NULL; } } NetworkConfigView::NetworkConfigView(ConnectionType type) - : delegate_(NULL), - advanced_button_(NULL), - advanced_button_container_(NULL) { + : child_config_view_(NULL), + delegate_(NULL), + advanced_button_(NULL) { DCHECK(GetActiveDialog() == NULL); SetActiveDialog(this); if (type == TYPE_WIFI) { child_config_view_ = new WifiConfigView(this, false /* show_8021x */); - CreateAdvancedButton(); + advanced_button_ = new views::NativeTextButton(this, + l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); } else if (type == TYPE_VPN) { child_config_view_ = new VPNConfigView(this); } else { NOTREACHED(); - child_config_view_ = NULL; } } @@ -143,7 +142,7 @@ string16 NetworkConfigView::GetDialogButtonLabel( ui::DialogButton button) const { if (button == ui::DIALOG_BUTTON_OK) return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); - return string16(); + return views::DialogDelegateView::GetDialogButtonLabel(button); } bool NetworkConfigView::IsDialogButtonEnabled(ui::DialogButton button) const { @@ -170,8 +169,8 @@ bool NetworkConfigView::Accept() { return result; } -views::View* NetworkConfigView::GetExtraView() { - return advanced_button_container_; +views::View* NetworkConfigView::CreateExtraView() { + return advanced_button_; } views::View* NetworkConfigView::GetInitiallyFocusedView() { @@ -254,24 +253,6 @@ void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { window->Show(); } -void NetworkConfigView::CreateAdvancedButton() { - advanced_button_ = new views::NativeTextButton(this, - l10n_util::GetStringUTF16( - IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); - - // Wrap the advanced button in a grid layout in order to left-align it. - advanced_button_container_ = new views::View(); - views::GridLayout* layout = new views::GridLayout(advanced_button_container_); - advanced_button_container_->SetLayoutManager(layout); - - int column_set_id = 0; - views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); - column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, - 0, views::GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, column_set_id); - layout->AddView(advanced_button_); -} - ControlledSettingIndicatorView::ControlledSettingIndicatorView() : managed_(false), image_view_(NULL) { diff --git a/chrome/browser/chromeos/options/network_config_view.h b/chrome/browser/chromeos/options/network_config_view.h index 30241b5..c60069f 100644 --- a/chrome/browser/chromeos/options/network_config_view.h +++ b/chrome/browser/chromeos/options/network_config_view.h @@ -22,7 +22,6 @@ class ImageSkia; namespace views { class ImageView; class NativeTextButton; -class View; } namespace chromeos { @@ -58,7 +57,7 @@ class NetworkConfigView : public views::DialogDelegateView, virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; virtual bool Cancel() OVERRIDE; virtual bool Accept() OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual views::View* GetInitiallyFocusedView() OVERRIDE; // views::WidgetDelegate methods. @@ -93,9 +92,6 @@ class NetworkConfigView : public views::DialogDelegateView, // Creates and shows a dialog containing this view. void ShowDialog(gfx::NativeWindow parent); - // Creates an "Advanced" button in the lower-left corner of the dialog. - void CreateAdvancedButton(); - // Resets the underlying view to show advanced options. void ShowAdvancedView(); @@ -107,7 +103,6 @@ class NetworkConfigView : public views::DialogDelegateView, // Button in lower-left corner, may be null or hidden. views::NativeTextButton* advanced_button_; - views::View* advanced_button_container_; DISALLOW_COPY_AND_ASSIGN(NetworkConfigView); }; diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index 8604d56..53a1588 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -540,11 +540,11 @@ bool AutofillDialogViews::IsDialogButtonEnabled(ui::DialogButton button) const { return true; } -views::View* AutofillDialogViews::GetExtraView() { +views::View* AutofillDialogViews::CreateExtraView() { return button_strip_extra_view_; } -views::View* AutofillDialogViews::GetFootnoteView() { +views::View* AutofillDialogViews::CreateFootnoteView() { // TODO(estade): add a view to contain the terms of service. return NULL; } diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h index d669492..9078c42 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h @@ -89,8 +89,8 @@ class AutofillDialogViews : public AutofillDialogView, virtual views::View* GetContentsView() OVERRIDE; virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; - virtual views::View* GetFootnoteView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; + virtual views::View* CreateFootnoteView() OVERRIDE; virtual bool Cancel() OVERRIDE; virtual bool Accept() OVERRIDE; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index 2447b07..f3bfc06 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -90,7 +90,7 @@ string16 BookmarkEditorView::GetDialogButtonLabel( ui::DialogButton button) const { if (button == ui::DIALOG_BUTTON_OK) return l10n_util::GetStringUTF16(IDS_SAVE); - return string16(); + return views::DialogDelegateView::GetDialogButtonLabel(button); } bool BookmarkEditorView::IsDialogButtonEnabled(ui::DialogButton button) const { @@ -104,6 +104,10 @@ bool BookmarkEditorView::IsDialogButtonEnabled(ui::DialogButton button) const { return true; } +views::View* BookmarkEditorView::CreateExtraView() { + return new_folder_button_.get(); +} + ui::ModalType BookmarkEditorView::GetModalType() const { return ui::MODAL_TYPE_WINDOW; } @@ -130,25 +134,6 @@ bool BookmarkEditorView::Accept() { return true; } -bool BookmarkEditorView::AreAcceleratorsEnabled(ui::DialogButton button) { - return !show_tree_ || !tree_view_->GetEditingNode(); -} - -void BookmarkEditorView::Layout() { - GetLayoutManager()->Layout(this); - - if (!show_tree_) - return; - - // Manually align the New Folder button with the Save and Cancel buttons. - gfx::Size size = new_folder_button_->GetPreferredSize(); - gfx::Rect parent_bounds = parent()->GetContentsBounds(); - int x = views::DialogDelegate::UseNewStyle() ? 0 : views::kPanelHorizMargin; - int y = views::DialogDelegate::UseNewStyle() ? GetLocalBounds().bottom() : - parent_bounds.bottom() - size.height() - views::kButtonVEdgeMargin; - new_folder_button_->SetBounds(x, y, size.width(), size.height()); -} - gfx::Size BookmarkEditorView::GetPreferredSize() { if (!show_tree_) return views::View::GetPreferredSize(); @@ -158,19 +143,6 @@ gfx::Size BookmarkEditorView::GetPreferredSize() { IDS_EDITBOOKMARK_DIALOG_HEIGHT_LINES)); } -void BookmarkEditorView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (show_tree_ && child == this) { - // Add and remove the New Folder button from the ClientView's hierarchy. - if (is_add) { - parent->AddChildView(new_folder_button_.get()); - } else { - parent->RemoveChildView(new_folder_button_.get()); - } - } -} - void BookmarkEditorView::OnTreeViewSelectionChanged( views::TreeView* tree_view) { } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.h b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.h index d1c4ff0..7c99e9b 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.h @@ -80,18 +80,14 @@ class BookmarkEditorView : public BookmarkEditor, // views::DialogDelegateView: virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual ui::ModalType GetModalType() const OVERRIDE; virtual bool CanResize() const OVERRIDE; virtual string16 GetWindowTitle() const OVERRIDE; virtual bool Accept() OVERRIDE; - virtual bool AreAcceleratorsEnabled(ui::DialogButton button) OVERRIDE; // views::View: - virtual void Layout() OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) OVERRIDE; // views::TreeViewController: virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view) OVERRIDE; diff --git a/chrome/browser/ui/views/confirm_bubble_views.cc b/chrome/browser/ui/views/confirm_bubble_views.cc index 399a078..9766599 100644 --- a/chrome/browser/ui/views/confirm_bubble_views.cc +++ b/chrome/browser/ui/views/confirm_bubble_views.cc @@ -62,10 +62,6 @@ string16 ConfirmBubbleViews::GetDialogButtonLabel( } bool ConfirmBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { - return IsDialogButtonVisible(button); -} - -bool ConfirmBubbleViews::IsDialogButtonVisible(ui::DialogButton button) const { switch (button) { case ui::DIALOG_BUTTON_OK: return !!(model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK); @@ -77,7 +73,7 @@ bool ConfirmBubbleViews::IsDialogButtonVisible(ui::DialogButton button) const { } } -views::View* ConfirmBubbleViews::GetExtraView() { +views::View* ConfirmBubbleViews::CreateExtraView() { return link_; } diff --git a/chrome/browser/ui/views/confirm_bubble_views.h b/chrome/browser/ui/views/confirm_bubble_views.h index aa6e06c..17f27b7 100644 --- a/chrome/browser/ui/views/confirm_bubble_views.h +++ b/chrome/browser/ui/views/confirm_bubble_views.h @@ -32,8 +32,7 @@ class ConfirmBubbleViews : public views::DialogDelegateView, // views::DialogDelegate implementation. virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; - virtual bool IsDialogButtonVisible(ui::DialogButton button) const OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual bool Cancel() OVERRIDE; virtual bool Accept() OVERRIDE; diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index d690e33..c77e983 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -321,7 +321,7 @@ string16 CreateApplicationShortcutView::GetDialogButtonLabel( ui::DialogButton button) const { if (button == ui::DIALOG_BUTTON_OK) return l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_COMMIT); - return string16(); + return views::DialogDelegateView::GetDialogButtonLabel(button); } bool CreateApplicationShortcutView::IsDialogButtonEnabled( diff --git a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc index d936a0b..0570066 100644 --- a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc +++ b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc @@ -30,7 +30,7 @@ MediaGalleriesDialogViews::MediaGalleriesDialogViews( window_(NULL), contents_(new views::View()), checkbox_container_(NULL), - add_gallery_container_(NULL), + add_gallery_button_(NULL), confirm_available_(false), accepted_(false) { InitChildViews(); @@ -173,17 +173,11 @@ ui::ModalType MediaGalleriesDialogViews::GetModalType() const { #endif } -views::View* MediaGalleriesDialogViews::GetExtraView() { - if (!add_gallery_container_) { - views::View* button = new views::NativeTextButton(this, - l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); - add_gallery_container_ = new views::View(); - add_gallery_container_->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); - add_gallery_container_->AddChildView(button); - } - - return add_gallery_container_; +views::View* MediaGalleriesDialogViews::CreateExtraView() { + DCHECK(!add_gallery_button_); + add_gallery_button_ = new views::NativeTextButton(this, + l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); + return add_gallery_button_; } bool MediaGalleriesDialogViews::Cancel() { @@ -200,7 +194,7 @@ void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, confirm_available_ = true; GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); - if (sender->parent() == add_gallery_container_) { + if (sender == add_gallery_button_) { controller_->OnAddFolderClicked(); return; } diff --git a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.h b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.h index ebb9e2e..f320973 100644 --- a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.h +++ b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.h @@ -16,6 +16,7 @@ class ConstrainedWindowViews; namespace views { class Checkbox; +class TextButton; } namespace chrome { @@ -44,7 +45,7 @@ class MediaGalleriesDialogViews : public MediaGalleriesDialog, virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; virtual ui::ModalType GetModalType() const OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual bool Cancel() OVERRIDE; virtual bool Accept() OVERRIDE; @@ -73,7 +74,7 @@ class MediaGalleriesDialogViews : public MediaGalleriesDialog, CheckboxMap checkbox_map_; views::View* checkbox_container_; - views::View* add_gallery_container_; + views::TextButton* add_gallery_button_; // This tracks whether the confirm button can be clicked. It starts as false // if no checkboxes are ticked. After there is any interaction, or some diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index abb92f4..b54f77e 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -29,6 +29,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/views/controls/button/text_button.h" #include "ui/views/controls/image_view.h" #include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" @@ -221,7 +222,6 @@ void HungRendererDialogView::KillRendererProcess( HungRendererDialogView::HungRendererDialogView() : hung_pages_table_(NULL), kill_button_(NULL), - kill_button_container_(NULL), initialized_(false) { InitClass(); } @@ -301,11 +301,14 @@ string16 HungRendererDialogView::GetDialogButtonLabel( ui::DialogButton button) const { if (button == ui::DIALOG_BUTTON_OK) return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT); - return string16(); + return views::DialogDelegateView::GetDialogButtonLabel(button); } -views::View* HungRendererDialogView::GetExtraView() { - return kill_button_container_; +views::View* HungRendererDialogView::CreateExtraView() { + DCHECK(!kill_button_); + kill_button_ = new views::NativeTextButton(this, + l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_END)); + return kill_button_; } bool HungRendererDialogView::Accept(bool window_closing) { @@ -372,8 +375,6 @@ void HungRendererDialogView::Init() { false, true); hung_pages_table_->SetGrouper(hung_pages_table_model_.get()); - CreateKillButtonView(); - using views::GridLayout; using views::ColumnSet; @@ -406,29 +407,6 @@ void HungRendererDialogView::Init() { initialized_ = true; } -void HungRendererDialogView::CreateKillButtonView() { - kill_button_ = new views::NativeTextButton(this, - l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_END)); - - kill_button_container_ = new View; - - using views::GridLayout; - using views::ColumnSet; - - GridLayout* layout = new GridLayout(kill_button_container_); - kill_button_container_->SetLayoutManager(layout); - - const int single_column_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); - column_set->AddPaddingColumn(0, frozen_icon_->width() + - kCentralColumnPadding); - column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_set_id); - layout->AddView(kill_button_); -} - gfx::Rect HungRendererDialogView::GetDisplayBounds( WebContents* contents) { #if defined(USE_AURA) diff --git a/chrome/browser/ui/views/hung_renderer_view.h b/chrome/browser/ui/views/hung_renderer_view.h index 753ee90..16cdd8c 100644 --- a/chrome/browser/ui/views/hung_renderer_view.h +++ b/chrome/browser/ui/views/hung_renderer_view.h @@ -9,7 +9,7 @@ #include "chrome/browser/favicon/favicon_tab_helper.h" #include "content/public/browser/web_contents_observer.h" #include "ui/base/models/table_model.h" -#include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/button/button.h" #include "ui/views/controls/table/table_grouper.h" #include "ui/views/controls/table/table_view.h" #include "ui/views/window/dialog_delegate.h" @@ -18,6 +18,10 @@ namespace content { class WebContents; } +namespace views { +class TextButton; +} + // Provides functionality to display information about a hung renderer. class HungPagesTableModel : public ui::TableModel, public views::TableGrouper { public: @@ -120,7 +124,7 @@ class HungRendererDialogView : public views::DialogDelegateView, virtual void WindowClosing() OVERRIDE; virtual int GetDialogButtons() const OVERRIDE; virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual bool Accept(bool window_closing) OVERRIDE; // views::ButtonListener overrides: @@ -144,7 +148,6 @@ class HungRendererDialogView : public views::DialogDelegateView, private: // Initialize the controls in this dialog. void Init(); - void CreateKillButtonView(); // Returns the bounds the dialog should be displayed at to be meaningfully // associated with the specified WebContents. @@ -155,11 +158,8 @@ class HungRendererDialogView : public views::DialogDelegateView, // Controls within the dialog box. views::TableView* hung_pages_table_; - // The button we insert into the ClientView to kill the errant process. This - // is parented to a container view that uses a grid layout to align it - // properly. + // The extra button inserted into the ClientView to kill the errant process. views::TextButton* kill_button_; - views::View* kill_button_container_; // The model that provides the contents of the table that shows a list of // pages affected by the hang. diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector.cc b/chrome/browser/ui/views/ssl_client_certificate_selector.cc index a66b208..8bf49b0 100644 --- a/chrome/browser/ui/views/ssl_client_certificate_selector.cc +++ b/chrome/browser/ui/views/ssl_client_certificate_selector.cc @@ -98,8 +98,7 @@ SSLClientCertificateSelector::SSLClientCertificateSelector( web_contents_(web_contents), window_(NULL), table_(NULL), - view_cert_button_(NULL), - view_cert_button_container_(NULL) { + view_cert_button_(NULL) { DVLOG(1) << __FUNCTION__; } @@ -137,8 +136,6 @@ void SSLClientCertificateSelector::Init() { layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); - CreateViewCertButton(); - StartObserving(); window_ = ConstrainedWindowViews::Create(web_contents_, this); @@ -213,8 +210,11 @@ views::View* SSLClientCertificateSelector::GetInitiallyFocusedView() { return table_; } -views::View* SSLClientCertificateSelector::GetExtraView() { - return view_cert_button_container_; +views::View* SSLClientCertificateSelector::CreateExtraView() { + DCHECK(!view_cert_button_); + view_cert_button_ = new views::NativeTextButton(this, + l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); + return view_cert_button_; } ui::ModalType SSLClientCertificateSelector::GetModalType() const { @@ -265,24 +265,6 @@ void SSLClientCertificateSelector::CreateCertTable() { table_->SetObserver(this); } -void SSLClientCertificateSelector::CreateViewCertButton() { - view_cert_button_ = new views::NativeTextButton(this, - l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); - - // Wrap the view cert button in a grid layout in order to left-align it. - view_cert_button_container_ = new views::View(); - views::GridLayout* layout = new views::GridLayout( - view_cert_button_container_); - view_cert_button_container_->SetLayoutManager(layout); - - int column_set_id = 0; - views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); - column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, - 0, views::GridLayout::USE_PREF, 0, 0); - layout->StartRow(0, column_set_id); - layout->AddView(view_cert_button_); -} - namespace chrome { void ShowSSLClientCertificateSelector( diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector.h b/chrome/browser/ui/views/ssl_client_certificate_selector.h index 317adda..573d8de 100644 --- a/chrome/browser/ui/views/ssl_client_certificate_selector.h +++ b/chrome/browser/ui/views/ssl_client_certificate_selector.h @@ -62,7 +62,7 @@ class SSLClientCertificateSelector : public SSLClientAuthObserver, virtual bool Cancel() OVERRIDE; virtual bool Accept() OVERRIDE; virtual views::View* GetInitiallyFocusedView() OVERRIDE; - virtual views::View* GetExtraView() OVERRIDE; + virtual views::View* CreateExtraView() OVERRIDE; virtual ui::ModalType GetModalType() const OVERRIDE; // views::ButtonListener: @@ -75,7 +75,6 @@ class SSLClientCertificateSelector : public SSLClientAuthObserver, private: void CreateCertTable(); - void CreateViewCertButton(); scoped_ptr<CertificateSelectorTableModel> model_; @@ -84,7 +83,6 @@ class SSLClientCertificateSelector : public SSLClientAuthObserver, WebContentsModalDialog* window_; views::TableView* table_; views::TextButton* view_cert_button_; - views::View* view_cert_button_container_; DISALLOW_COPY_AND_ASSIGN(SSLClientCertificateSelector); }; diff --git a/ui/views/controls/tree/tree_view.cc b/ui/views/controls/tree/tree_view.cc index e91d0f0..06351a4 100644 --- a/ui/views/controls/tree/tree_view.cc +++ b/ui/views/controls/tree/tree_view.cc @@ -168,6 +168,9 @@ void TreeView::StartEditing(TreeModelNode* node) { focus_manager_ = GetFocusManager(); if (focus_manager_) focus_manager_->AddFocusChangeListener(this); + + // Accelerate the return key to commit the pending edit. + AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); } void TreeView::CancelEdit() { @@ -183,6 +186,9 @@ void TreeView::CancelEdit() { } editor_->SetVisible(false); SchedulePaint(); + + // Remove the return key accelerator when there is no pending edit. + RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); } void TreeView::CommitEdit() { @@ -319,6 +325,12 @@ gfx::Size TreeView::GetPreferredSize() { return preferred_size_; } +bool TreeView::AcceleratorPressed(const ui::Accelerator& accelerator) { + DCHECK_EQ(accelerator.key_code(), ui::VKEY_RETURN); + CommitEdit(); + return true; +} + bool TreeView::OnMousePressed(const ui::MouseEvent& event) { return OnClickOrTap(event); } diff --git a/ui/views/controls/tree/tree_view.h b/ui/views/controls/tree/tree_view.h index 603fa26..9b06081 100644 --- a/ui/views/controls/tree/tree_view.h +++ b/ui/views/controls/tree/tree_view.h @@ -107,6 +107,7 @@ class VIEWS_EXPORT TreeView : public View, // View overrides: virtual void Layout() OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, diff --git a/ui/views/examples/widget_example.cc b/ui/views/examples/widget_example.cc index a4c221b..c91e1e8 100644 --- a/ui/views/examples/widget_example.cc +++ b/ui/views/examples/widget_example.cc @@ -6,6 +6,7 @@ #include "base/utf_string_conversions.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" #include "ui/views/view.h" #include "ui/views/widget/widget.h" @@ -18,13 +19,34 @@ namespace { class DialogExample : public DialogDelegateView { public: + DialogExample(); + virtual ~DialogExample(); virtual string16 GetWindowTitle() const OVERRIDE; + virtual View* CreateExtraView() OVERRIDE; + virtual View* CreateFootnoteView() OVERRIDE; }; +DialogExample::DialogExample() { + set_background(Background::CreateSolidBackground(SK_ColorGRAY)); + SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); + AddChildView(new Label(ASCIIToUTF16("Dialog contents label!"))); +} + +DialogExample::~DialogExample() { +} + string16 DialogExample::GetWindowTitle() const { return ASCIIToUTF16("Dialog Widget Example"); } +View* DialogExample::CreateExtraView() { + return new NativeTextButton(NULL, ASCIIToUTF16("Extra button!")); +} + +View* DialogExample::CreateFootnoteView() { + return new Label(ASCIIToUTF16("Footnote label!")); +} + } // namespace WidgetExample::WidgetExample() : ExampleBase("Widget") { @@ -34,7 +56,7 @@ WidgetExample::~WidgetExample() { } void WidgetExample::CreateExampleView(View* container) { - container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 2)); + container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10)); BuildButton(container, "Popup widget", POPUP); BuildButton(container, "Dialog widget", DIALOG); #if defined(OS_LINUX) @@ -79,11 +101,8 @@ void WidgetExample::ButtonPressed(Button* sender, const ui::Event& event) { ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_POPUP)); break; case DIALOG: { - Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); - params.delegate = new DialogExample(); - params.remove_standard_frame = true; - params.transparent = true; - ShowWidget(sender, params); + DialogDelegateView::CreateDialogWidget(new DialogExample(), NULL, + sender->GetWidget()->GetNativeView())->Show(); break; } case CHILD: diff --git a/ui/views/window/dialog_client_view.cc b/ui/views/window/dialog_client_view.cc index ba16988..94d1aeb 100644 --- a/ui/views/window/dialog_client_view.cc +++ b/ui/views/window/dialog_client_view.cc @@ -4,110 +4,30 @@ #include "ui/views/window/dialog_client_view.h" -#include "build/build_config.h" - -#if defined(OS_WIN) -#include <windows.h> -#include <uxtheme.h> -#include <vsstyle.h> -#endif - #include <algorithm> -#include "base/utf_string_conversions.h" -#include "grit/ui_strings.h" -#include "ui/base/hit_test.h" #include "ui/base/keycodes/keyboard_codes.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/font.h" -#include "ui/native_theme/native_theme.h" -#include "ui/views/controls/button/chrome_style.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/layout/layout_constants.h" -#include "ui/views/widget/root_view.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" namespace views { -namespace { -const int kDialogMinButtonWidth = 75; -const int kDialogButtonContentSpacing = 5; - -const int kChromeStyleDialogButtonLabelSpacing = 24; +namespace { // The group used by the buttons. This name is chosen voluntarily big not to // conflict with other groups that could be in the dialog content. const int kButtonGroup = 6666; -const gfx::Font& GetDialogButtonFont() { - static gfx::Font* font = NULL; - if (!font) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); - } - return *font; -} - -// Updates any of the standard buttons according to the delegate. -void UpdateButtonHelper(TextButton* button_view, - DialogDelegate* delegate, - ui::DialogButton button) { - string16 label = delegate->GetDialogButtonLabel(button); - if (!label.empty()) - button_view->SetText(label); - button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); - button_view->SetVisible(delegate->IsDialogButtonVisible(button)); +// Update |button|'s text and enabled state according to |delegate|'s state. +void UpdateButton(TextButton* button, + DialogDelegate* dialog, + ui::DialogButton type) { + button->SetText(dialog->GetDialogButtonLabel(type)); + button->SetEnabled(dialog->IsDialogButtonEnabled(type)); } -// DialogButton ---------------------------------------------------------------- - -// DialogButton forwards AcceleratorPressed to the delegate. It is used -// for the ok/cancel buttons of the window. - -template <class ButtonBase> -class DialogButton : public ButtonBase { - public: - // The button's class name. - static const char kViewClassName[]; - - DialogButton(ButtonListener* listener, - Widget* owner, - ui::DialogButton type, - const string16& title) - : ButtonBase(listener, title), - owner_(owner), - type_(type) { - } - - // Overridden to forward to the delegate. - virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { - if (!owner_->widget_delegate()->AsDialogDelegate()-> - AreAcceleratorsEnabled(type_)) { - return false; - } - return ButtonBase::AcceleratorPressed(accelerator); - } - - // Overridden from TextButton: - virtual std::string GetClassName() const { - return kViewClassName; - } - - private: - Widget* owner_; - const ui::DialogButton type_; - - DISALLOW_COPY_AND_ASSIGN(DialogButton); -}; - -template <> const char DialogButton<NativeTextButton>::kViewClassName[] = - "NativeDialogButton"; - -template <> const char DialogButton<TextButton>::kViewClassName[] = - "TextDialogButton"; } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -118,125 +38,24 @@ DialogClientView::DialogClientView(Widget* owner, View* contents_view) ok_button_(NULL), cancel_button_(NULL), default_button_(NULL), + focus_manager_(NULL), extra_view_(NULL), footnote_view_(NULL), - size_extra_view_height_to_buttons_(false), - notified_delegate_(false), - listening_to_focus_(false), - saved_focus_manager_(NULL) { - SkColor bg_color = owner->GetNativeTheme()->GetSystemColor( + notified_delegate_(false) { + const SkColor color = owner->GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_DialogBackground); - set_background(views::Background::CreateSolidBackground(bg_color)); + set_background(views::Background::CreateSolidBackground(color)); } DialogClientView::~DialogClientView() { -} - -void DialogClientView::ShowDialogButtons() { - DialogDelegate* dd = GetDialogDelegate(); - int buttons = dd->GetDialogButtons(); - if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { - string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); - if (label.empty()) - label = l10n_util::GetStringUTF16(IDS_APP_OK); - ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK, label); - if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) - ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); - AddChildView(ok_button_); - } - if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { - string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); - if (label.empty()) { - if (buttons & ui::DIALOG_BUTTON_OK) { - label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); - } else { - label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); - } - } - cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL, label); - cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, - ui::EF_NONE)); - AddChildView(cancel_button_); - } - if (!buttons) { - // Register the escape key as an accelerator which will close the window - // if there are no dialog buttons. - AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); - } -} - -void DialogClientView::SetDefaultButton(TextButton* new_default_button) { - if (default_button_ && default_button_ != new_default_button) { - default_button_->SetIsDefault(false); - default_button_ = NULL; - } - - if (new_default_button) { - default_button_ = new_default_button; - default_button_->SetIsDefault(true); - } -} - -void DialogClientView::OnWillChangeFocus(View* focused_before, - View* focused_now) { - // Chrome style dialogs do not move the default button with the focus. - // TODO(wittman): Remove all support for updating the default button on focus - // change once we move completely to Chrome style. See - // http://codereview.chromium.org/10230 for a rough idea of changes to be - // undone. - if (DialogDelegate::UseNewStyle()) - return; - - TextButton* new_default_button = NULL; - // TODO(wittman): Identify TextButtons in a better way than - // enumerating every possible subclass. - if (focused_now && - ((focused_now->GetClassName() == NativeTextButton::kViewClassName) || - (focused_now->GetClassName() == TextButton::kViewClassName) || - (focused_now->GetClassName() == - DialogButton<NativeTextButton>::kViewClassName) || - (focused_now->GetClassName() == - DialogButton<TextButton>::kViewClassName))) { - new_default_button = static_cast<TextButton*>(focused_now); - } else { - // The focused view is not a button, get the default button from the - // delegate. - DialogDelegate* dd = GetDialogDelegate(); - if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) - new_default_button = ok_button_; - if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) - != 0) - new_default_button = cancel_button_; - } - SetDefaultButton(new_default_button); -} - -void DialogClientView::OnDidChangeFocus(View* focused_before, - View* focused_now) { -} - -// Changing dialog labels will change button widths. -void DialogClientView::UpdateDialogButtons() { - DialogDelegate* dd = GetDialogDelegate(); - int buttons = dd->GetDialogButtons(); - - if (buttons & ui::DIALOG_BUTTON_OK) - UpdateButtonHelper(ok_button_, dd, ui::DIALOG_BUTTON_OK); - - if (buttons & ui::DIALOG_BUTTON_CANCEL) - UpdateButtonHelper(cancel_button_, dd, ui::DIALOG_BUTTON_CANCEL); - - LayoutDialogButtons(); - SchedulePaint(); + if (focus_manager_) + focus_manager_->RemoveFocusChangeListener(this); + focus_manager_ = NULL; } void DialogClientView::AcceptWindow() { - if (notified_delegate_) { - // Only notify the delegate once. See comment in header above - // notified_delegate_ for details. - return; - } - if (GetDialogDelegate()->Accept(false)) { + // Only notify the delegate once. See |notified_delegate_|'s comment. + if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { notified_delegate_ = true; Close(); } @@ -249,20 +68,16 @@ void DialogClientView::CancelWindow() { Close(); } -int DialogClientView::GetBottomMargin() { - return style_params_.button_shadow_margin; -} - -/////////////////////////////////////////////////////////////////////////////// -// DialogClientView, View overrides: - -void DialogClientView::NativeViewHierarchyChanged( - bool attached, - gfx::NativeView native_view, - internal::RootView* root_view) { - if (attached) { - UpdateFocusListener(); - } +void DialogClientView::UpdateDialogButtons() { + DialogDelegate* dialog = GetDialogDelegate(); + const int buttons = dialog->GetDialogButtons(); + // Ensure no buttons were added or removed; that isn't currently supported. + DCHECK_EQ((buttons & ui::DIALOG_BUTTON_CANCEL) == 0, cancel_button_ == NULL); + DCHECK_EQ((buttons & ui::DIALOG_BUTTON_OK) == 0, ok_button_ == NULL); + if (cancel_button_) + UpdateButton(cancel_button_, dialog, ui::DIALOG_BUTTON_CANCEL); + if (ok_button_) + UpdateButton(ok_button_, dialog, ui::DIALOG_BUTTON_OK); } /////////////////////////////////////////////////////////////////////////////// @@ -272,32 +87,18 @@ bool DialogClientView::CanClose() { if (notified_delegate_) return true; - DialogDelegate* dd = GetDialogDelegate(); - int buttons = dd->GetDialogButtons(); + DialogDelegate* dialog = GetDialogDelegate(); + int buttons = dialog->GetDialogButtons(); bool close = true; if ((buttons & ui::DIALOG_BUTTON_CANCEL) || (buttons == ui::DIALOG_BUTTON_NONE)) - close = dd->Cancel(); + close = dialog->Cancel(); else if (buttons & ui::DIALOG_BUTTON_OK) - close = dd->Accept(true); + close = dialog->Accept(true); notified_delegate_ = close; return close; } -void DialogClientView::WidgetClosing() { - if (listening_to_focus_) { - DCHECK(saved_focus_manager_); - if (saved_focus_manager_) - saved_focus_manager_->RemoveFocusChangeListener(this); - } -} - -int DialogClientView::NonClientHitTest(const gfx::Point& point) { - if (size_box_bounds_.Contains(point.x() - x(), point.y() - y())) - return HTBOTTOMRIGHT; - return ClientView::NonClientHitTest(point); -} - DialogClientView* DialogClientView::AsDialogClientView() { return this; } @@ -306,263 +107,216 @@ const DialogClientView* DialogClientView::AsDialogClientView() const { return this; } +void DialogClientView::OnWillChangeFocus(View* focused_before, + View* focused_now) { + // New style dialogs do not move the default button with the focus. + // TODO(msw|wittman): Remove this functionality once the new style had landed. + if (DialogDelegate::UseNewStyle()) + return; + + // Make the newly focused button default or restore the dialog's default. + const int default_button = GetDialogDelegate()->GetDefaultDialogButton(); + TextButton* new_default_button = NULL; + if (focused_now && + (focused_now->GetClassName() == TextButton::kViewClassName || + focused_now->GetClassName() == NativeTextButton::kViewClassName)) { + new_default_button = static_cast<TextButton*>(focused_now); + } else if (default_button == ui::DIALOG_BUTTON_OK && ok_button_) { + new_default_button = ok_button_; + } else if (default_button == ui::DIALOG_BUTTON_CANCEL && cancel_button_) { + new_default_button = cancel_button_; + } + + if (default_button_ && default_button_ != new_default_button) + default_button_->SetIsDefault(false); + default_button_ = new_default_button; + if (default_button_ && !default_button_->is_default()) + default_button_->SetIsDefault(true); +} + +void DialogClientView::OnDidChangeFocus(View* focused_before, + View* focused_now) { +} + //////////////////////////////////////////////////////////////////////////////// // DialogClientView, View overrides: -void DialogClientView::PaintChildren(gfx::Canvas* canvas) { - View::PaintChildren(canvas); - if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) - PaintSizeBox(canvas); +gfx::Insets DialogClientView::GetInsets() const { + // NOTE: The insets only apply to the buttons, extra view, and footnote view. + return DialogDelegate::UseNewStyle() ? gfx::Insets() : + gfx::Insets(kButtonVEdgeMargin, kButtonHEdgeMargin, + kButtonVEdgeMargin, kButtonHEdgeMargin); } -void DialogClientView::Layout() { - if (has_dialog_buttons()) - LayoutDialogButtons(); +gfx::Size DialogClientView::GetPreferredSize() { + // Initialize the size to fit the buttons and extra view row. + gfx::Size size( + (ok_button_ ? ok_button_->GetPreferredSize().width() : 0) + + (cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) + + (cancel_button_ && ok_button_ ? kRelatedButtonHSpacing : 0) + + (extra_view_ ? extra_view_->GetPreferredSize().width() : 0) + + (extra_view_ && has_dialog_buttons() ? kRelatedButtonHSpacing : 0), + GetButtonsAndExtraViewRowHeight() + kRelatedControlVerticalSpacing); + + // Increase the size as needed to fit the footnote view. + if (footnote_view_) { + gfx::Size footnote_size = footnote_view_->GetPreferredSize(); + size.Enlarge(0, footnote_size.height() + kRelatedControlVerticalSpacing); + size.set_width(std::max(size.width(), footnote_size.width())); + } - if (footnote_view_) - LayoutFootnoteView(); + // Inset the buttons, extra view, and footnote view. + const gfx::Insets insets = GetInsets(); + size.Enlarge(insets.width(), insets.bottom()); - LayoutContentsView(); + // Increase the size as needed to fit the contents view. + // NOTE: The contents view is not inset on the top or side client view edges. + gfx::Size contents_size = contents_view()->GetPreferredSize(); + size.Enlarge(0, contents_size.height()); + size.set_width(std::max(size.width(), contents_size.width())); + return size; } -void DialogClientView::ViewHierarchyChanged(bool is_add, View* parent, - View* child) { - if (is_add && child == this) { - // Can only add and update the dialog buttons _after_ they are added to the - // view hierarchy since they are native controls and require the - // Container's HWND. - ShowDialogButtons(); - ClientView::ViewHierarchyChanged(is_add, parent, child); - - UpdateFocusListener(); +void DialogClientView::Layout() { + gfx::Rect bounds = GetContentsBounds(); + bounds.Inset(GetInsets()); - // The "extra view" must be created and installed after the contents view - // has been inserted into the view hierarchy. - CreateExtraView(); - CreateFootnoteView(); - UpdateDialogButtons(); - Layout(); + // Layout the footnote view. + if (footnote_view_) { + const int height = footnote_view_->GetPreferredSize().height(); + footnote_view_->SetBounds(bounds.x(), bounds.bottom() - height, + bounds.width(), height); + bounds.Inset(0, 0, 0, height + kRelatedControlVerticalSpacing); } -} -gfx::Size DialogClientView::GetPreferredSize() { - gfx::Size prefsize = contents_view()->GetPreferredSize(); - int button_height = GetDialogButtonsAreaHeight(); - if (has_dialog_buttons()) { - // Make sure the view is sized to the buttons's width if they are wider than - // the contents. - int width = 0; - if (cancel_button_) - width += cancel_button_->GetPreferredSize().width(); + // Layout the row containing the buttons and the extra view. + if (has_dialog_buttons() || extra_view_) { + const int height = GetButtonsAndExtraViewRowHeight(); + gfx::Rect row_bounds(bounds.x(), bounds.bottom() - height, + bounds.width(), height); + if (cancel_button_) { + const gfx::Size size = cancel_button_->GetPreferredSize(); + row_bounds.set_width(row_bounds.width() - size.width()); + cancel_button_->SetBounds(row_bounds.right(), row_bounds.y(), + size.width(), height); + row_bounds.set_width(row_bounds.width() - kRelatedButtonHSpacing); + } if (ok_button_) { - width += ok_button_->GetPreferredSize().width(); - if (cancel_button_) - width += style_params_.related_button_hspacing; + const gfx::Size size = ok_button_->GetPreferredSize(); + row_bounds.set_width(row_bounds.width() - size.width()); + ok_button_->SetBounds(row_bounds.right(), row_bounds.y(), + size.width(), height); + row_bounds.set_width(row_bounds.width() - kRelatedButtonHSpacing); } if (extra_view_) { - width += extra_view_->GetPreferredSize().width(); - if (cancel_button_ || ok_button_) - width += style_params_.related_button_hspacing; + row_bounds.set_width(std::min(row_bounds.width(), + extra_view_->GetPreferredSize().width())); + extra_view_->SetBoundsRect(row_bounds); } - if (width > 0) { - width += 2 * style_params_.button_hedge_margin; - prefsize.set_width(std::max(prefsize.width(), width)); - } - } - 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())); + bounds.Inset(0, 0, 0, height + kRelatedControlVerticalSpacing); } - return prefsize; + // Layout the contents view to the top and side edges of the contents bounds. + // NOTE: The local insets do not apply to the contents view sides or top. + const gfx::Rect contents_bounds = GetContentsBounds(); + contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), + contents_bounds.width(), bounds.bottom() - contents_bounds.y()); } bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { - // We only expect Escape key. - DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); + DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE); Close(); return true; } +void DialogClientView::ViewHierarchyChanged(bool is_add, + View* parent, + View* child) { + ClientView::ViewHierarchyChanged(is_add, parent, child); + if (is_add && child == this) { + focus_manager_ = GetFocusManager(); + if (focus_manager_) + GetFocusManager()->AddFocusChangeListener(this); + + CreateDialogButtons(); + CreateExtraView(); + CreateFootnoteView(); + } +} + //////////////////////////////////////////////////////////////////////////////// // DialogClientView, ButtonListener implementation: void DialogClientView::ButtonPressed(Button* sender, const ui::Event& event) { - // We NULL check the delegate here since the buttons can receive WM_COMMAND - // messages even after they (and the window containing us) are destroyed. + // Check for a valid delegate to avoid handling events after destruction. if (!GetDialogDelegate()) return; - if (sender == ok_button_) { + if (sender == ok_button_) AcceptWindow(); - } else if (sender == cancel_button_) { + else if (sender == cancel_button_) CancelWindow(); - } else { + else NOTREACHED(); - } } //////////////////////////////////////////////////////////////////////////////// // DialogClientView, private: -DialogClientView::StyleParams::StyleParams() - : button_vedge_margin(kButtonVEdgeMargin), - button_hedge_margin(kButtonHEdgeMargin), - button_shadow_margin(0), - button_content_spacing(kDialogButtonContentSpacing), - related_button_hspacing(kRelatedButtonHSpacing) { - if (DialogDelegate::UseNewStyle()) { - button_vedge_margin = 0; - button_hedge_margin = 0; - button_shadow_margin = GetChromeStyleButtonShadowMargin(); - button_content_spacing = 0; - related_button_hspacing = 10; +void DialogClientView::CreateDialogButtons() { + DCHECK(!cancel_button_ && !ok_button_); + const int buttons = GetDialogDelegate()->GetDialogButtons(); + ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); + + if (buttons & ui::DIALOG_BUTTON_OK) { + ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); + if (buttons & ui::DIALOG_BUTTON_CANCEL) + ok_button_->AddAccelerator(escape); + AddChildView(ok_button_); } + if (buttons & ui::DIALOG_BUTTON_CANCEL) { + cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); + cancel_button_->AddAccelerator(escape); + AddChildView(cancel_button_); + } + UpdateDialogButtons(); + + // Use the escape key to close the window if there are no dialog buttons. + if (!has_dialog_buttons()) + AddAccelerator(escape); } -TextButton* DialogClientView::CreateDialogButton(ui::DialogButton type, - const string16& title) { +TextButton* DialogClientView::CreateDialogButton(ui::DialogButton type) { + const string16 title = GetDialogDelegate()->GetDialogButtonLabel(type); TextButton* button = NULL; if (DialogDelegate::UseNewStyle()) - button = new DialogButton<TextButton>(this, GetWidget(), type, title); + button = new TextButton(this, title); else - button = new DialogButton<NativeTextButton>(this, GetWidget(), type, title); - - if (!DialogDelegate::UseNewStyle()) - button->set_min_width(kDialogMinButtonWidth); - + button = new NativeTextButton(this, title); + const int kDialogMinButtonWidth = 75; + button->set_min_width(kDialogMinButtonWidth); button->SetGroup(kButtonGroup); - - if (GetDialogDelegate()->GetDefaultDialogButton() & type) { + if (type == GetDialogDelegate()->GetDefaultDialogButton()) { default_button_ = button; button->SetIsDefault(true); } - - if (DialogDelegate::UseNewStyle()) - ApplyChromeStyle(button); - return button; } -void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { - if (GetWidget()->widget_delegate()->CanResize() || - GetWidget()->widget_delegate()->CanMaximize()) { -#if defined(OS_WIN) - ui::NativeTheme* theme = GetNativeTheme(); - ui::NativeTheme::ExtraParams extra; - gfx::Size gripper_size = theme->GetPartSize( - ui::NativeTheme::kWindowResizeGripper, ui::NativeTheme::kNormal, extra); - - // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't - // a theme-supplied gripper. We should probably improvise - // something, which would also require changing |gripper_size| - // to have different default values, too... - size_box_bounds_ = GetContentsBounds(); - size_box_bounds_.set_x(size_box_bounds_.right() - gripper_size.width()); - size_box_bounds_.set_y(size_box_bounds_.bottom() - gripper_size.height()); - - theme->Paint(canvas->sk_canvas(), - ui::NativeTheme::kWindowResizeGripper, - ui::NativeTheme::kNormal, - size_box_bounds_, - extra); -#else - NOTIMPLEMENTED(); - // TODO(port): paint size box -#endif - } -} - -int DialogClientView::GetButtonsHeight() const { - int button_height = 0; - if (cancel_button_) - button_height = std::max(button_height, - cancel_button_->GetPreferredSize().height()); - if (ok_button_) - button_height = std::max(button_height, - ok_button_->GetPreferredSize().height()); - return button_height; -} - -int DialogClientView::GetDialogButtonsAreaHeight() const { - return !has_dialog_buttons() ? 0 : - GetButtonsHeight() + style_params_.button_content_spacing + - style_params_.button_vedge_margin; +int DialogClientView::GetButtonsAndExtraViewRowHeight() const { + return std::max(extra_view_ ? extra_view_->GetPreferredSize().height() : 0, + std::max(ok_button_ ? ok_button_->GetPreferredSize().height() : 0, + cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0)); } -int DialogClientView::GetFootnoteViewHeight() const { - return footnote_view_ ? footnote_view_->GetPreferredSize().height() : 0; -} +void DialogClientView::CreateExtraView() { + if (extra_view_) + return; -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(); - int button_x = lb.right() - ps.width() - style_params_.button_hedge_margin; - int button_y = bottom_y - ps.height(); - cancel_button_->SetBounds(button_x, button_y, ps.width(), ps.height()); - // The extra view bounds are dependent on this button. - extra_bounds.set_width(std::max(0, cancel_button_->x())); - extra_bounds.set_y(cancel_button_->y()); - } - if (ok_button_) { - gfx::Size ps = ok_button_->GetPreferredSize(); - int ok_button_right = lb.right() - style_params_.button_hedge_margin; - if (cancel_button_) - ok_button_right = cancel_button_->x() - - style_params_.related_button_hspacing; - int button_x = ok_button_right - ps.width(); - 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. - extra_bounds.set_width(std::max(0, ok_button_->x())); - extra_bounds.set_y(ok_button_->y()); - } + extra_view_ = GetDialogDelegate()->CreateExtraView(); if (extra_view_) { - gfx::Size ps = extra_view_->GetPreferredSize(); - extra_bounds.set_x(lb.x() + style_params_.button_hedge_margin); - int height = size_extra_view_height_to_buttons_ ? - std::max(ps.height(), button_height) : ps.height(); - extra_bounds.set_height(height); - extra_view_->SetBoundsRect(extra_bounds); - } -} - -void DialogClientView::LayoutContentsView() { - gfx::Rect lb = GetContentsBounds(); - 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_) { - extra_view_ = extra_view; extra_view_->SetGroup(kButtonGroup); AddChildView(extra_view_); - size_extra_view_height_to_buttons_ = - GetDialogDelegate()->GetSizeExtraViewHeightToButtons(); } } @@ -570,7 +324,7 @@ void DialogClientView::CreateFootnoteView() { if (footnote_view_) return; - footnote_view_ = GetDialogDelegate()->GetFootnoteView(); + footnote_view_ = GetDialogDelegate()->CreateFootnoteView(); if (footnote_view_) AddChildView(footnote_view_); } @@ -584,26 +338,4 @@ void DialogClientView::Close() { GetDialogDelegate()->OnClose(); } -void DialogClientView::UpdateFocusListener() { - FocusManager* focus_manager = GetFocusManager(); - // Listen for focus change events so we can update the default button. - // focus_manager can be NULL when the dialog is created on un-shown view. - // We start listening for focus changes when the page is visible. - // Focus manager could also change if window host changes a parent. - if (listening_to_focus_) { - if (saved_focus_manager_ == focus_manager) - return; - DCHECK(saved_focus_manager_); - if (saved_focus_manager_) - saved_focus_manager_->RemoveFocusChangeListener(this); - listening_to_focus_ = false; - } - saved_focus_manager_ = focus_manager; - // Listen for focus change events so we can update the default button. - if (focus_manager) { - focus_manager->AddFocusChangeListener(this); - listening_to_focus_ = true; - } -} - } // namespace views diff --git a/ui/views/window/dialog_client_view.h b/ui/views/window/dialog_client_view.h index c8136d4..cea86f4 100644 --- a/ui/views/window/dialog_client_view.h +++ b/ui/views/window/dialog_client_view.h @@ -15,22 +15,18 @@ namespace views { class DialogDelegate; class TextButton; class Widget; -namespace internal { -class RootView; -} - -/////////////////////////////////////////////////////////////////////////////// -// DialogClientView -// -// This ClientView subclass provides the content of a typical dialog box, -// including a strip of buttons at the bottom right of the window, default -// accelerator handlers for accept and cancel, and the ability for the -// 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. -// + +// DialogClientView provides adornments for a dialog's content view, including +// custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. +// The view also displays the delegate's extra view alongside the buttons and +// the delegate's footnote view below the buttons. The view appears like below. +// NOTE: The contents view is not inset on the top or side client view edges. +// +------------------------------+ +// | Contents View | +// +------------------------------+ +// | [Extra View] [OK] [Cancel] | +// | [ Footnote View ] | +// +------------------------------+ class VIEWS_EXPORT DialogClientView : public ClientView, public ButtonListener, public FocusChangeListener { @@ -38,38 +34,19 @@ class VIEWS_EXPORT DialogClientView : public ClientView, DialogClientView(Widget* widget, View* contents_view); virtual ~DialogClientView(); - // Adds the dialog buttons required by the supplied DialogDelegate to the - // view. - void ShowDialogButtons(); - - // Updates the enabled state and label of the buttons required by the - // supplied DialogDelegate - void UpdateDialogButtons(); - - // Accept the changes made in the window that contains this ClientView. + // Accept or Cancel the dialog. void AcceptWindow(); - - // Cancel the changes made in the window that contains this ClientView. void CancelWindow(); // Accessors in case the user wishes to adjust these buttons. TextButton* ok_button() const { return ok_button_; } TextButton* cancel_button() const { return cancel_button_; } - // Returns the number of pixels at the bottom of the dialog which are visually - // part of the frame, but are actually rendered by the DialogClientView. - int GetBottomMargin(); - - // Overridden from View: - virtual void NativeViewHierarchyChanged( - bool attached, - gfx::NativeView native_view, - internal::RootView* root_view) OVERRIDE; + // Update the dialog buttons to match the dialog's delegate. + void UpdateDialogButtons(); - // Overridden from ClientView: + // ClientView implementation: virtual bool CanClose() OVERRIDE; - virtual void WidgetClosing() OVERRIDE; - virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; virtual DialogClientView* AsDialogClientView() OVERRIDE; virtual const DialogClientView* AsDialogClientView() const OVERRIDE; @@ -80,58 +57,29 @@ class VIEWS_EXPORT DialogClientView : public ClientView, View* focused_now) OVERRIDE; protected: - // View overrides: - virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; - virtual void Layout() OVERRIDE; - virtual void ViewHierarchyChanged(bool is_add, View* parent, - View* child) OVERRIDE; + // View implementation: + virtual gfx::Insets GetInsets() const OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void Layout() OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; + virtual void ViewHierarchyChanged(bool is_add, + View* parent, + View* child) OVERRIDE; // ButtonListener implementation: - virtual void ButtonPressed(Button* sender, - const ui::Event& event) OVERRIDE; + virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; private: - // Parameters for the internal dialog styling. - struct StyleParams { - StyleParams(); + bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } - int button_vedge_margin; - int button_hedge_margin; - int button_shadow_margin; - int button_content_spacing; - int related_button_hspacing; - }; + // Create the necessary dialog buttons. + void CreateDialogButtons(); // Create a dialog button of the appropriate type. - TextButton* CreateDialogButton(ui::DialogButton type, const string16& title); - - // Paint the size box in the bottom right corner of the window if it is - // resizable. - void PaintSizeBox(gfx::Canvas* canvas); + TextButton* CreateDialogButton(ui::DialogButton type); - // Returns the greater of ok and cancel button's preferred height. - int GetButtonsHeight() const; - - // Returns the height of the dialog buttons area, including the spacing - // between bottom of contents view and top of buttons, the buttons height, - // 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); - - bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } + // Returns the height of the row containing the buttons and the extra view. + int GetButtonsAndExtraViewRowHeight() const; // Create and add the extra view, if supplied by the delegate. void CreateExtraView(); @@ -145,44 +93,28 @@ class VIEWS_EXPORT DialogClientView : public ClientView, // Closes the widget. void Close(); - // Updates focus listener. - void UpdateFocusListener(); - - // Parameters for the internal dialog styling. - StyleParams style_params_; - // The dialog buttons. TextButton* ok_button_; TextButton* cancel_button_; - // The button that is currently the default button if any. + // The button that is currently default; may be NULL. TextButton* default_button_; - // The button-level extra view, NULL unless the dialog delegate supplies one. + // Observe |focus_manager_| to update the default button with focus changes. + FocusManager* focus_manager_; + + // The extra view shown in the row of buttons; may be NULL. View* extra_view_; - // The view that resides beneath the dialog buttons, or NULL. + // The footnote view shown below the buttons; may be NULL. View* footnote_view_; - // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for - // details on this. - bool size_extra_view_height_to_buttons_; - - // The layout rect of the size box, when visible. - gfx::Rect size_box_bounds_; - // True if we've notified the delegate the window is closing and the delegate // allosed the close. In some situations it's possible to get two closes (see // http://crbug.com/71940). This is used to avoid notifying the delegate // twice, which can have bad consequences. bool notified_delegate_; - // true if focus listener is added. - bool listening_to_focus_; - - // When ancestor gets changed focus manager gets changed as well. - FocusManager* saved_focus_manager_; - DISALLOW_COPY_AND_ASSIGN(DialogClientView); }; diff --git a/ui/views/window/dialog_delegate.cc b/ui/views/window/dialog_delegate.cc index 80606fc..5f565de 100644 --- a/ui/views/window/dialog_delegate.cc +++ b/ui/views/window/dialog_delegate.cc @@ -6,6 +6,8 @@ #include "base/command_line.h" #include "base/logging.h" +#include "grit/ui_strings.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/ui_base_switches.h" #include "ui/views/bubble/bubble_border.h" #include "ui/views/bubble/bubble_frame_view.h" @@ -67,8 +69,14 @@ int DialogDelegate::GetDefaultDialogButton() const { } string16 DialogDelegate::GetDialogButtonLabel(ui::DialogButton button) const { - // Empty string results in defaults for - // ui::DIALOG_BUTTON_OK or ui::DIALOG_BUTTON_CANCEL. + if (button == ui::DIALOG_BUTTON_OK) + return l10n_util::GetStringUTF16(IDS_APP_OK); + if (button == ui::DIALOG_BUTTON_CANCEL) { + if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) + return l10n_util::GetStringUTF16(IDS_APP_CANCEL); + return l10n_util::GetStringUTF16(IDS_APP_CLOSE); + } + NOTREACHED(); return string16(); } @@ -76,23 +84,11 @@ bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const { return true; } -bool DialogDelegate::IsDialogButtonVisible(ui::DialogButton button) const { - return true; -} - -bool DialogDelegate::AreAcceleratorsEnabled(ui::DialogButton button) { - return true; -} - -View* DialogDelegate::GetExtraView() { +View* DialogDelegate::CreateExtraView() { return NULL; } -bool DialogDelegate::GetSizeExtraViewHeightToButtons() { - return false; -} - -View* DialogDelegate::GetFootnoteView() { +View* DialogDelegate::CreateFootnoteView() { return NULL; } diff --git a/ui/views/window/dialog_delegate.h b/ui/views/window/dialog_delegate.h index a039e8f..dc2e2ce 100644 --- a/ui/views/window/dialog_delegate.h +++ b/ui/views/window/dialog_delegate.h @@ -33,12 +33,7 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { static bool UseNewStyle(); // Returns a mask specifying which of the available DialogButtons are visible - // for the dialog. Note: If an OK button is provided, you should provide a - // CANCEL button. A dialog box with just an OK button is frowned upon and - // considered a very special case, so if you're planning on including one, - // you should reconsider, or beng says there will be stabbings. - // - // To use the extra button you need to override GetDialogButtons() + // for the dialog. Note: Dialogs with just an OK button are frowned upon. virtual int GetDialogButtons() const; // Returns the default dialog button. This should not be a mask as only @@ -55,29 +50,13 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { // Returns whether the specified dialog button is enabled. virtual bool IsDialogButtonEnabled(ui::DialogButton button) const; - // Returns whether the specified dialog button is visible. - virtual bool IsDialogButtonVisible(ui::DialogButton button) const; - - // Returns whether accelerators are enabled on the button. This is invoked - // when an accelerator is pressed, not at construction time. This - // returns true. - virtual bool AreAcceleratorsEnabled(ui::DialogButton button); - - // Override this function if with a view which will be shown in the same - // row as the OK and CANCEL buttons but flush to the left and extending - // up to the buttons. - virtual View* GetExtraView(); - - // Returns whether the height of the extra view should be at least as tall as - // the buttons. The default (false) is to give the extra view its preferred - // height. By returning true the height becomes - // 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(); + // Override this function to display an extra view adjacent to the buttons. + // Overrides may construct the view; this will only be called once per dialog. + virtual View* CreateExtraView(); + + // Override this function to display a footnote view below the buttons. + // Overrides may construct the view; this will only be called once per dialog. + virtual View* CreateFootnoteView(); // 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 |