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/local_storage_set_item_info_view.h" 6 7 #include <algorithm> 8 9 #include "base/utf_string_conversions.h" 10 #include "grit/generated_resources.h" 11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/gfx/color_utils.h" 13 #include "views/controls/label.h" 14 #include "views/controls/textfield/textfield.h" 15 #include "views/layout/grid_layout.h" 16 #include "views/layout/layout_constants.h" 17 18 static const int kLocalStorageSetItemInfoViewBorderSize = 1; 19 static const int kLocalStorageSetItemInfoViewInsetSize = 3; 20 21 /////////////////////////////////////////////////////////////////////////////// 22 // LocalStorageSetItemInfoView, public: 23 24 LocalStorageSetItemInfoView::LocalStorageSetItemInfoView() 25 : host_value_field_(NULL), 26 key_value_field_(NULL), 27 value_value_field_(NULL) { 28 } 29 30 LocalStorageSetItemInfoView::~LocalStorageSetItemInfoView() { 31 } 32 33 void LocalStorageSetItemInfoView::SetFields(const std::string& host, 34 const string16& key, 35 const string16& value) { 36 host_value_field_->SetText(UTF8ToWide(host)); 37 key_value_field_->SetText(key); 38 value_value_field_->SetText(value); 39 EnableLocalStorageDisplay(true); 40 } 41 42 void LocalStorageSetItemInfoView::EnableLocalStorageDisplay(bool enabled) { 43 host_value_field_->SetEnabled(enabled); 44 key_value_field_->SetEnabled(enabled); 45 value_value_field_->SetEnabled(enabled); 46 } 47 48 void LocalStorageSetItemInfoView::ClearLocalStorageDisplay() { 49 std::wstring no_cookie_string = 50 UTF16ToWide(l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_NONESELECTED)); 51 host_value_field_->SetText(no_cookie_string); 52 key_value_field_->SetText(no_cookie_string); 53 value_value_field_->SetText(no_cookie_string); 54 EnableLocalStorageDisplay(false); 55 } 56 57 /////////////////////////////////////////////////////////////////////////////// 58 // LocalStorageSetItemInfoView, views::View overrides: 59 60 void LocalStorageSetItemInfoView::ViewHierarchyChanged( 61 bool is_add, views::View* parent, views::View* child) { 62 if (is_add && child == this) 63 Init(); 64 } 65 66 /////////////////////////////////////////////////////////////////////////////// 67 // LocalStorageSetItemInfoView, private: 68 69 void LocalStorageSetItemInfoView::Init() { 70 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); 71 views::Border* border = views::Border::CreateSolidBorder( 72 kLocalStorageSetItemInfoViewBorderSize, border_color); 73 set_border(border); 74 75 // TODO(jorlow): These strings are not quite right, but we're post-freeze. 76 // http://crbug.com/68688 77 views::Label* host_label = new views::Label(UTF16ToWide( 78 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_DOMAIN_LABEL))); 79 host_value_field_ = new views::Textfield; 80 views::Label* key_label = new views::Label(UTF16ToWide( 81 l10n_util::GetStringUTF16(IDS_COOKIES_LOCAL_STORAGE_KEY_LABEL))); 82 key_value_field_ = new views::Textfield; 83 views::Label* value_label = new views::Label(UTF16ToWide( 84 l10n_util::GetStringUTF16(IDS_COOKIES_LOCAL_STORAGE_VALUE_LABEL))); 85 value_value_field_ = new views::Textfield; 86 87 using views::GridLayout; 88 89 GridLayout* layout = new GridLayout(this); 90 layout->SetInsets(kLocalStorageSetItemInfoViewInsetSize, 91 kLocalStorageSetItemInfoViewInsetSize, 92 kLocalStorageSetItemInfoViewInsetSize, 93 kLocalStorageSetItemInfoViewInsetSize); 94 SetLayoutManager(layout); 95 96 int three_column_layout_id = 0; 97 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); 98 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, 99 GridLayout::USE_PREF, 0, 0); 100 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 101 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 102 GridLayout::USE_PREF, 0, 0); 103 104 layout->StartRow(0, three_column_layout_id); 105 layout->AddView(host_label); 106 layout->AddView(host_value_field_); 107 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 108 layout->StartRow(0, three_column_layout_id); 109 layout->AddView(key_label); 110 layout->AddView(key_value_field_); 111 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 112 layout->StartRow(0, three_column_layout_id); 113 layout->AddView(value_label); 114 layout->AddView(value_value_field_); 115 116 // Color these borderless text areas the same as the containing dialog. 117 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); 118 // Now that the Textfields are in the view hierarchy, we can initialize them. 119 host_value_field_->SetReadOnly(true); 120 host_value_field_->RemoveBorder(); 121 host_value_field_->SetBackgroundColor(text_area_background); 122 key_value_field_->SetReadOnly(true); 123 key_value_field_->RemoveBorder(); 124 key_value_field_->SetBackgroundColor(text_area_background); 125 value_value_field_->SetReadOnly(true); 126 value_value_field_->RemoveBorder(); 127 value_value_field_->SetBackgroundColor(text_area_background); 128 } 129