| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/views/database_info_view.h" | 5 #include "chrome/browser/views/database_info_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/color_utils.h" | 9 #include "app/gfx/color_utils.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "views/grid_layout.h" | 14 #include "views/grid_layout.h" |
| 15 #include "views/controls/label.h" | 15 #include "views/controls/label.h" |
| 16 #include "views/controls/textfield/textfield.h" | 16 #include "views/controls/textfield/textfield.h" |
| 17 #include "views/standard_layout.h" | 17 #include "views/standard_layout.h" |
| 18 | 18 |
| 19 static const int kDatabaseInfoViewBorderSize = 1; | 19 static const int kDatabaseInfoViewBorderSize = 1; |
| 20 static const int kDatabaseInfoViewInsetSize = 3; | 20 static const int kDatabaseInfoViewInsetSize = 3; |
| 21 | 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 // DatabaseInfoView, public: | 23 // DatabaseInfoView, public: |
| 24 | 24 |
| 25 DatabaseInfoView::DatabaseInfoView() | 25 DatabaseInfoView::DatabaseInfoView() |
| 26 : description_value_field_(NULL), | 26 : name_value_field_(NULL), |
| 27 description_value_field_(NULL), |
| 27 size_value_field_(NULL), | 28 size_value_field_(NULL), |
| 28 last_modified_value_field_(NULL) { | 29 last_modified_value_field_(NULL) { |
| 29 } | 30 } |
| 30 | 31 |
| 31 DatabaseInfoView::~DatabaseInfoView() { | 32 DatabaseInfoView::~DatabaseInfoView() { |
| 32 } | 33 } |
| 33 | 34 |
| 34 void DatabaseInfoView::SetDatabaseInfo( | 35 void DatabaseInfoView::SetDatabaseInfo( |
| 35 const BrowsingDataDatabaseHelper::DatabaseInfo& database_info) { | 36 const BrowsingDataDatabaseHelper::DatabaseInfo& database_info) { |
| 37 name_value_field_->SetText(database_info.database_name.empty() ? |
| 38 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) : |
| 39 UTF8ToWide(database_info.database_name)); |
| 36 description_value_field_->SetText(UTF8ToWide(database_info.description)); | 40 description_value_field_->SetText(UTF8ToWide(database_info.description)); |
| 37 size_value_field_->SetText( | 41 size_value_field_->SetText( |
| 38 FormatBytes(database_info.size, | 42 FormatBytes(database_info.size, |
| 39 GetByteDisplayUnits(database_info.size), | 43 GetByteDisplayUnits(database_info.size), |
| 40 true)); | 44 true)); |
| 41 last_modified_value_field_->SetText( | 45 last_modified_value_field_->SetText( |
| 42 base::TimeFormatFriendlyDateAndTime(database_info.last_modified)); | 46 base::TimeFormatFriendlyDateAndTime(database_info.last_modified)); |
| 43 EnableDatabaseDisplay(true); | 47 EnableDatabaseDisplay(true); |
| 44 } | 48 } |
| 45 | 49 |
| 46 void DatabaseInfoView::EnableDatabaseDisplay(bool enabled) { | 50 void DatabaseInfoView::EnableDatabaseDisplay(bool enabled) { |
| 51 name_value_field_->SetEnabled(enabled); |
| 47 description_value_field_->SetEnabled(enabled); | 52 description_value_field_->SetEnabled(enabled); |
| 48 size_value_field_->SetEnabled(enabled); | 53 size_value_field_->SetEnabled(enabled); |
| 49 last_modified_value_field_->SetEnabled(enabled); | 54 last_modified_value_field_->SetEnabled(enabled); |
| 50 } | 55 } |
| 51 | 56 |
| 52 void DatabaseInfoView::ClearDatabaseDisplay() { | 57 void DatabaseInfoView::ClearDatabaseDisplay() { |
| 53 std::wstring no_cookie_string = | 58 const std::wstring kEmpty; |
| 54 l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); | 59 description_value_field_->SetText(kEmpty); |
| 55 description_value_field_->SetText(no_cookie_string); | 60 size_value_field_->SetText(kEmpty); |
| 56 size_value_field_->SetText(no_cookie_string); | 61 last_modified_value_field_->SetText(kEmpty); |
| 57 last_modified_value_field_->SetText(no_cookie_string); | |
| 58 EnableDatabaseDisplay(false); | 62 EnableDatabaseDisplay(false); |
| 59 } | 63 } |
| 60 | 64 |
| 61 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
| 62 // DatabaseInfoView, views::View overrides: | 66 // DatabaseInfoView, views::View overrides: |
| 63 | 67 |
| 64 void DatabaseInfoView::ViewHierarchyChanged(bool is_add, | 68 void DatabaseInfoView::ViewHierarchyChanged(bool is_add, |
| 65 views::View* parent, | 69 views::View* parent, |
| 66 views::View* child) { | 70 views::View* child) { |
| 67 if (is_add && child == this) | 71 if (is_add && child == this) |
| 68 Init(); | 72 Init(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
| 72 // DatabaseInfoView, private: | 76 // DatabaseInfoView, private: |
| 73 | 77 |
| 74 void DatabaseInfoView::Init() { | 78 void DatabaseInfoView::Init() { |
| 75 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); | 79 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); |
| 76 views::Border* border = views::Border::CreateSolidBorder( | 80 views::Border* border = views::Border::CreateSolidBorder( |
| 77 kDatabaseInfoViewBorderSize, border_color); | 81 kDatabaseInfoViewBorderSize, border_color); |
| 78 set_border(border); | 82 set_border(border); |
| 79 | 83 |
| 84 views::Label* name_label = new views::Label( |
| 85 l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); |
| 86 name_value_field_ = new views::Textfield; |
| 80 views::Label* description_label = new views::Label( | 87 views::Label* description_label = new views::Label( |
| 81 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL)); | 88 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL)); |
| 82 description_value_field_ = new views::Textfield; | 89 description_value_field_ = new views::Textfield; |
| 83 views::Label* size_label = new views::Label( | 90 views::Label* size_label = new views::Label( |
| 84 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); | 91 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); |
| 85 size_value_field_ = new views::Textfield; | 92 size_value_field_ = new views::Textfield; |
| 86 views::Label* last_modified_label = new views::Label( | 93 views::Label* last_modified_label = new views::Label( |
| 87 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); | 94 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); |
| 88 last_modified_value_field_ = new views::Textfield; | 95 last_modified_value_field_ = new views::Textfield; |
| 89 | 96 |
| 90 using views::GridLayout; | 97 using views::GridLayout; |
| 91 | 98 |
| 92 GridLayout* layout = new GridLayout(this); | 99 GridLayout* layout = new GridLayout(this); |
| 93 layout->SetInsets(kDatabaseInfoViewInsetSize, | 100 layout->SetInsets(kDatabaseInfoViewInsetSize, |
| 94 kDatabaseInfoViewInsetSize, | 101 kDatabaseInfoViewInsetSize, |
| 95 kDatabaseInfoViewInsetSize, | 102 kDatabaseInfoViewInsetSize, |
| 96 kDatabaseInfoViewInsetSize); | 103 kDatabaseInfoViewInsetSize); |
| 97 SetLayoutManager(layout); | 104 SetLayoutManager(layout); |
| 98 | 105 |
| 99 int three_column_layout_id = 0; | 106 int three_column_layout_id = 0; |
| 100 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); | 107 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); |
| 101 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 108 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 102 GridLayout::USE_PREF, 0, 0); | 109 GridLayout::USE_PREF, 0, 0); |
| 103 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 110 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 104 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 111 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 105 GridLayout::USE_PREF, 0, 0); | 112 GridLayout::USE_PREF, 0, 0); |
| 106 | 113 |
| 107 layout->StartRow(0, three_column_layout_id); | 114 layout->StartRow(0, three_column_layout_id); |
| 115 layout->AddView(name_label); |
| 116 layout->AddView(name_value_field_); |
| 117 layout->StartRow(0, three_column_layout_id); |
| 108 layout->AddView(description_label); | 118 layout->AddView(description_label); |
| 109 layout->AddView(description_value_field_); | 119 layout->AddView(description_value_field_); |
| 110 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 120 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 111 layout->StartRow(0, three_column_layout_id); | 121 layout->StartRow(0, three_column_layout_id); |
| 112 layout->AddView(size_label); | 122 layout->AddView(size_label); |
| 113 layout->AddView(size_value_field_); | 123 layout->AddView(size_value_field_); |
| 114 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 124 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 115 layout->StartRow(0, three_column_layout_id); | 125 layout->StartRow(0, three_column_layout_id); |
| 116 layout->AddView(last_modified_label); | 126 layout->AddView(last_modified_label); |
| 117 layout->AddView(last_modified_value_field_); | 127 layout->AddView(last_modified_value_field_); |
| 118 | 128 |
| 119 // Color these borderless text areas the same as the containing dialog. | 129 // Color these borderless text areas the same as the containing dialog. |
| 120 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); | 130 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); |
| 121 // Now that the Textfields are in the view hierarchy, we can initialize them. | 131 // Now that the Textfields are in the view hierarchy, we can initialize them. |
| 132 name_value_field_->SetReadOnly(true); |
| 133 name_value_field_->RemoveBorder(); |
| 134 name_value_field_->SetBackgroundColor(text_area_background); |
| 122 description_value_field_->SetReadOnly(true); | 135 description_value_field_->SetReadOnly(true); |
| 123 description_value_field_->RemoveBorder(); | 136 description_value_field_->RemoveBorder(); |
| 124 description_value_field_->SetBackgroundColor(text_area_background); | 137 description_value_field_->SetBackgroundColor(text_area_background); |
| 125 size_value_field_->SetReadOnly(true); | 138 size_value_field_->SetReadOnly(true); |
| 126 size_value_field_->RemoveBorder(); | 139 size_value_field_->RemoveBorder(); |
| 127 size_value_field_->SetBackgroundColor(text_area_background); | 140 size_value_field_->SetBackgroundColor(text_area_background); |
| 128 last_modified_value_field_->SetReadOnly(true); | 141 last_modified_value_field_->SetReadOnly(true); |
| 129 last_modified_value_field_->RemoveBorder(); | 142 last_modified_value_field_->RemoveBorder(); |
| 130 last_modified_value_field_->SetBackgroundColor(text_area_background); | 143 last_modified_value_field_->SetBackgroundColor(text_area_background); |
| 131 } | 144 } |
| OLD | NEW |