Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(922)

Unified Diff: chrome/browser/ui/views/intent_picker_bubble_view.cc

Issue 2134293002: Adding a ScrollView for IntentPickerBubbleView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the last test failing, moving the order of excecution and getting rid of the override SetUp(). Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/intent_picker_bubble_view.cc
diff --git a/chrome/browser/ui/views/intent_picker_bubble_view.cc b/chrome/browser/ui/views/intent_picker_bubble_view.cc
index c5f007a5ca7746472d5fe094fadf0bfffa071754..b09069c042f38f7045813a1570bfda321c55b23c 100644
--- a/chrome/browser/ui/views/intent_picker_bubble_view.cc
+++ b/chrome/browser/ui/views/intent_picker_bubble_view.cc
@@ -4,8 +4,6 @@
#include "chrome/browser/ui/views/intent_picker_bubble_view.h"
-#include <algorithm>
-
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/string_piece.h"
@@ -18,15 +16,17 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
+#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
+#include "ui/views/controls/scroll_view.h"
+#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/window/dialog_client_view.h"
namespace {
-// TODO(djacobo): Add a scroll bar and remove kMaxAppResults.
-// Discriminating app results when the list is longer than |kMaxAppResults|
+// Using |kMaxAppResults| as a measure of how many apps we want to show.
constexpr size_t kMaxAppResults = 3;
Yusuke Sato 2016/07/20 08:05:54 Please rebase this CL and use the throttle's.
djacobo_ 2016/07/20 21:18:30 Done.
// Main components sizes
constexpr int kRowHeight = 40;
@@ -39,7 +39,7 @@ constexpr int kLabelImageSeparation = 12;
// UI position wrt the Top Container
constexpr int kTopContainerMerge = 3;
-constexpr int kAppTagNoneSelected = -1;
+constexpr size_t kAppTagNoneSelected = -1;
// Arbitrary negative values to use as tags on the |always_button_| and
// |just_once_button_|. These are negative to differentiate from the app's tags
@@ -68,7 +68,7 @@ void IntentPickerBubbleView::ShowBubble(
}
IntentPickerBubbleView* delegate = new IntentPickerBubbleView(
- app_info, throttle_cb, handle->GetWebContents());
+ app_info, throttle_cb, handle->GetWebContents(), false);
delegate->set_margins(gfx::Insets());
delegate->set_parent_window(browser_view->GetNativeWindow());
views::Widget* widget =
@@ -128,6 +128,8 @@ void IntentPickerBubbleView::Init() {
always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color);
always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
always_button_->SetState(views::Button::STATE_DISABLED);
+ // Insets in the format top, left, bottom, right.
+ always_button_->SetBorder(views::Border::CreateEmptyBorder(16, 16, 16, 16));
just_once_button_ = new views::LabelButton(
this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE));
@@ -142,8 +144,19 @@ void IntentPickerBubbleView::Init() {
just_once_button_->SetTextColor(views::Button::STATE_HOVERED,
button_text_color);
just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
+ just_once_button_->SetBorder(
+ views::Border::CreateEmptyBorder(16, 16, 16, 16));
- for (size_t i = 0; i < std::min(app_info_.size(), kMaxAppResults); ++i) {
+ // Adding the |open_with| label to the picker.
+ header_layout->StartRow(0, 0);
+ AddChildView(header);
+
+ // Setting a view and a layout for a ScrollView for the apps' list.
+ views::View* scrollable_view = new views::View();
+ views::BoxLayout* scrollable_layout =
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
+ scrollable_view->SetLayoutManager(scrollable_layout);
+ for (size_t i = 0; i < app_info_.size(); ++i) {
views::LabelButton* tmp_label = new views::LabelButton(
this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first)));
tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS);
@@ -152,23 +165,33 @@ void IntentPickerBubbleView::Init() {
tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight));
tmp_label->set_tag(i);
- const gfx::ImageSkia* icon_ = app_info_[i].second.ToImageSkia();
- tmp_label->SetImage(views::ImageButton::STATE_NORMAL, *icon_);
- header_layout->StartRow(0, 0);
- header_layout->AddView(tmp_label);
+ if (!app_info_[i].second.IsEmpty()) {
+ tmp_label->SetImage(views::ImageButton::STATE_NORMAL,
+ *app_info_[i].second.ToImageSkia());
+ }
+ tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0));
+ app_label_ptr_.emplace_back(tmp_label);
+ scrollable_view->AddChildView(tmp_label);
}
- // Adding the Upper part of the Intent Picker |open_with| label and all the
- // app options to |this|.
- header_layout->StartRow(0, 0);
- header_layout->AddPaddingRow(0, 12);
- AddChildView(header);
+ views::ScrollView* scroll_view = new views::ScrollView();
+ scroll_view->SetContents(scrollable_view);
+ scroll_view->SetVerticalScrollBar(new views::OverlayScrollBar(false));
+ // This part gives the scroll a fixed width and height. The height depends on
+ // how many app candidates we got and how many we actually want to show.
+ if (app_info_.size() <= kMaxAppResults) {
+ scroll_view->ClipHeightTo(kMaxWidth, app_info_.size() * kRowHeight);
+ } else {
+ scroll_view->ClipHeightTo(kMaxWidth, (kMaxAppResults + 0.5) * kRowHeight);
Yusuke Sato 2016/07/19 10:23:58 Can you add a code comment to document why we need
djacobo_ 2016/07/20 21:18:30 Done.
+ }
+ AddChildView(scroll_view);
// The lower part of the Picker contains only the 2 buttons
// |just_once_button_| and |always_button_|.
View* footer = new View();
+ footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12));
views::BoxLayout* buttons_layout = new views::BoxLayout(
- views::BoxLayout::kHorizontal, 12, 12, kButtonSeparation);
+ views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation);
footer->SetLayoutManager(buttons_layout);
buttons_layout->set_main_axis_alignment(
@@ -181,16 +204,19 @@ void IntentPickerBubbleView::Init() {
IntentPickerBubbleView::IntentPickerBubbleView(
const std::vector<NameAndIcon>& app_info,
ThrottleCallback throttle_cb,
- content::WebContents* web_contents)
+ content::WebContents* web_contents,
+ bool was_callback_run)
: views::BubbleDialogDelegateView(nullptr /* anchor_view */,
views::BubbleBorder::TOP_CENTER),
WebContentsObserver(web_contents),
- was_callback_run_(false),
+ was_callback_run_(was_callback_run),
throttle_cb_(throttle_cb),
selected_app_tag_(kAppTagNoneSelected),
always_button_(nullptr),
just_once_button_(nullptr),
- app_info_(app_info) {}
+ app_info_(app_info) {
+ app_label_ptr_.clear();
Yusuke Sato 2016/07/19 10:23:58 std::vector is initially empty. please remove.
djacobo_ 2016/07/20 21:18:30 Done.
+}
IntentPickerBubbleView::~IntentPickerBubbleView() {
SetLayoutManager(nullptr);
@@ -215,24 +241,35 @@ void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
switch (sender->tag()) {
case static_cast<int>(Option::ALWAYS):
- throttle_cb_.Run(selected_app_tag_,
- arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
- was_callback_run_ = true;
+ if (!was_callback_run_) {
Yusuke Sato 2016/07/19 10:23:58 What's wrong with running a cb for the unit tests?
djacobo_ 2016/07/20 21:18:30 Yes, I will have a dummy method for receiving this
+ throttle_cb_.Run(
+ selected_app_tag_,
+ arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
+ was_callback_run_ = true;
+ }
GetWidget()->Close();
break;
case static_cast<int>(Option::JUST_ONCE):
- throttle_cb_.Run(
- selected_app_tag_,
- arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
- was_callback_run_ = true;
+ if (!was_callback_run_) {
+ throttle_cb_.Run(
+ selected_app_tag_,
+ arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
+ was_callback_run_ = true;
+ }
GetWidget()->Close();
break;
default:
- // TODO(djacobo): Paint the background of the selected button on a
- // different color, so the user has a clear remainder of his selection.
// The user cannot click on the |always_button_| or |just_once_button_|
// unless an explicit app has been selected.
+ if (selected_app_tag_ != kAppTagNoneSelected) {
+ app_label_ptr_[selected_app_tag_]->set_background(
+ views::Background::CreateSolidBackground(SK_ColorWHITE));
+ app_label_ptr_[selected_app_tag_]->SchedulePaint();
+ }
selected_app_tag_ = sender->tag();
+ app_label_ptr_[selected_app_tag_]->set_background(
+ views::Background::CreateSolidBackground(
+ SkColorSetRGB(0xeb, 0xeb, 0xeb)));
always_button_->SetState(views::Button::STATE_NORMAL);
just_once_button_->SetState(views::Button::STATE_NORMAL);
}
@@ -241,8 +278,15 @@ void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
gfx::Size IntentPickerBubbleView::GetPreferredSize() const {
gfx::Size ps;
ps.set_width(kMaxWidth);
- ps.set_height((std::min(app_info_.size(), kMaxAppResults)) * kRowHeight +
- kHeaderHeight + kFooterHeight);
+ int apps_height = app_info_.size();
+ // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so
+ // the user can notice that more options are available.
+ if (app_info_.size() > kMaxAppResults) {
+ apps_height = (kMaxAppResults + 0.5) * kRowHeight;
+ } else {
+ apps_height *= kRowHeight;
+ }
+ ps.set_height(apps_height + kHeaderHeight + kFooterHeight);
return ps;
}

Powered by Google App Engine
This is Rietveld 408576698