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