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

Side by Side Diff: chrome/browser/ui/views/infobars/link_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/link_infobar.h" 5 #include "chrome/browser/ui/views/infobars/link_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 "ui/base/resource/resource_bundle.h"
11 #include "views/controls/image_view.h" 9 #include "views/controls/image_view.h"
12 10
13 // LinkInfoBarDelegate -------------------------------------------------------- 11 // LinkInfoBarDelegate --------------------------------------------------------
14 12
15 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { 13 InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
16 return new LinkInfoBar(this); 14 return new LinkInfoBar(this);
17 } 15 }
18 16
19 // LinkInfoBar ---------------------------------------------------------------- 17 // LinkInfoBar ----------------------------------------------------------------
20 18
21 LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) 19 LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
22 : InfoBarView(delegate), 20 : InfoBarView(delegate),
23 icon_(new views::ImageView), 21 icon_(new views::ImageView) {
24 label_1_(new views::Label),
25 link_(new views::Link),
26 label_2_(new views::Label) {
27 // Set up the icon.
28 if (delegate->GetIcon()) 22 if (delegate->GetIcon())
29 icon_->SetImage(delegate->GetIcon()); 23 icon_->SetImage(delegate->GetIcon());
30 AddChildView(icon_); 24 AddChildView(icon_);
31 25
32 // Set up the labels.
33 size_t offset; 26 size_t offset;
34 string16 message_text = delegate->GetMessageTextWithOffset(&offset); 27 string16 message_text = delegate->GetMessageTextWithOffset(&offset);
35 if (offset != string16::npos) { 28 DCHECK_NE(string16::npos, offset);
36 label_1_->SetText(UTF16ToWideHack(message_text.substr(0, offset))); 29 label_1_ = CreateLabel(message_text.substr(0, offset));
37 label_2_->SetText(UTF16ToWideHack(message_text.substr(offset)));
38 } else {
39 label_1_->SetText(UTF16ToWideHack(message_text));
40 }
41 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
42 label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
43 label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
44 label_1_->SetColor(SK_ColorBLACK);
45 label_2_->SetColor(SK_ColorBLACK);
46 label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
47 label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
48 AddChildView(label_1_); 30 AddChildView(label_1_);
31
32 link_ = CreateLink(delegate->GetLinkText(), this,
33 background()->get_color());
34 AddChildView(link_);
35
36 label_2_ = CreateLabel(message_text.substr(offset));
49 AddChildView(label_2_); 37 AddChildView(label_2_);
50
51 // Set up the link.
52 link_->SetText(UTF16ToWideHack(delegate->GetLinkText()));
53 link_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
54 link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
55 link_->SetController(this);
56 link_->MakeReadableOverBackgroundColor(background()->get_color());
57 AddChildView(link_);
58 } 38 }
59 39
60 LinkInfoBar::~LinkInfoBar() { 40 LinkInfoBar::~LinkInfoBar() {
61 } 41 }
62 42
63 void LinkInfoBar::Layout() { 43 void LinkInfoBar::Layout() {
64 InfoBarView::Layout(); 44 InfoBarView::Layout();
65 45
66 // Layout the icon. 46 // Layout the icon.
67 gfx::Size icon_size = icon_->GetPreferredSize(); 47 gfx::Size icon_size = icon_->GetPreferredSize();
68 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size), 48 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
69 icon_size.width(), icon_size.height()); 49 icon_size.width(), icon_size.height());
70 50
71 int label_1_x = icon_->bounds().right() + kIconLabelSpacing; 51 int label_1_x = icon_->bounds().right() + kIconLabelSpacing;
72
73 // Figure out the amount of space available to the rest of the content now
74 // that the close button and the icon have been positioned.
75 int available_width = GetAvailableWidth() - label_1_x;
76
77 // Layout the left label.
78 gfx::Size label_1_size = label_1_->GetPreferredSize(); 52 gfx::Size label_1_size = label_1_->GetPreferredSize();
79 label_1_->SetBounds(label_1_x, OffsetY(this, label_1_size), 53 label_1_->SetBounds(label_1_x, OffsetY(this, label_1_size),
80 label_1_size.width(), label_1_size.height()); 54 label_1_size.width(), label_1_size.height());
81 55
82 // Layout the link.
83 gfx::Size link_size = link_->GetPreferredSize(); 56 gfx::Size link_size = link_->GetPreferredSize();
84 bool has_second_label = !label_2_->GetText().empty(); 57 link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
85 if (has_second_label) { 58 link_size.width(), link_size.height());
86 // Embed the link in the text string between the two labels.
87 link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
88 link_size.width(), link_size.height());
89 } else {
90 // Right-align the link toward the edge of the InfoBar.
91 link_->SetBounds(label_1_x + available_width - link_size.width(),
92 OffsetY(this, link_size), link_size.width(), link_size.height());
93 }
94 59
95 // Layout the right label (we do this regardless of whether or not it has
96 // text).
97 gfx::Size label_2_size = label_2_->GetPreferredSize(); 60 gfx::Size label_2_size = label_2_->GetPreferredSize();
98 label_2_->SetBounds(link_->bounds().right(), OffsetY(this, label_2_size), 61 label_2_->SetBounds(link_->bounds().right(), OffsetY(this, label_2_size),
99 label_2_size.width(), label_2_size.height()); 62 label_2_size.width(), label_2_size.height());
100 } 63 }
101 64
102 void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) { 65 void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
103 DCHECK_EQ(link_, source); 66 DCHECK_EQ(link_, source);
104 if (GetDelegate()->LinkClicked( 67 if (GetDelegate()->LinkClicked(
105 event_utils::DispositionFromEventFlags(event_flags))) 68 event_utils::DispositionFromEventFlags(event_flags)))
106 RemoveInfoBar(); 69 RemoveInfoBar();
107 } 70 }
108 71
109 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { 72 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
110 return delegate()->AsLinkInfoBarDelegate(); 73 return delegate()->AsLinkInfoBarDelegate();
111 } 74 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.cc ('k') | chrome/browser/ui/views/infobars/translate_infobar_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698