Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/ui/views/about_chrome_view.cc

Issue 8221027: Make views::Label and views::Link auto-color themselves to be readable over their background colo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/about_chrome_view.h" 5 #include "chrome/browser/ui/views/about_chrome_view.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <commdlg.h> 8 #include <commdlg.h>
9 #endif // defined(OS_WIN) 9 #endif // defined(OS_WIN)
10 10
(...skipping 15 matching lines...) Expand all
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/installer/util/browser_distribution.h" 27 #include "chrome/installer/util/browser_distribution.h"
28 #include "content/browser/user_metrics.h" 28 #include "content/browser/user_metrics.h"
29 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "grit/locale_settings.h" 31 #include "grit/locale_settings.h"
32 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/gfx/canvas.h" 35 #include "ui/gfx/canvas.h"
36 #include "ui/gfx/color_utils.h"
36 #include "views/controls/button/text_button.h" 37 #include "views/controls/button/text_button.h"
37 #include "views/controls/link.h" 38 #include "views/controls/link.h"
38 #include "views/controls/textfield/textfield.h" 39 #include "views/controls/textfield/textfield.h"
39 #include "views/controls/throbber.h" 40 #include "views/controls/throbber.h"
40 #include "views/layout/layout_constants.h" 41 #include "views/layout/layout_constants.h"
41 #include "views/view_text_utils.h" 42 #include "views/view_text_utils.h"
42 #include "views/widget/widget.h" 43 #include "views/widget/widget.h"
43 #include "webkit/glue/webkit_glue.h" 44 #include "webkit/glue/webkit_glue.h"
44 45
45 #if defined(OS_WIN) 46 #if defined(OS_WIN)
46 #include "base/win/win_util.h" 47 #include "base/win/win_util.h"
47 #include "chrome/browser/browser_process.h" 48 #include "chrome/browser/browser_process.h"
48 #include "chrome/browser/ui/views/restart_message_box.h" 49 #include "chrome/browser/ui/views/restart_message_box.h"
49 #include "chrome/installer/util/install_util.h" 50 #include "chrome/installer/util/install_util.h"
50 #endif // defined(OS_WIN) 51 #endif // defined(OS_WIN)
51 52
52 namespace { 53 namespace {
53 // These are used as placeholder text around the links in the text in the about 54 // These are used as placeholder text around the links in the text in the about
54 // dialog. 55 // dialog.
55 const string16 kBeginLink(ASCIIToUTF16("BEGIN_LINK")); 56 const string16 kBeginLink(ASCIIToUTF16("BEGIN_LINK"));
56 const string16 kEndLink(ASCIIToUTF16("END_LINK")); 57 const string16 kEndLink(ASCIIToUTF16("END_LINK"));
57 const string16 kBeginLinkChr(ASCIIToUTF16("BEGIN_LINK_CHR")); 58 const string16 kBeginLinkChr(ASCIIToUTF16("BEGIN_LINK_CHR"));
58 const string16 kBeginLinkOss(ASCIIToUTF16("BEGIN_LINK_OSS")); 59 const string16 kBeginLinkOss(ASCIIToUTF16("BEGIN_LINK_OSS"));
59 const string16 kEndLinkChr(ASCIIToUTF16("END_LINK_CHR")); 60 const string16 kEndLinkChr(ASCIIToUTF16("END_LINK_CHR"));
60 const string16 kEndLinkOss(ASCIIToUTF16("END_LINK_OSS")); 61 const string16 kEndLinkOss(ASCIIToUTF16("END_LINK_OSS"));
61 62
62 // The background bitmap used to draw the background color for the About box
63 // and the separator line (this is the image we will draw the logo on top of).
64 static const SkBitmap* kBackgroundBmp = NULL;
65
66 // Returns a substring from |text| between start and end. 63 // Returns a substring from |text| between start and end.
67 string16 StringSubRange(const string16& text, size_t start, size_t end) { 64 string16 StringSubRange(const string16& text, size_t start, size_t end) {
68 DCHECK(end > start); 65 DCHECK(end > start);
69 return text.substr(start, end - start); 66 return text.substr(start, end - start);
70 } 67 }
71 68
72 } // namespace 69 } // namespace
73 70
74 namespace browser { 71 namespace browser {
75 72
(...skipping 26 matching lines...) Expand all
102 chromium_url_appears_first_(true), 99 chromium_url_appears_first_(true),
103 text_direction_is_rtl_(false) { 100 text_direction_is_rtl_(false) {
104 DCHECK(profile); 101 DCHECK(profile);
105 102
106 Init(); 103 Init();
107 104
108 #if defined(OS_WIN) && !defined(USE_AURA) 105 #if defined(OS_WIN) && !defined(USE_AURA)
109 google_updater_ = new GoogleUpdate(); 106 google_updater_ = new GoogleUpdate();
110 google_updater_->set_status_listener(this); 107 google_updater_->set_status_listener(this);
111 #endif 108 #endif
112
113 if (kBackgroundBmp == NULL) {
114 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
115 kBackgroundBmp = rb.GetBitmapNamed(IDR_ABOUT_BACKGROUND_COLOR);
116 }
117 } 109 }
118 110
119 AboutChromeView::~AboutChromeView() { 111 AboutChromeView::~AboutChromeView() {
120 #if defined(OS_WIN) && !defined(USE_AURA) 112 #if defined(OS_WIN) && !defined(USE_AURA)
121 // The Google Updater will hold a pointer to us until it reports status, so we 113 // The Google Updater will hold a pointer to us until it reports status, so we
122 // need to let it know that we will no longer be listening. 114 // need to let it know that we will no longer be listening.
123 if (google_updater_) 115 if (google_updater_)
124 google_updater_->set_status_listener(NULL); 116 google_updater_->set_status_listener(NULL);
125 #endif 117 #endif
126 } 118 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 IDR_ABOUT_BACKGROUND_RTL : IDR_ABOUT_BACKGROUND); 151 IDR_ABOUT_BACKGROUND_RTL : IDR_ABOUT_BACKGROUND);
160 152
161 about_dlg_background_logo_->SetImage(*about_background_logo); 153 about_dlg_background_logo_->SetImage(*about_background_logo);
162 AddChildView(about_dlg_background_logo_); 154 AddChildView(about_dlg_background_logo_);
163 155
164 // Add the dialog labels. 156 // Add the dialog labels.
165 about_title_label_ = new views::Label( 157 about_title_label_ = new views::Label(
166 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 158 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
167 about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( 159 about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont(
168 ResourceBundle::BaseFont).DeriveFont(18)); 160 ResourceBundle::BaseFont).DeriveFont(18));
169 about_title_label_->SetColor(SK_ColorBLACK); 161 about_title_label_->SetBackgroundColor(SK_ColorWHITE);
162 about_title_label_->SetEnabledColor(SK_ColorBLACK);
170 AddChildView(about_title_label_); 163 AddChildView(about_title_label_);
171 164
172 // This is a text field so people can copy the version number from the dialog. 165 // This is a text field so people can copy the version number from the dialog.
173 version_label_ = new views::Textfield(); 166 version_label_ = new views::Textfield();
174 chrome::VersionInfo version_info; 167 chrome::VersionInfo version_info;
175 version_label_->SetText(UTF8ToUTF16(version_info.CreateVersionString())); 168 version_label_->SetText(UTF8ToUTF16(version_info.CreateVersionString()));
176 version_label_->SetReadOnly(true); 169 version_label_->SetReadOnly(true);
177 version_label_->RemoveBorder(); 170 version_label_->RemoveBorder();
178 version_label_->SetTextColor(SK_ColorBLACK); 171 version_label_->SetTextColor(SK_ColorBLACK);
179 version_label_->SetBackgroundColor(SK_ColorWHITE); 172 version_label_->SetBackgroundColor(SK_ColorWHITE);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 AddChildView(chromium_url_); 209 AddChildView(chromium_url_);
217 chromium_url_->set_listener(this); 210 chromium_url_->set_listener(this);
218 211
219 // The Open Source link within the main text of the dialog. 212 // The Open Source link within the main text of the dialog.
220 open_source_url_ = new views::Link( 213 open_source_url_ = new views::Link(
221 StringSubRange(text, text.find(kBeginLinkOss) + kBeginLinkOss.size(), 214 StringSubRange(text, text.find(kBeginLinkOss) + kBeginLinkOss.size(),
222 text.find(kEndLinkOss))); 215 text.find(kEndLinkOss)));
223 AddChildView(open_source_url_); 216 AddChildView(open_source_url_);
224 open_source_url_->set_listener(this); 217 open_source_url_->set_listener(this);
225 218
219 #if defined(OS_WIN)
220 SkColor background_color = color_utils::GetSysSkColor(COLOR_3DFACE);
221 copyright_label_->SetBackgroundColor(background_color);
222 main_text_label_->SetBackgroundColor(background_color);
223 chromium_url_->SetBackgroundColor(background_color);
224 open_source_url_->SetBackgroundColor(background_color);
225 #endif
226
226 // Add together all the strings in the dialog for the purpose of calculating 227 // Add together all the strings in the dialog for the purpose of calculating
227 // the height of the dialog. The space for the Terms of Service string is not 228 // the height of the dialog. The space for the Terms of Service string is not
228 // included (it is added later, if needed). 229 // included (it is added later, if needed).
229 string16 full_text = main_label_chunk1_ + chromium_url_->GetText() + 230 string16 full_text = main_label_chunk1_ + chromium_url_->GetText() +
230 main_label_chunk2_ + open_source_url_->GetText() + 231 main_label_chunk2_ + open_source_url_->GetText() +
231 main_label_chunk3_; 232 main_label_chunk3_;
232 233
233 dialog_dimensions_ = views::Widget::GetLocalizedContentsSize( 234 dialog_dimensions_ = views::Widget::GetLocalizedContentsSize(
234 IDS_ABOUT_DIALOG_WIDTH_CHARS, 235 IDS_ABOUT_DIALOG_WIDTH_CHARS,
235 IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES); 236 IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 std::min(max_x - update_label_x, sz.width()), 375 std::min(max_x - update_label_x, sz.width()),
375 sz.height()); 376 sz.height());
376 } 377 }
377 378
378 void AboutChromeView::OnPaint(gfx::Canvas* canvas) { 379 void AboutChromeView::OnPaint(gfx::Canvas* canvas) {
379 views::View::OnPaint(canvas); 380 views::View::OnPaint(canvas);
380 381
381 // Draw the background image color (and the separator) across the dialog. 382 // Draw the background image color (and the separator) across the dialog.
382 // This will become the background for the logo image at the top of the 383 // This will become the background for the logo image at the top of the
383 // dialog. 384 // dialog.
384 canvas->TileImageInt(*kBackgroundBmp, 0, 0, 385 SkBitmap* background = ResourceBundle::GetSharedInstance().GetBitmapNamed(
385 dialog_dimensions_.width(), kBackgroundBmp->height()); 386 IDR_ABOUT_BACKGROUND_COLOR);
387 canvas->TileImageInt(*background, 0, 0, dialog_dimensions_.width(),
388 background->height());
386 389
387 gfx::Font font = 390 gfx::Font font =
388 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); 391 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
389 392
390 const gfx::Rect label_bounds = main_text_label_->bounds(); 393 const gfx::Rect label_bounds = main_text_label_->bounds();
391 394
392 views::Link* link1 = 395 views::Link* link1 =
393 chromium_url_appears_first_ ? chromium_url_ : open_source_url_; 396 chromium_url_appears_first_ ? chromium_url_ : open_source_url_;
394 views::Link* link2 = 397 views::Link* link2 =
395 chromium_url_appears_first_ ? open_source_url_ : chromium_url_; 398 chromium_url_appears_first_ ? open_source_url_ : chromium_url_;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // We have updated controls on the parent, so we need to update its layout. 726 // We have updated controls on the parent, so we need to update its layout.
724 parent()->Layout(); 727 parent()->Layout();
725 728
726 // Check button may have appeared/disappeared. We cannot call this during 729 // Check button may have appeared/disappeared. We cannot call this during
727 // ViewHierarchyChanged because the view hasn't been added to a Widget yet. 730 // ViewHierarchyChanged because the view hasn't been added to a Widget yet.
728 if (GetWidget()) 731 if (GetWidget())
729 GetDialogClientView()->UpdateDialogButtons(); 732 GetDialogClientView()->UpdateDialogButtons();
730 } 733 }
731 734
732 #endif 735 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698