Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" | 7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" |
| 8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
| 9 #include "chrome/grit/locale_settings.h" | 9 #include "chrome/grit/locale_settings.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/views/controls/button/label_button.h" | 11 #include "ui/views/controls/button/label_button.h" |
| 12 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
| 13 #include "ui/views/layout/grid_layout.h" | 13 #include "ui/views/layout/fill_layout.h" |
| 14 #include "ui/views/layout/layout_constants.h" | |
| 15 | 14 |
| 16 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( | 15 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( |
| 17 views::View* anchor_view, | 16 views::View* anchor_view, |
| 18 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) | 17 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) |
| 19 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 18 : views::BubbleDialogDelegateView(anchor_view, |
| 20 anchor_view_(anchor_view), | 19 views::BubbleBorder::TOP_RIGHT), |
| 21 delegate_(std::move(delegate)), | 20 delegate_(std::move(delegate)) { |
| 22 heading_label_(nullptr), | |
| 23 content_label_(nullptr), | |
| 24 dismiss_button_(nullptr), | |
| 25 action_button_(nullptr), | |
| 26 acknowledged_(false) { | |
| 27 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); | 21 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); |
| 28 } | 22 } |
| 29 | 23 |
| 30 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} | 24 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} |
| 31 | 25 |
| 32 void ToolbarActionsBarBubbleViews::Show() { | 26 void ToolbarActionsBarBubbleViews::Show() { |
| 33 delegate_->OnBubbleShown(); | 27 delegate_->OnBubbleShown(); |
| 34 GetWidget()->Show(); | 28 GetWidget()->Show(); |
| 35 } | 29 } |
| 36 | 30 |
| 31 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { | |
| 32 return delegate_->GetHeadingText(); | |
| 33 } | |
| 34 | |
| 35 bool ToolbarActionsBarBubbleViews::Cancel() { | |
|
Devlin
2016/04/13 00:38:58
Is this called when the user hits escape?
Evan Stade
2016/04/13 15:31:03
yes (DCV handles the esc accelerator by activating
| |
| 36 delegate_->OnBubbleClosed( | |
| 37 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 bool ToolbarActionsBarBubbleViews::Accept() { | |
| 42 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 bool ToolbarActionsBarBubbleViews::Close() { | |
| 47 delegate_->OnBubbleClosed( | |
| 48 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION); | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 int ToolbarActionsBarBubbleViews::GetDialogButtons() const { | |
| 53 int buttons = ui::DIALOG_BUTTON_OK; | |
| 54 if (!delegate_->GetDismissButtonText().empty()) | |
| 55 buttons |= ui::DIALOG_BUTTON_CANCEL; | |
| 56 return buttons; | |
| 57 } | |
| 58 | |
| 59 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( | |
| 60 ui::DialogButton button) const { | |
| 61 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() | |
| 62 : delegate_->GetDismissButtonText(); | |
| 63 } | |
| 64 | |
| 37 void ToolbarActionsBarBubbleViews::Init() { | 65 void ToolbarActionsBarBubbleViews::Init() { |
| 38 views::GridLayout* layout = new views::GridLayout(this); | 66 SetLayoutManager(new views::FillLayout()); |
| 39 layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin, | |
| 40 views::kPanelVertMargin, views::kPanelHorizMargin); | |
| 41 SetLayoutManager(layout); | |
| 42 | 67 |
| 43 enum ColumnSetId { | |
| 44 HEADER_AND_BODY_COLUMN_SET = 0, | |
| 45 BUTTON_STRIP_COLUMN_SET, | |
| 46 }; | |
| 47 | |
| 48 views::ColumnSet* header_and_body_cs = | |
| 49 layout->AddColumnSet(HEADER_AND_BODY_COLUMN_SET); | |
| 50 header_and_body_cs->AddColumn(views::GridLayout::TRAILING, | |
| 51 views::GridLayout::LEADING, 1, | |
| 52 views::GridLayout::USE_PREF, 0, 0); | |
| 53 views::ColumnSet* buttons_cs = layout->AddColumnSet(BUTTON_STRIP_COLUMN_SET); | |
| 54 buttons_cs->AddPaddingColumn(1, 0); | |
| 55 buttons_cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, | |
| 56 0, views::GridLayout::USE_PREF, 0, 0); | |
| 57 buttons_cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
| 58 buttons_cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, | |
| 59 0, views::GridLayout::USE_PREF, 0, 0); | |
| 60 | |
| 61 // Add a header. | |
| 62 layout->StartRow(0, HEADER_AND_BODY_COLUMN_SET); | |
| 63 heading_label_ = new views::Label(delegate_->GetHeadingText()); | |
| 64 heading_label_->SetFontList( | |
| 65 ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 66 ui::ResourceBundle::MediumFont)); | |
| 67 heading_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 68 layout->AddView(heading_label_); | |
| 69 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); | |
| 70 int width = views::Widget::GetLocalizedContentsWidth( | 68 int width = views::Widget::GetLocalizedContentsWidth( |
| 71 IDS_EXTENSION_TOOLBAR_REDESIGN_NOTIFICATION_BUBBLE_WIDTH_CHARS); | 69 IDS_EXTENSION_TOOLBAR_REDESIGN_NOTIFICATION_BUBBLE_WIDTH_CHARS); |
| 72 | |
| 73 // Add the content string. | 70 // Add the content string. |
| 74 layout->StartRow(0, HEADER_AND_BODY_COLUMN_SET); | 71 views::Label* content_label = new views::Label( |
| 75 content_label_ = new views::Label( | 72 delegate_->GetBodyText(GetAnchorView()->id() == VIEW_ID_BROWSER_ACTION)); |
| 76 delegate_->GetBodyText(anchor_view_->id() == VIEW_ID_BROWSER_ACTION)); | 73 content_label->SetMultiLine(true); |
| 77 content_label_->SetMultiLine(true); | 74 content_label->SizeToFit(width); |
| 78 content_label_->SizeToFit(width); | 75 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 79 content_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 76 AddChildView(content_label); |
| 80 layout->AddView(content_label_); | |
| 81 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); | |
| 82 | |
| 83 layout->StartRow(0, BUTTON_STRIP_COLUMN_SET); | |
| 84 base::string16 dismiss_button_text = delegate_->GetDismissButtonText(); | |
| 85 if (!dismiss_button_text.empty()) { | |
| 86 dismiss_button_ = new views::LabelButton(this, dismiss_button_text); | |
| 87 dismiss_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 88 layout->AddView(dismiss_button_, 1, 1, views::GridLayout::TRAILING, | |
| 89 views::GridLayout::FILL); | |
| 90 } else { | |
| 91 layout->SkipColumns(1); | |
| 92 } | |
| 93 | |
| 94 action_button_ = | |
| 95 new views::LabelButton(this, delegate_->GetActionButtonText()); | |
| 96 action_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 97 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, | |
| 98 views::GridLayout::FILL); | |
| 99 } | 77 } |
| 100 | |
| 101 void ToolbarActionsBarBubbleViews::OnWidgetDestroying(views::Widget* widget) { | |
| 102 BubbleDelegateView::OnWidgetDestroying(widget); | |
| 103 if (!acknowledged_) { | |
| 104 ToolbarActionsBarBubbleDelegate::CloseAction close_action = | |
| 105 close_reason() == CloseReason::DEACTIVATION | |
| 106 ? ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION | |
| 107 : ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION; | |
| 108 delegate_->OnBubbleClosed(close_action); | |
| 109 acknowledged_ = true; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 void ToolbarActionsBarBubbleViews::ButtonPressed(views::Button* sender, | |
| 114 const ui::Event& event) { | |
| 115 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | |
| 116 acknowledged_ = true; | |
| 117 GetWidget()->Close(); | |
| 118 } | |
| OLD | NEW |