blob: 8094d4e02798c7f962e945def9c388e69bc594c8 (
plain)
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
|
// Copyright (c) 2010 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/views/infobars/translate_message_infobar.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
#include "chrome/browser/views/infobars/infobar_text_button.h"
#include "views/controls/image_view.h"
TranslateMessageInfoBar::TranslateMessageInfoBar(
TranslateInfoBarDelegate* delegate)
: TranslateInfoBarBase(delegate) {
label_ = CreateLabel(delegate->GetMessageInfoBarText());
AddChildView(label_);
string16 button_text = delegate->GetMessageInfoBarButtonText();
if (button_text.empty()) {
button_ = NULL;
} else {
button_ = InfoBarTextButton::Create(this, button_text);
AddChildView(button_);
}
}
void TranslateMessageInfoBar::Layout() {
TranslateInfoBarBase::Layout();
int x = icon_->bounds().right() + InfoBar::kIconLabelSpacing;
gfx::Size label_pref_size = label_->GetPreferredSize();
int available_width = GetAvailableWidth() - x;
gfx::Size button_pref_size;
if (button_) {
button_pref_size = button_->GetPreferredSize();
available_width -=
(button_pref_size.width() + InfoBar::kButtonInLabelSpacing);
}
label_->SetBounds(x, InfoBar::OffsetY(this, label_pref_size),
std::min(label_pref_size.width(), available_width),
label_pref_size.height());
if (button_) {
button_->SetBounds(label_->bounds().right() +
InfoBar::kButtonInLabelSpacing,
InfoBar::OffsetY(this, button_pref_size),
button_pref_size.width(), button_pref_size.height());
}
}
void TranslateMessageInfoBar::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender == button_) {
GetDelegate()->MessageInfoBarButtonPressed();
return;
}
TranslateInfoBarBase::ButtonPressed(sender, event);
}
|