Index: chrome/browser/chromeos/ui/echo_dialog_view.cc |
diff --git a/chrome/browser/chromeos/ui/echo_dialog_view.cc b/chrome/browser/chromeos/ui/echo_dialog_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e5eedef603598b24d500e32afd5ebce378c5d6f |
--- /dev/null |
+++ b/chrome/browser/chromeos/ui/echo_dialog_view.cc |
@@ -0,0 +1,163 @@ |
+// 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/views/controls/styled_label.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/window/dialog_client_view.h" |
+ |
+namespace { |
+ |
+const int kDialogContentTopInset = 20; |
+const int kDialogContentLeftInset = 20; |
+const int kDialogContentBottomInset = 20; |
+const int kDialogContentRightInset = 100; |
+ |
+const int kDialogContentWidth = |
+ 350 + kDialogContentLeftInset + kDialogContentRightInset; |
sky
2013/03/18 19:32:39
Shouldn't the 350 be localized?
tbarzic
2013/03/18 20:40:03
I don't think it does (it's the preferred size of
|
+ |
+} // 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); |
+ |
+ // TODO(tbarzic): Set style for service_name substring. |
+ |
+ label_ = new views::StyledLabel(text, this); |
+ label_->AddLink(ui::Range(offsets[1], offsets[1] + link.length())); |
+ |
+ label_->set_border(views::Border::CreateEmptyBorder( |
+ kDialogContentTopInset, |
+ kDialogContentLeftInset, |
+ kDialogContentBottomInset, |
+ kDialogContentRightInset)); |
+ |
+ label_->SizeToFit(kDialogContentWidth); |
+ |
+ 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); |
+ label_->AddLink(ui::Range(offset, offset + link.length())); |
+ |
+ label_->set_border(views::Border::CreateEmptyBorder( |
+ kDialogContentTopInset, |
+ kDialogContentLeftInset, |
+ kDialogContentBottomInset, |
+ kDialogContentRightInset)); |
+ |
+ label_->SizeToFit(kDialogContentWidth); |
+ |
+ AddChildView(label_); |
+} |
+ |
+void EchoDialogView::Show(gfx::NativeWindow parent) { |
+ DCHECK(cancel_button_label_id_); |
+ |
+ views::DialogDelegateView::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 ui::Range& range, |
+ int event_flags) { |
+ if (!listener_) |
+ return; |
+ listener_->OnMoreInfoLinkClicked(); |
+} |
+ |
+gfx::Size EchoDialogView::GetPreferredSize() { |
+ gfx::Size size = label_->GetPreferredSize(); |
+ gfx::Insets insets = GetInsets(); |
+ size.Enlarge(insets.width(), insets.height()); |
+ return size; |
+} |
+ |
+} // namespace chromeos |