Chromium Code Reviews| 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/views/notifier_settings_view.h" | 5 #include "ui/message_center/views/notifier_settings_view.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/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // The view to guarantee the 48px height and place the contents at the | 42 // The view to guarantee the 48px height and place the contents at the |
| 43 // middle. It also guarantee the left margin. | 43 // middle. It also guarantee the left margin. |
| 44 class EntryView : public views::View { | 44 class EntryView : public views::View { |
| 45 public: | 45 public: |
| 46 EntryView(views::View* contents); | 46 EntryView(views::View* contents); |
| 47 virtual ~EntryView(); | 47 virtual ~EntryView(); |
| 48 | 48 |
| 49 // Overridden from views::View: | 49 // Overridden from views::View: |
| 50 virtual void Layout() OVERRIDE; | 50 virtual void Layout() OVERRIDE; |
| 51 virtual gfx::Size GetPreferredSize() OVERRIDE; | 51 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 52 virtual void OnFocus() OVERRIDE; | |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(EntryView); | 55 DISALLOW_COPY_AND_ASSIGN(EntryView); |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 EntryView::EntryView(views::View* contents) { | 58 EntryView::EntryView(views::View* contents) { |
| 58 AddChildView(contents); | 59 AddChildView(contents); |
| 59 } | 60 } |
| 60 | 61 |
| 61 EntryView::~EntryView() { | 62 EntryView::~EntryView() { |
| 62 } | 63 } |
| 63 | 64 |
| 64 void EntryView::Layout() { | 65 void EntryView::Layout() { |
| 65 DCHECK_EQ(1, child_count()); | 66 DCHECK_EQ(1, child_count()); |
| 66 views::View* contents = child_at(0); | 67 views::View* contents = child_at(0); |
| 67 gfx::Size size = contents->GetPreferredSize(); | 68 int contents_width = width() - kMarginWidth * 2; |
| 69 int contents_height = contents->GetHeightForWidth(contents_width); | |
|
dharcourt
2013/04/05 16:07:03
Nit: contents_width/contents_height should be cont
Jun Mukai
2013/04/06 03:14:04
Done.
| |
| 68 int y = 0; | 70 int y = 0; |
| 69 if (size.height() < height()) | 71 if (contents_height < height()) |
| 70 y = (height() - size.height()) / 2; | 72 y = (height() - contents_height) / 2; |
|
dharcourt
2013/04/05 16:07:03
This _might_ be simpler as y = std::max((height()
Jun Mukai
2013/04/06 03:14:04
Done.
| |
| 71 contents->SetBounds(kMarginWidth, y, width() - kMarginWidth, size.height()); | 73 contents->SetBounds(kMarginWidth, y, contents_width, contents_height); |
| 72 } | 74 } |
| 73 | 75 |
| 74 gfx::Size EntryView::GetPreferredSize() { | 76 gfx::Size EntryView::GetPreferredSize() { |
| 75 DCHECK_EQ(1, child_count()); | 77 DCHECK_EQ(1, child_count()); |
| 76 gfx::Size size = child_at(0)->GetPreferredSize(); | 78 gfx::Size size = child_at(0)->GetPreferredSize(); |
| 77 size.ClampToMin(gfx::Size(kMinimumWindowWidth, kEntryHeight)); | 79 size.ClampToMin(gfx::Size(kMinimumWindowWidth, kEntryHeight)); |
| 78 return size; | 80 return size; |
| 79 } | 81 } |
| 80 | 82 |
| 83 void EntryView::OnFocus() { | |
| 84 ScrollRectToVisible(GetLocalBounds()); | |
| 85 } | |
| 86 | |
| 81 // The separator line between the title and the scroll view. Currently | 87 // The separator line between the title and the scroll view. Currently |
| 82 // it is achieved as a top border of the scroll view. | 88 // it is achieved as a top border of the scroll view. |
| 83 class Separator : public views::Border { | 89 class Separator : public views::Border { |
| 84 public: | 90 public: |
| 85 Separator(); | 91 Separator(); |
| 86 virtual ~Separator(); | 92 virtual ~Separator(); |
| 87 | 93 |
| 88 // Overridden from views::Border: | 94 // Overridden from views::Border: |
| 89 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | 95 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| 90 virtual gfx::Insets GetInsets() const OVERRIDE; | 96 virtual gfx::Insets GetInsets() const OVERRIDE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 NotifierButton(Notifier* notifier, views::ButtonListener* listener) | 140 NotifierButton(Notifier* notifier, views::ButtonListener* listener) |
| 135 : views::CustomButton(listener), | 141 : views::CustomButton(listener), |
| 136 notifier_(notifier), | 142 notifier_(notifier), |
| 137 icon_view_(NULL), | 143 icon_view_(NULL), |
| 138 checkbox_(new views::Checkbox(string16())) { | 144 checkbox_(new views::Checkbox(string16())) { |
| 139 DCHECK(notifier); | 145 DCHECK(notifier); |
| 140 SetLayoutManager(new views::BoxLayout( | 146 SetLayoutManager(new views::BoxLayout( |
| 141 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); | 147 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); |
| 142 checkbox_->SetChecked(notifier_->enabled); | 148 checkbox_->SetChecked(notifier_->enabled); |
| 143 checkbox_->set_listener(this); | 149 checkbox_->set_listener(this); |
| 144 checkbox_->set_focusable(true); | 150 checkbox_->set_focusable(false); |
|
dewittj
2013/04/05 20:48:41
I believe you could just remove this line, since f
Jun Mukai
2013/04/06 03:14:04
Done.
| |
| 145 AddChildView(checkbox_); | 151 AddChildView(checkbox_); |
| 146 UpdateIconImage(notifier_->icon); | 152 UpdateIconImage(notifier_->icon); |
| 147 AddChildView(new views::Label(notifier_->name)); | 153 AddChildView(new views::Label(notifier_->name)); |
| 148 } | 154 } |
| 149 | 155 |
| 150 void UpdateIconImage(const gfx::Image& icon) { | 156 void UpdateIconImage(const gfx::Image& icon) { |
| 151 notifier_->icon = icon; | 157 notifier_->icon = icon; |
| 152 if (icon.IsEmpty()) { | 158 if (icon.IsEmpty()) { |
| 153 delete icon_view_; | 159 delete icon_view_; |
| 154 icon_view_ = NULL; | 160 icon_view_ = NULL; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 AddChildView(scroller_); | 263 AddChildView(scroller_); |
| 258 | 264 |
| 259 views::View* contents_view = new views::View(); | 265 views::View* contents_view = new views::View(); |
| 260 contents_view->SetLayoutManager(new views::BoxLayout( | 266 contents_view->SetLayoutManager(new views::BoxLayout( |
| 261 views::BoxLayout::kVertical, 0, 0, 0)); | 267 views::BoxLayout::kVertical, 0, 0, 0)); |
| 262 | 268 |
| 263 views::Label* top_label = new views::Label(l10n_util::GetStringUTF16( | 269 views::Label* top_label = new views::Label(l10n_util::GetStringUTF16( |
| 264 IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)); | 270 IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)); |
| 265 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 271 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 266 top_label->SetMultiLine(true); | 272 top_label->SetMultiLine(true); |
| 267 top_label->SizeToFit(kMinimumWindowWidth - kMarginWidth); | 273 top_label->SizeToFit(kMinimumWindowWidth - kMarginWidth * 2); |
| 268 contents_view->AddChildView(new EntryView(top_label)); | 274 contents_view->AddChildView(new EntryView(top_label)); |
| 269 | 275 |
| 270 std::vector<Notifier*> notifiers; | 276 std::vector<Notifier*> notifiers; |
| 271 delegate_->GetNotifierList(¬ifiers); | 277 delegate_->GetNotifierList(¬ifiers); |
| 272 for (size_t i = 0; i < notifiers.size(); ++i) { | 278 for (size_t i = 0; i < notifiers.size(); ++i) { |
| 273 NotifierButton* button = new NotifierButton(notifiers[i], this); | 279 NotifierButton* button = new NotifierButton(notifiers[i], this); |
| 274 contents_view->AddChildView(new EntryView(button)); | 280 EntryView* entry = new EntryView(button); |
| 281 entry->set_focusable(true); | |
| 282 contents_view->AddChildView(entry); | |
| 275 buttons_.insert(button); | 283 buttons_.insert(button); |
| 276 } | 284 } |
| 277 scroller_->SetContents(contents_view); | 285 scroller_->SetContents(contents_view); |
| 278 | 286 |
| 279 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize())); | 287 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize())); |
| 280 } | 288 } |
| 281 | 289 |
| 282 NotifierSettingsView::~NotifierSettingsView() { | 290 NotifierSettingsView::~NotifierSettingsView() { |
| 283 settings_view_ = NULL; | 291 settings_view_ = NULL; |
| 284 } | 292 } |
| 285 | 293 |
| 286 void NotifierSettingsView::WindowClosing() { | 294 void NotifierSettingsView::WindowClosing() { |
| 287 if (delegate_) | 295 if (delegate_) |
| 288 delegate_->OnNotifierSettingsClosing(); | 296 delegate_->OnNotifierSettingsClosing(); |
| 289 } | 297 } |
| 290 | 298 |
| 291 views::View* NotifierSettingsView::GetContentsView() { | 299 views::View* NotifierSettingsView::GetContentsView() { |
| 292 return this; | 300 return this; |
| 293 } | 301 } |
| 294 | 302 |
| 295 bool NotifierSettingsView::CanResize() const { | 303 bool NotifierSettingsView::CanResize() const { |
| 296 return true; | 304 return true; |
| 297 } | 305 } |
| 298 | 306 |
| 299 void NotifierSettingsView::Layout() { | 307 void NotifierSettingsView::Layout() { |
| 300 int title_height = title_entry_->GetPreferredSize().height(); | 308 int title_height = title_entry_->GetPreferredSize().height(); |
| 301 title_entry_->SetBounds(0, 0, width(), title_height); | 309 title_entry_->SetBounds(0, 0, width(), title_height); |
| 310 views::View* contents_view = scroller_->contents(); | |
|
dewittj
2013/04/05 20:48:41
You are more familiar with scroll views than me bu
Jun Mukai
2013/04/06 03:14:04
That is a tricky part of the scroll view.
The size
| |
| 311 int contents_width = width(); | |
| 312 int contents_height = contents_view->GetHeightForWidth(contents_width); | |
|
dharcourt
2013/04/05 16:07:03
Nit: Same contents_width/contents_height -> conten
Jun Mukai
2013/04/06 03:14:04
Done.
| |
| 313 if (title_height + contents_height > kMinimumWindowHeight) { | |
| 314 contents_width -= scroller_->GetScrollBarWidth(); | |
| 315 contents_height = contents_view->GetHeightForWidth(contents_width); | |
| 316 } | |
| 317 contents_view->SetBounds(0, 0, contents_width, contents_height); | |
| 302 scroller_->SetBounds(0, title_height, width(), height() - title_height); | 318 scroller_->SetBounds(0, title_height, width(), height() - title_height); |
| 303 } | 319 } |
| 304 | 320 |
| 305 gfx::Size NotifierSettingsView::GetMinimumSize() { | 321 gfx::Size NotifierSettingsView::GetMinimumSize() { |
| 306 gfx::Size size(kMinimumWindowWidth, kMinimumWindowHeight); | 322 gfx::Size size(kMinimumWindowWidth, kMinimumWindowHeight); |
| 307 int total_height = title_entry_->GetPreferredSize().height() + | 323 int total_height = title_entry_->GetPreferredSize().height() + |
| 308 scroller_->contents()->GetPreferredSize().height(); | 324 scroller_->contents()->GetPreferredSize().height(); |
| 309 if (total_height > kMinimumWindowHeight) | 325 if (total_height > kMinimumWindowHeight) |
| 310 size.Enlarge(scroller_->GetScrollBarWidth(), 0); | 326 size.Enlarge(scroller_->GetScrollBarWidth(), 0); |
| 311 return size; | 327 return size; |
| 312 } | 328 } |
| 313 | 329 |
| 314 gfx::Size NotifierSettingsView::GetPreferredSize() { | 330 gfx::Size NotifierSettingsView::GetPreferredSize() { |
| 315 return GetMinimumSize(); | 331 return GetMinimumSize(); |
| 316 } | 332 } |
| 317 | 333 |
| 318 void NotifierSettingsView::ButtonPressed(views::Button* sender, | 334 void NotifierSettingsView::ButtonPressed(views::Button* sender, |
| 319 const ui::Event& event) { | 335 const ui::Event& event) { |
| 320 std::set<NotifierButton*>::iterator iter = buttons_.find( | 336 std::set<NotifierButton*>::iterator iter = buttons_.find( |
| 321 static_cast<NotifierButton*>(sender)); | 337 static_cast<NotifierButton*>(sender)); |
| 322 DCHECK(iter != buttons_.end()); | 338 DCHECK(iter != buttons_.end()); |
| 323 | 339 |
| 324 (*iter)->SetChecked(!(*iter)->checked()); | 340 (*iter)->SetChecked(!(*iter)->checked()); |
| 325 if (delegate_) | 341 if (delegate_) |
| 326 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); | 342 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); |
| 327 } | 343 } |
| 328 | 344 |
| 329 } // namespace message_center | 345 } // namespace message_center |
| OLD | NEW |