| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/confirm_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/confirm_infobar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); | 60 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); |
| 61 | 61 |
| 62 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); | 62 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ConfirmInfoBar::ViewHierarchyChanged( | 65 void ConfirmInfoBar::ViewHierarchyChanged( |
| 66 const ViewHierarchyChangedDetails& details) { | 66 const ViewHierarchyChangedDetails& details) { |
| 67 if (details.is_add && details.child == this && (label_ == NULL)) { | 67 if (details.is_add && details.child == this && (label_ == NULL)) { |
| 68 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 68 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| 69 label_ = CreateLabel(delegate->GetMessageText()); | 69 label_ = CreateLabel(delegate->GetMessageText()); |
| 70 AddChildView(label_); | 70 AddViewToContentArea(label_); |
| 71 | 71 |
| 72 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { | 72 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 73 if (delegate->OKButtonTriggersUACPrompt()) { | 73 if (delegate->OKButtonTriggersUACPrompt()) { |
| 74 // Use a label button even in MD mode as MD buttons don't support icons. | 74 // Use a label button even in MD mode as MD buttons don't support icons. |
| 75 views::LabelButton* ok_button = CreateLabelButton( | 75 views::LabelButton* ok_button = CreateLabelButton( |
| 76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | 76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 77 elevation_icon_setter_.reset(new ElevationIconSetter( | 77 elevation_icon_setter_.reset(new ElevationIconSetter( |
| 78 ok_button, | 78 ok_button, |
| 79 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); | 79 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); |
| 80 ok_button_ = ok_button; | 80 ok_button_ = ok_button; |
| 81 } else { | 81 } else { |
| 82 ok_button_ = CreateTextButton( | 82 ok_button_ = CreateTextButton( |
| 83 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | 83 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 84 } | 84 } |
| 85 AddChildView(ok_button_); | 85 AddViewToContentArea(ok_button_); |
| 86 ok_button_->SizeToPreferredSize(); | 86 ok_button_->SizeToPreferredSize(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 89 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 90 cancel_button_ = CreateTextButton( | 90 cancel_button_ = CreateTextButton( |
| 91 this, | 91 this, |
| 92 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 92 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 93 AddChildView(cancel_button_); | 93 AddViewToContentArea(cancel_button_); |
| 94 cancel_button_->SizeToPreferredSize(); | 94 cancel_button_->SizeToPreferredSize(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 base::string16 link_text(delegate->GetLinkText()); | 97 base::string16 link_text(delegate->GetLinkText()); |
| 98 link_ = CreateLink(link_text, this); | 98 link_ = CreateLink(link_text, this); |
| 99 AddChildView(link_); | 99 AddViewToContentArea(link_); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // This must happen after adding all other children so InfoBarView can ensure | 102 // This must happen after adding all other children so InfoBarView can ensure |
| 103 // the close button is the last child. | 103 // the close button is the last child. |
| 104 InfoBarView::ViewHierarchyChanged(details); | 104 InfoBarView::ViewHierarchyChanged(details); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ConfirmInfoBar::ButtonPressed(views::Button* sender, | 107 void ConfirmInfoBar::ButtonPressed(views::Button* sender, |
| 108 const ui::Event& event) { | 108 const ui::Event& event) { |
| 109 if (!owner()) | 109 if (!owner()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 int ConfirmInfoBar::NonLabelWidth() const { | 140 int ConfirmInfoBar::NonLabelWidth() const { |
| 141 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? | 141 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? |
| 142 0 : kEndOfLabelSpacing; | 142 0 : kEndOfLabelSpacing; |
| 143 if (ok_button_) | 143 if (ok_button_) |
| 144 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); | 144 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); |
| 145 width += cancel_button_ ? cancel_button_->width() : 0; | 145 width += cancel_button_ ? cancel_button_->width() : 0; |
| 146 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); | 146 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); |
| 147 } | 147 } |
| OLD | NEW |