| 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" | 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 10 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/views/controls/progress_bar.h" | 21 #include "ui/views/controls/progress_bar.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 22 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/controls/separator.h" | 23 #include "ui/views/controls/separator.h" |
| 24 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/view_targeter.h" | 25 #include "ui/views/view_targeter.h" |
| 26 #include "ui/views/view_targeter_delegate.h" | 26 #include "ui/views/view_targeter_delegate.h" |
| 27 | 27 |
| 28 namespace ash { | 28 namespace ash { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 bool UseMd() { |
| 32 return MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 33 } |
| 34 |
| 31 // A view that is used as ScrollView contents. It supports designating some of | 35 // A view that is used as ScrollView contents. It supports designating some of |
| 32 // the children as sticky header rows. The sticky header rows are not scrolled | 36 // the children as sticky header rows. The sticky header rows are not scrolled |
| 33 // above the top of the visible viewport until the next one "pushes" it up and | 37 // above the top of the visible viewport until the next one "pushes" it up and |
| 34 // are painted above other children. To indicate that a child is a sticky header | 38 // are painted above other children. To indicate that a child is a sticky header |
| 35 // row use set_id(VIEW_ID_STICKY_HEADER). | 39 // row use set_id(VIEW_ID_STICKY_HEADER). |
| 36 class ScrollContentsView : public views::View, | 40 class ScrollContentsView : public views::View, |
| 37 public views::ViewTargeterDelegate { | 41 public views::ViewTargeterDelegate { |
| 38 public: | 42 public: |
| 39 ScrollContentsView() { | 43 ScrollContentsView() { |
| 40 SetEventTargeter(base::MakeUnique<views::ViewTargeter>(this)); | 44 SetEventTargeter(base::MakeUnique<views::ViewTargeter>(this)); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 title_row_separator_(nullptr), | 293 title_row_separator_(nullptr), |
| 290 scroll_border_(nullptr), | 294 scroll_border_(nullptr), |
| 291 back_button_(nullptr) { | 295 back_button_(nullptr) { |
| 292 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 296 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 293 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 297 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 294 } | 298 } |
| 295 | 299 |
| 296 TrayDetailsView::~TrayDetailsView() {} | 300 TrayDetailsView::~TrayDetailsView() {} |
| 297 | 301 |
| 298 void TrayDetailsView::OnViewClicked(views::View* sender) { | 302 void TrayDetailsView::OnViewClicked(views::View* sender) { |
| 299 if (!MaterialDesignController::IsSystemTrayMenuMaterial() && title_row_ && | 303 if (!UseMd() && title_row_ && sender == title_row_->content()) { |
| 300 sender == title_row_->content()) { | |
| 301 TransitionToDefaultView(); | 304 TransitionToDefaultView(); |
| 302 return; | 305 return; |
| 303 } | 306 } |
| 304 | 307 |
| 305 HandleViewClicked(sender); | 308 HandleViewClicked(sender); |
| 306 } | 309 } |
| 307 | 310 |
| 308 void TrayDetailsView::ButtonPressed(views::Button* sender, | 311 void TrayDetailsView::ButtonPressed(views::Button* sender, |
| 309 const ui::Event& event) { | 312 const ui::Event& event) { |
| 310 if (MaterialDesignController::IsSystemTrayMenuMaterial() && | 313 if (UseMd() && sender == back_button_) { |
| 311 sender == back_button_) { | |
| 312 TransitionToDefaultView(); | 314 TransitionToDefaultView(); |
| 313 return; | 315 return; |
| 314 } | 316 } |
| 315 | 317 |
| 316 HandleButtonPressed(sender, event); | 318 HandleButtonPressed(sender, event); |
| 317 } | 319 } |
| 318 | 320 |
| 319 void TrayDetailsView::CreateTitleRow(int string_id) { | 321 void TrayDetailsView::CreateTitleRow(int string_id) { |
| 320 DCHECK(!title_row_); | 322 DCHECK(!title_row_); |
| 321 title_row_ = new SpecialPopupRow(); | 323 title_row_ = new SpecialPopupRow(); |
| 322 title_row_->SetTextLabel(string_id, this); | 324 title_row_->SetTextLabel(string_id, this); |
| 323 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 325 if (UseMd()) { |
| 324 title_row_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, | 326 title_row_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, |
| 325 kTitleRowPaddingBottom, 0)); | 327 kTitleRowPaddingBottom, 0)); |
| 326 AddChildViewAt(title_row_, 0); | 328 AddChildViewAt(title_row_, 0); |
| 327 // In material design, we use a customized bottom border which is nomally a | 329 // In material design, we use a customized bottom border which is nomally a |
| 328 // simple separator (views::Separator) but can be combined with an | 330 // simple separator (views::Separator) but can be combined with an |
| 329 // overlapping progress bar. | 331 // overlapping progress bar. |
| 330 title_row_separator_ = new views::View; | 332 title_row_separator_ = new views::View; |
| 331 title_row_separator_->SetLayoutManager(new TitleRowSeparatorLayout); | 333 title_row_separator_->SetLayoutManager(new TitleRowSeparatorLayout); |
| 332 views::Separator* separator = | 334 views::Separator* separator = |
| 333 new views::Separator(views::Separator::HORIZONTAL); | 335 new views::Separator(views::Separator::HORIZONTAL); |
| 334 separator->SetColor(kTitleRowSeparatorBorderColor); | 336 separator->SetColor(kTitleRowSeparatorBorderColor); |
| 335 separator->SetPreferredSize(kTitleRowSeparatorBorderHeight); | 337 separator->SetPreferredSize(kTitleRowSeparatorBorderHeight); |
| 336 separator->SetBorder(views::CreateEmptyBorder( | 338 separator->SetBorder(views::CreateEmptyBorder( |
| 337 kTitleRowSeparatorHeight - kTitleRowSeparatorBorderHeight, 0, 0, 0)); | 339 kTitleRowSeparatorHeight - kTitleRowSeparatorBorderHeight, 0, 0, 0)); |
| 338 title_row_separator_->AddChildView(separator); | 340 title_row_separator_->AddChildView(separator); |
| 339 AddChildViewAt(title_row_separator_, 1); | 341 AddChildViewAt(title_row_separator_, 1); |
| 340 } else { | 342 } else { |
| 341 AddChildViewAt(title_row_, child_count()); | 343 AddChildViewAt(title_row_, child_count()); |
| 342 } | 344 } |
| 343 | 345 |
| 344 CreateExtraTitleRowButtons(); | 346 CreateExtraTitleRowButtons(); |
| 345 | 347 |
| 346 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 348 if (UseMd()) |
| 347 back_button_ = title_row_->AddBackButton(this); | 349 back_button_ = title_row_->AddBackButton(this); |
| 348 | 350 |
| 349 Layout(); | 351 Layout(); |
| 350 } | 352 } |
| 351 | 353 |
| 352 void TrayDetailsView::CreateScrollableList() { | 354 void TrayDetailsView::CreateScrollableList() { |
| 353 DCHECK(!scroller_); | 355 DCHECK(!scroller_); |
| 354 scroll_content_ = new ScrollContentsView(); | 356 scroll_content_ = new ScrollContentsView(); |
| 355 scroller_ = new FixedSizedScrollView; | 357 scroller_ = new FixedSizedScrollView; |
| 356 scroller_->SetContentsView(scroll_content_); | 358 scroller_->SetContentsView(scroll_content_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 394 |
| 393 void TrayDetailsView::HandleButtonPressed(views::Button* sender, | 395 void TrayDetailsView::HandleButtonPressed(views::Button* sender, |
| 394 const ui::Event& event) {} | 396 const ui::Event& event) {} |
| 395 | 397 |
| 396 void TrayDetailsView::CreateExtraTitleRowButtons() {} | 398 void TrayDetailsView::CreateExtraTitleRowButtons() {} |
| 397 | 399 |
| 398 void TrayDetailsView::TransitionToDefaultView() { | 400 void TrayDetailsView::TransitionToDefaultView() { |
| 399 // Cache pointer to owner in this function scope. TrayDetailsView will be | 401 // Cache pointer to owner in this function scope. TrayDetailsView will be |
| 400 // deleted after called ShowDefaultView. | 402 // deleted after called ShowDefaultView. |
| 401 SystemTrayItem* owner = owner_; | 403 SystemTrayItem* owner = owner_; |
| 402 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 404 if (UseMd()) { |
| 403 if (back_button_ && back_button_->HasFocus()) | 405 if (back_button_ && back_button_->HasFocus()) |
| 404 owner->set_restore_focus(true); | 406 owner->set_restore_focus(true); |
| 405 } else { | 407 } else { |
| 406 if (title_row_ && title_row_->content() && | 408 if (title_row_ && title_row_->content() && |
| 407 title_row_->content()->HasFocus()) { | 409 title_row_->content()->HasFocus()) { |
| 408 owner->set_restore_focus(true); | 410 owner->set_restore_focus(true); |
| 409 } | 411 } |
| 410 } | 412 } |
| 411 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 413 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 412 owner->set_restore_focus(false); | 414 owner->set_restore_focus(false); |
| 413 } | 415 } |
| 414 | 416 |
| 415 void TrayDetailsView::Layout() { | 417 void TrayDetailsView::Layout() { |
| 416 if (bounds().IsEmpty()) { | 418 if (bounds().IsEmpty()) { |
| 417 views::View::Layout(); | 419 views::View::Layout(); |
| 418 return; | 420 return; |
| 419 } | 421 } |
| 420 | 422 |
| 421 if (scroller_) { | 423 if (scroller_) { |
| 422 scroller_->set_fixed_size(gfx::Size()); | 424 if (UseMd()) { |
| 423 gfx::Size size = GetPreferredSize(); | 425 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); |
| 426 gfx::Size pref_size = GetPreferredSize(); |
| 427 scroller()->ClipHeightTo( |
| 428 0, scroller_size.height() - (pref_size.height() - height())); |
| 429 } else { |
| 430 scroller_->set_fixed_size(gfx::Size()); |
| 431 gfx::Size size = GetPreferredSize(); |
| 424 | 432 |
| 425 // Set the scroller to fill the space above the bottom row, so that the | 433 // Set the scroller to fill the space above the bottom row, so that the |
| 426 // bottom row of the detailed view will always stay just above the title | 434 // bottom row of the detailed view will always stay just above the title |
| 427 // row. | 435 // row. |
| 428 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); | 436 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); |
| 429 scroller_->set_fixed_size( | 437 scroller_->set_fixed_size( |
| 430 gfx::Size(width() + scroller_->GetScrollBarWidth(), | 438 gfx::Size(width() + scroller_->GetScrollBarWidth(), |
| 431 scroller_size.height() - (size.height() - height()))); | 439 scroller_size.height() - (size.height() - height()))); |
| 440 } |
| 432 } | 441 } |
| 433 | 442 |
| 434 views::View::Layout(); | 443 views::View::Layout(); |
| 435 | 444 |
| 436 if (title_row_ && !MaterialDesignController::IsSystemTrayMenuMaterial()) { | 445 if (title_row_ && !UseMd()) { |
| 437 // Always make sure the title row is bottom-aligned in non-MD. | 446 // Always make sure the title row is bottom-aligned in non-MD. |
| 438 gfx::Rect fbounds = title_row_->bounds(); | 447 gfx::Rect fbounds = title_row_->bounds(); |
| 439 fbounds.set_y(height() - title_row_->height()); | 448 fbounds.set_y(height() - title_row_->height()); |
| 440 title_row_->SetBoundsRect(fbounds); | 449 title_row_->SetBoundsRect(fbounds); |
| 441 } | 450 } |
| 442 } | 451 } |
| 443 | 452 |
| 444 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { | 453 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { |
| 445 if (scroll_border_) { | 454 if (scroll_border_) { |
| 446 int index = GetIndexOf(scroller_); | 455 int index = GetIndexOf(scroller_); |
| 447 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | 456 if (index < child_count() - 1 && child_at(index + 1) != title_row_) |
| 448 scroll_border_->set_visible(true); | 457 scroll_border_->set_visible(true); |
| 449 else | 458 else |
| 450 scroll_border_->set_visible(false); | 459 scroll_border_->set_visible(false); |
| 451 } | 460 } |
| 452 | 461 |
| 453 views::View::OnPaintBorder(canvas); | 462 views::View::OnPaintBorder(canvas); |
| 454 } | 463 } |
| 455 | 464 |
| 456 } // namespace ash | 465 } // namespace ash |
| OLD | NEW |