Chromium Code Reviews| 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" | 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; | |
|
catmullings
2016/09/22 00:00:11
I replaced label_, the private variable, with a lo
| |
| 56 const base::string16& text = extra_view_info->text; | |
| 57 if (!text.empty()) { | |
| 58 if (extra_view_info->is_text_linked) { | |
| 59 views::Link* 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->AddChildView(icon); | |
| 70 parent->AddChildView(label); | |
| 71 return parent; | |
| 72 } | |
| 73 | |
| 74 return icon ? static_cast<views::View*>(icon) | |
| 75 : static_cast<views::View*>(label); | |
| 47 } | 76 } |
| 48 | 77 |
| 49 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { | 78 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { |
| 50 return delegate_->GetHeadingText(); | 79 return delegate_->GetHeadingText(); |
| 51 } | 80 } |
| 52 | 81 |
| 53 bool ToolbarActionsBarBubbleViews::Cancel() { | 82 bool ToolbarActionsBarBubbleViews::Cancel() { |
| 54 delegate_->OnBubbleClosed( | 83 delegate_->OnBubbleClosed( |
| 55 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 84 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
| 56 return true; | 85 return true; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 : delegate_->GetDismissButtonText(); | 143 : delegate_->GetDismissButtonText(); |
| 115 } | 144 } |
| 116 | 145 |
| 117 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 146 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
| 118 int event_flags) { | 147 int event_flags) { |
| 119 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 148 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 120 // Reset delegate so we don't send extra OnBubbleClosed()s. | 149 // Reset delegate so we don't send extra OnBubbleClosed()s. |
| 121 delegate_.reset(); | 150 delegate_.reset(); |
| 122 GetWidget()->Close(); | 151 GetWidget()->Close(); |
| 123 } | 152 } |
| OLD | NEW |