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/gfx/color_palette.h" | |
| 12 #include "ui/gfx/paint_vector_icon.h" | |
| 13 #include "ui/gfx/vector_icons_public.h" | |
| 11 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/controls/image_view.h" | |
| 12 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 13 #include "ui/views/controls/link.h" | 17 #include "ui/views/controls/link.h" |
| 14 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
| 15 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
| 16 | 20 |
| 17 namespace { | 21 namespace { |
| 18 const int kListPadding = 10; | 22 const int kListPadding = 10; |
| 19 } | 23 } |
| 20 | 24 |
| 21 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( | 25 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( |
| 22 views::View* anchor_view, | 26 views::View* anchor_view, |
| 23 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) | 27 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) |
| 24 : views::BubbleDialogDelegateView(anchor_view, | 28 : views::BubbleDialogDelegateView(anchor_view, |
| 25 views::BubbleBorder::TOP_RIGHT), | 29 views::BubbleBorder::TOP_RIGHT), |
| 26 delegate_(std::move(delegate)), | 30 delegate_(std::move(delegate)), |
| 27 item_list_(nullptr), | 31 item_list_(nullptr), |
| 28 learn_more_button_(nullptr) { | 32 link_(nullptr) { |
| 29 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); | 33 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); |
| 30 } | 34 } |
| 31 | 35 |
| 32 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} | 36 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} |
| 33 | 37 |
| 34 void ToolbarActionsBarBubbleViews::Show() { | 38 void ToolbarActionsBarBubbleViews::Show() { |
| 35 delegate_->OnBubbleShown(); | 39 delegate_->OnBubbleShown(); |
| 36 GetWidget()->Show(); | 40 GetWidget()->Show(); |
| 37 } | 41 } |
| 38 | 42 |
| 39 views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { | 43 views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { |
| 40 base::string16 text = delegate_->GetLearnMoreButtonText(); | 44 std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo> |
| 41 if (text.empty()) | 45 extra_view_info = delegate_->GetExtraViewInfo(); |
| 46 | |
| 47 if (!extra_view_info) | |
| 42 return nullptr; | 48 return nullptr; |
| 43 | 49 |
| 44 learn_more_button_ = new views::Link(text); | 50 gfx::VectorIconId resource_id = extra_view_info->resource_id; |
| 45 learn_more_button_->set_listener(this); | 51 views::ImageView* icon = nullptr; |
| 46 return learn_more_button_; | 52 if (resource_id != gfx::VectorIconId::VECTOR_ICON_NONE) { |
| 53 icon = new views::ImageView(); | |
|
Devlin
2016/10/20 17:04:07
nit: I know this is all safe, but this method is l
catmullings
2016/10/21 03:49:29
Done.
| |
| 54 icon->SetImage( | |
| 55 gfx::CreateVectorIcon(resource_id, 16, gfx::kChromeIconGrey)); | |
| 56 } | |
| 57 | |
| 58 views::Label* label = nullptr; | |
| 59 const base::string16& text = extra_view_info->text; | |
| 60 if (!text.empty()) { | |
| 61 if (extra_view_info->is_text_linked) { | |
| 62 link_ = new views::Link(text); | |
| 63 link_->set_listener(this); | |
| 64 label = link_; | |
| 65 } else { | |
| 66 label = new views::Label(text); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 if (icon && label) { | |
| 71 views::View* parent = new views::View(); | |
| 72 parent->SetLayoutManager( | |
| 73 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | |
| 74 views::kRelatedControlVerticalSpacing)); | |
| 75 parent->AddChildView(icon); | |
| 76 parent->AddChildView(label); | |
| 77 return parent; | |
| 78 } | |
| 79 | |
| 80 return icon ? static_cast<views::View*>(icon) | |
| 81 : static_cast<views::View*>(label); | |
| 47 } | 82 } |
| 48 | 83 |
| 49 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { | 84 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { |
| 50 return delegate_->GetHeadingText(); | 85 return delegate_->GetHeadingText(); |
| 51 } | 86 } |
| 52 | 87 |
| 53 bool ToolbarActionsBarBubbleViews::Cancel() { | 88 bool ToolbarActionsBarBubbleViews::Cancel() { |
| 54 delegate_->OnBubbleClosed( | 89 delegate_->OnBubbleClosed( |
| 55 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 90 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
| 56 return true; | 91 return true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 item_list_->SetBorder( | 124 item_list_->SetBorder( |
| 90 views::Border::CreateEmptyBorder(0, kListPadding, 0, 0)); | 125 views::Border::CreateEmptyBorder(0, kListPadding, 0, 0)); |
| 91 item_list_->SetMultiLine(true); | 126 item_list_->SetMultiLine(true); |
| 92 item_list_->SizeToFit(width); | 127 item_list_->SizeToFit(width); |
| 93 item_list_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 128 item_list_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 94 AddChildView(item_list_); | 129 AddChildView(item_list_); |
| 95 } | 130 } |
| 96 } | 131 } |
| 97 | 132 |
| 98 int ToolbarActionsBarBubbleViews::GetDialogButtons() const { | 133 int ToolbarActionsBarBubbleViews::GetDialogButtons() const { |
| 99 int buttons = ui::DIALOG_BUTTON_OK; | 134 int buttons = ui::DIALOG_BUTTON_NONE; |
| 135 if (!delegate_->GetActionButtonText().empty()) | |
| 136 buttons |= ui::DIALOG_BUTTON_OK; | |
| 100 if (!delegate_->GetDismissButtonText().empty()) | 137 if (!delegate_->GetDismissButtonText().empty()) |
| 101 buttons |= ui::DIALOG_BUTTON_CANCEL; | 138 buttons |= ui::DIALOG_BUTTON_CANCEL; |
| 102 return buttons; | 139 return buttons; |
| 103 } | 140 } |
| 104 | 141 |
| 105 int ToolbarActionsBarBubbleViews::GetDefaultDialogButton() const { | 142 int ToolbarActionsBarBubbleViews::GetDefaultDialogButton() const { |
| 106 // TODO(estade): we should set a default where approprite. See | 143 // TODO(estade): we should set a default where approprite. See |
| 107 // http://crbug.com/621122 | 144 // http://crbug.com/621122 |
| 108 return ui::DIALOG_BUTTON_NONE; | 145 return ui::DIALOG_BUTTON_NONE; |
| 109 } | 146 } |
| 110 | 147 |
| 111 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( | 148 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( |
| 112 ui::DialogButton button) const { | 149 ui::DialogButton button) const { |
| 113 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() | 150 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() |
| 114 : delegate_->GetDismissButtonText(); | 151 : delegate_->GetDismissButtonText(); |
| 115 } | 152 } |
| 116 | 153 |
| 117 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 154 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
| 118 int event_flags) { | 155 int event_flags) { |
| 119 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 156 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 120 // Reset delegate so we don't send extra OnBubbleClosed()s. | 157 // Reset delegate so we don't send extra OnBubbleClosed()s. |
| 121 delegate_.reset(); | 158 delegate_.reset(); |
| 122 GetWidget()->Close(); | 159 GetWidget()->Close(); |
| 123 } | 160 } |
| OLD | NEW |