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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "ui/views/layout/grid_layout.h" | 38 #include "ui/views/layout/grid_layout.h" |
39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
40 | 40 |
41 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
42 #include "ui/aura/window.h" | 42 #include "ui/aura/window.h" |
43 #endif | 43 #endif |
44 | 44 |
45 namespace message_center { | 45 namespace message_center { |
46 namespace { | 46 namespace { |
47 const int kButtonPainterInsets = 5; | 47 const int kButtonPainterInsets = 5; |
48 const int kMarginWidth = 20; | 48 // We really want the margin to be 20px, but various views are padded by |
49 const int kMenuButtonLeftPadding = 11; | 49 // whitespace. |
50 const int kMenuButtonRightPadding = 14; | 50 const int kDesiredMargin = 20; |
| 51 // The MenuButton has 2px whitespace built-in. |
| 52 const int kMenuButtonInnateMargin = 2; |
| 53 const int kMinimumHorizontalMargin = kDesiredMargin - kMenuButtonInnateMargin; |
| 54 // The EntryViews' leftmost view is a checkbox with 1px whitespace built in, so |
| 55 // the margin for entry views should be one less than the target margin. |
| 56 const int kCheckboxInnateMargin = 1; |
| 57 const int kEntryMargin = kDesiredMargin - kCheckboxInnateMargin; |
| 58 const int kMenuButtonLeftPadding = 12; |
| 59 const int kMenuButtonRightPadding = 13; |
51 const int kMenuButtonVerticalPadding = 9; | 60 const int kMenuButtonVerticalPadding = 9; |
| 61 const int kMenuWhitespaceOffset = 2; |
52 const int kMinimumWindowHeight = 480; | 62 const int kMinimumWindowHeight = 480; |
53 const int kMinimumWindowWidth = 320; | 63 const int kMinimumWindowWidth = 320; |
54 const int kSettingsTitleBottomMargin = 7; | 64 const int kSettingsTitleBottomMargin = 12; |
55 const int kSettingsTitleTopMargin = 15; | 65 const int kSettingsTitleTopMargin = 15; |
56 const int kSpaceInButtonComponents = 16; | 66 const int kSpaceInButtonComponents = 16; |
| 67 const int kTitleVerticalMargin = 1; |
| 68 const int kTitleElementSpacing = 10; |
57 const int kEntryHeight = kMinimumWindowHeight / 10; | 69 const int kEntryHeight = kMinimumWindowHeight / 10; |
58 | 70 |
59 // The view to guarantee the 48px height and place the contents at the | 71 // The view to guarantee the 48px height and place the contents at the |
60 // middle. It also guarantee the left margin. | 72 // middle. It also guarantee the left margin. |
61 class EntryView : public views::View { | 73 class EntryView : public views::View { |
62 public: | 74 public: |
63 EntryView(views::View* contents); | 75 EntryView(views::View* contents); |
64 virtual ~EntryView(); | 76 virtual ~EntryView(); |
65 | 77 |
66 // Overridden from views::View: | 78 // Overridden from views::View: |
(...skipping 12 matching lines...) Expand all Loading... |
79 EntryView::EntryView(views::View* contents) { | 91 EntryView::EntryView(views::View* contents) { |
80 AddChildView(contents); | 92 AddChildView(contents); |
81 } | 93 } |
82 | 94 |
83 EntryView::~EntryView() { | 95 EntryView::~EntryView() { |
84 } | 96 } |
85 | 97 |
86 void EntryView::Layout() { | 98 void EntryView::Layout() { |
87 DCHECK_EQ(1, child_count()); | 99 DCHECK_EQ(1, child_count()); |
88 views::View* content = child_at(0); | 100 views::View* content = child_at(0); |
89 int content_width = width() - kMarginWidth * 2; | 101 int content_width = width() - kEntryMargin * 2; |
90 int content_height = content->GetHeightForWidth(content_width); | 102 int content_height = content->GetHeightForWidth(content_width); |
91 int y = std::max((height() - content_height) / 2, 0); | 103 int y = std::max((height() - content_height) / 2, 0); |
92 content->SetBounds(kMarginWidth, y, content_width, content_height); | 104 content->SetBounds(kEntryMargin, y, content_width, content_height); |
93 } | 105 } |
94 | 106 |
95 gfx::Size EntryView::GetPreferredSize() { | 107 gfx::Size EntryView::GetPreferredSize() { |
96 DCHECK_EQ(1, child_count()); | 108 DCHECK_EQ(1, child_count()); |
97 gfx::Size size = child_at(0)->GetPreferredSize(); | 109 gfx::Size size = child_at(0)->GetPreferredSize(); |
98 size.SetToMax(gfx::Size(kMinimumWindowWidth, kEntryHeight)); | 110 size.SetToMax(gfx::Size(kMinimumWindowWidth, kEntryHeight)); |
99 return size; | 111 return size; |
100 } | 112 } |
101 | 113 |
102 void EntryView::GetAccessibleState(ui::AccessibleViewState* state) { | 114 void EntryView::GetAccessibleState(ui::AccessibleViewState* state) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 : ui::SimpleMenuModel(this), | 197 : ui::SimpleMenuModel(this), |
186 notifier_settings_provider_(notifier_settings_provider) { | 198 notifier_settings_provider_(notifier_settings_provider) { |
187 if (!notifier_settings_provider_) | 199 if (!notifier_settings_provider_) |
188 return; | 200 return; |
189 | 201 |
190 size_t num_menu_items = notifier_settings_provider_->GetNotifierGroupCount(); | 202 size_t num_menu_items = notifier_settings_provider_->GetNotifierGroupCount(); |
191 for (size_t i = 0; i < num_menu_items; ++i) { | 203 for (size_t i = 0; i < num_menu_items; ++i) { |
192 const NotifierGroup& group = | 204 const NotifierGroup& group = |
193 notifier_settings_provider_->GetNotifierGroupAt(i); | 205 notifier_settings_provider_->GetNotifierGroupAt(i); |
194 | 206 |
195 AddItem(i, group.login_info.empty() ? group.name : group.login_info); | 207 AddCheckItem(i, group.login_info.empty() ? group.name : group.login_info); |
196 } | 208 } |
197 } | 209 } |
198 | 210 |
199 NotifierGroupMenuModel::~NotifierGroupMenuModel() {} | 211 NotifierGroupMenuModel::~NotifierGroupMenuModel() {} |
200 | 212 |
201 bool NotifierGroupMenuModel::IsCommandIdChecked(int command_id) const { | 213 bool NotifierGroupMenuModel::IsCommandIdChecked(int command_id) const { |
202 return false; | 214 // If there's no provider, assume only one notifier group - the active one. |
| 215 if (!notifier_settings_provider_) |
| 216 return true; |
| 217 |
| 218 return notifier_settings_provider_->IsNotifierGroupActiveAt(command_id); |
203 } | 219 } |
204 | 220 |
205 bool NotifierGroupMenuModel::IsCommandIdEnabled(int command_id) const { | 221 bool NotifierGroupMenuModel::IsCommandIdEnabled(int command_id) const { |
206 return true; | 222 return true; |
207 } | 223 } |
208 | 224 |
209 bool NotifierGroupMenuModel::GetAcceleratorForCommandId( | 225 bool NotifierGroupMenuModel::GetAcceleratorForCommandId( |
210 int command_id, | 226 int command_id, |
211 ui::Accelerator* accelerator) { | 227 ui::Accelerator* accelerator) { |
212 return false; | 228 return false; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 310 } |
295 | 311 |
296 scoped_ptr<Notifier> notifier_; | 312 scoped_ptr<Notifier> notifier_; |
297 views::ImageView* icon_view_; | 313 views::ImageView* icon_view_; |
298 views::Checkbox* checkbox_; | 314 views::Checkbox* checkbox_; |
299 | 315 |
300 DISALLOW_COPY_AND_ASSIGN(NotifierButton); | 316 DISALLOW_COPY_AND_ASSIGN(NotifierButton); |
301 }; | 317 }; |
302 | 318 |
303 NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider) | 319 NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider) |
304 : provider_(provider) { | 320 : title_arrow_(NULL), |
| 321 title_label_(NULL), |
| 322 notifier_group_selector_(NULL), |
| 323 scroller_(NULL), |
| 324 provider_(provider) { |
305 // |provider_| may be NULL in tests. | 325 // |provider_| may be NULL in tests. |
306 if (provider_) | 326 if (provider_) |
307 provider_->AddObserver(this); | 327 provider_->AddObserver(this); |
308 | 328 |
309 set_focusable(true); | 329 set_focusable(true); |
310 set_focus_border(NULL); | 330 set_focus_border(NULL); |
311 set_background(views::Background::CreateSolidBackground( | 331 set_background(views::Background::CreateSolidBackground( |
312 kMessageCenterBackgroundColor)); | 332 kMessageCenterBackgroundColor)); |
313 if (get_use_acceleration_when_possible()) | 333 if (get_use_acceleration_when_possible()) |
314 SetPaintToLayer(true); | 334 SetPaintToLayer(true); |
315 | 335 |
316 gfx::Font title_font = | 336 gfx::Font title_font = |
317 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); | 337 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); |
318 title_label_ = new views::Label( | 338 title_label_ = new views::Label( |
319 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL), | 339 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL), |
320 title_font); | 340 title_font); |
321 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 341 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
322 title_label_->SetMultiLine(true); | 342 title_label_->SetMultiLine(true); |
323 title_label_->set_border( | 343 title_label_->set_border( |
324 views::Border::CreateEmptyBorder(kSettingsTitleTopMargin, | 344 views::Border::CreateEmptyBorder(kSettingsTitleTopMargin, |
325 kMarginWidth, | 345 kDesiredMargin, |
326 kSettingsTitleBottomMargin, | 346 kSettingsTitleBottomMargin, |
327 kMarginWidth)); | 347 kDesiredMargin)); |
328 | 348 |
329 AddChildView(title_label_); | 349 AddChildView(title_label_); |
330 | 350 |
331 scroller_ = new views::ScrollView(); | 351 scroller_ = new views::ScrollView(); |
332 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); | 352 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
333 AddChildView(scroller_); | 353 AddChildView(scroller_); |
334 | 354 |
335 std::vector<Notifier*> notifiers; | 355 std::vector<Notifier*> notifiers; |
336 if (provider_) | 356 if (provider_) |
337 provider_->GetNotifierList(¬ifiers); | 357 provider_->GetNotifierList(¬ifiers); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 void NotifierSettingsView::UpdateContentsView( | 391 void NotifierSettingsView::UpdateContentsView( |
372 const std::vector<Notifier*>& notifiers) { | 392 const std::vector<Notifier*>& notifiers) { |
373 buttons_.clear(); | 393 buttons_.clear(); |
374 | 394 |
375 views::View* contents_view = new views::View(); | 395 views::View* contents_view = new views::View(); |
376 contents_view->SetLayoutManager( | 396 contents_view->SetLayoutManager( |
377 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 397 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
378 | 398 |
379 views::View* contents_title_view = new views::View(); | 399 views::View* contents_title_view = new views::View(); |
380 contents_title_view->SetLayoutManager( | 400 contents_title_view->SetLayoutManager( |
381 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 5)); | 401 new views::BoxLayout(views::BoxLayout::kVertical, |
| 402 kMinimumHorizontalMargin, |
| 403 kTitleVerticalMargin, |
| 404 kTitleElementSpacing)); |
382 | 405 |
383 bool need_account_switcher = | 406 bool need_account_switcher = |
384 provider_ && provider_->GetNotifierGroupCount() > 1; | 407 provider_ && provider_->GetNotifierGroupCount() > 1; |
385 int top_label_resource_id = | 408 int top_label_resource_id = |
386 need_account_switcher ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER | 409 need_account_switcher ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER |
387 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION; | 410 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION; |
388 | 411 |
389 views::Label* top_label = | 412 views::Label* top_label = |
390 new views::Label(l10n_util::GetStringUTF16(top_label_resource_id)); | 413 new views::Label(l10n_util::GetStringUTF16(top_label_resource_id)); |
391 | 414 |
392 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 415 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
393 top_label->SetMultiLine(true); | 416 top_label->SetMultiLine(true); |
| 417 top_label->set_border(views::Border::CreateEmptyBorder( |
| 418 0, kMenuButtonInnateMargin, 0, kMenuButtonInnateMargin)); |
394 contents_title_view->AddChildView(top_label); | 419 contents_title_view->AddChildView(top_label); |
395 | 420 |
396 string16 notifier_group_text; | 421 string16 notifier_group_text; |
397 if (provider_) { | 422 if (provider_) { |
398 const NotifierGroup& active_group = provider_->GetActiveNotifierGroup(); | 423 const NotifierGroup& active_group = provider_->GetActiveNotifierGroup(); |
399 notifier_group_text = active_group.login_info.empty() | 424 notifier_group_text = active_group.login_info.empty() |
400 ? active_group.name | 425 ? active_group.name |
401 : active_group.login_info; | 426 : active_group.login_info; |
402 } | 427 } |
403 | 428 |
404 if (need_account_switcher) { | 429 if (need_account_switcher) { |
405 views::MenuButton* notifier_group_selector = | 430 notifier_group_selector_ = |
406 new views::MenuButton(NULL, notifier_group_text, this, true); | 431 new views::MenuButton(NULL, notifier_group_text, this, true); |
407 notifier_group_selector->set_border(new NotifierGroupMenuButtonBorder); | 432 notifier_group_selector_->set_border(new NotifierGroupMenuButtonBorder); |
408 notifier_group_selector->set_focus_border(NULL); | 433 notifier_group_selector_->set_focus_border(NULL); |
409 notifier_group_selector->set_animate_on_state_change(false); | 434 notifier_group_selector_->set_animate_on_state_change(false); |
410 notifier_group_selector->set_focusable(true); | 435 notifier_group_selector_->set_focusable(true); |
411 contents_title_view->AddChildView(notifier_group_selector); | 436 contents_title_view->AddChildView(notifier_group_selector_); |
412 } | 437 } |
413 | 438 |
414 contents_view->AddChildView(new EntryView(contents_title_view)); | 439 contents_view->AddChildView(contents_title_view); |
415 | 440 |
416 for (size_t i = 0; i < notifiers.size(); ++i) { | 441 for (size_t i = 0; i < notifiers.size(); ++i) { |
417 NotifierButton* button = new NotifierButton(notifiers[i], this); | 442 NotifierButton* button = new NotifierButton(notifiers[i], this); |
418 EntryView* entry = new EntryView(button); | 443 EntryView* entry = new EntryView(button); |
419 entry->set_focusable(true); | 444 entry->set_focusable(true); |
420 contents_view->AddChildView(entry); | 445 contents_view->AddChildView(entry); |
421 buttons_.insert(button); | 446 buttons_.insert(button); |
422 } | 447 } |
423 | 448 |
424 scroller_->SetContents(contents_view); | 449 scroller_->SetContents(contents_view); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 (*iter)->SetChecked(!(*iter)->checked()); | 515 (*iter)->SetChecked(!(*iter)->checked()); |
491 if (provider_) | 516 if (provider_) |
492 provider_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); | 517 provider_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); |
493 } | 518 } |
494 | 519 |
495 void NotifierSettingsView::OnMenuButtonClicked(views::View* source, | 520 void NotifierSettingsView::OnMenuButtonClicked(views::View* source, |
496 const gfx::Point& point) { | 521 const gfx::Point& point) { |
497 notifier_group_menu_model_.reset(new NotifierGroupMenuModel(provider_)); | 522 notifier_group_menu_model_.reset(new NotifierGroupMenuModel(provider_)); |
498 notifier_group_menu_runner_.reset( | 523 notifier_group_menu_runner_.reset( |
499 new views::MenuRunner(notifier_group_menu_model_.get())); | 524 new views::MenuRunner(notifier_group_menu_model_.get())); |
| 525 gfx::Rect menu_anchor = source->GetBoundsInScreen(); |
| 526 menu_anchor.Inset( |
| 527 gfx::Insets(0, kMenuWhitespaceOffset, 0, kMenuWhitespaceOffset)); |
500 if (views::MenuRunner::MENU_DELETED == | 528 if (views::MenuRunner::MENU_DELETED == |
501 notifier_group_menu_runner_->RunMenuAt(GetWidget(), | 529 notifier_group_menu_runner_->RunMenuAt(GetWidget(), |
502 NULL, | 530 notifier_group_selector_, |
503 source->GetBoundsInScreen(), | 531 menu_anchor, |
504 views::MenuItemView::BUBBLE_ABOVE, | 532 views::MenuItemView::BUBBLE_ABOVE, |
505 ui::MENU_SOURCE_MOUSE, | 533 ui::MENU_SOURCE_MOUSE, |
506 views::MenuRunner::CONTEXT_MENU)) | 534 views::MenuRunner::CONTEXT_MENU)) |
507 return; | 535 return; |
508 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); | 536 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); |
509 center_view->OnSettingsChanged(); | 537 center_view->OnSettingsChanged(); |
510 } | 538 } |
511 | 539 |
512 } // namespace message_center | 540 } // namespace message_center |
OLD | NEW |