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" |
| 11 #include "ash/common/system/tray/system_tray_item.h" | 11 #include "ash/common/system/tray/system_tray_item.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_popup_item_style.h" | |
| 14 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 13 #include "base/containers/adapters.h" | 15 #include "base/containers/adapters.h" |
| 16 #include "grit/ash_strings.h" | |
| 14 #include "third_party/skia/include/core/SkDrawLooper.h" | 17 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/compositor/paint_context.h" | 19 #include "ui/compositor/paint_context.h" |
| 16 #include "ui/compositor/paint_recorder.h" | 20 #include "ui/compositor/paint_recorder.h" |
| 17 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 19 #include "ui/views/background.h" | 23 #include "ui/views/background.h" |
| 20 #include "ui/views/border.h" | 24 #include "ui/views/border.h" |
| 25 #include "ui/views/controls/label.h" | |
| 21 #include "ui/views/controls/progress_bar.h" | 26 #include "ui/views/controls/progress_bar.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 27 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/controls/separator.h" | 28 #include "ui/views/controls/separator.h" |
| 24 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/view_targeter.h" | 30 #include "ui/views/view_targeter.h" |
| 26 #include "ui/views/view_targeter_delegate.h" | 31 #include "ui/views/view_targeter_delegate.h" |
| 27 | 32 |
| 28 namespace ash { | 33 namespace ash { |
| 29 namespace { | 34 namespace { |
| 30 | 35 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 }; | 262 }; |
| 258 | 263 |
| 259 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) | 264 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) |
| 260 : owner_(owner), | 265 : owner_(owner), |
| 261 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), | 266 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), |
| 262 title_row_(nullptr), | 267 title_row_(nullptr), |
| 263 scroller_(nullptr), | 268 scroller_(nullptr), |
| 264 scroll_content_(nullptr), | 269 scroll_content_(nullptr), |
| 265 progress_bar_(nullptr), | 270 progress_bar_(nullptr), |
| 266 scroll_border_(nullptr), | 271 scroll_border_(nullptr), |
| 272 tri_view_(nullptr), | |
| 273 label_(nullptr), | |
| 267 back_button_(nullptr) { | 274 back_button_(nullptr) { |
| 268 SetLayoutManager(box_layout_); | 275 SetLayoutManager(box_layout_); |
| 269 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 276 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 270 } | 277 } |
| 271 | 278 |
| 272 TrayDetailsView::~TrayDetailsView() {} | 279 TrayDetailsView::~TrayDetailsView() {} |
| 273 | 280 |
| 274 void TrayDetailsView::OnViewClicked(views::View* sender) { | 281 void TrayDetailsView::OnViewClicked(views::View* sender) { |
| 275 if (!UseMd() && title_row_ && sender == title_row_->content()) { | 282 if (!UseMd() && title_row_ && sender == title_row_->content()) { |
| 276 TransitionToDefaultView(); | 283 TransitionToDefaultView(); |
| 277 return; | 284 return; |
| 278 } | 285 } |
| 279 | 286 |
| 280 HandleViewClicked(sender); | 287 HandleViewClicked(sender); |
| 281 } | 288 } |
| 282 | 289 |
| 283 void TrayDetailsView::ButtonPressed(views::Button* sender, | 290 void TrayDetailsView::ButtonPressed(views::Button* sender, |
| 284 const ui::Event& event) { | 291 const ui::Event& event) { |
| 285 if (UseMd() && sender == back_button_) { | 292 if (UseMd() && sender == back_button_) { |
| 286 TransitionToDefaultView(); | 293 TransitionToDefaultView(); |
| 287 return; | 294 return; |
| 288 } | 295 } |
| 289 | 296 |
| 290 HandleButtonPressed(sender, event); | 297 HandleButtonPressed(sender, event); |
| 291 } | 298 } |
| 292 | 299 |
| 293 void TrayDetailsView::CreateTitleRow(int string_id) { | 300 void TrayDetailsView::CreateTitleRow(int string_id) { |
| 294 DCHECK(!title_row_); | |
| 295 title_row_ = new SpecialPopupRow(); | |
| 296 title_row_->SetTextLabel(string_id, this); | |
| 297 if (UseMd()) { | 301 if (UseMd()) { |
| 298 title_row_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, | 302 DCHECK(!tri_view_); |
| 299 kTitleRowPaddingBottom, 0)); | 303 |
| 300 AddChildViewAt(title_row_, 0); | 304 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); |
| 305 | |
| 306 back_button_ = CreateBackButton(); | |
| 307 tri_view_->AddView(TriView::Container::START, back_button_); | |
| 308 | |
| 309 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 310 label_ = TrayPopupUtils::CreateDefaultLabel(); | |
| 311 label_->SetText(rb.GetLocalizedString(string_id)); | |
| 312 TrayPopupItemStyle style(GetNativeTheme(), | |
|
bruthig
2016/11/14 04:39:11
You should be reapplying the style to |label_| in
tdanderson
2016/11/14 19:24:59
Done.
| |
| 313 TrayPopupItemStyle::FontStyle::TITLE); | |
| 314 style.SetupLabel(label_); | |
| 315 tri_view_->AddView(TriView::Container::CENTER, label_); | |
| 316 | |
| 317 tri_view_->SetContainerVisible(TriView::Container::END, false); | |
| 318 | |
| 319 tri_view_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, | |
| 320 kTitleRowPaddingBottom, 0)); | |
| 321 AddChildViewAt(tri_view_, 0); | |
| 301 views::Separator* separator = | 322 views::Separator* separator = |
| 302 new views::Separator(views::Separator::HORIZONTAL); | 323 new views::Separator(views::Separator::HORIZONTAL); |
| 303 separator->SetColor(kHorizontalSeparatorColor); | 324 separator->SetColor(kHorizontalSeparatorColor); |
| 304 separator->SetPreferredSize(kTitleRowSeparatorHeight); | 325 separator->SetPreferredSize(kTitleRowSeparatorHeight); |
| 305 separator->SetBorder(views::CreateEmptyBorder( | 326 separator->SetBorder(views::CreateEmptyBorder( |
| 306 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0)); | 327 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0)); |
| 307 AddChildViewAt(separator, kTitleRowSeparatorIndex); | 328 AddChildViewAt(separator, kTitleRowSeparatorIndex); |
| 308 } else { | 329 } else { |
| 330 DCHECK(!title_row_); | |
|
bruthig
2016/11/14 04:39:11
If you move this DCHECK and the one on line 302 ab
tdanderson
2016/11/14 19:24:59
Done.
| |
| 331 title_row_ = new SpecialPopupRow(); | |
| 332 title_row_->SetTextLabel(string_id, this); | |
| 309 AddChildViewAt(title_row_, child_count()); | 333 AddChildViewAt(title_row_, child_count()); |
| 310 } | 334 } |
| 311 | 335 |
| 312 CreateExtraTitleRowButtons(); | 336 CreateExtraTitleRowButtons(); |
| 313 | |
| 314 if (UseMd()) | |
| 315 back_button_ = title_row_->AddBackButton(this); | |
| 316 | |
| 317 Layout(); | 337 Layout(); |
| 318 } | 338 } |
| 319 | 339 |
| 320 void TrayDetailsView::CreateScrollableList() { | 340 void TrayDetailsView::CreateScrollableList() { |
| 321 DCHECK(!scroller_); | 341 DCHECK(!scroller_); |
| 322 scroll_content_ = new ScrollContentsView(); | 342 scroll_content_ = new ScrollContentsView(); |
| 323 scroller_ = new FixedSizedScrollView; | 343 scroller_ = new FixedSizedScrollView; |
| 324 scroller_->SetContentsView(scroll_content_); | 344 scroller_->SetContentsView(scroll_content_); |
| 325 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. | 345 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. |
| 326 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). | 346 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 349 scroll_content_->AddChildView(new ScrollSeparator); | 369 scroll_content_->AddChildView(new ScrollSeparator); |
| 350 } | 370 } |
| 351 | 371 |
| 352 void TrayDetailsView::Reset() { | 372 void TrayDetailsView::Reset() { |
| 353 RemoveAllChildViews(true); | 373 RemoveAllChildViews(true); |
| 354 title_row_ = nullptr; | 374 title_row_ = nullptr; |
| 355 scroller_ = nullptr; | 375 scroller_ = nullptr; |
| 356 scroll_content_ = nullptr; | 376 scroll_content_ = nullptr; |
| 357 progress_bar_ = nullptr; | 377 progress_bar_ = nullptr; |
| 358 back_button_ = nullptr; | 378 back_button_ = nullptr; |
| 379 label_ = nullptr; | |
| 380 tri_view_ = nullptr; | |
| 359 } | 381 } |
| 360 | 382 |
| 361 void TrayDetailsView::ShowProgress(double value, bool visible) { | 383 void TrayDetailsView::ShowProgress(double value, bool visible) { |
| 362 DCHECK(UseMd()); | 384 DCHECK(UseMd()); |
| 363 DCHECK(title_row_); | 385 DCHECK(tri_view_); |
| 364 if (!progress_bar_) { | 386 if (!progress_bar_) { |
| 365 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight); | 387 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight); |
| 366 progress_bar_->SetVisible(false); | 388 progress_bar_->SetVisible(false); |
| 367 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1); | 389 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1); |
| 368 } | 390 } |
| 369 | 391 |
| 370 progress_bar_->SetValue(value); | 392 progress_bar_->SetValue(value); |
| 371 progress_bar_->SetVisible(visible); | 393 progress_bar_->SetVisible(visible); |
| 372 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible); | 394 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible); |
| 373 } | 395 } |
| 374 | 396 |
| 397 views::CustomButton* TrayDetailsView::CreateSettingsButton(LoginStatus status) { | |
|
bruthig
2016/11/14 04:39:11
nit: Might benefit from a DCHECK(UseMd());
Same ap
tdanderson
2016/11/14 19:24:59
Done.
| |
| 398 SystemMenuButton* button = new SystemMenuButton( | |
| 399 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon, | |
| 400 IDS_ASH_STATUS_TRAY_SETTINGS); | |
| 401 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | |
| 402 button->SetState(views::Button::STATE_DISABLED); | |
| 403 return button; | |
| 404 } | |
| 405 | |
| 406 views::CustomButton* TrayDetailsView::CreateHelpButton(LoginStatus status) { | |
| 407 SystemMenuButton* button = | |
| 408 new SystemMenuButton(this, SystemMenuButton::InkDropStyle::SQUARE, | |
| 409 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); | |
| 410 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | |
| 411 button->SetState(views::Button::STATE_DISABLED); | |
| 412 return button; | |
| 413 } | |
| 414 | |
| 375 void TrayDetailsView::HandleViewClicked(views::View* view) { | 415 void TrayDetailsView::HandleViewClicked(views::View* view) { |
| 376 NOTREACHED(); | 416 NOTREACHED(); |
| 377 } | 417 } |
| 378 | 418 |
| 379 void TrayDetailsView::HandleButtonPressed(views::Button* sender, | 419 void TrayDetailsView::HandleButtonPressed(views::Button* sender, |
| 380 const ui::Event& event) { | 420 const ui::Event& event) { |
| 381 NOTREACHED(); | 421 NOTREACHED(); |
| 382 } | 422 } |
| 383 | 423 |
| 384 void TrayDetailsView::CreateExtraTitleRowButtons() {} | 424 void TrayDetailsView::CreateExtraTitleRowButtons() {} |
| 385 | 425 |
| 386 void TrayDetailsView::TransitionToDefaultView() { | 426 void TrayDetailsView::TransitionToDefaultView() { |
| 387 // Cache pointer to owner in this function scope. TrayDetailsView will be | 427 // Cache pointer to owner in this function scope. TrayDetailsView will be |
| 388 // deleted after called ShowDefaultView. | 428 // deleted after called ShowDefaultView. |
| 389 SystemTrayItem* owner = owner_; | 429 SystemTrayItem* owner = owner_; |
| 390 if (UseMd()) { | 430 if (UseMd()) { |
| 391 if (back_button_ && back_button_->HasFocus()) | 431 if (back_button_ && back_button_->HasFocus()) |
| 392 owner->set_restore_focus(true); | 432 owner->set_restore_focus(true); |
| 393 } else { | 433 } else { |
| 394 if (title_row_ && title_row_->content() && | 434 if (title_row_ && title_row_->content() && |
| 395 title_row_->content()->HasFocus()) { | 435 title_row_->content()->HasFocus()) { |
| 396 owner->set_restore_focus(true); | 436 owner->set_restore_focus(true); |
| 397 } | 437 } |
| 398 } | 438 } |
| 399 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 439 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 400 owner->set_restore_focus(false); | 440 owner->set_restore_focus(false); |
| 401 } | 441 } |
| 402 | 442 |
| 443 views::Button* TrayDetailsView::CreateBackButton() { | |
| 444 SystemMenuButton* button = new SystemMenuButton( | |
| 445 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuArrowBackIcon, | |
| 446 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); | |
| 447 return button; | |
| 448 } | |
| 449 | |
| 403 void TrayDetailsView::Layout() { | 450 void TrayDetailsView::Layout() { |
| 404 if (UseMd()) { | 451 if (UseMd()) { |
| 405 views::View::Layout(); | 452 views::View::Layout(); |
| 406 if (scroller_ && !scroller_->is_bounded()) | 453 if (scroller_ && !scroller_->is_bounded()) |
| 407 scroller_->ClipHeightTo(0, scroller_->height()); | 454 scroller_->ClipHeightTo(0, scroller_->height()); |
| 408 } | 455 } |
| 409 | 456 |
| 410 if (UseMd() || bounds().IsEmpty()) { | 457 if (UseMd() || bounds().IsEmpty()) { |
| 411 views::View::Layout(); | 458 views::View::Layout(); |
| 412 return; | 459 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | 498 if (index < child_count() - 1 && child_at(index + 1) != title_row_) |
| 452 scroll_border_->set_visible(true); | 499 scroll_border_->set_visible(true); |
| 453 else | 500 else |
| 454 scroll_border_->set_visible(false); | 501 scroll_border_->set_visible(false); |
| 455 } | 502 } |
| 456 | 503 |
| 457 views::View::OnPaintBorder(canvas); | 504 views::View::OnPaintBorder(canvas); |
| 458 } | 505 } |
| 459 | 506 |
| 460 } // namespace ash | 507 } // namespace ash |
| OLD | NEW |