[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / infobars / translate_message_infobar.cc
blobf4d02f18c18506535893c0043d0423a69eb834ed
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()),
14 label_(NULL),
15 button_(NULL) {
18 TranslateMessageInfoBar::~TranslateMessageInfoBar() {
21 void TranslateMessageInfoBar::Layout() {
22 TranslateInfoBarBase::Layout();
24 int x = StartX();
25 const int width =
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;
31 if (button_)
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());
40 AddChildView(label_);
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) {
56 if (!owner())
57 return; // We're closing; don't call anything, it might access the owner.
58 if (sender == button_)
59 GetDelegate()->MessageInfoBarButtonPressed();
60 else
61 TranslateInfoBarBase::ButtonPressed(sender, event);
64 int TranslateMessageInfoBar::ContentMinimumWidth() const {
65 return label_->GetMinimumSize().width() + NonLabelWidth();
68 int TranslateMessageInfoBar::NonLabelWidth() const {
69 if (!button_)
70 return 0;
71 return button_->width() + (label_->text().empty() ? 0 : kEndOfLabelSpacing);