| 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/indexed_db_info_view.h" | 5 #include "chrome/browser/views/indexed_db_info_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "gfx/color_utils.h" | 12 #include "gfx/color_utils.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 kIndexedDBInfoViewBorderSize = 1; | 19 static const int kIndexedDBInfoViewBorderSize = 1; |
| 20 static const int kIndexedDBInfoViewInsetSize = 3; | 20 static const int kIndexedDBInfoViewInsetSize = 3; |
| 21 | 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 // IndexedDBInfoView, public: | 23 // IndexedDBInfoView, public: |
| 24 | 24 |
| 25 IndexedDBInfoView::IndexedDBInfoView() | 25 IndexedDBInfoView::IndexedDBInfoView() |
| 26 : name_value_field_(NULL), | 26 : origin_value_field_(NULL), |
| 27 origin_value_field_(NULL), | |
| 28 size_value_field_(NULL), | 27 size_value_field_(NULL), |
| 29 last_modified_value_field_(NULL) { | 28 last_modified_value_field_(NULL) { |
| 30 } | 29 } |
| 31 | 30 |
| 32 IndexedDBInfoView::~IndexedDBInfoView() { | 31 IndexedDBInfoView::~IndexedDBInfoView() { |
| 33 } | 32 } |
| 34 | 33 |
| 35 void IndexedDBInfoView::SetIndexedDBInfo( | 34 void IndexedDBInfoView::SetIndexedDBInfo( |
| 36 const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info) { | 35 const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info) { |
| 37 name_value_field_->SetText( | |
| 38 indexed_db_info.database_name.empty() ? | |
| 39 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) : | |
| 40 UTF8ToWide(indexed_db_info.database_name)); | |
| 41 origin_value_field_->SetText(UTF8ToWide(indexed_db_info.origin)); | 36 origin_value_field_->SetText(UTF8ToWide(indexed_db_info.origin)); |
| 42 size_value_field_->SetText( | 37 size_value_field_->SetText( |
| 43 FormatBytes(indexed_db_info.size, | 38 FormatBytes(indexed_db_info.size, |
| 44 GetByteDisplayUnits(indexed_db_info.size), | 39 GetByteDisplayUnits(indexed_db_info.size), |
| 45 true)); | 40 true)); |
| 46 last_modified_value_field_->SetText( | 41 last_modified_value_field_->SetText( |
| 47 base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified)); | 42 base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified)); |
| 48 EnableIndexedDBDisplay(true); | 43 EnableIndexedDBDisplay(true); |
| 49 } | 44 } |
| 50 | 45 |
| 51 void IndexedDBInfoView::EnableIndexedDBDisplay(bool enabled) { | 46 void IndexedDBInfoView::EnableIndexedDBDisplay(bool enabled) { |
| 52 name_value_field_->SetEnabled(enabled); | |
| 53 origin_value_field_->SetEnabled(enabled); | 47 origin_value_field_->SetEnabled(enabled); |
| 54 size_value_field_->SetEnabled(enabled); | 48 size_value_field_->SetEnabled(enabled); |
| 55 last_modified_value_field_->SetEnabled(enabled); | 49 last_modified_value_field_->SetEnabled(enabled); |
| 56 } | 50 } |
| 57 | 51 |
| 58 void IndexedDBInfoView::ClearIndexedDBDisplay() { | 52 void IndexedDBInfoView::ClearIndexedDBDisplay() { |
| 59 std::wstring no_cookie_string = | 53 std::wstring no_cookie_string = |
| 60 l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); | 54 l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); |
| 61 name_value_field_->SetText(no_cookie_string); | |
| 62 origin_value_field_->SetText(no_cookie_string); | 55 origin_value_field_->SetText(no_cookie_string); |
| 63 size_value_field_->SetText(no_cookie_string); | 56 size_value_field_->SetText(no_cookie_string); |
| 64 last_modified_value_field_->SetText(no_cookie_string); | 57 last_modified_value_field_->SetText(no_cookie_string); |
| 65 EnableIndexedDBDisplay(false); | 58 EnableIndexedDBDisplay(false); |
| 66 } | 59 } |
| 67 | 60 |
| 68 /////////////////////////////////////////////////////////////////////////////// | 61 /////////////////////////////////////////////////////////////////////////////// |
| 69 // IndexedDBInfoView, views::View overrides: | 62 // IndexedDBInfoView, views::View overrides: |
| 70 | 63 |
| 71 void IndexedDBInfoView::ViewHierarchyChanged(bool is_add, | 64 void IndexedDBInfoView::ViewHierarchyChanged(bool is_add, |
| 72 views::View* parent, | 65 views::View* parent, |
| 73 views::View* child) { | 66 views::View* child) { |
| 74 if (is_add && child == this) | 67 if (is_add && child == this) |
| 75 Init(); | 68 Init(); |
| 76 } | 69 } |
| 77 | 70 |
| 78 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
| 79 // IndexedDBInfoView, private: | 72 // IndexedDBInfoView, private: |
| 80 | 73 |
| 81 void IndexedDBInfoView::Init() { | 74 void IndexedDBInfoView::Init() { |
| 82 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); | 75 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); |
| 83 views::Border* border = views::Border::CreateSolidBorder( | 76 views::Border* border = views::Border::CreateSolidBorder( |
| 84 kIndexedDBInfoViewBorderSize, border_color); | 77 kIndexedDBInfoViewBorderSize, border_color); |
| 85 set_border(border); | 78 set_border(border); |
| 86 | 79 |
| 87 views::Label* name_label = new views::Label( | |
| 88 l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); | |
| 89 name_value_field_ = new views::Textfield; | |
| 90 views::Label* origin_label = new views::Label( | 80 views::Label* origin_label = new views::Label( |
| 91 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL)); | 81 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL)); |
| 92 origin_value_field_ = new views::Textfield; | 82 origin_value_field_ = new views::Textfield; |
| 93 views::Label* size_label = new views::Label( | 83 views::Label* size_label = new views::Label( |
| 94 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); | 84 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); |
| 95 size_value_field_ = new views::Textfield; | 85 size_value_field_ = new views::Textfield; |
| 96 views::Label* last_modified_label = new views::Label( | 86 views::Label* last_modified_label = new views::Label( |
| 97 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); | 87 l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL)); |
| 98 last_modified_value_field_ = new views::Textfield; | 88 last_modified_value_field_ = new views::Textfield; |
| 99 | 89 |
| 100 using views::GridLayout; | 90 using views::GridLayout; |
| 101 | 91 |
| 102 GridLayout* layout = new GridLayout(this); | 92 GridLayout* layout = new GridLayout(this); |
| 103 layout->SetInsets(kIndexedDBInfoViewInsetSize, | 93 layout->SetInsets(kIndexedDBInfoViewInsetSize, |
| 104 kIndexedDBInfoViewInsetSize, | 94 kIndexedDBInfoViewInsetSize, |
| 105 kIndexedDBInfoViewInsetSize, | 95 kIndexedDBInfoViewInsetSize, |
| 106 kIndexedDBInfoViewInsetSize); | 96 kIndexedDBInfoViewInsetSize); |
| 107 SetLayoutManager(layout); | 97 SetLayoutManager(layout); |
| 108 | 98 |
| 109 int three_column_layout_id = 0; | 99 int three_column_layout_id = 0; |
| 110 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); | 100 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); |
| 111 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 101 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 112 GridLayout::USE_PREF, 0, 0); | 102 GridLayout::USE_PREF, 0, 0); |
| 113 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 103 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 114 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 104 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 115 GridLayout::USE_PREF, 0, 0); | 105 GridLayout::USE_PREF, 0, 0); |
| 116 | 106 |
| 117 layout->StartRow(0, three_column_layout_id); | 107 layout->StartRow(0, three_column_layout_id); |
| 118 layout->AddView(name_label); | |
| 119 layout->AddView(name_value_field_); | |
| 120 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | |
| 121 layout->StartRow(0, three_column_layout_id); | |
| 122 layout->AddView(origin_label); | 108 layout->AddView(origin_label); |
| 123 layout->AddView(origin_value_field_); | 109 layout->AddView(origin_value_field_); |
| 124 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 110 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 125 layout->StartRow(0, three_column_layout_id); | 111 layout->StartRow(0, three_column_layout_id); |
| 126 layout->AddView(size_label); | 112 layout->AddView(size_label); |
| 127 layout->AddView(size_value_field_); | 113 layout->AddView(size_value_field_); |
| 128 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 114 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 129 layout->StartRow(0, three_column_layout_id); | 115 layout->StartRow(0, three_column_layout_id); |
| 130 layout->AddView(last_modified_label); | 116 layout->AddView(last_modified_label); |
| 131 layout->AddView(last_modified_value_field_); | 117 layout->AddView(last_modified_value_field_); |
| 132 | 118 |
| 133 // Color these borderless text areas the same as the containing dialog. | 119 // Color these borderless text areas the same as the containing dialog. |
| 134 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); | 120 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); |
| 135 // Now that the Textfields are in the view hierarchy, we can initialize them. | 121 // Now that the Textfields are in the view hierarchy, we can initialize them. |
| 136 name_value_field_->SetReadOnly(true); | |
| 137 name_value_field_->RemoveBorder(); | |
| 138 name_value_field_->SetBackgroundColor(text_area_background); | |
| 139 origin_value_field_->SetReadOnly(true); | 122 origin_value_field_->SetReadOnly(true); |
| 140 origin_value_field_->RemoveBorder(); | 123 origin_value_field_->RemoveBorder(); |
| 141 origin_value_field_->SetBackgroundColor(text_area_background); | 124 origin_value_field_->SetBackgroundColor(text_area_background); |
| 142 size_value_field_->SetReadOnly(true); | 125 size_value_field_->SetReadOnly(true); |
| 143 size_value_field_->RemoveBorder(); | 126 size_value_field_->RemoveBorder(); |
| 144 size_value_field_->SetBackgroundColor(text_area_background); | 127 size_value_field_->SetBackgroundColor(text_area_background); |
| 145 last_modified_value_field_->SetReadOnly(true); | 128 last_modified_value_field_->SetReadOnly(true); |
| 146 last_modified_value_field_->RemoveBorder(); | 129 last_modified_value_field_->RemoveBorder(); |
| 147 last_modified_value_field_->SetBackgroundColor(text_area_background); | 130 last_modified_value_field_->SetBackgroundColor(text_area_background); |
| 148 } | 131 } |
| OLD | NEW |