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/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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 93 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
95 return true; | 94 return true; |
96 } | 95 } |
97 | 96 |
98 bool ToolbarActionsBarBubbleViews::Accept() { | 97 bool ToolbarActionsBarBubbleViews::Accept() { |
99 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | 98 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); |
100 return true; | 99 return true; |
101 } | 100 } |
102 | 101 |
103 bool ToolbarActionsBarBubbleViews::Close() { | 102 bool ToolbarActionsBarBubbleViews::Close() { |
104 delegate_->OnBubbleClosed(close_reason_); | 103 // If delegate_->OnBubbleClosed() was called by LinkClicked(), the bubble may |
Devlin
2017/04/20 16:12:15
We could make this a little less corner-casey (and
tapted
2017/04/21 00:24:33
Done.
| |
104 // close automatically in response to the delegate action (e.g. losing focus | |
105 // when a tab is opened). | |
106 if (!delegate_notified_of_close_) { | |
107 delegate_->OnBubbleClosed( | |
108 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION); | |
109 } | |
105 return true; | 110 return true; |
106 } | 111 } |
107 | 112 |
108 void ToolbarActionsBarBubbleViews::Init() { | 113 void ToolbarActionsBarBubbleViews::Init() { |
109 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | 114 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
110 SetLayoutManager(new views::BoxLayout( | 115 SetLayoutManager(new views::BoxLayout( |
111 views::BoxLayout::kVertical, 0, 0, | 116 views::BoxLayout::kVertical, 0, 0, |
112 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL))); | 117 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL))); |
113 | 118 |
114 // Add the content string. | 119 // Add the content string. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 } | 157 } |
153 | 158 |
154 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( | 159 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( |
155 ui::DialogButton button) const { | 160 ui::DialogButton button) const { |
156 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() | 161 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() |
157 : delegate_->GetDismissButtonText(); | 162 : delegate_->GetDismissButtonText(); |
158 } | 163 } |
159 | 164 |
160 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 165 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
161 int event_flags) { | 166 int event_flags) { |
162 close_reason_ = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE; | 167 delegate_notified_of_close_ = true; |
168 // Force the delegate action to happen here rather than in Close(). Close() is | |
Devlin
2017/04/20 16:12:15
Similarly here, we could just have this be the nor
tapted
2017/04/21 00:24:33
Done.
| |
169 // called from Widget::CanClose() so attempting to open a link there can cause | |
170 // recursion. | |
171 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | |
172 // Note that the Widget may or may not already be closed at this point, | |
173 // depending on delegate_->ShouldCloseOnDeactivate(). Widget::Close() protects | |
174 // against multiple calls (so long as they are not nested), and Widget | |
175 // destruction is asynchronous, so it is safe to call Close() again. | |
163 GetWidget()->Close(); | 176 GetWidget()->Close(); |
164 } | 177 } |
OLD | NEW |