OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/views/cookie_info_view.h" | 5 #include "chrome/browser/ui/views/cookie_info_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 14 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
17 #include "net/cookies/canonical_cookie.h" | 17 #include "net/cookies/canonical_cookie.h" |
18 #include "net/cookies/parsed_cookie.h" | 18 #include "net/cookies/parsed_cookie.h" |
19 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/color_utils.h" | |
23 #include "ui/native_theme/native_theme.h" | 22 #include "ui/native_theme/native_theme.h" |
24 #include "ui/views/border.h" | |
25 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 24 #include "ui/views/controls/textfield/textfield.h" |
27 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
28 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
29 #include "ui/views/window/dialog_delegate.h" | 27 #include "ui/views/window/dialog_delegate.h" |
30 | 28 |
31 namespace { | 29 namespace { |
32 | 30 |
33 const int kCookieInfoViewBorderSize = 1; | |
34 const int kCookieInfoViewInsetSize = 3; | |
35 | |
36 // Adjustment to the spacing between subsequent label-field lines. | 31 // Adjustment to the spacing between subsequent label-field lines. |
37 const int kExtraLineHeightPadding = 3; | 32 const int kExtraLineHeightPadding = 3; |
38 | 33 |
39 } // namespace | 34 } // namespace |
40 | 35 |
41 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
42 // CookieInfoView, public: | 37 // CookieInfoView, public: |
43 | 38 |
44 CookieInfoView::CookieInfoView() | 39 CookieInfoView::CookieInfoView() |
45 : name_label_(NULL), | 40 : name_label_(NULL), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 Init(); | 117 Init(); |
123 } | 118 } |
124 | 119 |
125 void CookieInfoView::AddLabelRow(int layout_id, views::GridLayout* layout, | 120 void CookieInfoView::AddLabelRow(int layout_id, views::GridLayout* layout, |
126 views::Label* label, | 121 views::Label* label, |
127 views::Textfield* text_field) { | 122 views::Textfield* text_field) { |
128 layout->StartRow(0, layout_id); | 123 layout->StartRow(0, layout_id); |
129 layout->AddView(label); | 124 layout->AddView(label); |
130 layout->AddView(text_field, 2, 1, views::GridLayout::FILL, | 125 layout->AddView(text_field, 2, 1, views::GridLayout::FILL, |
131 views::GridLayout::CENTER); | 126 views::GridLayout::CENTER); |
132 layout->AddPaddingRow(0, views::DialogDelegate::UseNewStyle() ? | 127 layout->AddPaddingRow(0, kExtraLineHeightPadding); |
133 kExtraLineHeightPadding : | |
134 views::kRelatedControlSmallVerticalSpacing); | |
135 | |
136 | 128 |
137 // Now that the Textfield is in the view hierarchy, it can be initialized. | 129 // Now that the Textfield is in the view hierarchy, it can be initialized. |
138 text_field->SetReadOnly(true); | 130 text_field->SetReadOnly(true); |
139 text_field->RemoveBorder(); | 131 text_field->RemoveBorder(); |
140 // Color these borderless text areas the same as the containing dialog. | 132 // Color these borderless text areas the same as the containing dialog. |
141 text_field->SetBackgroundColor(GetNativeTheme()->GetSystemColor( | 133 text_field->SetBackgroundColor(GetNativeTheme()->GetSystemColor( |
142 ui::NativeTheme::kColorId_DialogBackground)); | 134 ui::NativeTheme::kColorId_DialogBackground)); |
143 text_field->SetTextColor(SkColorSetRGB(0x78, 0x78, 0x78)); | 135 text_field->SetTextColor(SkColorSetRGB(0x78, 0x78, 0x78)); |
144 } | 136 } |
145 | 137 |
146 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
147 // CookieInfoView, private: | 139 // CookieInfoView, private: |
148 | 140 |
149 void CookieInfoView::Init() { | 141 void CookieInfoView::Init() { |
150 // Ensure we don't run this more than once and leak memory. | 142 // Ensure we don't run this more than once and leak memory. |
151 DCHECK(!name_label_); | 143 DCHECK(!name_label_); |
152 | |
153 #if defined(USE_AURA) || !defined(OS_WIN) | |
154 SkColor border_color = SK_ColorGRAY; | |
155 #else | |
156 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); | |
157 #endif | |
158 | |
159 name_label_ = new views::Label( | 144 name_label_ = new views::Label( |
160 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_NAME_LABEL)); | 145 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_NAME_LABEL)); |
161 name_value_field_ = new views::Textfield; | 146 name_value_field_ = new views::Textfield; |
162 content_label_ = new views::Label( | 147 content_label_ = new views::Label( |
163 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_CONTENT_LABEL)); | 148 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_CONTENT_LABEL)); |
164 content_value_field_ = new views::Textfield; | 149 content_value_field_ = new views::Textfield; |
165 domain_label_ = new views::Label( | 150 domain_label_ = new views::Label( |
166 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); | 151 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); |
167 domain_value_field_ = new views::Textfield; | 152 domain_value_field_ = new views::Textfield; |
168 path_label_ = new views::Label( | 153 path_label_ = new views::Label( |
169 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_PATH_LABEL)); | 154 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_PATH_LABEL)); |
170 path_value_field_ = new views::Textfield; | 155 path_value_field_ = new views::Textfield; |
171 send_for_label_ = new views::Label( | 156 send_for_label_ = new views::Label( |
172 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); | 157 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); |
173 send_for_value_field_ = new views::Textfield; | 158 send_for_value_field_ = new views::Textfield; |
174 created_label_ = new views::Label( | 159 created_label_ = new views::Label( |
175 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_CREATED_LABEL)); | 160 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_CREATED_LABEL)); |
176 created_value_field_ = new views::Textfield; | 161 created_value_field_ = new views::Textfield; |
177 expires_label_ = new views::Label( | 162 expires_label_ = new views::Label( |
178 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); | 163 l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); |
179 expires_value_field_ = new views::Textfield; | 164 expires_value_field_ = new views::Textfield; |
180 | 165 |
181 using views::GridLayout; | 166 views::GridLayout* layout = new views::GridLayout(this); |
182 using views::ColumnSet; | 167 layout->SetInsets(0, views::kButtonHEdgeMarginNew, |
183 | 168 0, views::kButtonHEdgeMarginNew); |
184 GridLayout* layout = new GridLayout(this); | |
185 if (views::DialogDelegate::UseNewStyle()) { | |
186 layout->SetInsets( | |
187 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew); | |
188 } else { | |
189 set_border(views::Border::CreateSolidBorder(kCookieInfoViewBorderSize, | |
190 border_color)); | |
191 layout->SetInsets(kCookieInfoViewInsetSize, | |
192 kCookieInfoViewInsetSize, | |
193 kCookieInfoViewInsetSize, | |
194 kCookieInfoViewInsetSize); | |
195 } | |
196 SetLayoutManager(layout); | 169 SetLayoutManager(layout); |
197 | 170 |
198 int three_column_layout_id = 0; | 171 int three_column_layout_id = 0; |
199 ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); | 172 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id); |
200 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 173 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
201 GridLayout::USE_PREF, 0, 0); | 174 0, views::GridLayout::USE_PREF, 0, 0); |
202 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 175 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
203 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 176 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
204 GridLayout::USE_PREF, 0, 0); | 177 0, views::GridLayout::USE_PREF, 0, 0); |
205 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 178 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
206 GridLayout::USE_PREF, 0, 0); | 179 1, views::GridLayout::USE_PREF, 0, 0); |
207 | 180 |
208 AddLabelRow(three_column_layout_id, layout, name_label_, name_value_field_); | 181 AddLabelRow(three_column_layout_id, layout, name_label_, name_value_field_); |
209 AddLabelRow(three_column_layout_id, layout, content_label_, | 182 AddLabelRow(three_column_layout_id, layout, content_label_, |
210 content_value_field_); | 183 content_value_field_); |
211 AddLabelRow(three_column_layout_id, layout, domain_label_, | 184 AddLabelRow(three_column_layout_id, layout, domain_label_, |
212 domain_value_field_); | 185 domain_value_field_); |
213 AddLabelRow(three_column_layout_id, layout, path_label_, path_value_field_); | 186 AddLabelRow(three_column_layout_id, layout, path_label_, path_value_field_); |
214 AddLabelRow(three_column_layout_id, layout, send_for_label_, | 187 AddLabelRow(three_column_layout_id, layout, send_for_label_, |
215 send_for_value_field_); | 188 send_for_value_field_); |
216 AddLabelRow(three_column_layout_id, layout, created_label_, | 189 AddLabelRow(three_column_layout_id, layout, created_label_, |
217 created_value_field_); | 190 created_value_field_); |
218 AddLabelRow(three_column_layout_id, layout, expires_label_, | 191 AddLabelRow(three_column_layout_id, layout, expires_label_, |
219 expires_value_field_); | 192 expires_value_field_); |
220 } | 193 } |
OLD | NEW |