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..4e1af74ed77c3bca543f051ef7313f92ee6e32dd |
--- /dev/null |
+++ b/chrome/browser/chromeos/ui/echo_dialog_view.cc |
@@ -0,0 +1,166 @@ |
+// 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 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); |
+ |
+ // TODO(tbarzic): Set style for service_name substring. |
+ |
+ label_ = new views::StyledLabel(text, this); |
+ label_->AddLink(ui::Range(offsets[1], offsets[1] + link.length())); |
+ |
+ 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); |
+ label_->AddLink(ui::Range(offset, offset + link.length())); |
+ |
+ SetLabelBorderAndBounds(); |
+ |
+ 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 = |
+ 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 |