| 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/common/system/tray/tray_details_view.h" | 5 #include "ash/common/system/tray/tray_details_view.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_view_ids.h" | 7 #include "ash/common/ash_view_ids.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | |
| 10 #include "ash/common/system/tray/system_menu_button.h" | 9 #include "ash/common/system/tray/system_menu_button.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_item.h" | 11 #include "ash/common/system/tray/system_tray_item.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_style.h" | 13 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 15 #include "ash/common/system/tray/tray_popup_utils.h" | 14 #include "ash/common/system/tray/tray_popup_utils.h" |
| 16 #include "ash/common/system/tray/tri_view.h" | 15 #include "ash/common/system/tray/tri_view.h" |
| 17 #include "base/containers/adapters.h" | 16 #include "base/containers/adapters.h" |
| 18 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 19 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 AddChildViewAt(title_row_, child_count()); | 355 AddChildViewAt(title_row_, child_count()); |
| 357 } | 356 } |
| 358 | 357 |
| 359 CreateExtraTitleRowButtons(); | 358 CreateExtraTitleRowButtons(); |
| 360 Layout(); | 359 Layout(); |
| 361 } | 360 } |
| 362 | 361 |
| 363 void TrayDetailsView::CreateScrollableList() { | 362 void TrayDetailsView::CreateScrollableList() { |
| 364 DCHECK(!scroller_); | 363 DCHECK(!scroller_); |
| 365 scroll_content_ = new ScrollContentsView(); | 364 scroll_content_ = new ScrollContentsView(); |
| 366 scroller_ = new FixedSizedScrollView; | 365 scroller_ = new views::ScrollView; |
| 367 scroller_->SetContentsView(scroll_content_); | 366 scroller_->SetContents(scroll_content_); |
| 368 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. | 367 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. |
| 369 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). | 368 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). |
| 370 scroller_->SetPaintToLayer(); | 369 scroller_->SetPaintToLayer(); |
| 371 scroller_->set_background( | 370 scroller_->set_background( |
| 372 views::Background::CreateSolidBackground(kBackgroundColor)); | 371 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 373 scroller_->layer()->SetMasksToBounds(true); | 372 scroller_->layer()->SetMasksToBounds(true); |
| 374 | 373 |
| 375 // Note: |scroller_| takes ownership of |scroll_border_|. | 374 // Note: |scroller_| takes ownership of |scroll_border_|. |
| 376 if (!UseMd()) { | 375 if (!UseMd()) { |
| 377 // In MD, the scroller is always the last thing, so this border is | 376 // In MD, the scroller is always the last thing, so this border is |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 484 |
| 486 views::Button* TrayDetailsView::CreateBackButton() { | 485 views::Button* TrayDetailsView::CreateBackButton() { |
| 487 DCHECK(UseMd()); | 486 DCHECK(UseMd()); |
| 488 SystemMenuButton* button = new SystemMenuButton( | 487 SystemMenuButton* button = new SystemMenuButton( |
| 489 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuArrowBackIcon, | 488 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuArrowBackIcon, |
| 490 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); | 489 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); |
| 491 return button; | 490 return button; |
| 492 } | 491 } |
| 493 | 492 |
| 494 void TrayDetailsView::Layout() { | 493 void TrayDetailsView::Layout() { |
| 495 if (UseMd()) { | |
| 496 views::View::Layout(); | |
| 497 if (scroller_ && !scroller_->is_bounded()) | |
| 498 scroller_->ClipHeightTo(0, scroller_->height()); | |
| 499 return; | |
| 500 } | |
| 501 | |
| 502 if (bounds().IsEmpty()) { | |
| 503 views::View::Layout(); | |
| 504 return; | |
| 505 } | |
| 506 | |
| 507 if (scroller_) { | |
| 508 scroller_->set_fixed_size(gfx::Size()); | |
| 509 gfx::Size size = GetPreferredSize(); | |
| 510 | |
| 511 // Set the scroller to fill the space above the bottom row, so that the | |
| 512 // bottom row of the detailed view will always stay just above the title | |
| 513 // row. | |
| 514 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); | |
| 515 scroller_->set_fixed_size( | |
| 516 gfx::Size(width() + scroller_->GetScrollBarLayoutWidth(), | |
| 517 scroller_size.height() - (size.height() - height()))); | |
| 518 } | |
| 519 | |
| 520 views::View::Layout(); | 494 views::View::Layout(); |
| 521 | 495 if (scroller_ && !scroller_->is_bounded()) |
| 522 if (title_row_) { | 496 scroller_->ClipHeightTo(0, scroller_->height()); |
| 523 // Always make sure the title row is bottom-aligned in non-MD. | |
| 524 gfx::Rect fbounds = title_row_->bounds(); | |
| 525 fbounds.set_y(height() - title_row_->height()); | |
| 526 title_row_->SetBoundsRect(fbounds); | |
| 527 } | |
| 528 } | 497 } |
| 529 | 498 |
| 530 int TrayDetailsView::GetHeightForWidth(int width) const { | 499 int TrayDetailsView::GetHeightForWidth(int width) const { |
| 531 if (!UseMd() || bounds().IsEmpty()) | 500 if (!UseMd() || bounds().IsEmpty()) |
| 532 return views::View::GetHeightForWidth(width); | 501 return views::View::GetHeightForWidth(width); |
| 533 | 502 |
| 534 // The height of the bubble that contains this detailed view is set to | 503 // The height of the bubble that contains this detailed view is set to |
| 535 // the preferred height of the default view, and that determines the | 504 // the preferred height of the default view, and that determines the |
| 536 // initial height of |this|. Always request to stay the same height. | 505 // initial height of |this|. Always request to stay the same height. |
| 537 return height(); | 506 return height(); |
| 538 } | 507 } |
| 539 | 508 |
| 540 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { | 509 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { |
| 541 if (scroll_border_) { | 510 if (scroll_border_) { |
| 542 int index = GetIndexOf(scroller_); | 511 int index = GetIndexOf(scroller_); |
| 543 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | 512 if (index < child_count() - 1 && child_at(index + 1) != title_row_) |
| 544 scroll_border_->set_visible(true); | 513 scroll_border_->set_visible(true); |
| 545 else | 514 else |
| 546 scroll_border_->set_visible(false); | 515 scroll_border_->set_visible(false); |
| 547 } | 516 } |
| 548 | 517 |
| 549 views::View::OnPaintBorder(canvas); | 518 views::View::OnPaintBorder(canvas); |
| 550 } | 519 } |
| 551 | 520 |
| 552 } // namespace ash | 521 } // namespace ash |
| OLD | NEW |