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

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

Powered by Google App Engine
This is Rietveld 408576698