| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/options/advanced_page_view.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/options/options_util.h" | |
| 11 #include "chrome/browser/ui/views/options/advanced_contents_view.h" | |
| 12 #include "chrome/browser/ui/views/options/managed_prefs_banner_view.h" | |
| 13 #include "chrome/common/chrome_constants.h" | |
| 14 #include "grit/chromium_strings.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "grit/locale_settings.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 18 #include "ui/base/message_box_flags.h" | |
| 19 #include "views/controls/message_box_view.h" | |
| 20 #include "views/controls/button/native_button.h" | |
| 21 #include "views/controls/scroll_view.h" | |
| 22 #include "views/layout/grid_layout.h" | |
| 23 #include "views/layout/layout_constants.h" | |
| 24 #include "views/window/dialog_delegate.h" | |
| 25 #include "views/window/window.h" | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 // A dialog box that asks the user to confirm resetting settings. | |
| 30 class ResetDefaultsConfirmBox : public views::DialogDelegate { | |
| 31 public: | |
| 32 // This box is modal to |parent_hwnd|. | |
| 33 static void ShowConfirmBox(HWND parent_hwnd, AdvancedPageView* page_view) { | |
| 34 // When the window closes, it will delete itself. | |
| 35 new ResetDefaultsConfirmBox(parent_hwnd, page_view); | |
| 36 } | |
| 37 | |
| 38 protected: | |
| 39 // views::DialogDelegate | |
| 40 virtual std::wstring GetDialogButtonLabel( | |
| 41 ui::MessageBoxFlags::DialogButton button) const { | |
| 42 switch (button) { | |
| 43 case ui::MessageBoxFlags::DIALOGBUTTON_OK: | |
| 44 return UTF16ToWide( | |
| 45 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_OKLABEL)); | |
| 46 case ui::MessageBoxFlags::DIALOGBUTTON_CANCEL: | |
| 47 return UTF16ToWide( | |
| 48 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_CANCELLABEL)); | |
| 49 default: | |
| 50 break; | |
| 51 } | |
| 52 NOTREACHED(); | |
| 53 return std::wstring(); | |
| 54 } | |
| 55 virtual std::wstring GetWindowTitle() const { | |
| 56 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 57 } | |
| 58 virtual bool Accept() { | |
| 59 advanced_page_view_->ResetToDefaults(); | |
| 60 return true; | |
| 61 } | |
| 62 // views::WindowDelegate | |
| 63 virtual void DeleteDelegate() { delete this; } | |
| 64 virtual bool IsModal() const { return true; } | |
| 65 virtual views::View* GetContentsView() { return message_box_view_; } | |
| 66 | |
| 67 private: | |
| 68 ResetDefaultsConfirmBox(HWND parent_hwnd, AdvancedPageView* page_view) | |
| 69 : advanced_page_view_(page_view) { | |
| 70 int dialog_width = views::Window::GetLocalizedContentsWidth( | |
| 71 IDS_OPTIONS_RESET_CONFIRM_BOX_WIDTH_CHARS); | |
| 72 // Also deleted when the window closes. | |
| 73 message_box_view_ = new MessageBoxView( | |
| 74 ui::MessageBoxFlags::kFlagHasMessage | | |
| 75 ui::MessageBoxFlags::kFlagHasOKButton, | |
| 76 UTF16ToWide( | |
| 77 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_MESSAGE)).c_str(), | |
| 78 std::wstring(), | |
| 79 dialog_width); | |
| 80 views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), this)->Show(); | |
| 81 } | |
| 82 virtual ~ResetDefaultsConfirmBox() { } | |
| 83 | |
| 84 MessageBoxView* message_box_view_; | |
| 85 AdvancedPageView* advanced_page_view_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(ResetDefaultsConfirmBox); | |
| 88 }; | |
| 89 | |
| 90 } // namespace | |
| 91 | |
| 92 /////////////////////////////////////////////////////////////////////////////// | |
| 93 // AdvancedPageView, public: | |
| 94 | |
| 95 AdvancedPageView::AdvancedPageView(Profile* profile) | |
| 96 : advanced_scroll_view_(NULL), | |
| 97 reset_to_default_button_(NULL), | |
| 98 OptionsPageView(profile) { | |
| 99 } | |
| 100 | |
| 101 AdvancedPageView::~AdvancedPageView() { | |
| 102 } | |
| 103 | |
| 104 void AdvancedPageView::ResetToDefaults() { | |
| 105 OptionsUtil::ResetToDefaults(profile()); | |
| 106 } | |
| 107 | |
| 108 /////////////////////////////////////////////////////////////////////////////// | |
| 109 // AdvancedPageView, views::ButtonListener implementation: | |
| 110 | |
| 111 void AdvancedPageView::ButtonPressed( | |
| 112 views::Button* sender, const views::Event& event) { | |
| 113 if (sender == reset_to_default_button_) { | |
| 114 UserMetricsRecordAction(UserMetricsAction("Options_ResetToDefaults"), | |
| 115 NULL); | |
| 116 ResetDefaultsConfirmBox::ShowConfirmBox( | |
| 117 GetWindow()->GetNativeWindow(), this); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 /////////////////////////////////////////////////////////////////////////////// | |
| 122 // AdvancedPageView, OptionsPageView implementation: | |
| 123 | |
| 124 void AdvancedPageView::InitControlLayout() { | |
| 125 reset_to_default_button_ = new views::NativeButton( | |
| 126 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_RESET))); | |
| 127 advanced_scroll_view_ = new AdvancedScrollViewContainer(profile()); | |
| 128 | |
| 129 using views::GridLayout; | |
| 130 using views::ColumnSet; | |
| 131 | |
| 132 GridLayout* layout = GridLayout::CreatePanel(this); | |
| 133 SetLayoutManager(layout); | |
| 134 | |
| 135 const int single_column_view_set_id = 0; | |
| 136 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); | |
| 137 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
| 138 GridLayout::USE_PREF, 0, 0); | |
| 139 layout->StartRow(0, single_column_view_set_id); | |
| 140 layout->AddView( | |
| 141 new ManagedPrefsBannerView(profile()->GetPrefs(), OPTIONS_PAGE_ADVANCED)); | |
| 142 | |
| 143 layout->StartRow(1, single_column_view_set_id); | |
| 144 layout->AddView(advanced_scroll_view_); | |
| 145 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 146 | |
| 147 layout->StartRow(0, single_column_view_set_id); | |
| 148 layout->AddView(reset_to_default_button_, 1, 1, | |
| 149 GridLayout::TRAILING, GridLayout::CENTER); | |
| 150 } | |
| OLD | NEW |