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" | |
9 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | 8 #include "chrome/browser/ui/views/harmony/layout_delegate.h" |
10 #include "chrome/grit/locale_settings.h" | 9 #include "chrome/grit/locale_settings.h" |
11 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
13 #include "ui/gfx/paint_vector_icon.h" | 12 #include "ui/gfx/paint_vector_icon.h" |
14 #include "ui/gfx/vector_icons_public.h" | 13 #include "ui/gfx/vector_icons_public.h" |
15 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
16 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
17 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
18 #include "ui/views/controls/link.h" | 17 #include "ui/views/controls/link.h" |
19 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 const int kIconSize = 16; | 21 const int kIconSize = 16; |
23 } | 22 } |
24 | 23 |
25 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( | 24 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( |
26 views::View* anchor_view, | 25 views::View* anchor_view, |
| 26 const gfx::Point& anchor_point, |
| 27 bool anchored_to_action, |
27 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) | 28 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) |
28 : views::BubbleDialogDelegateView(anchor_view, | 29 : views::BubbleDialogDelegateView(anchor_view, |
29 views::BubbleBorder::TOP_RIGHT), | 30 views::BubbleBorder::TOP_RIGHT), |
30 delegate_(std::move(delegate)), | 31 delegate_(std::move(delegate)), |
31 item_list_(nullptr), | 32 item_list_(nullptr), |
32 link_(nullptr) { | 33 link_(nullptr), |
| 34 anchored_to_action_(anchored_to_action) { |
33 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); | 35 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); |
| 36 if (!anchor_view) |
| 37 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
34 } | 38 } |
35 | 39 |
36 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} | 40 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} |
37 | 41 |
38 void ToolbarActionsBarBubbleViews::Show() { | 42 void ToolbarActionsBarBubbleViews::Show() { |
39 delegate_->OnBubbleShown(); | 43 delegate_->OnBubbleShown(); |
40 GetWidget()->Show(); | 44 GetWidget()->Show(); |
41 } | 45 } |
42 | 46 |
43 views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { | 47 views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 110 } |
107 | 111 |
108 void ToolbarActionsBarBubbleViews::Init() { | 112 void ToolbarActionsBarBubbleViews::Init() { |
109 LayoutDelegate* delegate = LayoutDelegate::Get(); | 113 LayoutDelegate* delegate = LayoutDelegate::Get(); |
110 SetLayoutManager(new views::BoxLayout( | 114 SetLayoutManager(new views::BoxLayout( |
111 views::BoxLayout::kVertical, 0, 0, | 115 views::BoxLayout::kVertical, 0, 0, |
112 delegate->GetMetric( | 116 delegate->GetMetric( |
113 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING))); | 117 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING))); |
114 | 118 |
115 // Add the content string. | 119 // Add the content string. |
116 views::Label* content_label = new views::Label( | 120 views::Label* content_label = |
117 delegate_->GetBodyText(GetAnchorView()->id() == VIEW_ID_BROWSER_ACTION)); | 121 new views::Label(delegate_->GetBodyText(anchored_to_action_)); |
118 content_label->SetMultiLine(true); | 122 content_label->SetMultiLine(true); |
119 int width = views::Widget::GetLocalizedContentsWidth( | 123 int width = views::Widget::GetLocalizedContentsWidth( |
120 IDS_EXTENSION_TOOLBAR_REDESIGN_NOTIFICATION_BUBBLE_WIDTH_CHARS); | 124 IDS_EXTENSION_TOOLBAR_REDESIGN_NOTIFICATION_BUBBLE_WIDTH_CHARS); |
121 content_label->SizeToFit(width); | 125 content_label->SizeToFit(width); |
122 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
123 AddChildView(content_label); | 127 AddChildView(content_label); |
124 | 128 |
125 base::string16 item_list = delegate_->GetItemListText(); | 129 base::string16 item_list = delegate_->GetItemListText(); |
126 | 130 |
127 if (!item_list.empty()) { | 131 if (!item_list.empty()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 : delegate_->GetDismissButtonText(); | 163 : delegate_->GetDismissButtonText(); |
160 } | 164 } |
161 | 165 |
162 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 166 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
163 int event_flags) { | 167 int event_flags) { |
164 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 168 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
165 // Reset delegate so we don't send extra OnBubbleClosed()s. | 169 // Reset delegate so we don't send extra OnBubbleClosed()s. |
166 delegate_.reset(); | 170 delegate_.reset(); |
167 GetWidget()->Close(); | 171 GetWidget()->Close(); |
168 } | 172 } |
OLD | NEW |