Skip to content

Commit

Permalink
Add a throbber for "Connecting..." device in Bluetooth details view.
Browse files Browse the repository at this point in the history
* Adds HoverHighlightView::AddRightView() to add a generic view to the right side. I keep AddRightIcon() as a convenient function and wire it to AddRightView().
* Adds throbber for "Connecting..." device using the API above.

BUG=663154
TEST=manually tested.

Review-Url: https://codereview.chromium.org/2504243002
Cr-Commit-Position: refs/heads/master@{#432809}
  • Loading branch information
fukino authored and Commit bot committed Nov 17, 2016
1 parent f4fd198 commit d1325de
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
3 changes: 3 additions & 0 deletions ash/common/system/chromeos/bluetooth/tray_bluetooth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ class BluetoothDetailedView : public TrayDetailsView {
container->AddIconAndLabels(
image, text, l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
ThrobberView* throbber = new ThrobberView;
throbber->Start();
container->AddRightView(throbber);
}

// Add settings entries.
Expand Down
6 changes: 3 additions & 3 deletions ash/common/system/chromeos/palette/common_palette_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CommonPaletteTool::OnEnable() {
start_time_ = base::TimeTicks::Now();

if (highlight_view_) {
highlight_view_->SetRightIconVisible(true);
highlight_view_->SetRightViewVisible(true);
highlight_view_->SetAccessiblityState(
HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
}
Expand All @@ -70,7 +70,7 @@ void CommonPaletteTool::OnDisable() {
AddHistogramTimes(GetToolId(), base::TimeTicks::Now() - start_time_);

if (highlight_view_) {
highlight_view_->SetRightIconVisible(false);
highlight_view_->SetRightViewVisible(false);
highlight_view_->SetAccessiblityState(
HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) {
highlight_view_->SetAccessiblityState(
HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
} else {
highlight_view_->SetRightIconVisible(false);
highlight_view_->SetRightViewVisible(false);
highlight_view_->SetAccessiblityState(
HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
}
Expand Down
44 changes: 25 additions & 19 deletions ash/common/system/tray/hover_highlight_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,45 @@ bool HoverHighlightView::GetTooltipText(const gfx::Point& p,
return true;
}

// TODO(tdanderson|fukino): Consider changing this to a more generic type
// to permit other elements, such as a spinner.
void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image,
int icon_size) {
DCHECK(!right_icon_);
DCHECK(!right_view_);

if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
DCHECK(tri_view_);
views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView();
right_icon->SetImage(image);
AddRightView(right_icon);
return;
}

views::ImageView* right_icon = new FixedSizedImageView(icon_size, icon_size);
right_icon->SetImage(image);
AddRightView(right_icon);
}

right_icon_ = TrayPopupUtils::CreateMainImageView();
right_icon_->SetImage(image);
right_icon_->SetEnabled(enabled());
tri_view_->AddView(TriView::Container::END, right_icon_);
void HoverHighlightView::AddRightView(views::View* view) {
DCHECK(!right_view_);

right_view_ = view;
right_view_->SetEnabled(enabled());
if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
DCHECK(tri_view_);
tri_view_->AddView(TriView::Container::END, right_view_);
tri_view_->SetContainerVisible(TriView::Container::END, true);
return;
}

DCHECK(box_layout_);

right_icon_ = new FixedSizedImageView(icon_size, icon_size);
right_icon_->SetImage(image);
right_icon_->SetEnabled(enabled());
AddChildView(right_icon_);
AddChildView(right_view_);
}

// TODO(tdanderson): Ensure all checkable detailed view rows use this
// mechanism, and share the code that sets the accessible state for
// a checkbox. See crbug.com/652674.
void HoverHighlightView::SetRightIconVisible(bool visible) {
if (!right_icon_)
void HoverHighlightView::SetRightViewVisible(bool visible) {
if (!right_view_)
return;

right_icon_->SetVisible(visible);
right_view_->SetVisible(visible);
Layout();
}

Expand Down Expand Up @@ -392,8 +398,8 @@ void HoverHighlightView::OnEnabledChanged() {
left_icon_->SetEnabled(enabled());
if (text_label_)
text_label_->SetEnabled(enabled());
if (right_icon_)
right_icon_->SetEnabled(enabled());
if (right_view_)
right_view_->SetEnabled(enabled());
} else {
if (!enabled())
SetHoverHighlight(false);
Expand Down
10 changes: 7 additions & 3 deletions ash/common/system/tray/hover_highlight_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ class HoverHighlightView : public ActionableView {
// the other Add* functions first). |icon_size| is the size of the icon in DP.
void AddRightIcon(const gfx::ImageSkia& image, int icon_size);

// Hide or show the right icon.
void SetRightIconVisible(bool visible);
// Add an optional right view to an already established view (call one of
// the other Add* functions first).
void AddRightView(views::View* view);

// Hide or show the right view.
void SetRightViewVisible(bool visible);

// Allows view to expand its height.
// Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
Expand Down Expand Up @@ -174,7 +178,7 @@ class HoverHighlightView : public ActionableView {
views::Label* sub_text_label_ = nullptr;
views::BoxLayout* box_layout_ = nullptr; // Not used in material design.
views::ImageView* left_icon_ = nullptr;
views::ImageView* right_icon_ = nullptr;
views::View* right_view_ = nullptr;
TriView* tri_view_ = nullptr; // Only used in material design.
SkColor highlight_color_ = 0; // Not used in material design.
SkColor default_color_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/tray_accessibility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ HoverHighlightView* AccessibilityDetailedView::AddScrollListItem(
gfx::ImageSkia check_mark =
CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700);
container->AddRightIcon(check_mark, check_mark.width());
container->SetRightIconVisible(checked);
container->SetRightViewVisible(checked);
} else {
container->AddCheckableLabel(text, highlight, checked);
}
Expand Down

0 comments on commit d1325de

Please sign in to comment.