Chromium Code Reviews| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 245 |
| 246 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); } | 246 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); } |
| 247 | 247 |
| 248 bool visible_ = false; | 248 bool visible_ = false; |
| 249 | 249 |
| 250 DISALLOW_COPY_AND_ASSIGN(ScrollBorder); | 250 DISALLOW_COPY_AND_ASSIGN(ScrollBorder); |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) | 253 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) |
| 254 : owner_(owner), | 254 : owner_(owner), |
| 255 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), | |
| 255 title_row_(nullptr), | 256 title_row_(nullptr), |
| 256 scroller_(nullptr), | 257 scroller_(nullptr), |
| 257 scroll_content_(nullptr), | 258 scroll_content_(nullptr), |
| 258 progress_bar_(nullptr), | 259 progress_bar_(nullptr), |
| 259 scroll_border_(nullptr), | 260 scroll_border_(nullptr), |
| 260 back_button_(nullptr) { | 261 back_button_(nullptr) { |
| 261 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 262 SetLayoutManager(box_layout_); |
| 262 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 263 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 263 } | 264 } |
| 264 | 265 |
| 265 TrayDetailsView::~TrayDetailsView() {} | 266 TrayDetailsView::~TrayDetailsView() {} |
| 266 | 267 |
| 267 void TrayDetailsView::OnViewClicked(views::View* sender) { | 268 void TrayDetailsView::OnViewClicked(views::View* sender) { |
| 268 if (!UseMd() && title_row_ && sender == title_row_->content()) { | 269 if (!UseMd() && title_row_ && sender == title_row_->content()) { |
| 269 TransitionToDefaultView(); | 270 TransitionToDefaultView(); |
| 270 return; | 271 return; |
| 271 } | 272 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 Layout(); | 311 Layout(); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void TrayDetailsView::CreateScrollableList() { | 314 void TrayDetailsView::CreateScrollableList() { |
| 314 DCHECK(!scroller_); | 315 DCHECK(!scroller_); |
| 315 scroll_content_ = new ScrollContentsView(); | 316 scroll_content_ = new ScrollContentsView(); |
| 316 scroller_ = new FixedSizedScrollView; | 317 scroller_ = new FixedSizedScrollView; |
| 317 scroller_->SetContentsView(scroll_content_); | 318 scroller_->SetContentsView(scroll_content_); |
| 318 | 319 |
| 319 // Note: |scroller_| takes ownership of |scroll_border_|. | 320 // Note: |scroller_| takes ownership of |scroll_border_|. |
| 320 scroll_border_ = new ScrollBorder; | 321 if (!UseMd()) { |
| 321 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); | 322 // In MD, the scroller is always the last thing, so this border is |
| 323 // unnecessary and reserves extra space we don't want. | |
| 324 scroll_border_ = new ScrollBorder; | |
| 325 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); | |
| 326 } | |
| 322 | 327 |
| 323 AddChildView(scroller_); | 328 AddChildView(scroller_); |
| 329 box_layout_->SetFlexForView(scroller_, 1); | |
| 324 } | 330 } |
| 325 | 331 |
| 326 void TrayDetailsView::AddScrollSeparator() { | 332 void TrayDetailsView::AddScrollSeparator() { |
| 327 DCHECK(scroll_content_); | 333 DCHECK(scroll_content_); |
| 328 // Do not draw the separator if it is the very first item | 334 // Do not draw the separator if it is the very first item |
| 329 // in the scrollable list. | 335 // in the scrollable list. |
| 330 if (scroll_content_->has_children()) | 336 if (scroll_content_->has_children()) |
| 331 scroll_content_->AddChildView(new ScrollSeparator); | 337 scroll_content_->AddChildView(new ScrollSeparator); |
| 332 } | 338 } |
| 333 | 339 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 if (title_row_ && title_row_->content() && | 382 if (title_row_ && title_row_->content() && |
| 377 title_row_->content()->HasFocus()) { | 383 title_row_->content()->HasFocus()) { |
| 378 owner->set_restore_focus(true); | 384 owner->set_restore_focus(true); |
| 379 } | 385 } |
| 380 } | 386 } |
| 381 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 387 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 382 owner->set_restore_focus(false); | 388 owner->set_restore_focus(false); |
| 383 } | 389 } |
| 384 | 390 |
| 385 void TrayDetailsView::Layout() { | 391 void TrayDetailsView::Layout() { |
| 386 if (bounds().IsEmpty()) { | 392 if (UseMd()) { |
| 393 views::View::Layout(); | |
| 394 if (scroller_ && !scroller_->is_bounded()) | |
| 395 scroller_->ClipHeightTo(0, scroller_->height()); | |
|
tdanderson
2016/11/11 20:09:55
It seems this only ever be reached once during the
Evan Stade
2016/11/11 22:07:24
you mean if more rows are added, or if the scrolle
| |
| 396 } | |
| 397 | |
| 398 if (UseMd() || bounds().IsEmpty()) { | |
| 387 views::View::Layout(); | 399 views::View::Layout(); |
| 388 return; | 400 return; |
| 389 } | 401 } |
| 390 | 402 |
| 391 if (scroller_) { | 403 if (scroller_) { |
| 392 if (UseMd()) { | 404 scroller_->set_fixed_size(gfx::Size()); |
| 393 gfx::Size scroller_size = scroller()->GetPreferredSize(); | 405 gfx::Size size = GetPreferredSize(); |
| 394 gfx::Size pref_size = GetPreferredSize(); | |
| 395 scroller()->ClipHeightTo( | |
| 396 0, scroller_size.height() - (pref_size.height() - height())); | |
| 397 } else { | |
| 398 scroller_->set_fixed_size(gfx::Size()); | |
| 399 gfx::Size size = GetPreferredSize(); | |
| 400 | 406 |
| 401 // Set the scroller to fill the space above the bottom row, so that the | 407 // Set the scroller to fill the space above the bottom row, so that the |
| 402 // bottom row of the detailed view will always stay just above the title | 408 // bottom row of the detailed view will always stay just above the title |
| 403 // row. | 409 // row. |
| 404 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); | 410 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); |
| 405 scroller_->set_fixed_size( | 411 scroller_->set_fixed_size( |
| 406 gfx::Size(width() + scroller_->GetScrollBarWidth(), | 412 gfx::Size(width() + scroller_->GetScrollBarWidth(), |
| 407 scroller_size.height() - (size.height() - height()))); | 413 scroller_size.height() - (size.height() - height()))); |
| 408 } | |
| 409 } | 414 } |
| 410 | 415 |
| 411 views::View::Layout(); | 416 views::View::Layout(); |
| 412 | 417 |
| 413 if (title_row_ && !UseMd()) { | 418 if (title_row_) { |
| 414 // Always make sure the title row is bottom-aligned in non-MD. | 419 // Always make sure the title row is bottom-aligned in non-MD. |
| 415 gfx::Rect fbounds = title_row_->bounds(); | 420 gfx::Rect fbounds = title_row_->bounds(); |
| 416 fbounds.set_y(height() - title_row_->height()); | 421 fbounds.set_y(height() - title_row_->height()); |
| 417 title_row_->SetBoundsRect(fbounds); | 422 title_row_->SetBoundsRect(fbounds); |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 426 int TrayDetailsView::GetHeightForWidth(int width) const { | |
| 427 if (!UseMd() || bounds().IsEmpty()) | |
| 428 return views::View::GetHeightForWidth(width); | |
| 429 | |
| 430 // The height of the bubble that contains this detailed view is set to | |
| 431 // the preferred height of the default view, and that determines the | |
| 432 // initial height of |this|. Always request to stay the same height. | |
| 433 return height(); | |
| 434 } | |
| 435 | |
| 421 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { | 436 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { |
| 422 if (scroll_border_) { | 437 if (scroll_border_) { |
| 423 int index = GetIndexOf(scroller_); | 438 int index = GetIndexOf(scroller_); |
| 424 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | 439 if (index < child_count() - 1 && child_at(index + 1) != title_row_) |
| 425 scroll_border_->set_visible(true); | 440 scroll_border_->set_visible(true); |
| 426 else | 441 else |
| 427 scroll_border_->set_visible(false); | 442 scroll_border_->set_visible(false); |
| 428 } | 443 } |
| 429 | 444 |
| 430 views::View::OnPaintBorder(canvas); | 445 views::View::OnPaintBorder(canvas); |
| 431 } | 446 } |
| 432 | 447 |
| 433 } // namespace ash | 448 } // namespace ash |
| OLD | NEW |