| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/common/system/tray/hover_highlight_view.h" | 5 #include "ash/common/system/tray/hover_highlight_view.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/fixed_sized_image_view.h" | 7 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 8 #include "ash/common/system/tray/tray_constants.h" | 8 #include "ash/common/system/tray/tray_constants.h" |
| 9 #include "ash/common/system/tray/view_click_listener.h" | 9 #include "ash/common/system/tray/view_click_listener.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 HoverHighlightView::~HoverHighlightView() {} | 40 HoverHighlightView::~HoverHighlightView() {} |
| 41 | 41 |
| 42 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, | 42 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, |
| 43 base::string16* tooltip) const { | 43 base::string16* tooltip) const { |
| 44 if (tooltip_.empty()) | 44 if (tooltip_.empty()) |
| 45 return false; | 45 return false; |
| 46 *tooltip = tooltip_; | 46 *tooltip = tooltip_; |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image) { | 50 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, |
| 51 int icon_size) { |
| 51 DCHECK(box_layout_); | 52 DCHECK(box_layout_); |
| 52 DCHECK(!right_icon_); | 53 DCHECK(!right_icon_); |
| 53 | 54 |
| 54 right_icon_ = new views::ImageView(); | 55 right_icon_ = new FixedSizedImageView(icon_size, icon_size); |
| 55 right_icon_->SetImageSize( | |
| 56 gfx::Size(kTrayPopupDetailsIconWidth, kTrayPopupDetailsIconWidth)); | |
| 57 right_icon_->SetImage(image); | 56 right_icon_->SetImage(image); |
| 58 right_icon_->SetEnabled(enabled()); | 57 right_icon_->SetEnabled(enabled()); |
| 59 AddChildView(right_icon_); | 58 AddChildView(right_icon_); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void HoverHighlightView::SetRightIconVisible(bool visible) { | 61 void HoverHighlightView::SetRightIconVisible(bool visible) { |
| 63 if (!right_icon_) | 62 if (!right_icon_) |
| 64 return; | 63 return; |
| 65 | 64 |
| 66 right_icon_->SetVisible(visible); | 65 right_icon_->SetVisible(visible); |
| 67 Layout(); | 66 Layout(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, | 69 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, |
| 71 const base::string16& text, | 70 const base::string16& text, |
| 72 bool highlight) { | 71 bool highlight) { |
| 73 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, | 72 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, |
| 74 kTrayPopupPaddingBetweenItems); | 73 kTrayPopupPaddingBetweenItems); |
| 75 SetLayoutManager(box_layout_); | 74 SetLayoutManager(box_layout_); |
| 76 DoAddIconAndLabel(image, text, highlight); | 75 DoAddIconAndLabel(image, kTrayPopupDetailsIconWidth, text, highlight); |
| 77 } | 76 } |
| 78 | 77 |
| 79 void HoverHighlightView::AddIndentedIconAndLabel(const gfx::ImageSkia& image, | 78 void HoverHighlightView::AddIconAndLabelCustomSize(const gfx::ImageSkia& image, |
| 80 const base::string16& text, | 79 const base::string16& text, |
| 81 bool highlight) { | 80 bool highlight, |
| 82 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, | 81 int icon_size, |
| 83 kTrayPopupPaddingHorizontal, 0, | 82 int indent, |
| 84 kTrayPopupPaddingBetweenItems); | 83 int space_between_items) { |
| 84 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, indent, 0, |
| 85 space_between_items); |
| 85 SetLayoutManager(box_layout_); | 86 SetLayoutManager(box_layout_); |
| 86 DoAddIconAndLabel(image, text, highlight); | 87 DoAddIconAndLabel(image, icon_size, text, highlight); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, | 90 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, |
| 91 int icon_size, |
| 90 const base::string16& text, | 92 const base::string16& text, |
| 91 bool highlight) { | 93 bool highlight) { |
| 92 DCHECK(box_layout_); | 94 DCHECK(box_layout_); |
| 93 | 95 |
| 94 views::ImageView* image_view = | 96 views::ImageView* image_view = new FixedSizedImageView(icon_size, 0); |
| 95 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); | |
| 96 image_view->SetImage(image); | 97 image_view->SetImage(image); |
| 97 image_view->SetEnabled(enabled()); | 98 image_view->SetEnabled(enabled()); |
| 98 AddChildView(image_view); | 99 AddChildView(image_view); |
| 99 | 100 |
| 100 text_label_ = new views::Label(text); | 101 text_label_ = new views::Label(text); |
| 101 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 102 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 102 text_label_->SetFontList(GetFontList(highlight)); | 103 text_label_->SetFontList(GetFontList(highlight)); |
| 103 if (text_default_color_) | 104 if (text_default_color_) |
| 104 text_label_->SetEnabledColor(text_default_color_); | 105 text_label_->SetEnabledColor(text_default_color_); |
| 105 text_label_->SetEnabled(enabled()); | 106 text_label_->SetEnabled(enabled()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 bool highlight, | 145 bool highlight, |
| 145 bool checked) { | 146 bool checked) { |
| 146 checkable_ = true; | 147 checkable_ = true; |
| 147 checked_ = checked; | 148 checked_ = checked; |
| 148 if (checked) { | 149 if (checked) { |
| 149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 150 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 150 const gfx::ImageSkia* check = | 151 const gfx::ImageSkia* check = |
| 151 rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia(); | 152 rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia(); |
| 152 int margin = kTrayPopupPaddingHorizontal + | 153 int margin = kTrayPopupPaddingHorizontal + |
| 153 kTrayPopupDetailsLabelExtraLeftMargin - kCheckLabelPadding; | 154 kTrayPopupDetailsLabelExtraLeftMargin - kCheckLabelPadding; |
| 154 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, | 155 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, |
| 155 kCheckLabelPadding)); | 156 kCheckLabelPadding); |
| 157 SetLayoutManager(box_layout_); |
| 156 views::ImageView* image_view = new FixedSizedImageView(margin, 0); | 158 views::ImageView* image_view = new FixedSizedImageView(margin, 0); |
| 157 image_view->SetImage(check); | 159 image_view->SetImage(check); |
| 158 image_view->SetHorizontalAlignment(views::ImageView::TRAILING); | 160 image_view->SetHorizontalAlignment(views::ImageView::TRAILING); |
| 159 image_view->SetEnabled(enabled()); | 161 image_view->SetEnabled(enabled()); |
| 160 AddChildView(image_view); | 162 AddChildView(image_view); |
| 161 | 163 |
| 162 text_label_ = new views::Label(text); | 164 text_label_ = new views::Label(text); |
| 163 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 165 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 164 text_label_->SetFontList(GetFontList(highlight)); | 166 text_label_->SetFontList(GetFontList(highlight)); |
| 165 text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); | 167 text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { | 265 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { |
| 264 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); | 266 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void HoverHighlightView::OnFocus() { | 269 void HoverHighlightView::OnFocus() { |
| 268 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 270 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 269 ActionableView::OnFocus(); | 271 ActionableView::OnFocus(); |
| 270 } | 272 } |
| 271 | 273 |
| 272 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |