| OLD | NEW |
| 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_details_view.h" | 5 #include "ash/system/tray/tray_details_view.h" |
| 6 | 6 |
| 7 #include "ash/ash_view_ids.h" | 7 #include "ash/ash_view_ids.h" |
| 8 #include "ash/strings/grit/ash_strings.h" | 8 #include "ash/strings/grit/ash_strings.h" |
| 9 #include "ash/system/tray/hover_highlight_view.h" |
| 9 #include "ash/system/tray/system_menu_button.h" | 10 #include "ash/system/tray/system_menu_button.h" |
| 10 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/system/tray/system_tray_item.h" | 12 #include "ash/system/tray/system_tray_item.h" |
| 12 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
| 13 #include "ash/system/tray/tray_popup_item_style.h" | 14 #include "ash/system/tray/tray_popup_item_style.h" |
| 14 #include "ash/system/tray/tray_popup_utils.h" | 15 #include "ash/system/tray/tray_popup_utils.h" |
| 15 #include "ash/system/tray/tri_view.h" | 16 #include "ash/system/tray/tri_view.h" |
| 16 #include "base/containers/adapters.h" | 17 #include "base/containers/adapters.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "third_party/skia/include/core/SkDrawLooper.h" | 19 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/compositor/paint_context.h" | 22 #include "ui/compositor/paint_context.h" |
| 21 #include "ui/compositor/paint_recorder.h" | 23 #include "ui/compositor/paint_recorder.h" |
| 22 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/skia_paint_util.h" | 27 #include "ui/gfx/skia_paint_util.h" |
| 28 #include "ui/gfx/vector_icon_types.h" |
| 24 #include "ui/native_theme/native_theme.h" | 29 #include "ui/native_theme/native_theme.h" |
| 25 #include "ui/views/background.h" | 30 #include "ui/views/background.h" |
| 26 #include "ui/views/border.h" | 31 #include "ui/views/border.h" |
| 32 #include "ui/views/controls/image_view.h" |
| 27 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/progress_bar.h" | 34 #include "ui/views/controls/progress_bar.h" |
| 29 #include "ui/views/controls/scroll_view.h" | 35 #include "ui/views/controls/scroll_view.h" |
| 30 #include "ui/views/controls/separator.h" | 36 #include "ui/views/controls/separator.h" |
| 31 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/view_targeter.h" | 38 #include "ui/views/view_targeter.h" |
| 33 #include "ui/views/view_targeter_delegate.h" | 39 #include "ui/views/view_targeter_delegate.h" |
| 34 | 40 |
| 35 namespace ash { | 41 namespace ash { |
| 36 namespace { | 42 namespace { |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). | 304 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). |
| 299 scroller_->SetPaintToLayer(); | 305 scroller_->SetPaintToLayer(); |
| 300 scroller_->set_background(views::Background::CreateThemedSolidBackground( | 306 scroller_->set_background(views::Background::CreateThemedSolidBackground( |
| 301 scroller_, ui::NativeTheme::kColorId_BubbleBackground)); | 307 scroller_, ui::NativeTheme::kColorId_BubbleBackground)); |
| 302 scroller_->layer()->SetMasksToBounds(true); | 308 scroller_->layer()->SetMasksToBounds(true); |
| 303 | 309 |
| 304 AddChildView(scroller_); | 310 AddChildView(scroller_); |
| 305 box_layout_->SetFlexForView(scroller_, 1); | 311 box_layout_->SetFlexForView(scroller_, 1); |
| 306 } | 312 } |
| 307 | 313 |
| 314 HoverHighlightView* TrayDetailsView::AddScrollListItem( |
| 315 const gfx::VectorIcon& icon, |
| 316 const base::string16& text) { |
| 317 HoverHighlightView* item = new HoverHighlightView(this); |
| 318 if (icon.is_empty()) |
| 319 item->AddLabelRow(text); |
| 320 else |
| 321 item->AddIconAndLabel(gfx::CreateVectorIcon(icon, kMenuIconColor), text); |
| 322 scroll_content_->AddChildView(item); |
| 323 return item; |
| 324 } |
| 325 |
| 326 HoverHighlightView* TrayDetailsView::AddScrollListCheckableItem( |
| 327 const gfx::VectorIcon& icon, |
| 328 const base::string16& text, |
| 329 bool checked) { |
| 330 HoverHighlightView* item = AddScrollListItem(icon, text); |
| 331 TrayPopupUtils::InitializeAsCheckableRow(item, checked); |
| 332 return item; |
| 333 } |
| 334 |
| 335 HoverHighlightView* TrayDetailsView::AddScrollListCheckableItemWithoutIcon( |
| 336 const base::string16& text, |
| 337 bool checked) { |
| 338 return AddScrollListCheckableItem(gfx::kNoneIcon, text, checked); |
| 339 } |
| 340 |
| 341 TriView* TrayDetailsView::AddScrollListSubHeader(const gfx::VectorIcon& icon, |
| 342 int text_id) { |
| 343 TriView* header = TrayPopupUtils::CreateSubHeaderRowView(!icon.is_empty()); |
| 344 TrayPopupUtils::ConfigureAsStickyHeader(header); |
| 345 |
| 346 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 347 label->SetText(l10n_util::GetStringUTF16(text_id)); |
| 348 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 349 style.SetupLabel(label); |
| 350 header->AddView(TriView::Container::CENTER, label); |
| 351 |
| 352 if (!icon.is_empty()) { |
| 353 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView(); |
| 354 image_view->SetImage(gfx::CreateVectorIcon( |
| 355 icon, GetNativeTheme()->GetSystemColor( |
| 356 ui::NativeTheme::kColorId_ProminentButtonColor))); |
| 357 header->AddView(TriView::Container::START, image_view); |
| 358 } |
| 359 |
| 360 scroll_content_->AddChildView(header); |
| 361 return header; |
| 362 } |
| 363 |
| 364 TriView* TrayDetailsView::AddScrollListSubHeaderWithoutIcon(int text_id) { |
| 365 return AddScrollListSubHeader(gfx::kNoneIcon, text_id); |
| 366 } |
| 367 |
| 308 void TrayDetailsView::Reset() { | 368 void TrayDetailsView::Reset() { |
| 309 RemoveAllChildViews(true); | 369 RemoveAllChildViews(true); |
| 310 scroller_ = nullptr; | 370 scroller_ = nullptr; |
| 311 scroll_content_ = nullptr; | 371 scroll_content_ = nullptr; |
| 312 progress_bar_ = nullptr; | 372 progress_bar_ = nullptr; |
| 313 back_button_ = nullptr; | 373 back_button_ = nullptr; |
| 314 tri_view_ = nullptr; | 374 tri_view_ = nullptr; |
| 315 } | 375 } |
| 316 | 376 |
| 317 void TrayDetailsView::ShowProgress(double value, bool visible) { | 377 void TrayDetailsView::ShowProgress(double value, bool visible) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 if (bounds().IsEmpty()) | 453 if (bounds().IsEmpty()) |
| 394 return views::View::GetHeightForWidth(width); | 454 return views::View::GetHeightForWidth(width); |
| 395 | 455 |
| 396 // The height of the bubble that contains this detailed view is set to | 456 // The height of the bubble that contains this detailed view is set to |
| 397 // the preferred height of the default view, and that determines the | 457 // the preferred height of the default view, and that determines the |
| 398 // initial height of |this|. Always request to stay the same height. | 458 // initial height of |this|. Always request to stay the same height. |
| 399 return height(); | 459 return height(); |
| 400 } | 460 } |
| 401 | 461 |
| 402 } // namespace ash | 462 } // namespace ash |
| OLD | NEW |