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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h"
7 #include "chrome/browser/translate/translate_infobar_delegate.h"
8 #include "ui/views/controls/button/label_button.h"
9 #include "ui/views/controls/label.h"
11 TranslateMessageInfoBar::TranslateMessageInfoBar(
12 scoped_ptr
<TranslateInfoBarDelegate
> delegate
)
13 : TranslateInfoBarBase(delegate
.Pass()),
18 TranslateMessageInfoBar::~TranslateMessageInfoBar() {
21 void TranslateMessageInfoBar::Layout() {
22 TranslateInfoBarBase::Layout();
26 std::min(label_
->width(), std::max(0, EndX() - x
- NonLabelWidth()));
27 label_
->SetBounds(x
, OffsetY(label_
), width
, label_
->height());
28 if (!label_
->text().empty())
29 x
= label_
->bounds().right() + kEndOfLabelSpacing
;
32 button_
->SetPosition(gfx::Point(x
, OffsetY(button_
)));
35 void TranslateMessageInfoBar::ViewHierarchyChanged(
36 const ViewHierarchyChangedDetails
& details
) {
37 if (details
.is_add
&& (details
.child
== this) && (label_
== NULL
)) {
38 TranslateInfoBarDelegate
* delegate
= GetDelegate();
39 label_
= CreateLabel(delegate
->GetMessageInfoBarText());
42 base::string16
button_text(delegate
->GetMessageInfoBarButtonText());
43 if (!button_text
.empty()) {
44 button_
= CreateLabelButton(this, button_text
);
45 AddChildView(button_
);
49 // This must happen after adding all other children so InfoBarView can ensure
50 // the close button is the last child.
51 TranslateInfoBarBase::ViewHierarchyChanged(details
);
54 void TranslateMessageInfoBar::ButtonPressed(views::Button
* sender
,
55 const ui::Event
& event
) {
57 return; // We're closing; don't call anything, it might access the owner.
58 if (sender
== button_
)
59 GetDelegate()->MessageInfoBarButtonPressed();
61 TranslateInfoBarBase::ButtonPressed(sender
, event
);
64 int TranslateMessageInfoBar::ContentMinimumWidth() const {
65 return label_
->GetMinimumSize().width() + NonLabelWidth();
68 int TranslateMessageInfoBar::NonLabelWidth() const {
71 return button_
->width() + (label_
->text().empty() ? 0 : kEndOfLabelSpacing
);