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

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

Issue 6574011: Cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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/infobars/confirm_infobar.h" 5 #include "chrome/browser/ui/views/infobars/confirm_infobar.h"
6 6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/tab_contents/infobar_delegate.h" 7 #include "chrome/browser/tab_contents/infobar_delegate.h"
9 #include "chrome/browser/ui/views/event_utils.h" 8 #include "chrome/browser/ui/views/event_utils.h"
10 #include "chrome/browser/ui/views/infobars/infobar_text_button.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "views/controls/image_view.h" 9 #include "views/controls/image_view.h"
10 #include "views/controls/button/text_button.h"
13 #include "views/controls/label.h" 11 #include "views/controls/label.h"
14 12
15 // AlertInfoBar, public: ------------------------------------------------------- 13 // AlertInfoBar, public: -------------------------------------------------------
16 14
17 AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate) 15 AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate)
18 : InfoBarView(delegate) { 16 : InfoBarView(delegate) {
19 label_ = new views::Label( 17 label_ = CreateLabel(delegate->GetMessageText());
20 UTF16ToWideHack(delegate->GetMessageText()),
21 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
22 label_->SetColor(SK_ColorBLACK);
23 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
24 AddChildView(label_); 18 AddChildView(label_);
25 19
26 icon_ = new views::ImageView; 20 icon_ = new views::ImageView;
27 if (delegate->GetIcon()) 21 if (delegate->GetIcon())
28 icon_->SetImage(delegate->GetIcon()); 22 icon_->SetImage(delegate->GetIcon());
29 AddChildView(icon_); 23 AddChildView(icon_);
30 } 24 }
31 25
32 AlertInfoBar::~AlertInfoBar() { 26 AlertInfoBar::~AlertInfoBar() {
33 } 27 }
34 28
35 // AlertInfoBar, views::View overrides: ---------------------------------------- 29 // AlertInfoBar, views::View overrides: ----------------------------------------
36 30
37 void AlertInfoBar::Layout() { 31 void AlertInfoBar::Layout() {
38 // Layout the close button. 32 // Layout the close button.
39 InfoBarView::Layout(); 33 InfoBarView::Layout();
40 34
41 // Layout the icon and text. 35 // Layout the icon and text.
42 gfx::Size icon_size = icon_->GetPreferredSize(); 36 gfx::Size icon_size = icon_->GetPreferredSize();
43 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size), 37 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
44 icon_size.width(), icon_size.height()); 38 icon_size.width(), icon_size.height());
45 39
46 gfx::Size text_size = label_->GetPreferredSize(); 40 int available_width = std::max(0,
47 int text_width = std::min(text_size.width(),
48 GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing); 41 GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing);
42 gfx::Size label_size = label_->GetPreferredSize();
49 label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing, 43 label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing,
50 OffsetY(this, text_size), text_width, text_size.height()); 44 OffsetY(this, label_size), std::min(label_size.width(), available_width),
45 label_size.height());
51 } 46 }
52 47
53 // ConfirmInfoBarDelegate ----------------------------------------------------- 48 // ConfirmInfoBarDelegate -----------------------------------------------------
54 49
55 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { 50 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
56 return new ConfirmInfoBar(this); 51 return new ConfirmInfoBar(this);
57 } 52 }
58 53
59 // ConfirmInfoBar ------------------------------------------------------------- 54 // ConfirmInfoBar -------------------------------------------------------------
60 55
61 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) 56 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
62 : AlertInfoBar(delegate), 57 : AlertInfoBar(delegate),
63 ok_button_(NULL),
64 cancel_button_(NULL),
65 link_(NULL),
66 initialized_(false) { 58 initialized_(false) {
67 ok_button_ = InfoBarTextButton::Create(this, 59 ok_button_ = CreateTextButton(this,
68 (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) ? 60 (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) ?
69 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK) : 61 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK) :
70 string16()); 62 string16(),
71 ok_button_->SetAccessibleName(WideToUTF16Hack(ok_button_->text())); 63 delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_OK));
72 cancel_button_ = InfoBarTextButton::Create(this, 64 cancel_button_ = CreateTextButton(this,
73 (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) ? 65 (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) ?
74 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL) : 66 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL) :
75 string16()); 67 string16(),
76 cancel_button_->SetAccessibleName(WideToUTF16Hack(cancel_button_->text())); 68 delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_CANCEL));
77 69
78 // Set up the link. 70 link_ = CreateLink(delegate->GetLinkText(), this, background()->get_color());
79 link_ = new views::Link;
80 link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
81 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
82 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
83 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
84 link_->SetController(this);
85 link_->MakeReadableOverBackgroundColor(background()->get_color());
86 } 71 }
87 72
88 ConfirmInfoBar::~ConfirmInfoBar() { 73 ConfirmInfoBar::~ConfirmInfoBar() {
89 if (!initialized_) { 74 if (!initialized_) {
90 delete ok_button_; 75 delete ok_button_;
91 delete cancel_button_; 76 delete cancel_button_;
92 delete link_; 77 delete link_;
93 } 78 }
94 } 79 }
95 80
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) { 152 void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) {
168 DCHECK_EQ(link_, source); 153 DCHECK_EQ(link_, source);
169 if (GetDelegate()->LinkClicked( 154 if (GetDelegate()->LinkClicked(
170 event_utils::DispositionFromEventFlags(event_flags))) 155 event_utils::DispositionFromEventFlags(event_flags)))
171 RemoveInfoBar(); 156 RemoveInfoBar();
172 } 157 }
173 158
174 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { 159 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
175 return delegate()->AsConfirmInfoBarDelegate(); 160 return delegate()->AsConfirmInfoBarDelegate();
176 } 161 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/confirm_infobar.h ('k') | chrome/browser/ui/views/infobars/infobar_text_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698