diff options
author | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 00:57:53 +0000 |
---|---|---|
committer | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 00:57:53 +0000 |
commit | a0c4919137680d489b2ae36d870137d64bb036de (patch) | |
tree | cd13ac0e51e571af043fd0464a065562ebb60602 /ash/system | |
parent | 0e36041499e26100bdcf3bc93c7f41364591f74e (diff) | |
download | chromium_src-a0c4919137680d489b2ae36d870137d64bb036de.zip chromium_src-a0c4919137680d489b2ae36d870137d64bb036de.tar.gz chromium_src-a0c4919137680d489b2ae36d870137d64bb036de.tar.bz2 |
Refactor SpecialPopupRow out of tray_views.h/cc into its own files.
BUG=176144
TBR=sky
Review URL: https://codereview.chromium.org/12263021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182360 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system')
-rw-r--r-- | ash/system/tray/special_popup_row.cc | 154 | ||||
-rw-r--r-- | ash/system/tray/special_popup_row.h | 53 | ||||
-rw-r--r-- | ash/system/tray/tray_details_view.h | 2 | ||||
-rw-r--r-- | ash/system/tray/tray_views.cc | 133 | ||||
-rw-r--r-- | ash/system/tray/tray_views.h | 26 |
5 files changed, 208 insertions, 160 deletions
diff --git a/ash/system/tray/special_popup_row.cc b/ash/system/tray/special_popup_row.cc new file mode 100644 index 0000000..c357aa5 --- /dev/null +++ b/ash/system/tray/special_popup_row.cc @@ -0,0 +1,154 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/tray/special_popup_row.h" + +#include "ash/system/tray/tray_constants.h" +#include "ash/system/tray/tray_views.h" +#include "grit/ash_resources.h" +#include "grit/ash_strings.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/rect.h" +#include "ui/views/border.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/painter.h" + +namespace ash { +namespace internal { + +namespace { + +const int kIconPaddingLeft = 5; +const int kSpecialPopupRowHeight = 55; +const int kBorderHeight = 3; +const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae); +const SkColor kBorderGradientLight = SkColorSetRGB(0xe8, 0xe8, 0xe8); + +views::View* CreatePopupHeaderButtonsContainer() { + views::View* view = new views::View; + view->SetLayoutManager(new + views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); + view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); + return view; +} + +class SpecialPopupRowBorder : public views::Border { + public: + SpecialPopupRowBorder() + : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark, + kBorderGradientLight)) { + } + + virtual ~SpecialPopupRowBorder() {} + + private: + virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { + views::Painter::PaintPainterAt(canvas, painter_.get(), + gfx::Rect(gfx::Size(view.width(), kBorderHeight))); + } + + virtual gfx::Insets GetInsets() const OVERRIDE { + return gfx::Insets(kBorderHeight, 0, 0, 0); + } + + scoped_ptr<views::Painter> painter_; + + DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder); +}; + +} // namespace + +SpecialPopupRow::SpecialPopupRow() + : content_(NULL), + button_container_(NULL) { + views::Background* background = views::Background::CreateBackgroundPainter( + true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, + kHeaderBackgroundColorDark)); + background->SetNativeControlColor(kHeaderBackgroundColorDark); + set_background(background); + set_border(new SpecialPopupRowBorder); + SetLayoutManager( + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); +} + +SpecialPopupRow::~SpecialPopupRow() { +} + +void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + HoverHighlightView* container = new HoverHighlightView(listener); + container->SetLayoutManager(new + views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); + + container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); + container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); + container->set_text_highlight_color(kHeaderTextColorHover); + container->set_text_default_color(kHeaderTextColorNormal); + + container->AddIconAndLabel( + *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), + rb.GetLocalizedString(string_id), + gfx::Font::BOLD); + + container->set_border(views::Border::CreateEmptyBorder(0, + kTrayPopupPaddingHorizontal, 0, 0)); + + container->SetAccessibleName( + rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); + SetContent(container); +} + +void SpecialPopupRow::SetContent(views::View* view) { + CHECK(!content_); + content_ = view; + AddChildViewAt(content_, 0); +} + +void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { + if (!button_container_) { + button_container_ = CreatePopupHeaderButtonsContainer(); + AddChildView(button_container_); + } + button_container_->AddChildView(button); +} + +void SpecialPopupRow::AddThrobber(ThrobberView* throbber) { + if (!button_container_) { + button_container_ = CreatePopupHeaderButtonsContainer(); + AddChildView(button_container_); + } + button_container_->AddChildView(throbber); +} + +gfx::Size SpecialPopupRow::GetPreferredSize() { + gfx::Size size = views::View::GetPreferredSize(); + size.set_height(kSpecialPopupRowHeight); + return size; +} + +void SpecialPopupRow::Layout() { + views::View::Layout(); + gfx::Rect content_bounds = GetContentsBounds(); + if (content_bounds.IsEmpty()) + return; + if (!button_container_) { + content_->SetBoundsRect(GetContentsBounds()); + return; + } + + gfx::Rect bounds(button_container_->GetPreferredSize()); + bounds.set_height(content_bounds.height()); + gfx::Rect container_bounds = content_bounds; + container_bounds.ClampToCenteredSize(bounds.size()); + container_bounds.set_x(content_bounds.width() - container_bounds.width()); + button_container_->SetBoundsRect(container_bounds); + + bounds = content_->bounds(); + bounds.set_width(button_container_->x()); + content_->SetBoundsRect(bounds); +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/tray/special_popup_row.h b/ash/system/tray/special_popup_row.h new file mode 100644 index 0000000..32821f57 --- /dev/null +++ b/ash/system/tray/special_popup_row.h @@ -0,0 +1,53 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ +#define ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ + +#include "ui/gfx/size.h" +#include "ui/views/view.h" + +namespace views { +class Label; +} + +namespace ash { +namespace internal { + +class ThrobberView; +class TrayItemView; +class TrayPopupHeaderButton; +class ViewClickListener; + +// The 'special' looking row in the uber-tray popups. This is usually the bottom +// row in the popups, and has a fixed height. +class SpecialPopupRow : public views::View { + public: + SpecialPopupRow(); + virtual ~SpecialPopupRow(); + + void SetTextLabel(int string_id, ViewClickListener* listener); + void SetContent(views::View* view); + + void AddButton(TrayPopupHeaderButton* button); + void AddThrobber(ThrobberView* throbber); + + views::View* content() const { return content_; } + + private: + // Overridden from views::View. + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void Layout() OVERRIDE; + + views::View* content_; + views::View* button_container_; + views::Label* text_label_; + + DISALLOW_COPY_AND_ASSIGN(SpecialPopupRow); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ diff --git a/ash/system/tray/tray_details_view.h b/ash/system/tray/tray_details_view.h index 3801e80..073873a 100644 --- a/ash/system/tray/tray_details_view.h +++ b/ash/system/tray/tray_details_view.h @@ -5,6 +5,7 @@ #ifndef ASH_SYSTEM_TRAY_TRAY_DETAILS_VIEW_H_ #define ASH_SYSTEM_TRAY_TRAY_DETAILS_VIEW_H_ +#include "ash/system/tray/special_popup_row.h" #include "ui/views/view.h" namespace views { @@ -19,7 +20,6 @@ namespace internal { class FixedSizedScrollView; class ScrollBorder; -class SpecialPopupRow; class ViewClickListener; class TrayDetailsView : public views::View { diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc index 2e6e7c5..f44d49e 100644 --- a/ash/system/tray/tray_views.cc +++ b/ash/system/tray/tray_views.cc @@ -35,10 +35,8 @@ namespace ash { namespace internal { namespace { -const int kIconPaddingLeft = 5; const int kPopupDetailLabelExtraLeftMargin = 8; const int kCheckLabelPadding = 4; -const int kSpecialPopupRowHeight = 55; const int kTrayPopupLabelButtonPaddingHorizontal = 16; const int kTrayPopupLabelButtonPaddingVertical = 8; @@ -83,42 +81,6 @@ const int kTrayPopupLabelButtonBorderImagesHovered[] = { IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, }; -views::View* CreatePopupHeaderButtonsContainer() { - views::View* view = new views::View; - view->SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); - view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); - return view; -} - -const int kBorderHeight = 3; -const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae); -const SkColor kBorderGradientLight = SkColorSetRGB(0xe8, 0xe8, 0xe8); - -class SpecialPopupRowBorder : public views::Border { - public: - SpecialPopupRowBorder() - : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark, - kBorderGradientLight)) { - } - - virtual ~SpecialPopupRowBorder() {} - - private: - virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { - views::Painter::PaintPainterAt(canvas, painter_.get(), - gfx::Rect(gfx::Size(view.width(), kBorderHeight))); - } - - virtual gfx::Insets GetInsets() const OVERRIDE { - return gfx::Insets(kBorderHeight, 0, 0, 0); - } - - scoped_ptr<views::Painter> painter_; - - DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder); -}; - } //////////////////////////////////////////////////////////////////////////////// @@ -700,101 +662,6 @@ void ThrobberView::ScheduleAnimation(bool start_throbber) { layer()->SetOpacity(start_throbber ? 1.0 : 0.0); } -//////////////////////////////////////////////////////////////////////////////// -// SpecialPopupRow - -SpecialPopupRow::SpecialPopupRow() - : content_(NULL), - button_container_(NULL) { - views::Background* background = views::Background::CreateBackgroundPainter( - true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, - kHeaderBackgroundColorDark)); - background->SetNativeControlColor(kHeaderBackgroundColorDark); - set_background(background); - set_border(new SpecialPopupRowBorder); - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); -} - -SpecialPopupRow::~SpecialPopupRow() { -} - -void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - HoverHighlightView* container = new HoverHighlightView(listener); - container->SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); - - container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); - container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); - container->set_text_highlight_color(kHeaderTextColorHover); - container->set_text_default_color(kHeaderTextColorNormal); - - container->AddIconAndLabel( - *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), - rb.GetLocalizedString(string_id), - gfx::Font::BOLD); - - container->set_border(views::Border::CreateEmptyBorder(0, - kTrayPopupPaddingHorizontal, 0, 0)); - - container->SetAccessibleName( - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); - SetContent(container); -} - -void SpecialPopupRow::SetContent(views::View* view) { - CHECK(!content_); - content_ = view; - AddChildViewAt(content_, 0); -} - -void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { - if (!button_container_) { - button_container_ = CreatePopupHeaderButtonsContainer(); - AddChildView(button_container_); - } - - button_container_->AddChildView(button); -} - -void SpecialPopupRow::AddThrobber(ThrobberView* throbber) { - if (!button_container_) { - button_container_ = CreatePopupHeaderButtonsContainer(); - AddChildView(button_container_); - } - - button_container_->AddChildView(throbber); -} - -gfx::Size SpecialPopupRow::GetPreferredSize() { - gfx::Size size = views::View::GetPreferredSize(); - size.set_height(kSpecialPopupRowHeight); - return size; -} - -void SpecialPopupRow::Layout() { - views::View::Layout(); - gfx::Rect content_bounds = GetContentsBounds(); - if (content_bounds.IsEmpty()) - return; - if (!button_container_) { - content_->SetBoundsRect(GetContentsBounds()); - return; - } - - gfx::Rect bounds(button_container_->GetPreferredSize()); - bounds.set_height(content_bounds.height()); - gfx::Rect container_bounds = content_bounds; - container_bounds.ClampToCenteredSize(bounds.size()); - container_bounds.set_x(content_bounds.width() - container_bounds.width()); - button_container_->SetBoundsRect(container_bounds); - - bounds = content_->bounds(); - bounds.set_width(button_container_->x()); - content_->SetBoundsRect(bounds); -} - void SetupLabelForTray(views::Label* label) { // Making label_font static to avoid the time penalty of DeriveFont for // all but the first call. diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h index 6db419c..7b458dd 100644 --- a/ash/system/tray/tray_views.h +++ b/ash/system/tray/tray_views.h @@ -319,32 +319,6 @@ class ThrobberView : public views::View { DISALLOW_COPY_AND_ASSIGN(ThrobberView); }; -// The 'special' looking row in the uber-tray popups. This is usually the bottom -// row in the popups, and has a fixed height. -class SpecialPopupRow : public views::View { - public: - SpecialPopupRow(); - virtual ~SpecialPopupRow(); - - void SetTextLabel(int string_id, ViewClickListener* listener); - void SetContent(views::View* view); - - void AddButton(TrayPopupHeaderButton* button); - void AddThrobber(ThrobberView* throbber); - - views::View* content() const { return content_; } - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void Layout() OVERRIDE; - - views::View* content_; - views::View* button_container_; - views::Label* text_label_; - DISALLOW_COPY_AND_ASSIGN(SpecialPopupRow); -}; - // Sets up a Label properly for the tray (sets color, font etc.). void SetupLabelForTray(views::Label* label); |