Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/ui/echo_dialog_view.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/ui/echo_dialog_listener.h" | |
| 8 #include "grit/generated_resources.h" | |
| 9 #include "ui/base/l10n/l10n_util.h" | |
| 10 #include "ui/views/controls/styled_label.h" | |
| 11 #include "ui/views/widget/widget.h" | |
| 12 #include "ui/views/window/dialog_client_view.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const int kDialogContentTopInset = 20; | |
| 17 const int kDialogContentLeftInset = 20; | |
| 18 const int kDialogContentBottomInset = 20; | |
| 19 const int kDialogContentRightInset = 100; | |
| 20 | |
| 21 const int kDialogContentWidth = | |
| 22 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
| |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace chromeos { | |
| 27 | |
| 28 EchoDialogView::EchoDialogView(EchoDialogListener* listener) | |
| 29 : label_(NULL), | |
| 30 listener_(listener), | |
| 31 ok_button_label_id_(0), | |
| 32 cancel_button_label_id_(0) { | |
| 33 } | |
| 34 | |
| 35 EchoDialogView::~EchoDialogView() {} | |
| 36 | |
| 37 void EchoDialogView::InitForEnabledEcho(const string16& service_name, | |
| 38 const string16& origin) { | |
| 39 ok_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON; | |
| 40 cancel_button_label_id_ = IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON; | |
| 41 | |
| 42 string16 link = | |
| 43 l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE); | |
| 44 | |
| 45 std::vector<size_t> offsets; | |
| 46 string16 text = l10n_util::GetStringFUTF16(IDS_ECHO_CONSENT_DIALOG_TEXT, | |
| 47 service_name, | |
| 48 link, | |
| 49 &offsets); | |
| 50 | |
| 51 // TODO(tbarzic): Set style for service_name substring. | |
| 52 | |
| 53 label_ = new views::StyledLabel(text, this); | |
| 54 label_->AddLink(ui::Range(offsets[1], offsets[1] + link.length())); | |
| 55 | |
| 56 label_->set_border(views::Border::CreateEmptyBorder( | |
| 57 kDialogContentTopInset, | |
| 58 kDialogContentLeftInset, | |
| 59 kDialogContentBottomInset, | |
| 60 kDialogContentRightInset)); | |
| 61 | |
| 62 label_->SizeToFit(kDialogContentWidth); | |
| 63 | |
| 64 AddChildView(label_); | |
| 65 } | |
| 66 | |
| 67 void EchoDialogView::InitForDisabledEcho() { | |
| 68 ok_button_label_id_ = 0; | |
| 69 cancel_button_label_id_ = IDS_ECHO_CONSENT_DISMISS_BUTTON; | |
| 70 | |
| 71 string16 link = | |
| 72 l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL_LEARN_MORE); | |
| 73 | |
| 74 size_t offset; | |
| 75 string16 text = l10n_util::GetStringFUTF16( | |
| 76 IDS_ECHO_DISABLED_CONSENT_DIALOG_TEXT, link, &offset); | |
| 77 | |
| 78 label_ = new views::StyledLabel(text, this); | |
| 79 label_->AddLink(ui::Range(offset, offset + link.length())); | |
| 80 | |
| 81 label_->set_border(views::Border::CreateEmptyBorder( | |
| 82 kDialogContentTopInset, | |
| 83 kDialogContentLeftInset, | |
| 84 kDialogContentBottomInset, | |
| 85 kDialogContentRightInset)); | |
| 86 | |
| 87 label_->SizeToFit(kDialogContentWidth); | |
| 88 | |
| 89 AddChildView(label_); | |
| 90 } | |
| 91 | |
| 92 void EchoDialogView::Show(gfx::NativeWindow parent) { | |
| 93 DCHECK(cancel_button_label_id_); | |
| 94 | |
| 95 views::DialogDelegateView::CreateDialogWidget(this, parent, parent); | |
| 96 GetWidget()->SetSize(GetWidget()->GetRootView()->GetPreferredSize()); | |
| 97 GetWidget()->Show(); | |
| 98 } | |
| 99 | |
| 100 int EchoDialogView::GetDefaultDialogButton() const { | |
| 101 return ui::DIALOG_BUTTON_NONE; | |
| 102 } | |
| 103 | |
| 104 int EchoDialogView::GetDialogButtons() const { | |
| 105 int buttons = ui::DIALOG_BUTTON_NONE; | |
| 106 if (ok_button_label_id_) | |
| 107 buttons |= ui::DIALOG_BUTTON_OK; | |
| 108 if (cancel_button_label_id_) | |
| 109 buttons |= ui::DIALOG_BUTTON_CANCEL; | |
| 110 return buttons; | |
| 111 } | |
| 112 | |
| 113 bool EchoDialogView::Accept() { | |
| 114 if (listener_) { | |
| 115 listener_->OnAccept(); | |
| 116 listener_ = NULL; | |
| 117 } | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 bool EchoDialogView::Cancel() { | |
| 122 if (listener_) { | |
| 123 listener_->OnCancel(); | |
| 124 listener_ = NULL; | |
| 125 } | |
| 126 return true; | |
| 127 } | |
| 128 | |
| 129 string16 EchoDialogView::GetDialogButtonLabel(ui::DialogButton button) const { | |
| 130 if (button == ui::DIALOG_BUTTON_OK && ok_button_label_id_) | |
| 131 return l10n_util::GetStringUTF16(ok_button_label_id_); | |
| 132 if (button == ui::DIALOG_BUTTON_CANCEL && cancel_button_label_id_) | |
| 133 return l10n_util::GetStringUTF16(cancel_button_label_id_); | |
| 134 return string16(); | |
| 135 } | |
| 136 | |
| 137 ui::ModalType EchoDialogView::GetModalType() const { | |
| 138 return ui::MODAL_TYPE_WINDOW; | |
| 139 } | |
| 140 | |
| 141 bool EchoDialogView::ShouldShowWindowTitle() const { | |
| 142 return false; | |
| 143 } | |
| 144 | |
| 145 bool EchoDialogView::ShouldShowWindowIcon() const { | |
| 146 return false; | |
| 147 } | |
| 148 | |
| 149 void EchoDialogView::StyledLabelLinkClicked(const ui::Range& range, | |
| 150 int event_flags) { | |
| 151 if (!listener_) | |
| 152 return; | |
| 153 listener_->OnMoreInfoLinkClicked(); | |
| 154 } | |
| 155 | |
| 156 gfx::Size EchoDialogView::GetPreferredSize() { | |
| 157 gfx::Size size = label_->GetPreferredSize(); | |
| 158 gfx::Insets insets = GetInsets(); | |
| 159 size.Enlarge(insets.width(), insets.height()); | |
| 160 return size; | |
| 161 } | |
| 162 | |
| 163 } // namespace chromeos | |
| OLD | NEW |