Commit 688a15be authored by siyua's avatar siyua Committed by Commit Bot

[Autofill Auth UI] Add prgress bar to BubbleFrameView.

Add it to (bubble) dialog's parent class so that it can be reused.
It is added to the top of the dialog.

Add some screenshots in bug comment 17 to visualize this change (It
will not be shown in the bubble in the screenshots, just to make it
easier to see what it will look like).

Bug: 991037
Change-Id: I4b18bfa510efbd585c50154c66613fc9a7c80b12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1830092
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703921}
parent 3f789b50
......@@ -66,6 +66,10 @@ int GetOverflowLength(const gfx::Rect& available_bounds,
std::max(0, window_bounds.right() - available_bounds.right());
}
// The height of the progress indicator shown at the top of the bubble frame
// view.
constexpr int kProgressIndicatorHeight = 4;
} // namespace
// static
......@@ -91,6 +95,12 @@ BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins,
close->SetTooltipText(base::string16());
#endif
close_ = AddChildView(std::move(close));
auto progress_indicator = std::make_unique<ProgressBar>(
kProgressIndicatorHeight, /*allow_round_corner=*/false);
progress_indicator->SetBackgroundColor(SK_ColorTRANSPARENT);
progress_indicator->SetVisible(false);
progress_indicator_ = AddChildView(std::move(progress_indicator));
}
BubbleFrameView::~BubbleFrameView() = default;
......@@ -265,6 +275,12 @@ void BubbleFrameView::SetTitleView(std::unique_ptr<View> title_view) {
AddChildViewAt(title_view.release(), GetIndexOf(title_icon_) + 1);
}
void BubbleFrameView::SetProgress(base::Optional<double> progress) {
progress_indicator_->SetVisible(progress.has_value());
if (progress)
progress_indicator_->SetValue(progress.value());
}
const char* BubbleFrameView::GetClassName() const {
return kViewClassName;
}
......@@ -313,6 +329,11 @@ void BubbleFrameView::Layout() {
(!custom_title_ && !default_title_->GetVisible()));
const gfx::Rect contents_bounds = GetContentsBounds();
progress_indicator_->SetBounds(contents_bounds.x(), contents_bounds.y(),
contents_bounds.width(),
kProgressIndicatorHeight);
gfx::Rect bounds = contents_bounds;
bounds.Inset(title_margins_);
......
......@@ -16,6 +16,7 @@
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/progress_bar.h"
#include "ui/views/input_event_activation_protector.h"
#include "ui/views/window/non_client_view.h"
......@@ -60,6 +61,10 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
// label. If there is an existing title view it will be deleted.
void SetTitleView(std::unique_ptr<View> title_view);
// Updates the current progress value of |progress_indicator_|. If progress is
// absent, hides |the progress_indicator|.
void SetProgress(base::Optional<double> progress);
// View:
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
......@@ -167,6 +172,7 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
private:
FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, RemoveFootnoteView);
FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, LayoutWithIcon);
FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, LayoutWithProgressIndicator);
FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, IgnorePossiblyUnintendedClicks);
FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CloseReasons);
FRIEND_TEST_ALL_PREFIXES(BubbleDialogDelegateViewTest, CloseMethods);
......@@ -234,6 +240,10 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
// The optional close button (the X).
Button* close_ = nullptr;
// The optional progress bar. Used to indicate bubble pending state. By
// default it is invisible.
ProgressBar* progress_indicator_ = nullptr;
// The optional header view.
View* header_view_ = nullptr;
......
......@@ -1265,4 +1265,24 @@ TEST_F(BubbleFrameViewTest, IgnorePossiblyUnintendedClicks) {
EXPECT_TRUE(bubble->IsClosed());
}
// Ensures that layout is correct when the progress indicator is visible.
TEST_F(BubbleFrameViewTest, LayoutWithProgressIndicator) {
TestBubbleDialogDelegateView delegate;
TestAnchor anchor(CreateParams(Widget::InitParams::TYPE_WINDOW));
delegate.SetAnchorView(anchor.widget().GetContentsView());
Widget* bubble = BubbleDialogDelegateView::CreateBubble(&delegate);
bubble->Show();
BubbleFrameView* frame = delegate.GetBubbleFrameView();
frame->SetProgress(/*infinite animation*/ -1);
View* progress_indicator = frame->progress_indicator_;
// Ensures the progress indicator is visible and takes full widget width.
EXPECT_TRUE(progress_indicator->GetVisible());
EXPECT_EQ(progress_indicator->x(), 0);
EXPECT_EQ(progress_indicator->y(), 0);
EXPECT_EQ(progress_indicator->width(),
bubble->GetWindowBoundsInScreen().width());
}
} // namespace views
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