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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc

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

Powered by Google App Engine
This is Rietveld 408576698