Commit 41badf1e authored by Melissa Zhang's avatar Melissa Zhang Committed by Commit Bot

[Sharesheet] Anchor bubble to centre of Files app

Bug: 1097623
Change-Id: Ib864f2ddef5774f11394c0bcf53792c27333b1a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355167Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Melissa Zhang <melzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798921}
parent a00caf6f
...@@ -2047,6 +2047,8 @@ static_library("ui") { ...@@ -2047,6 +2047,8 @@ static_library("ui") {
"views/profiles/profile_indicator_icon.h", "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.cc",
"views/relaunch_notification/relaunch_notification_controller_platform_impl_chromeos.h", "views/relaunch_notification/relaunch_notification_controller_platform_impl_chromeos.h",
"views/sharesheet_bubble_view.cc",
"views/sharesheet_bubble_view.h",
# On chromeos, file manager extension handles the file open/save dialog. # On chromeos, file manager extension handles the file open/save dialog.
"views/select_file_dialog_extension.cc", "views/select_file_dialog_extension.cc",
...@@ -3779,8 +3781,6 @@ static_library("ui") { ...@@ -3779,8 +3781,6 @@ static_library("ui") {
"views/send_tab_to_self/send_tab_to_self_icon_view.h", "views/send_tab_to_self/send_tab_to_self_icon_view.h",
"views/session_crashed_bubble_view.cc", "views/session_crashed_bubble_view.cc",
"views/session_crashed_bubble_view.h", "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.cc",
"views/sharing/sharing_dialog_view.h", "views/sharing/sharing_dialog_view.h",
"views/sharing/sharing_icon_view.cc", "views/sharing/sharing_icon_view.cc",
......
...@@ -9,8 +9,11 @@ ...@@ -9,8 +9,11 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharesheet/sharesheet_service_delegate.h" #include "chrome/browser/sharesheet/sharesheet_service_delegate.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
...@@ -39,6 +42,8 @@ constexpr int kButtonHeight = 104; ...@@ -39,6 +42,8 @@ constexpr int kButtonHeight = 104;
constexpr int kButtonLineHeight = 20; constexpr int kButtonLineHeight = 20;
constexpr int kButtonPadding = 8; constexpr int kButtonPadding = 8;
constexpr int kBubbleTopPaddingFromWindow = 36;
constexpr int kCornerRadius = 12; constexpr int kCornerRadius = 12;
constexpr int kMaxTargetsPerRow = 4; constexpr int kMaxTargetsPerRow = 4;
// TargetViewHeight is 2*kButtonHeight + kButtonPadding // TargetViewHeight is 2*kButtonHeight + kButtonPadding
...@@ -115,9 +120,28 @@ SharesheetBubbleView::SharesheetBubbleView( ...@@ -115,9 +120,28 @@ SharesheetBubbleView::SharesheetBubbleView(
content::WebContents* web_contents, content::WebContents* web_contents,
sharesheet::SharesheetServiceDelegate* delegate) sharesheet::SharesheetServiceDelegate* delegate)
: delegate_(delegate) { : delegate_(delegate) {
// TODO(crbug.com/1097623): Make the bubble located in the center of the // TODO(crbug.com/1097623): When supporting open from multiple apps,
// invoke window. // pass in |app_id| and get NativeWindow from it.
set_parent_window(web_contents->GetNativeView()); Profile* const profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
gfx::NativeWindow parent =
extensions::AppWindowRegistry::Get(profile)
->GetCurrentAppWindowForApp(extension_misc::kFilesManagerAppId)
->GetNativeWindow();
set_parent_window(parent);
View* parent_view =
views::Widget::GetWidgetForNativeWindow(parent)->GetRootView();
// Horizontally centered
int x_within_parent_view = parent_view->GetMirroredXInView(
(parent_view->bounds().width() - kBubbleWidth) / 2);
// Get position in screen, taking parent view origin into account. This is
// 0,0 in fullscreen on the primary display, but not on secondary displays, or
// in Hosted App windows.
gfx::Point origin = parent_view->GetBoundsInScreen().origin();
origin += gfx::Vector2d(x_within_parent_view, kBubbleTopPaddingFromWindow);
SetAnchorRect(gfx::Rect(origin, gfx::Size()));
CreateBubble(); CreateBubble();
} }
...@@ -233,6 +257,7 @@ gfx::Size SharesheetBubbleView::CalculatePreferredSize() const { ...@@ -233,6 +257,7 @@ gfx::Size SharesheetBubbleView::CalculatePreferredSize() const {
} }
void SharesheetBubbleView::CreateBubble() { void SharesheetBubbleView::CreateBubble() {
set_close_on_deactivate(true);
SetButtons(ui::DIALOG_BUTTON_NONE); SetButtons(ui::DIALOG_BUTTON_NONE);
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
......
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