Commit db4dffa1 authored by Melissa Zhang's avatar Melissa Zhang Committed by Commit Bot

[Sharesheet] Adding Sharesheet Button to toolbar

This CL adds a temporary button to the toolbar that will be used to
trigger the sharesheet during development.

Bug: 1097623
Change-Id: Icb9029fbd508e6e358bd82381886dbd7b6050cae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2262400Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Melissa Zhang <melzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784312}
parent 4319f836
......@@ -3521,6 +3521,8 @@ static_library("browser") {
"serial/serial_chooser_context.h",
"serial/serial_chooser_context_factory.cc",
"serial/serial_chooser_context_factory.h",
"sharesheet/sharesheet_service_delegate.cc",
"sharesheet/sharesheet_service_delegate.h",
"sharing/click_to_call/click_to_call_context_menu_observer.cc",
"sharing/click_to_call/click_to_call_context_menu_observer.h",
"sharing/click_to_call/click_to_call_metrics.cc",
......
......@@ -403,6 +403,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/try_chrome_dialog_win/try_chrome_dialog.h",
# Ensure that only the public interface of performance_manager gets used.
......
// 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/sharesheet/sharesheet_service_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharesheet/sharesheet_service.h"
#include "chrome/browser/ui/views/sharesheet_bubble_view.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/view.h"
namespace sharesheet {
SharesheetServiceDelegate::SharesheetServiceDelegate(
content::WebContents* web_contents,
views::View* bubble_anchor_view)
: sharesheet_bubble_view_(
std::make_unique<SharesheetBubbleView>(bubble_anchor_view)) {
Profile* const profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
sharesheet_service_ = std::make_unique<SharesheetService>(profile);
}
SharesheetServiceDelegate::~SharesheetServiceDelegate() = default;
void SharesheetServiceDelegate::ShowBubble() {
sharesheet_bubble_view_->ShowBubble();
}
} // namespace sharesheet
// 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_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_
#define CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_
#include <memory>
class SharesheetBubbleView;
namespace content {
class WebContents;
} // namespace content
namespace views {
class View;
}
namespace sharesheet {
class SharesheetService;
class SharesheetServiceDelegate {
public:
explicit SharesheetServiceDelegate(content::WebContents* web_contents,
views::View* bubble_anchor_view);
~SharesheetServiceDelegate();
SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete;
SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) =
delete;
void ShowBubble();
private:
std::unique_ptr<SharesheetBubbleView> sharesheet_bubble_view_;
std::unique_ptr<SharesheetService> sharesheet_service_;
};
} // namespace sharesheet
#endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_
......@@ -3701,6 +3701,8 @@ static_library("ui") {
"views/send_tab_to_self/send_tab_to_self_icon_view.h",
"views/session_crashed_bubble_view.cc",
"views/session_crashed_bubble_view.h",
"views/sharesheet_bubble_view.cc",
"views/sharesheet_bubble_view.h",
"views/sharing/sharing_dialog_view.cc",
"views/sharing/sharing_dialog_view.h",
"views/sharing/sharing_icon_view.cc",
......@@ -3805,6 +3807,8 @@ static_library("ui") {
"views/toolbar/home_button.h",
"views/toolbar/reload_button.cc",
"views/toolbar/reload_button.h",
"views/toolbar/sharesheet_button.cc",
"views/toolbar/sharesheet_button.h",
"views/toolbar/toolbar_account_icon_container_view.cc",
"views/toolbar/toolbar_account_icon_container_view.h",
"views/toolbar/toolbar_action_view.cc",
......
// 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_bubble_view.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
SharesheetBubbleView::SharesheetBubbleView(views::View* anchor_view) {
SetButtons(ui::DIALOG_BUTTON_NONE);
SetAnchorView(anchor_view);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_RELATED_CONTROL_VERTICAL)));
}
SharesheetBubbleView::~SharesheetBubbleView() = default;
void SharesheetBubbleView::ShowBubble() {
views::Widget* widget = views::BubbleDialogDelegateView::CreateBubble(this);
GetWidget()->GetRootView()->Layout();
widget->Show();
}
gfx::Size SharesheetBubbleView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
gfx::Size size = gfx::Size(width, GetHeightForWidth(width));
return size;
}
// 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_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SHARESHEET_BUBBLE_VIEW_H_
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
class SharesheetBubbleView : public views::BubbleDialogDelegateView {
public:
explicit SharesheetBubbleView(views::View* anchor_view);
SharesheetBubbleView(const SharesheetBubbleView&) = delete;
SharesheetBubbleView& operator=(const SharesheetBubbleView&) = delete;
~SharesheetBubbleView() override;
void ShowBubble();
// views::BubbleDialogDelegateView overrides
gfx::Size CalculatePreferredSize() const override;
};
#endif // CHROME_BROWSER_UI_VIEWS_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/toolbar/sharesheet_button.h"
#include <memory>
#include "chrome/browser/sharesheet/sharesheet_service_delegate.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/gfx/paint_vector_icon.h"
SharesheetButton::SharesheetButton(Browser* browser)
: ToolbarButton(this), browser_(browser) {}
SharesheetButton::~SharesheetButton() = default;
void SharesheetButton::UpdateIcon() {
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(vector_icons::kHelpIcon, GetIconSize(),
GetThemeProvider()->GetColor(
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)));
}
void SharesheetButton::ButtonPressed(views::Button* sender,
const ui::Event& event) {
// On button press show sharesheet bubble.
auto sharesheet_service_delegate =
std::make_unique<sharesheet::SharesheetServiceDelegate>(
browser_->tab_strip_model()->GetActiveWebContents(),
/* bubble_anchor_view */ this);
sharesheet_service_delegate->ShowBubble();
}
int SharesheetButton::GetIconSize() const {
const bool touch_ui = ui::TouchUiController::Get()->touch_ui();
return (touch_ui && !browser_->app_controller()) ? kDefaultTouchableIconSize
: kDefaultIconSize;
}
// 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_TOOLBAR_SHARESHEET_BUTTON_H_
#define CHROME_BROWSER_UI_VIEWS_TOOLBAR_SHARESHEET_BUTTON_H_
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
class Browser;
class SharesheetButton : public ToolbarButton, public views::ButtonListener {
public:
explicit SharesheetButton(Browser* browser);
SharesheetButton(const SharesheetButton&) = delete;
SharesheetButton& operator=(const SharesheetButton&) = delete;
~SharesheetButton() override;
void UpdateIcon();
private:
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
int GetIconSize() const;
Browser* const browser_;
};
#endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_SHARESHEET_BUTTON_H_
......@@ -54,6 +54,7 @@
#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/home_button.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "chrome/browser/ui/views/toolbar/sharesheet_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_account_icon_container_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
......@@ -233,6 +234,13 @@ void ToolbarView::Init() {
media_button = std::make_unique<MediaToolbarButtonView>(browser_);
}
std::unique_ptr<SharesheetButton> sharesheet_button;
#if defined(OS_CHROMEOS)
if (base::FeatureList::IsEnabled(features::kSharesheet)) {
sharesheet_button = std::make_unique<SharesheetButton>(browser_);
}
#endif
std::unique_ptr<ToolbarAccountIconContainerView>
toolbar_account_icon_container;
bool show_avatar_toolbar_button = true;
......@@ -270,6 +278,9 @@ void ToolbarView::Init() {
if (media_button)
media_button_ = AddChildView(std::move(media_button));
if (sharesheet_button)
sharesheet_button_ = AddChildView(std::move(sharesheet_button));
if (toolbar_account_icon_container) {
toolbar_account_icon_container_ =
AddChildView(std::move(toolbar_account_icon_container));
......@@ -927,6 +938,9 @@ void ToolbarView::LoadImages() {
if (media_button_)
media_button_->UpdateIcon();
if (sharesheet_button_)
sharesheet_button_->UpdateIcon();
if (avatar_)
avatar_->UpdateIcon();
......
......@@ -49,6 +49,7 @@ class ExtensionsToolbarContainer;
class HomeButton;
class MediaToolbarButtonView;
class ReloadButton;
class SharesheetButton;
class ToolbarButton;
class ToolbarAccountIconContainerView;
......@@ -272,6 +273,7 @@ class ToolbarView : public views::AccessiblePaneView,
media_router::CastToolbarButton* cast_ = nullptr;
ToolbarAccountIconContainerView* toolbar_account_icon_container_ = nullptr;
AvatarToolbarButton* avatar_ = nullptr;
SharesheetButton* sharesheet_button_ = nullptr;
MediaToolbarButtonView* media_button_ = nullptr;
BrowserAppMenuButton* app_menu_button_ = nullptr;
......
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