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

Side by Side Diff: chrome/browser/views/infobars/infobars.cc

Issue 3127009: Convert infobar APIs to UTF-16. (Closed)
Patch Set: works Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/infobars/infobars.h" 5 #include "chrome/browser/views/infobars/infobars.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/slide_animation.h" 9 #include "app/slide_animation.h"
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "app/win_util.h" 11 #include "app/win_util.h"
12 #endif // defined(OS_WIN) 12 #endif // defined(OS_WIN)
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/views/event_utils.h" 15 #include "chrome/browser/views/event_utils.h"
15 #include "chrome/browser/views/infobars/infobar_container.h" 16 #include "chrome/browser/views/infobars/infobar_container.h"
16 #include "gfx/canvas.h" 17 #include "gfx/canvas.h"
17 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
19 #include "views/background.h" 20 #include "views/background.h"
20 #include "views/controls/button/image_button.h" 21 #include "views/controls/button/image_button.h"
21 #include "views/controls/button/native_button.h" 22 #include "views/controls/button/native_button.h"
22 #include "views/controls/image_view.h" 23 #include "views/controls/image_view.h"
23 #include "views/controls/label.h" 24 #include "views/controls/label.h"
24 #include "views/focus/external_focus_tracker.h" 25 #include "views/focus/external_focus_tracker.h"
25 #include "views/widget/widget.h" 26 #include "views/widget/widget.h"
26 27
27 // static 28 // static
28 const double InfoBar::kDefaultTargetHeight = 36.0; 29 const double InfoBar::kDefaultTargetHeight = 36.0;
29 const int InfoBar::kHorizontalPadding = 6; 30 const int InfoBar::kHorizontalPadding = 6;
30 const int InfoBar::kIconLabelSpacing = 6; 31 const int InfoBar::kIconLabelSpacing = 6;
31 const int InfoBar::kButtonButtonSpacing = 10; 32 const int InfoBar::kButtonButtonSpacing = 10;
32 const int InfoBar::kEndOfLabelSpacing = 16; 33 const int InfoBar::kEndOfLabelSpacing = 16;
33 const int InfoBar::kCloseButtonSpacing = 12; 34 const int InfoBar::kCloseButtonSpacing = 12;
34 const int InfoBar::kButtonInLabelSpacing = 5; 35 const int InfoBar::kButtonInLabelSpacing = 5;
35 36
36 static const SkColor kInfoBackgroundColorTop = SkColorSetRGB(170, 214, 112);
37 static const SkColor kInfoBackgroundColorBottom = SkColorSetRGB(146, 205, 114);
38
39 static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183); 37 static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183);
40 static const SkColor kWarningBackgroundColorBottom = 38 static const SkColor kWarningBackgroundColorBottom =
41 SkColorSetRGB(250, 230, 145); 39 SkColorSetRGB(250, 230, 145);
42 40
43 static const SkColor kErrorBackgroundColorTop = kWarningBackgroundColorTop; 41 static const SkColor kErrorBackgroundColorTop = kWarningBackgroundColorTop;
44 static const SkColor kErrorBackgroundColorBottom = 42 static const SkColor kErrorBackgroundColorBottom =
45 kWarningBackgroundColorBottom; 43 kWarningBackgroundColorBottom;
46 44
47 static const SkColor kPageActionBackgroundColorTop = 45 static const SkColor kPageActionBackgroundColorTop =
48 SkColorSetRGB(218, 231, 249); 46 SkColorSetRGB(218, 231, 249);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 286
289 void InfoBar::DeleteSelf() { 287 void InfoBar::DeleteSelf() {
290 delete this; 288 delete this;
291 } 289 }
292 290
293 // AlertInfoBar, public: ------------------------------------------------------- 291 // AlertInfoBar, public: -------------------------------------------------------
294 292
295 AlertInfoBar::AlertInfoBar(AlertInfoBarDelegate* delegate) 293 AlertInfoBar::AlertInfoBar(AlertInfoBarDelegate* delegate)
296 : InfoBar(delegate) { 294 : InfoBar(delegate) {
297 label_ = new views::Label( 295 label_ = new views::Label(
298 delegate->GetMessageText(), 296 UTF16ToWideHack(delegate->GetMessageText()),
299 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); 297 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
300 label_->SetColor(SK_ColorBLACK); 298 label_->SetColor(SK_ColorBLACK);
301 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 299 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
302 AddChildView(label_); 300 AddChildView(label_);
303 301
304 icon_ = new views::ImageView; 302 icon_ = new views::ImageView;
305 if (delegate->GetIcon()) 303 if (delegate->GetIcon())
306 icon_->SetImage(delegate->GetIcon()); 304 icon_->SetImage(delegate->GetIcon());
307 AddChildView(icon_); 305 AddChildView(icon_);
308 } 306 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 label_1_(new views::Label), 341 label_1_(new views::Label),
344 label_2_(new views::Label), 342 label_2_(new views::Label),
345 link_(new views::Link) { 343 link_(new views::Link) {
346 // Set up the icon. 344 // Set up the icon.
347 if (delegate->GetIcon()) 345 if (delegate->GetIcon())
348 icon_->SetImage(delegate->GetIcon()); 346 icon_->SetImage(delegate->GetIcon());
349 AddChildView(icon_); 347 AddChildView(icon_);
350 348
351 // Set up the labels. 349 // Set up the labels.
352 size_t offset; 350 size_t offset;
353 std::wstring message_text = delegate->GetMessageTextWithOffset(&offset); 351 string16 message_text = delegate->GetMessageTextWithOffset(&offset);
354 if (offset != std::wstring::npos) { 352 if (offset != string16::npos) {
355 label_1_->SetText(message_text.substr(0, offset)); 353 label_1_->SetText(UTF16ToWideHack(message_text.substr(0, offset)));
356 label_2_->SetText(message_text.substr(offset)); 354 label_2_->SetText(UTF16ToWideHack(message_text.substr(offset)));
357 } else { 355 } else {
358 label_1_->SetText(message_text); 356 label_1_->SetText(UTF16ToWideHack(message_text));
359 } 357 }
360 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 358 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
361 label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); 359 label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
362 label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); 360 label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
363 label_1_->SetColor(SK_ColorBLACK); 361 label_1_->SetColor(SK_ColorBLACK);
364 label_2_->SetColor(SK_ColorBLACK); 362 label_2_->SetColor(SK_ColorBLACK);
365 label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 363 label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
366 label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 364 label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
367 AddChildView(label_1_); 365 AddChildView(label_1_);
368 AddChildView(label_2_); 366 AddChildView(label_2_);
369 367
370 // Set up the link. 368 // Set up the link.
371 link_->SetText(delegate->GetLinkText()); 369 link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
372 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); 370 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
373 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 371 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
374 link_->SetController(this); 372 link_->SetController(this);
375 link_->MakeReadableOverBackgroundColor(background()->get_color()); 373 link_->MakeReadableOverBackgroundColor(background()->get_color());
376 AddChildView(link_); 374 AddChildView(link_);
377 } 375 }
378 376
379 LinkInfoBar::~LinkInfoBar() { 377 LinkInfoBar::~LinkInfoBar() {
380 } 378 }
381 379
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 437 }
440 438
441 // ConfirmInfoBar, public: ----------------------------------------------------- 439 // ConfirmInfoBar, public: -----------------------------------------------------
442 440
443 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) 441 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
444 : AlertInfoBar(delegate), 442 : AlertInfoBar(delegate),
445 ok_button_(NULL), 443 ok_button_(NULL),
446 cancel_button_(NULL), 444 cancel_button_(NULL),
447 link_(NULL), 445 link_(NULL),
448 initialized_(false) { 446 initialized_(false) {
449 ok_button_ = new views::NativeButton( 447 ok_button_ = new views::NativeButton(this,
450 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); 448 UTF16ToWideHack(delegate->GetButtonLabel(
449 ConfirmInfoBarDelegate::BUTTON_OK)));
451 ok_button_->SetAccessibleName(ok_button_->label()); 450 ok_button_->SetAccessibleName(ok_button_->label());
452 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK_DEFAULT) 451 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK_DEFAULT)
453 ok_button_->SetAppearsAsDefault(true); 452 ok_button_->SetAppearsAsDefault(true);
454 if (delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_OK)) 453 if (delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_OK))
455 ok_button_->SetNeedElevation(true); 454 ok_button_->SetNeedElevation(true);
456 cancel_button_ = new views::NativeButton( 455 cancel_button_ = new views::NativeButton(
457 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 456 this, UTF16ToWideHack(
457 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)));
458 cancel_button_->SetAccessibleName(cancel_button_->label()); 458 cancel_button_->SetAccessibleName(cancel_button_->label());
459 459
460 // Set up the link. 460 // Set up the link.
461 link_ = new views::Link; 461 link_ = new views::Link;
462 link_->SetText(delegate->GetLinkText()); 462 link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
463 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 463 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
464 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); 464 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
465 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 465 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
466 link_->SetController(this); 466 link_->SetController(this);
467 link_->MakeReadableOverBackgroundColor(background()->get_color()); 467 link_->MakeReadableOverBackgroundColor(background()->get_color());
468 } 468 }
469 469
470 ConfirmInfoBar::~ConfirmInfoBar() { 470 ConfirmInfoBar::~ConfirmInfoBar() {
471 if (!initialized_) { 471 if (!initialized_) {
472 delete ok_button_; 472 delete ok_button_;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 584
585 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { 585 InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
586 return new LinkInfoBar(this); 586 return new LinkInfoBar(this);
587 } 587 }
588 588
589 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- 589 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: --------------------------
590 590
591 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { 591 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
592 return new ConfirmInfoBar(this); 592 return new ConfirmInfoBar(this);
593 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698