| 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/local_storage_info_view.h" | 5 #include "chrome/browser/views/appcache_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 kLocalStorageInfoViewBorderSize = 1; | 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 static const int kLocalStorageInfoViewInsetSize = 3; | 20 // AppCacheInfoView, public: |
| 21 | 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 22 AppCacheInfoView::AppCacheInfoView() |
| 23 // LocalStorageInfoView, public: | 23 : manifest_url_field_(NULL), |
| 24 | 24 size_field_(NULL), |
| 25 LocalStorageInfoView::LocalStorageInfoView() | 25 creation_date_field_(NULL), |
| 26 : origin_value_field_(NULL), | 26 last_access_field_(NULL) { |
| 27 size_value_field_(NULL), | |
| 28 last_modified_value_field_(NULL) { | |
| 29 } | 27 } |
| 30 | 28 |
| 31 LocalStorageInfoView::~LocalStorageInfoView() { | 29 AppCacheInfoView::~AppCacheInfoView() { |
| 32 } | 30 } |
| 33 | 31 |
| 34 void LocalStorageInfoView::SetLocalStorageInfo( | 32 void AppCacheInfoView::SetAppCacheInfo( |
| 35 const BrowsingDataLocalStorageHelper::LocalStorageInfo& | 33 const BrowsingDataAppCacheHelper::AppCacheInfo* info) { |
| 36 local_storage_info) { | 34 DCHECK(info); |
| 37 origin_value_field_->SetText(UTF8ToWide(local_storage_info.origin)); | 35 manifest_url_field_->SetText(UTF8ToWide(info->manifest_url.spec())); |
| 38 size_value_field_->SetText( | 36 size_field_->SetText( |
| 39 FormatBytes(local_storage_info.size, | 37 FormatBytes(info->size, GetByteDisplayUnits(info->size), true)); |
| 40 GetByteDisplayUnits(local_storage_info.size), | 38 creation_date_field_->SetText( |
| 41 true)); | 39 base::TimeFormatFriendlyDateAndTime(info->creation_time)); |
| 42 last_modified_value_field_->SetText( | 40 last_access_field_->SetText( |
| 43 base::TimeFormatFriendlyDateAndTime(local_storage_info.last_modified)); | 41 base::TimeFormatFriendlyDateAndTime(info->last_access_time)); |
| 44 EnableLocalStorageDisplay(true); | 42 EnableAppCacheDisplay(true); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void LocalStorageInfoView::EnableLocalStorageDisplay(bool enabled) { | 45 void AppCacheInfoView::EnableAppCacheDisplay(bool enabled) { |
| 48 origin_value_field_->SetEnabled(enabled); | 46 manifest_url_field_->SetEnabled(enabled); |
| 49 size_value_field_->SetEnabled(enabled); | 47 size_field_->SetEnabled(enabled); |
| 50 last_modified_value_field_->SetEnabled(enabled); | 48 creation_date_field_->SetEnabled(enabled); |
| 49 last_access_field_->SetEnabled(enabled); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void LocalStorageInfoView::ClearLocalStorageDisplay() { | 52 void AppCacheInfoView::ClearAppCacheDisplay() { |
| 54 std::wstring no_cookie_string = | 53 const string16 kEmpty; |
| 55 l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); | 54 manifest_url_field_->SetText(kEmpty); |
| 56 origin_value_field_->SetText(no_cookie_string); | 55 size_field_->SetText(kEmpty); |
| 57 size_value_field_->SetText(no_cookie_string); | 56 creation_date_field_->SetText(kEmpty); |
| 58 last_modified_value_field_->SetText(no_cookie_string); | 57 last_access_field_->SetText(kEmpty); |
| 59 EnableLocalStorageDisplay(false); | 58 EnableAppCacheDisplay(false); |
| 60 } | 59 } |
| 61 | 60 |
| 62 /////////////////////////////////////////////////////////////////////////////// | 61 /////////////////////////////////////////////////////////////////////////////// |
| 63 // LocalStorageInfoView, views::View overrides: | 62 // AppCacheInfoView, views::View overrides: |
| 64 | 63 |
| 65 void LocalStorageInfoView::ViewHierarchyChanged(bool is_add, | 64 void AppCacheInfoView::ViewHierarchyChanged(bool is_add, |
| 66 views::View* parent, | 65 views::View* parent, |
| 67 views::View* child) { | 66 views::View* child) { |
| 68 if (is_add && child == this) | 67 if (is_add && child == this) |
| 69 Init(); | 68 Init(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
| 73 // LocalStorageInfoView, private: | 72 // AppCacheInfoView, private: |
| 74 | 73 |
| 75 void LocalStorageInfoView::Init() { | 74 |
| 75 void AppCacheInfoView::Init() { |
| 76 const int kInfoViewBorderSize = 1; |
| 77 const int kInfoViewInsetSize = 3; |
| 78 const int kLayoutId = 0; |
| 79 |
| 76 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); | 80 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); |
| 77 views::Border* border = views::Border::CreateSolidBorder( | 81 views::Border* border = views::Border::CreateSolidBorder( |
| 78 kLocalStorageInfoViewBorderSize, border_color); | 82 kInfoViewBorderSize, border_color); |
| 79 set_border(border); | 83 set_border(border); |
| 80 | 84 |
| 81 views::Label* origin_label = new views::Label( | 85 views::Label* manifest_url_label = new views::Label( |
| 82 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL)); | 86 l10n_util::GetString(IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL)); |
| 83 origin_value_field_ = new views::Textfield; | 87 manifest_url_field_ = new views::Textfield; |
| 84 views::Label* size_label = new views::Label( | 88 views::Label* size_label = new views::Label( |
| 85 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); | 89 l10n_util::GetString(IDS_COOKIES_SIZE_LABEL)); |
| 86 size_value_field_ = new views::Textfield; | 90 size_field_ = new views::Textfield; |
| 87 views::Label* last_modified_label = new views::Label( | 91 views::Label* creation_date_label = new views::Label( |
| 88 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); | 92 l10n_util::GetString(IDS_COOKIES_COOKIE_CREATED_LABEL)); |
| 89 last_modified_value_field_ = new views::Textfield; | 93 creation_date_field_ = new views::Textfield; |
| 94 views::Label* last_access_label = new views::Label( |
| 95 l10n_util::GetString(IDS_COOKIES_LAST_ACCESSED_LABEL)); |
| 96 last_access_field_ = new views::Textfield; |
| 90 | 97 |
| 91 using views::GridLayout; | 98 using views::GridLayout; |
| 92 | 99 |
| 93 GridLayout* layout = new GridLayout(this); | 100 GridLayout* layout = new GridLayout(this); |
| 94 layout->SetInsets(kLocalStorageInfoViewInsetSize, | 101 layout->SetInsets(kInfoViewInsetSize, kInfoViewInsetSize, |
| 95 kLocalStorageInfoViewInsetSize, | 102 kInfoViewInsetSize, kInfoViewInsetSize); |
| 96 kLocalStorageInfoViewInsetSize, | |
| 97 kLocalStorageInfoViewInsetSize); | |
| 98 SetLayoutManager(layout); | 103 SetLayoutManager(layout); |
| 99 | 104 |
| 100 int three_column_layout_id = 0; | 105 views::ColumnSet* column_set = layout->AddColumnSet(kLayoutId); |
| 101 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); | |
| 102 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 106 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 103 GridLayout::USE_PREF, 0, 0); | 107 GridLayout::USE_PREF, 0, 0); |
| 104 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 108 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 105 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 109 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 106 GridLayout::USE_PREF, 0, 0); | 110 GridLayout::USE_PREF, 0, 0); |
| 107 | 111 |
| 108 layout->StartRow(0, three_column_layout_id); | 112 AddRow(kLayoutId, layout, manifest_url_label, manifest_url_field_, true); |
| 109 layout->AddView(origin_label); | 113 AddRow(kLayoutId, layout, size_label, size_field_, true); |
| 110 layout->AddView(origin_value_field_); | 114 AddRow(kLayoutId, layout, creation_date_label, creation_date_field_, true); |
| 111 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 115 AddRow(kLayoutId, layout, last_access_label, last_access_field_, false); |
| 112 layout->StartRow(0, three_column_layout_id); | 116 } |
| 113 layout->AddView(size_label); | 117 |
| 114 layout->AddView(size_value_field_); | 118 void AppCacheInfoView::AddRow( |
| 115 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 119 int layout_id, views::GridLayout* layout, views::Label* label, |
| 116 layout->StartRow(0, three_column_layout_id); | 120 views::Textfield* field, bool add_padding_row) { |
| 117 layout->AddView(last_modified_label); | 121 // Add to the view hierarchy. |
| 118 layout->AddView(last_modified_value_field_); | 122 layout->StartRow(0, layout_id); |
| 123 layout->AddView(label); |
| 124 layout->AddView(field); |
| 119 | 125 |
| 120 // Color these borderless text areas the same as the containing dialog. | 126 // Color these borderless text areas the same as the containing dialog. |
| 121 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); | 127 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); |
| 122 // Now that the Textfields are in the view hierarchy, we can initialize them. | 128 |
| 123 origin_value_field_->SetReadOnly(true); | 129 // Init them now that they're in the view heirarchy. |
| 124 origin_value_field_->RemoveBorder(); | 130 field->SetReadOnly(true); |
| 125 origin_value_field_->SetBackgroundColor(text_area_background); | 131 field->RemoveBorder(); |
| 126 size_value_field_->SetReadOnly(true); | 132 field->SetBackgroundColor(text_area_background); |
| 127 size_value_field_->RemoveBorder(); | 133 |
| 128 size_value_field_->SetBackgroundColor(text_area_background); | 134 if (add_padding_row) |
| 129 last_modified_value_field_->SetReadOnly(true); | 135 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 130 last_modified_value_field_->RemoveBorder(); | |
| 131 last_modified_value_field_->SetBackgroundColor(text_area_background); | |
| 132 } | 136 } |
| 133 | |
| OLD | NEW |