Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / confirm_bubble_views.cc
blob2ba5d52a5ec42d74349706c747323d01e4d988c1
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/confirm_bubble_views.h"
7 #include "chrome/browser/ui/confirm_bubble.h"
8 #include "chrome/browser/ui/confirm_bubble_model.h"
9 #include "chrome/browser/ui/views/constrained_window_views.h"
10 #include "ui/views/controls/label.h"
11 #include "ui/views/controls/link.h"
12 #include "ui/views/layout/grid_layout.h"
13 #include "ui/views/layout/layout_constants.h"
14 #include "ui/views/widget/widget.h"
16 ConfirmBubbleViews::ConfirmBubbleViews(ConfirmBubbleModel* model)
17 : model_(model),
18 link_(NULL) {
19 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
20 SetLayoutManager(layout);
22 // Use a fixed maximum message width, so longer messages will wrap.
23 const int kMaxMessageWidth = 400;
24 views::ColumnSet* cs = layout->AddColumnSet(0);
25 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
26 views::GridLayout::FIXED, kMaxMessageWidth, false);
28 // Add the message label.
29 views::Label* label = new views::Label(model_->GetMessageText());
30 DCHECK(!label->text().empty());
31 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
32 label->SetMultiLine(true);
33 label->SizeToFit(kMaxMessageWidth);
34 layout->StartRow(0, 0);
35 layout->AddView(label);
37 // Initialize the link.
38 link_ = new views::Link(model_->GetLinkText());
39 link_->set_listener(this);
40 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
43 ConfirmBubbleViews::~ConfirmBubbleViews() {
46 base::string16 ConfirmBubbleViews::GetDialogButtonLabel(
47 ui::DialogButton button) const {
48 switch (button) {
49 case ui::DIALOG_BUTTON_OK:
50 return model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK);
51 case ui::DIALOG_BUTTON_CANCEL:
52 return model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL);
53 default:
54 NOTREACHED();
55 return DialogDelegateView::GetDialogButtonLabel(button);
59 bool ConfirmBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
60 switch (button) {
61 case ui::DIALOG_BUTTON_OK:
62 return !!(model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK);
63 case ui::DIALOG_BUTTON_CANCEL:
64 return !!(model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL);
65 default:
66 NOTREACHED();
67 return false;
71 views::View* ConfirmBubbleViews::CreateExtraView() {
72 return link_;
75 bool ConfirmBubbleViews::Cancel() {
76 model_->Cancel();
77 return true;
80 bool ConfirmBubbleViews::Accept() {
81 model_->Accept();
82 return true;
85 ui::ModalType ConfirmBubbleViews::GetModalType() const {
86 return ui::MODAL_TYPE_WINDOW;
89 base::string16 ConfirmBubbleViews::GetWindowTitle() const {
90 return model_->GetTitle();
93 void ConfirmBubbleViews::LinkClicked(views::Link* source, int event_flags) {
94 if (source == link_) {
95 model_->LinkClicked();
96 GetWidget()->Close();
100 namespace chrome {
102 void ShowConfirmBubble(gfx::NativeView view,
103 const gfx::Point& origin,
104 ConfirmBubbleModel* model) {
105 CreateBrowserModalDialogViews(new ConfirmBubbleViews(model), view)->Show();
108 } // namespace chrome