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

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

Issue 2827603005: Cater for the "double close" when clicking "Learn More" on auto-dismiss extension bubbles. (Closed)
Patch Set: resilience Created 3 years, 8 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
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/harmony/chrome_layout_provider.h" 7 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
8 #include "chrome/grit/locale_settings.h" 8 #include "chrome/grit/locale_settings.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
11 #include "ui/gfx/paint_vector_icon.h" 11 #include "ui/gfx/paint_vector_icon.h"
12 #include "ui/views/controls/button/label_button.h" 12 #include "ui/views/controls/button/label_button.h"
13 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
14 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
15 #include "ui/views/controls/link.h" 15 #include "ui/views/controls/link.h"
16 #include "ui/views/layout/box_layout.h" 16 #include "ui/views/layout/box_layout.h"
17 17
18 namespace { 18 namespace {
19 const int kIconSize = 16; 19 const int kIconSize = 16;
20 } 20 }
21 21
22 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( 22 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews(
23 views::View* anchor_view, 23 views::View* anchor_view,
24 const gfx::Point& anchor_point, 24 const gfx::Point& anchor_point,
25 bool anchored_to_action, 25 bool anchored_to_action,
26 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) 26 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate)
27 : views::BubbleDialogDelegateView(anchor_view, 27 : views::BubbleDialogDelegateView(anchor_view,
28 views::BubbleBorder::TOP_RIGHT), 28 views::BubbleBorder::TOP_RIGHT),
29 delegate_(std::move(delegate)), 29 delegate_(std::move(delegate)),
30 close_reason_( 30 delegate_notified_of_close_(false),
31 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION),
32 item_list_(nullptr), 31 item_list_(nullptr),
33 link_(nullptr), 32 link_(nullptr),
34 anchored_to_action_(anchored_to_action) { 33 anchored_to_action_(anchored_to_action) {
35 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); 34 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate());
36 if (!anchor_view) 35 if (!anchor_view)
37 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 36 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
38 } 37 }
39 38
40 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} 39 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {}
41 40
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 82
84 return icon ? static_cast<views::View*>(icon.release()) 83 return icon ? static_cast<views::View*>(icon.release())
85 : static_cast<views::View*>(label.release()); 84 : static_cast<views::View*>(label.release());
86 } 85 }
87 86
88 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { 87 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const {
89 return delegate_->GetHeadingText(); 88 return delegate_->GetHeadingText();
90 } 89 }
91 90
92 bool ToolbarActionsBarBubbleViews::Cancel() { 91 bool ToolbarActionsBarBubbleViews::Cancel() {
92 DCHECK(!delegate_notified_of_close_);
93 delegate_notified_of_close_ = true;
93 delegate_->OnBubbleClosed( 94 delegate_->OnBubbleClosed(
94 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); 95 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION);
95 return true; 96 return true;
96 } 97 }
97 98
98 bool ToolbarActionsBarBubbleViews::Accept() { 99 bool ToolbarActionsBarBubbleViews::Accept() {
100 DCHECK(!delegate_notified_of_close_);
101 delegate_notified_of_close_ = true;
99 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); 102 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE);
100 return true; 103 return true;
101 } 104 }
102 105
103 bool ToolbarActionsBarBubbleViews::Close() { 106 bool ToolbarActionsBarBubbleViews::Close() {
104 delegate_->OnBubbleClosed(close_reason_); 107 // If the user took any action, the delegate will have been notified already.
108 // Otherwise, this was dismissal due to deactivation.
109 if (!delegate_notified_of_close_) {
110 delegate_notified_of_close_ = true;
111 delegate_->OnBubbleClosed(
112 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION);
113 }
105 return true; 114 return true;
106 } 115 }
107 116
108 void ToolbarActionsBarBubbleViews::Init() { 117 void ToolbarActionsBarBubbleViews::Init() {
109 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); 118 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
110 SetLayoutManager(new views::BoxLayout( 119 SetLayoutManager(new views::BoxLayout(
111 views::BoxLayout::kVertical, 0, 0, 120 views::BoxLayout::kVertical, 0, 0,
112 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL))); 121 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
113 122
114 // Add the content string. 123 // Add the content string.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 161 }
153 162
154 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( 163 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel(
155 ui::DialogButton button) const { 164 ui::DialogButton button) const {
156 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() 165 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText()
157 : delegate_->GetDismissButtonText(); 166 : delegate_->GetDismissButtonText();
158 } 167 }
159 168
160 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, 169 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link,
161 int event_flags) { 170 int event_flags) {
162 close_reason_ = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE; 171 DCHECK(!delegate_notified_of_close_);
172 delegate_notified_of_close_ = true;
173 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE);
174 // Note that the Widget may or may not already be closed at this point,
175 // depending on delegate_->ShouldCloseOnDeactivate(). Widget::Close() protects
176 // against multiple calls (so long as they are not nested), and Widget
177 // destruction is asynchronous, so it is safe to call Close() again.
163 GetWidget()->Close(); 178 GetWidget()->Close();
164 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698