Commit b207368a authored by Angela Gyi's avatar Angela Gyi Committed by Chromium LUCI CQ

[Sharesheet] Move title preview to SharesheetContentPreview class.

This CL refactors the title preview feature in the sharesheet
by moving it into a dedicated SharesheetContentPreviews class.

Bug: 1167935
Change-Id: I2671c0e53e04779e8fe8bdf3d37d30f91161d3a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636734Reviewed-by: default avatarMelissa Zhang <melzhang@chromium.org>
Reviewed-by: default avatarMaggie Cai <mxcai@chromium.org>
Commit-Queue: Angela Gyi <angelagyi@google.com>
Cr-Commit-Position: refs/heads/master@{#845512}
parent 3f26aff3
......@@ -81,10 +81,7 @@ constexpr int kExpandViewPaddingTop = 16;
constexpr int kExpandViewPaddingBottom = 8;
constexpr int kShortSpacing = 20;
constexpr int kSpacing = 24;
constexpr int kTitleLineHeight = 24;
constexpr SkColor kShareTitleColor = gfx::kGoogleGrey900;
constexpr SkColor kShareTargetTitleColor = gfx::kGoogleGrey700;
constexpr auto kAnimateDelay = base::TimeDelta::FromMilliseconds(100);
......@@ -159,35 +156,10 @@ void SharesheetBubbleView::ShowBubble(
/* inside_border_insets */ gfx::Insets(),
/* between_child_spacing */ 0, /* collapse_margins_spacing */ true));
// Add Title label
auto* title = main_view_->AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_SHARESHEET_TITLE_LABEL),
ash::CONTEXT_SHARESHEET_BUBBLE_TITLE, ash::STYLE_SHARESHEET));
title->SetLineHeight(kTitleLineHeight);
title->SetEnabledColor(kShareTitleColor);
title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title->SetProperty(views::kMarginsKey, gfx::Insets(kSpacing));
// Add content preview text descriptor.
if (base::FeatureList::IsEnabled(features::kSharesheetContentPreviews) &&
(intent_->file_urls.has_value())) {
// Remove the margin under the title for file_title
title->SetProperty(views::kMarginsKey,
gfx::Insets(kSpacing, kSpacing, 0, kSpacing));
// This displays text data only for the first file_url provided.
auto* file_title = main_view_->AddChildView(std::make_unique<views::Label>(
base::ASCIIToUTF16(
(intent_->file_urls.value().front().ExtractFileName())),
ash::CONTEXT_SHARESHEET_BUBBLE_BODY_SECONDARY));
file_title->SetLineHeight(kTitleLineHeight);
file_title->SetEnabledColor(kShareTargetTitleColor);
file_title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
file_title->SetProperty(views::kMarginsKey,
gfx::Insets(3, kSpacing, kSpacing, kSpacing));
main_view_->AddChildView(
std::make_unique<SharesheetContentPreviews>(intent_->Clone()));
}
// Adds view for content previews including the title, text descriptor
// and image preview.
main_view_->AddChildView(
std::make_unique<SharesheetContentPreviews>(intent_->Clone()));
if (targets.empty()) {
auto* image =
......
......@@ -28,6 +28,10 @@ class SharesheetBubbleView : public views::BubbleDialogDelegateView {
METADATA_HEADER(SharesheetBubbleView);
using TargetInfo = sharesheet::TargetInfo;
// These constants are shared between sharesheet UI related classes.
static constexpr int kSpacing = 24;
static constexpr int kTitleLineHeight = 24;
SharesheetBubbleView(views::View* anchor_view,
sharesheet::SharesheetServiceDelegate* delegate);
SharesheetBubbleView(gfx::NativeWindow native_window,
......
......@@ -6,21 +6,72 @@
#include <utility>
#include "ash/public/cpp/ash_typography.h"
#include "chrome/browser/ui/ash/sharesheet/sharesheet_bubble_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
constexpr SkColor kShareTitleColor = gfx::kGoogleGrey900;
constexpr SkColor kTitlePreviewColor = gfx::kGoogleGrey700;
SharesheetContentPreviews::SharesheetContentPreviews(
apps::mojom::IntentPtr intent) {
intent_ = std::move(intent);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
/* inside_border_insets */ gfx::Insets(),
/* between_child_spacing */ 0, /* collapse_margins_spacing */ true));
ShowShareTitle();
// SharesheetContentPreviews will display the Share title as
// well as preview of the shared data when the
// features::kSharesheetContentPreviews flag is enabled.
if (base::FeatureList::IsEnabled(features::kSharesheetContentPreviews)) {
ShowFileTitlePreview();
}
}
SharesheetContentPreviews::~SharesheetContentPreviews() = default;
void SharesheetContentPreviews::SetTitlePreview() {
// TODO(crbug.com/2631548): Add code to add a new
// label view to reflect file name to the
// content previews view.
NOTIMPLEMENTED();
void SharesheetContentPreviews::ShowShareTitle() {
auto share_title = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_SHARESHEET_TITLE_LABEL),
ash::CONTEXT_SHARESHEET_BUBBLE_TITLE, ash::STYLE_SHARESHEET);
auto* share_title_ = AddChildView(std::move(share_title));
share_title_->SetLineHeight(SharesheetBubbleView::kTitleLineHeight);
share_title_->SetEnabledColor(kShareTitleColor);
share_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
share_title_->SetProperty(views::kMarginsKey,
gfx::Insets(SharesheetBubbleView::kSpacing,
SharesheetBubbleView::kSpacing, 0,
SharesheetBubbleView::kSpacing));
}
void SharesheetContentPreviews::ShowFileTitlePreview() {
if (intent_->file_urls.has_value()) {
auto* file_title = AddChildView(std::make_unique<views::Label>(
base::ASCIIToUTF16(
(intent_->file_urls.value().front().ExtractFileName())),
ash::CONTEXT_SHARESHEET_BUBBLE_BODY_SECONDARY));
file_title->SetLineHeight(SharesheetBubbleView::kTitleLineHeight);
file_title->SetEnabledColor(kTitlePreviewColor);
file_title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
file_title->SetProperty(views::kMarginsKey,
gfx::Insets(3, SharesheetBubbleView::kSpacing,
SharesheetBubbleView::kSpacing,
SharesheetBubbleView::kSpacing));
}
}
void SharesheetContentPreviews::SetImagePreview() {
void SharesheetContentPreviews::ShowImagePreview() {
// TODO(crbug.com/2631548): Add code to add a new
// image view to show image preview to the
// content previews view.
......
......@@ -19,11 +19,14 @@ class SharesheetContentPreviews : public views::View {
delete;
private:
// Adds the share title to the view.
void ShowShareTitle();
// Adds the title preview to the view.
void SetTitlePreview();
void ShowFileTitlePreview();
// Adds the image preview to the view.
void SetImagePreview();
void ShowImagePreview();
apps::mojom::IntentPtr intent_;
};
......
......@@ -16,7 +16,7 @@ class SharesheetImageDecode {
SharesheetImageDecode& operator=(const SharesheetImageDecode&) = delete;
private:
// Encodes the FilePath |GURL| into encoded bytes.
// Encodes the FilePath |url| into encoded bytes.
void URLToEncodedBytes(const base::FilePath& url);
// Decodes the string of encoded bytes |image_data|
......
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