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