Commit 5cf92fe4 authored by Melissa Zhang's avatar Melissa Zhang Committed by Commit Bot

[Sharesheet] Added expanded view with Apps List

Adds expansion from default view to expanded view with apps list. This
CL also moves Sharesheet UI classes into their own folder.

Bug:1130406

Change-Id: I17824948bdb20a5e3cfa6b7ac93b0216ee43cf61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409480
Commit-Queue: Melissa Zhang <melzhang@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809216}
parent 0a874553
......@@ -418,7 +418,7 @@ include_rules = [
"+chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h",
"+chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h",
"+chrome/browser/ui/views/extensions/request_file_system_dialog_view.h",
"+chrome/browser/ui/views/sharesheet_bubble_view.h",
"+chrome/browser/ui/views/sharesheet/sharesheet_bubble_view.h",
"+chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.h",
# Ensure that only the public interface of performance_manager gets used.
......
......@@ -10,7 +10,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharesheet/sharesheet_service.h"
#include "chrome/browser/sharesheet/sharesheet_service_factory.h"
#include "chrome/browser/ui/views/sharesheet_bubble_view.h"
#include "chrome/browser/ui/views/sharesheet/sharesheet_bubble_view.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/view.h"
......
......@@ -2083,8 +2083,12 @@ static_library("ui") {
"views/profiles/profile_indicator_icon.h",
"views/relaunch_notification/relaunch_notification_controller_platform_impl_chromeos.cc",
"views/relaunch_notification/relaunch_notification_controller_platform_impl_chromeos.h",
"views/sharesheet_bubble_view.cc",
"views/sharesheet_bubble_view.h",
"views/sharesheet/sharesheet_bubble_view.cc",
"views/sharesheet/sharesheet_bubble_view.h",
"views/sharesheet/sharesheet_expand_button.cc",
"views/sharesheet/sharesheet_expand_button.h",
"views/sharesheet/sharesheet_target_button.cc",
"views/sharesheet/sharesheet_target_button.h",
# On chromeos, file manager extension handles the file open/save dialog.
"views/select_file_dialog_extension.cc",
......
file://chrome/browser/sharesheet/OWNERS
# COMPONENT: Platform>Apps>Foundation
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_SHARESHEET_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SHARESHEET_BUBBLE_VIEW_H_
#ifndef CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_BUBBLE_VIEW_H_
#include <vector>
......@@ -12,6 +12,10 @@
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
namespace views {
class GridLayout;
}
namespace sharesheet {
class SharesheetServiceDelegate;
}
......@@ -20,6 +24,8 @@ namespace content {
class WebContents;
}
class SharesheetExpandButton;
class SharesheetBubbleView : public views::BubbleDialogDelegateView,
public views::ButtonListener {
public:
......@@ -52,6 +58,9 @@ class SharesheetBubbleView : public views::BubbleDialogDelegateView,
void OnWidgetDestroyed(views::Widget* widget) override;
void CreateBubble();
std::unique_ptr<views::View> MakeScrollableTargetView();
void PopulateLayoutsWithTargets(views::GridLayout* default_layout,
views::GridLayout* expanded_layout);
void OnDialogClosed();
void UpdateAnchorPosition();
void SetToDefaultBubbleSizing();
......@@ -61,14 +70,18 @@ class SharesheetBubbleView : public views::BubbleDialogDelegateView,
std::vector<TargetInfo> targets_;
base::string16 active_target_;
apps::mojom::IntentPtr intent_;
int width_ = 0;
int height_ = 0;
bool user_cancelled = true;
bool user_cancelled_ = true;
bool show_expanded_view_ = false;
views::View* root_view_ = nullptr;
views::View* main_view_ = nullptr;
views::View* expanded_view_ = nullptr;
views::View* share_action_view_ = nullptr;
views::View* parent_view_ = nullptr;
SharesheetExpandButton* expand_button_ = nullptr;
};
#endif // CHROME_BROWSER_UI_VIEWS_SHARESHEET_BUBBLE_VIEW_H_
#endif // CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_BUBBLE_VIEW_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/sharesheet/sharesheet_expand_button.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/layout/box_layout.h"
namespace {
// Sizes are in px.
constexpr int kDefaultBubbleWidth = 416;
constexpr int kCaretIconSize = 20;
constexpr int kHeight = 32;
constexpr int kLineHeight = 20;
constexpr int kBetweenChildSpacing = 8;
constexpr int kMarginSpacing = 24;
constexpr char kLabelFont[] = "Roboto, Medium, 14px";
constexpr SkColor kLabelColor = gfx::kGoogleBlue600;
} // namespace
SharesheetExpandButton::SharesheetExpandButton(views::ButtonListener* listener)
: Button(listener) {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(6, 16, 6, 16),
kBetweenChildSpacing, true));
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kCenter);
icon_ = AddChildView(std::make_unique<views::ImageView>());
label_ = AddChildView(std::make_unique<views::Label>());
label_->SetFontList(gfx::FontList(kLabelFont));
label_->SetLineHeight(kLineHeight);
label_->SetEnabledColor(kLabelColor);
SetDefaultView();
}
void SharesheetExpandButton::SetDefaultView() {
icon_->SetImage(
gfx::CreateVectorIcon(kCaretDownIcon, kCaretIconSize, kLabelColor));
// TODO(crbug.com/1130409) Add translation for this and below strings.
label_->SetText(base::UTF8ToUTF16(base::StringPiece("More apps")));
}
void SharesheetExpandButton::SetExpandedView() {
icon_->SetImage(
gfx::CreateVectorIcon(kCaretUpIcon, kCaretIconSize, kLabelColor));
label_->SetText(base::UTF8ToUTF16(base::StringPiece("Fewer apps")));
}
gfx::Size SharesheetExpandButton::CalculatePreferredSize() const {
// Width is bubble width - left and right margins
return gfx::Size((kDefaultBubbleWidth - 2 * kMarginSpacing), kHeight);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_EXPAND_BUTTON_H_
#define CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_EXPAND_BUTTON_H_
#include "chrome/browser/sharesheet/sharesheet_types.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
class SharesheetExpandButton : public views::Button {
public:
explicit SharesheetExpandButton(views::ButtonListener* listener);
SharesheetExpandButton(const SharesheetExpandButton&) = delete;
SharesheetExpandButton& operator=(const SharesheetExpandButton&) = delete;
void SetDefaultView();
void SetExpandedView();
private:
// views::View overrides
gfx::Size CalculatePreferredSize() const override;
views::ImageView* icon_ = nullptr;
views::Label* label_ = nullptr;
};
#endif // CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_EXPAND_BUTTON_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/sharesheet/sharesheet_target_button.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/font_list.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h"
namespace {
// Sizes are in px.
// kButtonWidth = 76px width + 2*8px for padding on left and right
constexpr int kButtonWidth = 92;
// kButtonHeight = 88px height + 2*8px for padding on top and bottom.
constexpr int kButtonHeight = 104;
// kButtonTextMaxWidth is button max width without padding.
constexpr int kButtonTextMaxWidth = 76;
constexpr int kButtonLineHeight = 20;
constexpr int kButtonMaxLines = 2;
constexpr int kButtonPadding = 8;
constexpr char kButtonLabelFont[] = "Roboto, Medium, 14px";
constexpr char kButtonSecondaryLabelFont[] = "Roboto, Regular, 13px";
constexpr SkColor kShareTargetTitleColor = gfx::kGoogleGrey700;
constexpr SkColor kShareTargetSecondaryTitleColor = gfx::kGoogleGrey600;
} // namespace
// A button that represents a candidate share target.
SharesheetTargetButton::SharesheetTargetButton(
views::ButtonListener* listener,
const base::string16& display_name,
const base::string16& secondary_display_name,
const gfx::ImageSkia* icon)
: Button(listener) {
// TODO(crbug.com/1097623) Margins shouldn't be within
// SharesheetTargetButton as the margins are different in |expanded_view_|.
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(kButtonPadding),
kButtonPadding, true));
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kStart);
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
auto* image = AddChildView(std::make_unique<views::ImageView>());
image->set_can_process_events_within_subtree(false);
if (!icon->isNull()) {
image->SetImage(icon);
}
auto label_view = std::make_unique<views::View>();
label_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(), 0, true));
auto* label =
label_view->AddChildView(std::make_unique<views::Label>(display_name));
label->SetFontList(gfx::FontList(kButtonLabelFont));
label->SetEnabledColor(kShareTargetTitleColor);
SetLabelProperties(label);
if (secondary_display_name != base::string16() &&
secondary_display_name != display_name) {
auto* secondary_label = label_view->AddChildView(
std::make_unique<views::Label>(secondary_display_name));
secondary_label->SetFontList(gfx::FontList(kButtonSecondaryLabelFont));
secondary_label->SetEnabledColor(kShareTargetSecondaryTitleColor);
SetLabelProperties(secondary_label);
} else {
// If there is no secondary label, let the initial label stretch across
// multiple lines.
label->SetMultiLine(true);
label->SetMaxLines(kButtonMaxLines);
}
AddChildView(std::move(label_view));
SetFocusForPlatform();
}
void SharesheetTargetButton::SetLabelProperties(views::Label* label) {
label->SetLineHeight(kButtonLineHeight);
label->SetMaximumWidth(kButtonTextMaxWidth);
label->SetBackgroundColor(SK_ColorTRANSPARENT);
label->SetHandlesTooltips(true);
label->SetTooltipText(label->GetText());
label->SetMultiLine(false);
label->SetAutoColorReadabilityEnabled(false);
label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
}
// Button is 76px width x 88px height + 8px padding along all sides.
gfx::Size SharesheetTargetButton::CalculatePreferredSize() const {
return gfx::Size(kButtonWidth, kButtonHeight);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_TARGET_BUTTON_H_
#define CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_TARGET_BUTTON_H_
#include "chrome/browser/sharesheet/sharesheet_types.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h"
class SharesheetTargetButton : public views::Button {
public:
SharesheetTargetButton(views::ButtonListener* listener,
const base::string16& display_name,
const base::string16& secondary_display_name,
const gfx::ImageSkia* icon);
SharesheetTargetButton(const SharesheetTargetButton&) = delete;
SharesheetTargetButton& operator=(const SharesheetTargetButton&) = delete;
private:
void SetLabelProperties(views::Label* label);
// views::View overrides
gfx::Size CalculatePreferredSize() const override;
};
#endif // CHROME_BROWSER_UI_VIEWS_SHARESHEET_SHARESHEET_TARGET_BUTTON_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment