Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: ui/message_center/views/notifier_settings_view.cc

Issue 2480813003: Reduce views::Border creation verbosity by promoting factory functions (Closed)
Patch Set: fix bad merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | ui/views/border.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 rb.GetImageSkiaNamed(IDR_NOTIFICATION_ADVANCED_SETTINGS_HOVER)); 267 rb.GetImageSkiaNamed(IDR_NOTIFICATION_ADVANCED_SETTINGS_HOVER));
268 learn_more_->SetImage( 268 learn_more_->SetImage(
269 views::Button::STATE_PRESSED, 269 views::Button::STATE_PRESSED,
270 rb.GetImageSkiaNamed(IDR_NOTIFICATION_ADVANCED_SETTINGS_PRESSED)); 270 rb.GetImageSkiaNamed(IDR_NOTIFICATION_ADVANCED_SETTINGS_PRESSED));
271 learn_more_->SetState(views::Button::STATE_NORMAL); 271 learn_more_->SetState(views::Button::STATE_NORMAL);
272 int learn_more_border_width = (kLearnMoreTargetWidth - kLearnMoreSize) / 2; 272 int learn_more_border_width = (kLearnMoreTargetWidth - kLearnMoreSize) / 2;
273 int learn_more_border_height = 273 int learn_more_border_height =
274 (kLearnMoreTargetHeight - kLearnMoreSize) / 2; 274 (kLearnMoreTargetHeight - kLearnMoreSize) / 2;
275 // The image itself is quite small, this large invisible border creates a 275 // The image itself is quite small, this large invisible border creates a
276 // much bigger click target. 276 // much bigger click target.
277 learn_more_->SetBorder( 277 learn_more_->SetBorder(views::CreateEmptyBorder(
278 views::Border::CreateEmptyBorder(learn_more_border_height, 278 learn_more_border_height, learn_more_border_width,
279 learn_more_border_width, 279 learn_more_border_height, learn_more_border_width));
280 learn_more_border_height,
281 learn_more_border_width));
282 learn_more_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, 280 learn_more_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
283 views::ImageButton::ALIGN_MIDDLE); 281 views::ImageButton::ALIGN_MIDDLE);
284 } 282 }
285 283
286 UpdateIconImage(notifier_->icon); 284 UpdateIconImage(notifier_->icon);
287 } 285 }
288 286
289 NotifierSettingsView::NotifierButton::~NotifierButton() { 287 NotifierSettingsView::NotifierButton::~NotifierButton() {
290 } 288 }
291 289
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); 428 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor));
431 SetPaintToLayer(true); 429 SetPaintToLayer(true);
432 430
433 title_label_ = new views::Label( 431 title_label_ = new views::Label(
434 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL), 432 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL),
435 ui::ResourceBundle::GetSharedInstance().GetFontList( 433 ui::ResourceBundle::GetSharedInstance().GetFontList(
436 ui::ResourceBundle::MediumFont)); 434 ui::ResourceBundle::MediumFont));
437 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 435 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
438 title_label_->SetMultiLine(true); 436 title_label_->SetMultiLine(true);
439 title_label_->SetBorder( 437 title_label_->SetBorder(
440 views::Border::CreateEmptyBorder(kComputedTitleTopMargin, 438 views::CreateEmptyBorder(kComputedTitleTopMargin, kTitleMargin,
441 kTitleMargin, 439 kComputedTitleBottomMargin, kTitleMargin));
442 kComputedTitleBottomMargin,
443 kTitleMargin));
444 440
445 AddChildView(title_label_); 441 AddChildView(title_label_);
446 442
447 scroller_ = new views::ScrollView(); 443 scroller_ = new views::ScrollView();
448 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); 444 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
449 AddChildView(scroller_); 445 AddChildView(scroller_);
450 446
451 std::vector<Notifier*> notifiers; 447 std::vector<Notifier*> notifiers;
452 if (provider_) 448 if (provider_)
453 provider_->GetNotifierList(&notifiers); 449 provider_->GetNotifierList(&notifiers);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 views::BoxLayout::kVertical, 0, 0, kComputedTitleElementSpacing)); 497 views::BoxLayout::kVertical, 0, 0, kComputedTitleElementSpacing));
502 498
503 bool need_account_switcher = 499 bool need_account_switcher =
504 provider_ && provider_->GetNotifierGroupCount() > 1; 500 provider_ && provider_->GetNotifierGroupCount() > 1;
505 int top_label_resource_id = 501 int top_label_resource_id =
506 need_account_switcher ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER 502 need_account_switcher ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER
507 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION; 503 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION;
508 504
509 views::Label* top_label = 505 views::Label* top_label =
510 new views::Label(l10n_util::GetStringUTF16(top_label_resource_id)); 506 new views::Label(l10n_util::GetStringUTF16(top_label_resource_id));
511 top_label->SetBorder(views::Border::CreateEmptyBorder( 507 top_label->SetBorder(views::CreateEmptyBorder(
512 gfx::Insets(0, kTitleMargin - settings::kHorizontalMargin))); 508 gfx::Insets(0, kTitleMargin - settings::kHorizontalMargin)));
513 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 509 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
514 top_label->SetMultiLine(true); 510 top_label->SetMultiLine(true);
515 511
516 contents_title_view->AddChildView(top_label); 512 contents_title_view->AddChildView(top_label);
517 513
518 if (need_account_switcher) { 514 if (need_account_switcher) {
519 const NotifierGroup& active_group = provider_->GetActiveNotifierGroup(); 515 const NotifierGroup& active_group = provider_->GetActiveNotifierGroup();
520 base::string16 notifier_group_text = active_group.login_info.empty() ? 516 base::string16 notifier_group_text = active_group.login_info.empty() ?
521 active_group.name : active_group.login_info; 517 active_group.name : active_group.login_info;
522 notifier_group_model_.reset(new NotifierGroupComboboxModel(provider_)); 518 notifier_group_model_.reset(new NotifierGroupComboboxModel(provider_));
523 notifier_group_combobox_ = new views::Combobox(notifier_group_model_.get()); 519 notifier_group_combobox_ = new views::Combobox(notifier_group_model_.get());
524 notifier_group_combobox_->set_listener(this); 520 notifier_group_combobox_->set_listener(this);
525 521
526 // Move the combobox over enough to align with the checkboxes. 522 // Move the combobox over enough to align with the checkboxes.
527 views::View* combobox_spacer = new views::View(); 523 views::View* combobox_spacer = new views::View();
528 combobox_spacer->SetLayoutManager(new views::FillLayout()); 524 combobox_spacer->SetLayoutManager(new views::FillLayout());
529 int padding = views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( 525 int padding = views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(
530 views::LabelButton::STYLE_TEXTBUTTON) 526 views::LabelButton::STYLE_TEXTBUTTON)
531 .left() - 527 .left() -
532 notifier_group_combobox_->border()->GetInsets().left(); 528 notifier_group_combobox_->border()->GetInsets().left();
533 combobox_spacer->SetBorder( 529 combobox_spacer->SetBorder(views::CreateEmptyBorder(0, padding, 0, 0));
534 views::Border::CreateEmptyBorder(0, padding, 0, 0));
535 combobox_spacer->AddChildView(notifier_group_combobox_); 530 combobox_spacer->AddChildView(notifier_group_combobox_);
536 531
537 contents_title_view->AddChildView(combobox_spacer); 532 contents_title_view->AddChildView(combobox_spacer);
538 } 533 }
539 534
540 contents_view->AddChildView(contents_title_view); 535 contents_view->AddChildView(contents_title_view);
541 536
542 size_t notifier_count = notifiers.size(); 537 size_t notifier_count = notifiers.size();
543 for (size_t i = 0; i < notifier_count; ++i) { 538 for (size_t i = 0; i < notifier_count; ++i) {
544 NotifierButton* button = new NotifierButton(provider_, notifiers[i], this); 539 NotifierButton* button = new NotifierButton(provider_, notifiers[i], this);
545 EntryView* entry = new EntryView(button); 540 EntryView* entry = new EntryView(button);
546 541
547 // This code emulates separators using borders. We will create an invisible 542 // This code emulates separators using borders. We will create an invisible
548 // border on the last notifier, as the spec leaves a space for it. 543 // border on the last notifier, as the spec leaves a space for it.
549 std::unique_ptr<views::Border> entry_border; 544 std::unique_ptr<views::Border> entry_border;
550 if (i == notifier_count - 1) { 545 if (i == notifier_count - 1) {
551 entry_border = views::Border::CreateEmptyBorder( 546 entry_border =
552 0, 0, settings::kEntrySeparatorHeight, 0); 547 views::CreateEmptyBorder(0, 0, settings::kEntrySeparatorHeight, 0);
553 } else { 548 } else {
554 entry_border = 549 entry_border =
555 views::Border::CreateSolidSidedBorder(0, 550 views::CreateSolidSidedBorder(0, 0, settings::kEntrySeparatorHeight,
556 0, 551 0, settings::kEntrySeparatorColor);
557 settings::kEntrySeparatorHeight,
558 0,
559 settings::kEntrySeparatorColor);
560 } 552 }
561 entry->SetBorder(std::move(entry_border)); 553 entry->SetBorder(std::move(entry_border));
562 entry->SetFocusBehavior(FocusBehavior::ALWAYS); 554 entry->SetFocusBehavior(FocusBehavior::ALWAYS);
563 contents_view->AddChildView(entry); 555 contents_view->AddChildView(entry);
564 buttons_.insert(button); 556 buttons_.insert(button);
565 } 557 }
566 558
567 scroller_->SetContents(contents_view); 559 scroller_->SetContents(contents_view);
568 560
569 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize())); 561 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize()));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 provider_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); 626 provider_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked());
635 } 627 }
636 628
637 void NotifierSettingsView::OnPerformAction(views::Combobox* combobox) { 629 void NotifierSettingsView::OnPerformAction(views::Combobox* combobox) {
638 provider_->SwitchToNotifierGroup(combobox->selected_index()); 630 provider_->SwitchToNotifierGroup(combobox->selected_index());
639 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); 631 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent());
640 center_view->OnSettingsChanged(); 632 center_view->OnSettingsChanged();
641 } 633 }
642 634
643 } // namespace message_center 635 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | ui/views/border.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698