1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/infobars/link_infobar.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/ui/views/event_utils.h"
#include "views/controls/image_view.h"
// LinkInfoBarDelegate --------------------------------------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
return new LinkInfoBar(this);
}
// LinkInfoBar ----------------------------------------------------------------
LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate)
: InfoBarView(delegate),
icon_(new views::ImageView) {
if (delegate->GetIcon())
icon_->SetImage(delegate->GetIcon());
AddChildView(icon_);
size_t offset;
string16 message_text = delegate->GetMessageTextWithOffset(&offset);
DCHECK_NE(string16::npos, offset);
label_1_ = CreateLabel(message_text.substr(0, offset));
AddChildView(label_1_);
link_ = CreateLink(delegate->GetLinkText(), this,
background()->get_color());
AddChildView(link_);
label_2_ = CreateLabel(message_text.substr(offset));
AddChildView(label_2_);
}
LinkInfoBar::~LinkInfoBar() {
}
void LinkInfoBar::Layout() {
InfoBarView::Layout();
// Layout the icon.
gfx::Size icon_size = icon_->GetPreferredSize();
icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size),
icon_size.width(), icon_size.height());
int label_1_x = icon_->bounds().right() + kIconLabelSpacing;
gfx::Size label_1_size = label_1_->GetPreferredSize();
label_1_->SetBounds(label_1_x, OffsetY(this, label_1_size),
label_1_size.width(), label_1_size.height());
gfx::Size link_size = link_->GetPreferredSize();
link_->SetBounds(label_1_->bounds().right(), OffsetY(this, link_size),
link_size.width(), link_size.height());
gfx::Size label_2_size = label_2_->GetPreferredSize();
label_2_->SetBounds(link_->bounds().right(), OffsetY(this, label_2_size),
label_2_size.width(), label_2_size.height());
}
void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) {
DCHECK_EQ(link_, source);
if (GetDelegate()->LinkClicked(
event_utils::DispositionFromEventFlags(event_flags)))
RemoveInfoBar();
}
LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
return delegate()->AsLinkInfoBarDelegate();
}
|