Commit a4c8e406 authored by Connie Wan's avatar Connie Wan Committed by Commit Bot

Add a throbber to the WebUI Tab Counter

See attached bug and inline comments for details. The throbber is used to visually indicate that a background tab has been created, to ensure the user is aware of the activity. It is not meant to exactly represent the loading state of the background tabs.

Bug: 1085560
Change-Id: Id51096620a487eb549fe1395f3199f59fe49a806
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212812Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Commit-Queue: Taylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772422}
parent 138bfbad
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/layout/flex_layout.h" #include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/layout_provider.h" #include "ui/views/layout/layout_provider.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
...@@ -211,6 +212,9 @@ class WebUITabCounterButton : public views::Button, ...@@ -211,6 +212,9 @@ class WebUITabCounterButton : public views::Button,
void UpdateText(int num_tabs); void UpdateText(int num_tabs);
void UpdateColors(); void UpdateColors();
void MaybeStartThrobber(TabStripModel* tab_strip_model,
const TabStripModelChange& change);
void MaybeStopThrobber();
void Init(); void Init();
// views::Button: // views::Button:
...@@ -239,6 +243,8 @@ class WebUITabCounterButton : public views::Button, ...@@ -239,6 +243,8 @@ class WebUITabCounterButton : public views::Button,
views::Label* disappearing_label_; views::Label* disappearing_label_;
views::View* border_view_; views::View* border_view_;
std::unique_ptr<TabCounterAnimator> animator_; std::unique_ptr<TabCounterAnimator> animator_;
views::Throbber* throbber_;
base::OneShotTimer throbber_timer_;
std::unique_ptr<ui::SimpleMenuModel> menu_model_; std::unique_ptr<ui::SimpleMenuModel> menu_model_;
std::unique_ptr<views::MenuRunner> menu_runner_; std::unique_ptr<views::MenuRunner> menu_runner_;
...@@ -307,6 +313,39 @@ void WebUITabCounterButton::UpdateColors() { ...@@ -307,6 +313,39 @@ void WebUITabCounterButton::UpdateColors() {
current_text_color)); current_text_color));
} }
void WebUITabCounterButton::MaybeStartThrobber(
TabStripModel* tab_strip_model,
const TabStripModelChange& change) {
// Start the throbber if at least one background tab is created during this
// TabStripModelChange. New active tabs are ignored since the user doesn't
// need the additional visual indication that a tab was created.
if (change.type() == TabStripModelChange::kInserted) {
const auto& contents = change.GetInsert()->contents;
if (contents.size() > 1 ||
tab_strip_model->GetActiveWebContents() != contents[0].contents) {
throbber_->Start();
// Automatically stop the throbber after 1 second. Currently we do not
// check the real loading state of the new tab(s), as that adds
// unnecessary complexity. The purpose of the throbber is just to indicate
// to the user that some activity has happened in the background, which
// may not otherwise have been obvious because the tab strip is hidden in
// this mode.
throbber_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(1000),
this, &WebUITabCounterButton::MaybeStopThrobber);
}
}
}
void WebUITabCounterButton::MaybeStopThrobber() {
// Stop the throbber if no other background tabs have been created. Otherwise,
// reset the timer to keep the throbber running smoothly.
if (throbber_timer_.IsRunning())
throbber_timer_.Reset();
else
throbber_->Stop();
}
void WebUITabCounterButton::Init() { void WebUITabCounterButton::Init() {
SetID(VIEW_ID_WEBUI_TAB_STRIP_TAB_COUNTER); SetID(VIEW_ID_WEBUI_TAB_STRIP_TAB_COUNTER);
...@@ -334,6 +373,8 @@ void WebUITabCounterButton::Init() { ...@@ -334,6 +373,8 @@ void WebUITabCounterButton::Init() {
animator_ = std::make_unique<TabCounterAnimator>( animator_ = std::make_unique<TabCounterAnimator>(
appearing_label_, disappearing_label_, border_view_); appearing_label_, disappearing_label_, border_view_);
throbber_ = AddChildView(std::make_unique<views::Throbber>());
set_context_menu_controller(this); set_context_menu_controller(this);
menu_model_ = std::make_unique<ui::SimpleMenuModel>(this); menu_model_ = std::make_unique<ui::SimpleMenuModel>(this);
menu_model_->AddItemWithIcon( menu_model_->AddItemWithIcon(
...@@ -390,6 +431,7 @@ void WebUITabCounterButton::Layout() { ...@@ -390,6 +431,7 @@ void WebUITabCounterButton::Layout() {
appearing_label_->SetBounds(0, 0, border_width, kDesiredBorderHeight); appearing_label_->SetBounds(0, 0, border_width, kDesiredBorderHeight);
disappearing_label_->SetBounds(0, -kOffscreenLabelDistance, border_width, disappearing_label_->SetBounds(0, -kOffscreenLabelDistance, border_width,
kDesiredBorderHeight); kDesiredBorderHeight);
throbber_->SetBoundsRect(GetLocalBounds());
animator_->LayoutIfAnimating(); animator_->LayoutIfAnimating();
} }
...@@ -399,6 +441,7 @@ void WebUITabCounterButton::OnTabStripModelChanged( ...@@ -399,6 +441,7 @@ void WebUITabCounterButton::OnTabStripModelChanged(
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) { const TabStripSelectionChange& selection) {
UpdateText(tab_strip_model->count()); UpdateText(tab_strip_model->count());
MaybeStartThrobber(tab_strip_model, change);
} }
void WebUITabCounterButton::ShowContextMenuForViewImpl( void WebUITabCounterButton::ShowContextMenuForViewImpl(
......
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