Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: ash/system/tray/tray_views.cc

Issue 12180027: Add spinner UI to show bluetooth is discovering devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a subclass of SmoothedThrobber and override GetTooltipText to show tooltip on throbber. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/tray/tray_views.h" 5 #include "ash/system/tray/tray_views.h"
6 6
7 #include "ash/ash_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/system/tray/tray_constants.h" 8 #include "ash/system/tray/tray_constants.h"
9 #include "ash/system/tray/tray_item_view.h" 9 #include "ash/system/tray/tray_item_view.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "grit/ash_resources.h" 11 #include "grit/ash_resources.h"
12 #include "grit/ash_strings.h" 12 #include "grit/ash_strings.h"
13 #include "grit/ui_resources.h" 13 #include "grit/ui_resources.h"
14 #include "ui/base/accessibility/accessible_view_state.h" 14 #include "ui/base/accessibility/accessible_view_state.h"
15 #include "ui/base/events/event.h" 15 #include "ui/base/events/event.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
21 #include "ui/gfx/text_constants.h" 23 #include "ui/gfx/text_constants.h"
22 #include "ui/gfx/vector2d.h" 24 #include "ui/gfx/vector2d.h"
23 #include "ui/native_theme/native_theme.h" 25 #include "ui/native_theme/native_theme.h"
24 #include "ui/views/border.h" 26 #include "ui/views/border.h"
25 #include "ui/views/controls/button/image_button.h" 27 #include "ui/views/controls/button/image_button.h"
26 #include "ui/views/controls/label.h" 28 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/box_layout.h" 29 #include "ui/views/layout/box_layout.h"
28 #include "ui/views/layout/fill_layout.h" 30 #include "ui/views/layout/fill_layout.h"
29 #include "ui/views/layout/grid_layout.h" 31 #include "ui/views/layout/grid_layout.h"
30 #include "ui/views/painter.h" 32 #include "ui/views/painter.h"
31 33
32 namespace ash { 34 namespace ash {
33 namespace internal { 35 namespace internal {
34 36
35 namespace { 37 namespace {
36 const int kIconPaddingLeft = 5; 38 const int kIconPaddingLeft = 5;
37 const int kPopupDetailLabelExtraLeftMargin = 8; 39 const int kPopupDetailLabelExtraLeftMargin = 8;
38 const int kCheckLabelPadding = 4; 40 const int kCheckLabelPadding = 4;
39 const int kSpecialPopupRowHeight = 55; 41 const int kSpecialPopupRowHeight = 55;
40 const int kTrayPopupLabelButtonPaddingHorizontal = 16; 42 const int kTrayPopupLabelButtonPaddingHorizontal = 16;
41 const int kTrayPopupLabelButtonPaddingVertical = 8; 43 const int kTrayPopupLabelButtonPaddingVertical = 8;
42 44
45 // Time in ms per throbber frame.
46 const int kThrobberFrameMs = 50;
47
48 // Duration for showing/hiding animation in milliseconds.
49 const int kThrobberAnimationDurationMs = 200;
50
43 const int kBarImagesActive[] = { 51 const int kBarImagesActive[] = {
44 IDR_SLIDER_ACTIVE_LEFT, 52 IDR_SLIDER_ACTIVE_LEFT,
45 IDR_SLIDER_ACTIVE_CENTER, 53 IDR_SLIDER_ACTIVE_CENTER,
46 IDR_SLIDER_ACTIVE_RIGHT, 54 IDR_SLIDER_ACTIVE_RIGHT,
47 }; 55 };
48 56
49 const int kBarImagesDisabled[] = { 57 const int kBarImagesDisabled[] = {
50 IDR_SLIDER_DISABLED_LEFT, 58 IDR_SLIDER_DISABLED_LEFT,
51 IDR_SLIDER_DISABLED_CENTER, 59 IDR_SLIDER_DISABLED_CENTER,
52 IDR_SLIDER_DISABLED_RIGHT, 60 IDR_SLIDER_DISABLED_RIGHT,
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 bar_image_y + image_height_ - 3, 612 bar_image_y + image_height_ - 3,
605 rect.width(), 613 rect.width(),
606 title_size.height()); 614 title_size.height());
607 } 615 }
608 } 616 }
609 617
610 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { 618 void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
611 image_->Update(control_on); 619 image_->Update(control_on);
612 } 620 }
613 621
622 SystemTrayThrobber::SystemTrayThrobber(int frame_delay_ms)
623 : views::SmoothedThrobber(frame_delay_ms) {
624 }
625
626 SystemTrayThrobber::~SystemTrayThrobber() {
627 }
628
629 void SystemTrayThrobber::SetTooltipText(const string16& tooltip_text) {
630 tooltip_text_ = tooltip_text;
631 }
632
633 bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p,
634 string16* tooltip) const {
635 if (tooltip_text_.empty())
636 return false;
637
638 *tooltip = tooltip_text_;
639 return true;
640 }
641
642 ThrobberView::ThrobberView() {
643 throbber_ = new SystemTrayThrobber(kThrobberFrameMs);
644 throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs);
645 AddChildView(throbber_);
646
647 SetPaintToLayer(true);
648 layer()->SetFillsBoundsOpaquely(false);
649 layer()->SetOpacity(0.0);
650 }
651
652 ThrobberView::~ThrobberView() {
653 }
654
655 gfx::Size ThrobberView::GetPreferredSize() {
656 return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight);
657 }
658
659 void ThrobberView::Layout() {
660 View* child = child_at(0);
661 gfx::Size ps = child->GetPreferredSize();
662 child->SetBounds((width() - ps.width()) / 2,
663 (height() - ps.height()) / 2,
664 ps.width(), ps.height());
665 SizeToPreferredSize();
666 }
667
668 bool ThrobberView::GetTooltipText(const gfx::Point& p,
669 string16* tooltip) const {
670 if (tooltip_text_.empty())
671 return false;
672
673 *tooltip = tooltip_text_;
674 return true;
675 }
676
677 void ThrobberView::Start() {
678 ScheduleAnimation(true);
679 throbber_->Start();
680 }
681
682 void ThrobberView::Stop() {
683 ScheduleAnimation(false);
684 throbber_->Stop();
685 }
686
687 void ThrobberView::SetTooltipText(const string16& tooltip_text) {
688 tooltip_text_ = tooltip_text;
689 throbber_->SetTooltipText(tooltip_text);
690 }
691
692 void ThrobberView::ScheduleAnimation(bool start_throbber) {
693 // Stop any previous animation.
694 layer()->GetAnimator()->StopAnimating();
695
696 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
697 animation.SetTransitionDuration(
698 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs));
699
700 layer()->SetOpacity(start_throbber ? 1.0 : 0.0);
701 }
702
614 //////////////////////////////////////////////////////////////////////////////// 703 ////////////////////////////////////////////////////////////////////////////////
615 // SpecialPopupRow 704 // SpecialPopupRow
616 705
617 SpecialPopupRow::SpecialPopupRow() 706 SpecialPopupRow::SpecialPopupRow()
618 : content_(NULL), 707 : content_(NULL),
619 button_container_(NULL) { 708 button_container_(NULL) {
620 views::Background* background = views::Background::CreateBackgroundPainter( 709 views::Background* background = views::Background::CreateBackgroundPainter(
621 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, 710 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight,
622 kHeaderBackgroundColorDark)); 711 kHeaderBackgroundColorDark));
623 background->SetNativeControlColor(kHeaderBackgroundColorDark); 712 background->SetNativeControlColor(kHeaderBackgroundColorDark);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 751
663 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { 752 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) {
664 if (!button_container_) { 753 if (!button_container_) {
665 button_container_ = CreatePopupHeaderButtonsContainer(); 754 button_container_ = CreatePopupHeaderButtonsContainer();
666 AddChildView(button_container_); 755 AddChildView(button_container_);
667 } 756 }
668 757
669 button_container_->AddChildView(button); 758 button_container_->AddChildView(button);
670 } 759 }
671 760
761 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) {
762 if (!button_container_) {
763 button_container_ = CreatePopupHeaderButtonsContainer();
764 AddChildView(button_container_);
765 }
766
767 button_container_->AddChildView(throbber);
768 }
769
672 gfx::Size SpecialPopupRow::GetPreferredSize() { 770 gfx::Size SpecialPopupRow::GetPreferredSize() {
673 gfx::Size size = views::View::GetPreferredSize(); 771 gfx::Size size = views::View::GetPreferredSize();
674 size.set_height(kSpecialPopupRowHeight); 772 size.set_height(kSpecialPopupRowHeight);
675 return size; 773 return size;
676 } 774 }
677 775
678 void SpecialPopupRow::Layout() { 776 void SpecialPopupRow::Layout() {
679 views::View::Layout(); 777 views::View::Layout();
680 gfx::Rect content_bounds = GetContentsBounds(); 778 gfx::Rect content_bounds = GetContentsBounds();
681 if (content_bounds.IsEmpty()) 779 if (content_bounds.IsEmpty())
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 tray_view->set_border(views::Border::CreateEmptyBorder( 838 tray_view->set_border(views::Border::CreateEmptyBorder(
741 kTrayLabelItemVerticalPaddingVeriticalAlignment, 839 kTrayLabelItemVerticalPaddingVeriticalAlignment,
742 horizontal_padding, 840 horizontal_padding,
743 kTrayLabelItemVerticalPaddingVeriticalAlignment, 841 kTrayLabelItemVerticalPaddingVeriticalAlignment,
744 horizontal_padding)); 842 horizontal_padding));
745 } 843 }
746 } 844 }
747 845
748 } // namespace internal 846 } // namespace internal
749 } // namespace ash 847 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698