| 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 16 matching lines...) Expand all Loading... |
| 27 const gfx::FontList& GetFontList(bool highlight) { | 27 const gfx::FontList& GetFontList(bool highlight) { |
| 28 return ui::ResourceBundle::GetSharedInstance().GetFontList( | 28 return ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont); | 29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 namespace ash { | 34 namespace ash { |
| 35 | 35 |
| 36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) | 36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) |
| 37 : listener_(listener), | 37 : listener_(listener), highlight_color_(kHoverBackgroundColor) { |
| 38 text_label_(NULL), | |
| 39 highlight_color_(kHoverBackgroundColor), | |
| 40 default_color_(0), | |
| 41 text_highlight_color_(0), | |
| 42 text_default_color_(0), | |
| 43 hover_(false), | |
| 44 expandable_(false), | |
| 45 checkable_(false), | |
| 46 checked_(false) { | |
| 47 set_notify_enter_exit_on_child(true); | 38 set_notify_enter_exit_on_child(true); |
| 48 } | 39 } |
| 49 | 40 |
| 50 HoverHighlightView::~HoverHighlightView() {} | 41 HoverHighlightView::~HoverHighlightView() {} |
| 51 | 42 |
| 52 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, | 43 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, |
| 53 base::string16* tooltip) const { | 44 base::string16* tooltip) const { |
| 54 if (tooltip_.empty()) | 45 if (tooltip_.empty()) |
| 55 return false; | 46 return false; |
| 56 *tooltip = tooltip_; | 47 *tooltip = tooltip_; |
| 57 return true; | 48 return true; |
| 58 } | 49 } |
| 59 | 50 |
| 51 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image) { |
| 52 DCHECK(box_layout_); |
| 53 DCHECK(!right_icon_); |
| 54 |
| 55 right_icon_ = new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); |
| 56 right_icon_->SetImage(image); |
| 57 right_icon_->SetEnabled(enabled()); |
| 58 AddChildView(right_icon_); |
| 59 } |
| 60 |
| 61 void HoverHighlightView::SetRightIconVisible(bool visible) { |
| 62 if (!right_icon_) |
| 63 return; |
| 64 |
| 65 right_icon_->SetVisible(visible); |
| 66 Layout(); |
| 67 } |
| 68 |
| 60 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, | 69 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, |
| 61 const base::string16& text, | 70 const base::string16& text, |
| 62 bool highlight) { | 71 bool highlight) { |
| 63 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, | 72 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, |
| 64 kTrayPopupPaddingBetweenItems)); | 73 kTrayPopupPaddingBetweenItems); |
| 74 SetLayoutManager(box_layout_); |
| 65 DoAddIconAndLabel(image, text, highlight); | 75 DoAddIconAndLabel(image, text, highlight); |
| 66 } | 76 } |
| 67 | 77 |
| 68 void HoverHighlightView::AddIndentedIconAndLabel(const gfx::ImageSkia& image, | 78 void HoverHighlightView::AddIndentedIconAndLabel(const gfx::ImageSkia& image, |
| 69 const base::string16& text, | 79 const base::string16& text, |
| 70 bool highlight) { | 80 bool highlight) { |
| 71 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 81 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 72 kTrayPopupPaddingHorizontal, 0, | 82 kTrayPopupPaddingHorizontal, 0, |
| 73 kTrayPopupPaddingBetweenItems)); | 83 kTrayPopupPaddingBetweenItems); |
| 84 SetLayoutManager(box_layout_); |
| 74 DoAddIconAndLabel(image, text, highlight); | 85 DoAddIconAndLabel(image, text, highlight); |
| 75 } | 86 } |
| 76 | 87 |
| 77 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, | 88 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, |
| 78 const base::string16& text, | 89 const base::string16& text, |
| 79 bool highlight) { | 90 bool highlight) { |
| 91 DCHECK(box_layout_); |
| 92 |
| 80 views::ImageView* image_view = | 93 views::ImageView* image_view = |
| 81 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); | 94 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); |
| 82 image_view->SetImage(image); | 95 image_view->SetImage(image); |
| 83 image_view->SetEnabled(enabled()); | 96 image_view->SetEnabled(enabled()); |
| 84 AddChildView(image_view); | 97 AddChildView(image_view); |
| 85 | 98 |
| 86 text_label_ = new views::Label(text); | 99 text_label_ = new views::Label(text); |
| 87 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 100 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 88 text_label_->SetFontList(GetFontList(highlight)); | 101 text_label_->SetFontList(GetFontList(highlight)); |
| 89 if (text_default_color_) | 102 if (text_default_color_) |
| 90 text_label_->SetEnabledColor(text_default_color_); | 103 text_label_->SetEnabledColor(text_default_color_); |
| 91 text_label_->SetEnabled(enabled()); | 104 text_label_->SetEnabled(enabled()); |
| 92 AddChildView(text_label_); | 105 AddChildView(text_label_); |
| 106 box_layout_->SetFlexForView(text_label_, 1); |
| 93 | 107 |
| 94 SetAccessibleName(text); | 108 SetAccessibleName(text); |
| 95 } | 109 } |
| 96 | 110 |
| 97 views::Label* HoverHighlightView::AddLabel(const base::string16& text, | 111 views::Label* HoverHighlightView::AddLabel(const base::string16& text, |
| 98 gfx::HorizontalAlignment alignment, | 112 gfx::HorizontalAlignment alignment, |
| 99 bool highlight) { | 113 bool highlight) { |
| 100 SetLayoutManager(new views::FillLayout()); | 114 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 115 SetLayoutManager(box_layout_); |
| 101 text_label_ = new views::Label(text); | 116 text_label_ = new views::Label(text); |
| 102 int left_margin = kTrayPopupPaddingHorizontal; | 117 int left_margin = kTrayPopupPaddingHorizontal; |
| 103 int right_margin = kTrayPopupPaddingHorizontal; | 118 int right_margin = kTrayPopupPaddingHorizontal; |
| 104 if (alignment != gfx::ALIGN_CENTER) { | 119 if (alignment != gfx::ALIGN_CENTER) { |
| 105 if (base::i18n::IsRTL()) | 120 if (base::i18n::IsRTL()) |
| 106 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; | 121 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; |
| 107 else | 122 else |
| 108 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; | 123 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; |
| 109 } | 124 } |
| 110 text_label_->SetBorder( | 125 text_label_->SetBorder( |
| 111 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); | 126 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); |
| 112 text_label_->SetHorizontalAlignment(alignment); | 127 text_label_->SetHorizontalAlignment(alignment); |
| 113 text_label_->SetFontList(GetFontList(highlight)); | 128 text_label_->SetFontList(GetFontList(highlight)); |
| 114 // Do not set alpha value in disable color. It will have issue with elide | 129 // Do not set alpha value in disable color. It will have issue with elide |
| 115 // blending filter in disabled state for rendering label text color. | 130 // blending filter in disabled state for rendering label text color. |
| 116 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); | 131 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); |
| 117 if (text_default_color_) | 132 if (text_default_color_) |
| 118 text_label_->SetEnabledColor(text_default_color_); | 133 text_label_->SetEnabledColor(text_default_color_); |
| 119 text_label_->SetEnabled(enabled()); | 134 text_label_->SetEnabled(enabled()); |
| 120 AddChildView(text_label_); | 135 AddChildView(text_label_); |
| 136 box_layout_->SetFlexForView(text_label_, 1); |
| 121 | 137 |
| 122 SetAccessibleName(text); | 138 SetAccessibleName(text); |
| 123 return text_label_; | 139 return text_label_; |
| 124 } | 140 } |
| 125 | 141 |
| 126 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text, | 142 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text, |
| 127 bool highlight, | 143 bool highlight, |
| 128 bool checked) { | 144 bool checked) { |
| 129 checkable_ = true; | 145 checkable_ = true; |
| 130 checked_ = checked; | 146 checked_ = checked; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 return AddLabel(text, gfx::ALIGN_LEFT, highlight); | 173 return AddLabel(text, gfx::ALIGN_LEFT, highlight); |
| 158 } | 174 } |
| 159 | 175 |
| 160 void HoverHighlightView::SetExpandable(bool expandable) { | 176 void HoverHighlightView::SetExpandable(bool expandable) { |
| 161 if (expandable != expandable_) { | 177 if (expandable != expandable_) { |
| 162 expandable_ = expandable; | 178 expandable_ = expandable; |
| 163 InvalidateLayout(); | 179 InvalidateLayout(); |
| 164 } | 180 } |
| 165 } | 181 } |
| 166 | 182 |
| 183 void HoverHighlightView::SetHighlight(bool highlight) { |
| 184 DCHECK(text_label_); |
| 185 text_label_->SetFontList(GetFontList(highlight)); |
| 186 text_label_->InvalidateLayout(); |
| 187 } |
| 188 |
| 167 void HoverHighlightView::SetHoverHighlight(bool hover) { | 189 void HoverHighlightView::SetHoverHighlight(bool hover) { |
| 168 if (!enabled() && hover) | 190 if (!enabled() && hover) |
| 169 return; | 191 return; |
| 170 if (hover_ == hover) | 192 if (hover_ == hover) |
| 171 return; | 193 return; |
| 172 hover_ = hover; | 194 hover_ = hover; |
| 173 if (!text_label_) | 195 if (!text_label_) |
| 174 return; | 196 return; |
| 175 if (hover_ && text_highlight_color_) | 197 if (hover_ && text_highlight_color_) |
| 176 text_label_->SetEnabledColor(text_highlight_color_); | 198 text_label_->SetEnabledColor(text_highlight_color_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { | 263 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { |
| 242 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); | 264 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); |
| 243 } | 265 } |
| 244 | 266 |
| 245 void HoverHighlightView::OnFocus() { | 267 void HoverHighlightView::OnFocus() { |
| 246 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 268 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 247 ActionableView::OnFocus(); | 269 ActionableView::OnFocus(); |
| 248 } | 270 } |
| 249 | 271 |
| 250 } // namespace ash | 272 } // namespace ash |
| OLD | NEW |