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() { |
|
Devlin
2016/09/07 18:37:50
Nice! This method already reads a lot better than
catmullings
2016/09/08 15:42:30
Done.
| |
| 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 base::string16& text = extra_view_info->text; |
|
Devlin
2016/09/07 18:37:50
const&
catmullings
2016/09/08 15:42:30
Done.
| |
| 45 learn_more_button_->set_listener(this); | 48 int resource_id = extra_view_info->resource_id; |
| 46 return learn_more_button_; | 49 |
| 50 if (resource_id != -1 && !text.empty()) { | |
| 51 views::View* parent = new views::View(); | |
| 52 | |
| 53 views::ImageView* icon = new views::ImageView(); | |
| 54 icon->SetImage( | |
| 55 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | |
| 56 parent->AddChildView(icon); | |
| 57 | |
| 58 parent->AddChildView( | |
| 59 ConvertTextToView(text, extra_view_info->is_text_linked)); | |
| 60 return parent; | |
| 61 } | |
| 62 | |
| 63 if (resource_id != -1) { | |
| 64 views::ImageView* icon = new views::ImageView(); | |
| 65 icon->SetImage( | |
| 66 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | |
|
Devlin
2016/09/07 18:37:49
It still looks like we have a bit of duplicate cod
catmullings
2016/09/08 15:42:30
This is much cleaner and easier to follow.
Change
catmullings
2016/09/08 15:42:30
Done.
| |
| 67 return icon; | |
| 68 } | |
| 69 | |
| 70 if (!text.empty()) | |
| 71 return ConvertTextToView(text, extra_view_info->is_text_linked); | |
| 72 | |
| 73 return nullptr; | |
| 47 } | 74 } |
| 48 | 75 |
| 49 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { | 76 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { |
| 50 return delegate_->GetHeadingText(); | 77 return delegate_->GetHeadingText(); |
| 51 } | 78 } |
| 52 | 79 |
| 53 bool ToolbarActionsBarBubbleViews::Cancel() { | 80 bool ToolbarActionsBarBubbleViews::Cancel() { |
| 54 delegate_->OnBubbleClosed( | 81 delegate_->OnBubbleClosed( |
| 55 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 82 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
| 56 return true; | 83 return true; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 : delegate_->GetDismissButtonText(); | 141 : delegate_->GetDismissButtonText(); |
| 115 } | 142 } |
| 116 | 143 |
| 117 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 144 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
| 118 int event_flags) { | 145 int event_flags) { |
| 119 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 146 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 120 // Reset delegate so we don't send extra OnBubbleClosed()s. | 147 // Reset delegate so we don't send extra OnBubbleClosed()s. |
| 121 delegate_.reset(); | 148 delegate_.reset(); |
| 122 GetWidget()->Close(); | 149 GetWidget()->Close(); |
| 123 } | 150 } |
| 151 | |
| 152 views::View* ToolbarActionsBarBubbleViews::ConvertTextToView( | |
| 153 const base::string16& text, | |
| 154 bool is_text_linked) { | |
| 155 if (is_text_linked) { | |
| 156 link_ = new views::Link(text); | |
|
Devlin
2016/09/07 18:37:50
I think we can make link_ a views::Label* label_,
catmullings
2016/09/08 15:42:29
I removed this method since it is no longer need i
catmullings
2016/09/08 15:42:30
Done.
| |
| 157 link_->set_listener(this); | |
| 158 return link_; | |
| 159 } else { | |
| 160 views::Label* label = new views::Label(text); | |
| 161 return label; | |
| 162 } | |
| 163 } | |
| OLD | NEW |