| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/notifier_settings.h" | 5 #include "ui/message_center/notifier_settings.h" |
| 6 | 6 |
| 7 #include "grit/ui_strings.h" | 7 #include "grit/ui_strings.h" |
| 8 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 checkbox_(new views::Checkbox(string16())) { | 43 checkbox_(new views::Checkbox(string16())) { |
| 44 SetLayoutManager(new views::BoxLayout( | 44 SetLayoutManager(new views::BoxLayout( |
| 45 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); | 45 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); |
| 46 checkbox_->SetChecked(notifier.enabled); | 46 checkbox_->SetChecked(notifier.enabled); |
| 47 checkbox_->set_listener(this); | 47 checkbox_->set_listener(this); |
| 48 AddChildView(checkbox_); | 48 AddChildView(checkbox_); |
| 49 UpdateIconImage(notifier_.icon); | 49 UpdateIconImage(notifier_.icon); |
| 50 AddChildView(new views::Label(notifier.name)); | 50 AddChildView(new views::Label(notifier.name)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void UpdateIconImage(gfx::ImageSkia icon) { | 53 void UpdateIconImage(const gfx::ImageSkia& icon) { |
| 54 notifier_.icon = icon; | 54 notifier_.icon = icon; |
| 55 if (icon.isNull()) { | 55 if (icon.isNull()) { |
| 56 delete icon_view_; | 56 delete icon_view_; |
| 57 icon_view_ = NULL; | 57 icon_view_ = NULL; |
| 58 } else { | 58 } else { |
| 59 if (!icon_view_) { | 59 if (!icon_view_) { |
| 60 icon_view_ = new views::ImageView(); | 60 icon_view_ = new views::ImageView(); |
| 61 AddChildViewAt(icon_view_, 1); | 61 AddChildViewAt(icon_view_, 1); |
| 62 } | 62 } |
| 63 icon_view_->SetImage(icon); | 63 icon_view_->SetImage(icon); |
| 64 icon_view_->SetImageSize(gfx::Size(kSettingsIconSize, kSettingsIconSize)); | 64 icon_view_->SetImageSize(gfx::Size(kSettingsIconSize, kSettingsIconSize)); |
| 65 } | 65 } |
| 66 SchedulePaint(); | 66 SchedulePaint(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetChecked(bool checked) { | 69 void SetChecked(bool checked) { |
| 70 checkbox_->SetChecked(checked); | 70 checkbox_->SetChecked(checked); |
| 71 notifier_.enabled = checked; | 71 notifier_.enabled = checked; |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool checked() const { | 74 bool checked() const { |
| 75 return checkbox_->checked(); | 75 return checkbox_->checked(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 std::string id() const { | 78 std::string id() const { |
| 79 return notifier_.id; | 79 return notifier_.id; |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 // views::ButtonListener overrides: |
| 83 void ButtonPressed(views::Button* button, const ui::Event& event) { | 84 void ButtonPressed(views::Button* button, const ui::Event& event) { |
| 84 DCHECK(button == checkbox_); | 85 DCHECK(button == checkbox_); |
| 85 // The checkbox state has already changed at this point, but we'll update | 86 // The checkbox state has already changed at this point, but we'll update |
| 86 // the state on NotifierSettingsView::ButtonPressed() too, so here change | 87 // the state on NotifierSettingsView::ButtonPressed() too, so here change |
| 87 // back to the previous state. | 88 // back to the previous state. |
| 88 checkbox_->SetChecked(!checkbox_->checked()); | 89 checkbox_->SetChecked(!checkbox_->checked()); |
| 89 CustomButton::NotifyClick(event); | 90 CustomButton::NotifyClick(event); |
| 90 } | 91 } |
| 91 | 92 |
| 92 NotifierSettingsView::Notifier notifier_; | 93 NotifierSettingsView::Notifier notifier_; |
| 93 views::ImageView* icon_view_; | 94 views::ImageView* icon_view_; |
| 94 views::Checkbox* checkbox_; | 95 views::Checkbox* checkbox_; |
| 95 | 96 |
| 96 DISALLOW_COPY_AND_ASSIGN(NotifierButton); | 97 DISALLOW_COPY_AND_ASSIGN(NotifierButton); |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 NotifierSettingsView::Notifier::Notifier( | 100 NotifierSettingsView::Notifier::Notifier( |
| 100 const std::string& id, | 101 const std::string& id, |
| 101 NotifierSettingsView::Notifier::NotifierType type, | 102 NotifierSettingsView::Notifier::NotifierType type, |
| 102 const string16& name) | 103 const string16& name) |
| 103 : id(id), | 104 : id(id), |
| 104 name(name), | 105 name(name), |
| 105 enabled(true), | 106 enabled(true), |
| 106 type(type) { | 107 type(type) { |
| 107 } | 108 } |
| 108 | 109 |
| 109 // static | 110 // static |
| 110 NotifierSettingsView* NotifierSettingsView::Create(Delegate* delegate) { | 111 NotifierSettingsView* NotifierSettingsView::Create(Delegate* delegate, |
| 112 gfx::NativeView context) { |
| 111 NotifierSettingsView* view = new NotifierSettingsView(delegate); | 113 NotifierSettingsView* view = new NotifierSettingsView(delegate); |
| 112 views::Widget* widget = new views::Widget; | 114 views::Widget* widget = new views::Widget; |
| 113 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 115 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 114 params.delegate = view; | 116 params.delegate = view; |
| 117 params.context = context; |
| 115 widget->Init(params); | 118 widget->Init(params); |
| 116 widget->Show(); | 119 widget->Show(); |
| 117 | 120 |
| 118 return view; | 121 return view; |
| 119 } | 122 } |
| 120 | 123 |
| 121 void NotifierSettingsView::UpdateIconImage(const std::string& id, | 124 void NotifierSettingsView::UpdateIconImage(const std::string& id, |
| 122 const gfx::ImageSkia& icon) { | 125 const gfx::ImageSkia& icon) { |
| 123 for (std::set<NotifierButton*>::iterator iter = buttons_.begin(); | 126 for (std::set<NotifierButton*>::iterator iter = buttons_.begin(); |
| 124 iter != buttons_.end(); ++iter) { | 127 iter != buttons_.end(); ++iter) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const ui::Event& event) { | 183 const ui::Event& event) { |
| 181 std::set<NotifierButton*>::iterator iter = buttons_.find( | 184 std::set<NotifierButton*>::iterator iter = buttons_.find( |
| 182 static_cast<NotifierButton*>(sender)); | 185 static_cast<NotifierButton*>(sender)); |
| 183 DCHECK(iter != buttons_.end()); | 186 DCHECK(iter != buttons_.end()); |
| 184 | 187 |
| 185 (*iter)->SetChecked(!(*iter)->checked()); | 188 (*iter)->SetChecked(!(*iter)->checked()); |
| 186 delegate_->SetNotifierEnabled((*iter)->id(), (*iter)->checked()); | 189 delegate_->SetNotifierEnabled((*iter)->id(), (*iter)->checked()); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace message_center | 192 } // namespace message_center |
| OLD | NEW |