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
)
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 string16
ConfirmBubbleViews::GetDialogButtonLabel(
47 ui::DialogButton button
) const {
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
);
55 return DialogDelegateView::GetDialogButtonLabel(button
);
59 bool ConfirmBubbleViews::IsDialogButtonEnabled(ui::DialogButton button
) const {
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
);
71 views::View
* ConfirmBubbleViews::CreateExtraView() {
75 bool ConfirmBubbleViews::Cancel() {
80 bool ConfirmBubbleViews::Accept() {
85 ui::ModalType
ConfirmBubbleViews::GetModalType() const {
86 return ui::MODAL_TYPE_WINDOW
;
89 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();
102 void ShowConfirmBubble(gfx::NativeView view
,
103 const gfx::Point
& origin
,
104 ConfirmBubbleModel
* model
) {
105 CreateBrowserModalDialogViews(new ConfirmBubbleViews(model
), view
)->Show();
108 } // namespace chrome