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), |
|
catmullings
2016/08/13 00:35:53
In the ExtraViewInfo struct, if the text is not me
Devlin
2016/08/22 20:59:42
We shouldn't. Links have extra behavior, and you
catmullings
2016/08/31 00:03:31
Done.
| |
| 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 base::string16 text = extra_view_info->text; | |
|
Devlin
2016/08/22 20:59:42
we need to check if extra_view_info is null, right
Devlin
2016/08/22 20:59:42
Let's also avoid the copy of the base::string16.
catmullings
2016/08/31 00:03:30
Done.
catmullings
2016/08/31 00:03:30
Done.
| |
| 45 int resource_id = extra_view_info->resource_id; | |
| 46 | |
| 47 if (text.empty() && resource_id != -1) { | |
|
Devlin
2016/08/22 20:59:42
Why do we return if resource_id != -1?
catmullings
2016/08/31 00:03:30
Should be == .
Done.
| |
| 42 return nullptr; | 48 return nullptr; |
| 49 } | |
| 43 | 50 |
| 44 learn_more_button_ = new views::Link(text); | 51 views::View* parent = nullptr; |
| 45 learn_more_button_->set_listener(this); | 52 |
| 46 return learn_more_button_; | 53 if (resource_id != -1 && !text.empty()) { |
| 54 parent = new views::View(); | |
| 55 } | |
| 56 | |
| 57 if (resource_id != -1) { | |
| 58 views::ImageView* icon = new views::ImageView(); | |
| 59 icon->SetImage( | |
| 60 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | |
| 61 if (text.empty()) { | |
|
Devlin
2016/08/22 20:59:42
it looks like there's a lot of duplicate checking
catmullings
2016/08/31 00:03:31
Will followup with you about this offline.
catmullings
2016/09/06 19:16:23
What do you think of this change?
| |
| 62 return icon; | |
| 63 } else { | |
| 64 parent->AddChildView(icon); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 if (!text.empty()) { | |
| 69 if (extra_view_info->is_text_linked) { | |
| 70 link_ = new views::Link(text); | |
| 71 link_->set_listener(this); | |
| 72 if (resource_id == -1) { | |
| 73 return link_; | |
| 74 } else { | |
| 75 parent->AddChildView(link_); | |
| 76 } | |
| 77 } else { | |
| 78 views::Label* label = new views::Label(text); | |
| 79 if (resource_id == -1) { | |
| 80 return label; | |
| 81 } else { | |
| 82 parent->AddChildView(label); | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 return parent; | |
| 47 } | 88 } |
| 48 | 89 |
| 49 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { | 90 base::string16 ToolbarActionsBarBubbleViews::GetWindowTitle() const { |
| 50 return delegate_->GetHeadingText(); | 91 return delegate_->GetHeadingText(); |
| 51 } | 92 } |
| 52 | 93 |
| 53 bool ToolbarActionsBarBubbleViews::Cancel() { | 94 bool ToolbarActionsBarBubbleViews::Cancel() { |
| 54 delegate_->OnBubbleClosed( | 95 delegate_->OnBubbleClosed( |
| 55 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 96 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
| 56 return true; | 97 return true; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 : delegate_->GetDismissButtonText(); | 155 : delegate_->GetDismissButtonText(); |
| 115 } | 156 } |
| 116 | 157 |
| 117 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, | 158 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
| 118 int event_flags) { | 159 int event_flags) { |
| 119 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 160 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 120 // Reset delegate so we don't send extra OnBubbleClosed()s. | 161 // Reset delegate so we don't send extra OnBubbleClosed()s. |
| 121 delegate_.reset(); | 162 delegate_.reset(); |
| 122 GetWidget()->Close(); | 163 GetWidget()->Close(); |
| 123 } | 164 } |
| OLD | NEW |