1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/ui/echo_dialog_view.h"
#include "chrome/browser/chromeos/ui/echo_dialog_listener.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
namespace {
const int kDialogLabelTopInset = 20;
const int kDialogLabelLeftInset = 20;
const int kDialogLabelBottomInset = 20;
const int kDialogLabelRightInset = 100;
const int kDialogLabelPreferredWidth =
350 + kDialogLabelLeftInset + kDialogLabelRightInset;
} // namespace
namespace chromeos {
EchoDialogView::EchoDialogView(EchoDialogListener* listener)
: label_(NULL),
listener_(listener),
ok_button_label_id_(0),
cancel_button_label_id_(0) {
}
EchoDialogView::~EchoDialogView() {}
void EchoDialogView::InitForEnabledEcho(const string16& service_name,
const string16& origin) {
ok_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON;
cancel_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON;
string16 link =
l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE);
std::vector<size_t> offsets;
string16 text = l10n_util::GetStringFUTF16(IDS_ECHO_CONSENT_DIALOG_TEXT,
service_name,
link,
&offsets);
label_ = new views::StyledLabel(text, this);
views::StyledLabel::RangeStyleInfo service_name_style;
service_name_style.font_style = gfx::Font::UNDERLINE;
service_name_style.tooltip = origin;
label_->AddStyleRange(
gfx::Range(offsets[0], offsets[0] + service_name.length()),
service_name_style);
views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink();
link_style.font_style = gfx::Font::NORMAL;
label_->AddStyleRange(gfx::Range(offsets[1], offsets[1] + link.length()),
link_style);
SetLabelBorderAndBounds();
AddChildView(label_);
}
void EchoDialogView::InitForDisabledEcho() {
ok_button_label_id_ = 0;
cancel_button_label_id_ = IDS_ECHO_CONSENT_DISMISS_BUTTON;
string16 link =
l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE);
size_t offset;
string16 text = l10n_util::GetStringFUTF16(
IDS_ECHO_DISABLED_CONSENT_DIALOG_TEXT, link, &offset);
label_ = new views::StyledLabel(text, this);
views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink();
link_style.font_style = gfx::Font::NORMAL;
label_->AddStyleRange(gfx::Range(offset, offset + link.length()), link_style);
SetLabelBorderAndBounds();
AddChildView(label_);
}
void EchoDialogView::Show(gfx::NativeWindow parent) {
DCHECK(cancel_button_label_id_);
views::DialogDelegate::CreateDialogWidget(this, parent, parent);
GetWidget()->SetSize(GetWidget()->GetRootView()->GetPreferredSize());
GetWidget()->Show();
}
int EchoDialogView::GetDefaultDialogButton() const {
return ui::DIALOG_BUTTON_NONE;
}
int EchoDialogView::GetDialogButtons() const {
int buttons = ui::DIALOG_BUTTON_NONE;
if (ok_button_label_id_)
buttons |= ui::DIALOG_BUTTON_OK;
if (cancel_button_label_id_)
buttons |= ui::DIALOG_BUTTON_CANCEL;
return buttons;
}
bool EchoDialogView::Accept() {
if (listener_) {
listener_->OnAccept();
listener_ = NULL;
}
return true;
}
bool EchoDialogView::Cancel() {
if (listener_) {
listener_->OnCancel();
listener_ = NULL;
}
return true;
}
string16 EchoDialogView::GetDialogButtonLabel(ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK && ok_button_label_id_)
return l10n_util::GetStringUTF16(ok_button_label_id_);
if (button == ui::DIALOG_BUTTON_CANCEL && cancel_button_label_id_)
return l10n_util::GetStringUTF16(cancel_button_label_id_);
return string16();
}
ui::ModalType EchoDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
bool EchoDialogView::ShouldShowWindowTitle() const {
return false;
}
bool EchoDialogView::ShouldShowWindowIcon() const {
return false;
}
void EchoDialogView::StyledLabelLinkClicked(const gfx::Range& range,
int event_flags) {
if (!listener_)
return;
listener_->OnMoreInfoLinkClicked();
}
gfx::Size EchoDialogView::GetPreferredSize() {
gfx::Size size =
gfx::Size(kDialogLabelPreferredWidth,
label_->GetHeightForWidth(kDialogLabelPreferredWidth));
gfx::Insets insets = GetInsets();
size.Enlarge(insets.width(), insets.height());
return size;
}
void EchoDialogView::SetLabelBorderAndBounds() {
label_->set_border(views::Border::CreateEmptyBorder(
kDialogLabelTopInset,
kDialogLabelLeftInset,
kDialogLabelBottomInset,
kDialogLabelRightInset));
label_->SetBounds(label_->x(),
label_->y(),
kDialogLabelPreferredWidth,
label_->GetHeightForWidth(kDialogLabelPreferredWidth));
}
} // namespace chromeos
|