Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: ash/common/system/tray/tray_details_view.cc

Issue 2497813002: Modify Ash MD system menu layout for title rows (Closed)
Patch Set: trybots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/tray/tray_details_view.h ('k') | ash/common/system/tray_accessibility.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_menu_button.h"
10 #include "ash/common/system/tray/system_tray.h" 11 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_item.h" 12 #include "ash/common/system/tray/system_tray_item.h"
12 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_popup_item_style.h"
15 #include "ash/common/system/tray/tray_popup_utils.h"
16 #include "ash/common/system/tray/tri_view.h"
13 #include "base/containers/adapters.h" 17 #include "base/containers/adapters.h"
18 #include "grit/ash_strings.h"
14 #include "third_party/skia/include/core/SkDrawLooper.h" 19 #include "third_party/skia/include/core/SkDrawLooper.h"
20 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/compositor/paint_context.h" 21 #include "ui/compositor/paint_context.h"
16 #include "ui/compositor/paint_recorder.h" 22 #include "ui/compositor/paint_recorder.h"
17 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
19 #include "ui/views/background.h" 25 #include "ui/views/background.h"
20 #include "ui/views/border.h" 26 #include "ui/views/border.h"
27 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/progress_bar.h" 28 #include "ui/views/controls/progress_bar.h"
22 #include "ui/views/controls/scroll_view.h" 29 #include "ui/views/controls/scroll_view.h"
23 #include "ui/views/controls/separator.h" 30 #include "ui/views/controls/separator.h"
24 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/view_targeter.h" 32 #include "ui/views/view_targeter.h"
26 #include "ui/views/view_targeter_delegate.h" 33 #include "ui/views/view_targeter_delegate.h"
27 34
28 namespace ash { 35 namespace ash {
29 namespace { 36 namespace {
30 37
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 }; 279 };
273 280
274 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) 281 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner)
275 : owner_(owner), 282 : owner_(owner),
276 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), 283 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)),
277 title_row_(nullptr), 284 title_row_(nullptr),
278 scroller_(nullptr), 285 scroller_(nullptr),
279 scroll_content_(nullptr), 286 scroll_content_(nullptr),
280 progress_bar_(nullptr), 287 progress_bar_(nullptr),
281 scroll_border_(nullptr), 288 scroll_border_(nullptr),
289 tri_view_(nullptr),
290 label_(nullptr),
282 back_button_(nullptr) { 291 back_button_(nullptr) {
283 SetLayoutManager(box_layout_); 292 SetLayoutManager(box_layout_);
284 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 293 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
285 } 294 }
286 295
287 TrayDetailsView::~TrayDetailsView() {} 296 TrayDetailsView::~TrayDetailsView() {}
288 297
289 void TrayDetailsView::OnViewClicked(views::View* sender) { 298 void TrayDetailsView::OnViewClicked(views::View* sender) {
290 if (!UseMd() && title_row_ && sender == title_row_->content()) { 299 if (!UseMd() && title_row_ && sender == title_row_->content()) {
291 TransitionToDefaultView(); 300 TransitionToDefaultView();
292 return; 301 return;
293 } 302 }
294 303
295 HandleViewClicked(sender); 304 HandleViewClicked(sender);
296 } 305 }
297 306
298 void TrayDetailsView::ButtonPressed(views::Button* sender, 307 void TrayDetailsView::ButtonPressed(views::Button* sender,
299 const ui::Event& event) { 308 const ui::Event& event) {
300 if (UseMd() && sender == back_button_) { 309 if (UseMd() && sender == back_button_) {
301 TransitionToDefaultView(); 310 TransitionToDefaultView();
302 return; 311 return;
303 } 312 }
304 313
305 HandleButtonPressed(sender, event); 314 HandleButtonPressed(sender, event);
306 } 315 }
307 316
308 void TrayDetailsView::CreateTitleRow(int string_id) { 317 void TrayDetailsView::CreateTitleRow(int string_id) {
318 DCHECK(!tri_view_);
309 DCHECK(!title_row_); 319 DCHECK(!title_row_);
310 title_row_ = new SpecialPopupRow(); 320
311 title_row_->SetTextLabel(string_id, this);
312 if (UseMd()) { 321 if (UseMd()) {
313 title_row_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, 322 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
314 kTitleRowPaddingBottom, 0)); 323
315 AddChildViewAt(title_row_, 0); 324 back_button_ = CreateBackButton();
325 tri_view_->AddView(TriView::Container::START, back_button_);
326
327 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
328 label_ = TrayPopupUtils::CreateDefaultLabel();
329 label_->SetText(rb.GetLocalizedString(string_id));
330 UpdateStyle();
331 tri_view_->AddView(TriView::Container::CENTER, label_);
332
333 tri_view_->SetContainerVisible(TriView::Container::END, false);
334
335 tri_view_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0,
336 kTitleRowPaddingBottom, 0));
337 AddChildViewAt(tri_view_, 0);
316 views::Separator* separator = 338 views::Separator* separator =
317 new views::Separator(views::Separator::HORIZONTAL); 339 new views::Separator(views::Separator::HORIZONTAL);
318 separator->SetColor(kHorizontalSeparatorColor); 340 separator->SetColor(kHorizontalSeparatorColor);
319 separator->SetPreferredSize(kTitleRowSeparatorHeight); 341 separator->SetPreferredSize(kTitleRowSeparatorHeight);
320 separator->SetBorder(views::CreateEmptyBorder( 342 separator->SetBorder(views::CreateEmptyBorder(
321 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0)); 343 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0));
322 AddChildViewAt(separator, kTitleRowSeparatorIndex); 344 AddChildViewAt(separator, kTitleRowSeparatorIndex);
323 } else { 345 } else {
346 title_row_ = new SpecialPopupRow();
347 title_row_->SetTextLabel(string_id, this);
324 AddChildViewAt(title_row_, child_count()); 348 AddChildViewAt(title_row_, child_count());
325 } 349 }
326 350
327 CreateExtraTitleRowButtons(); 351 CreateExtraTitleRowButtons();
328
329 if (UseMd())
330 back_button_ = title_row_->AddBackButton(this);
331
332 Layout(); 352 Layout();
333 } 353 }
334 354
335 void TrayDetailsView::CreateScrollableList() { 355 void TrayDetailsView::CreateScrollableList() {
336 DCHECK(!scroller_); 356 DCHECK(!scroller_);
337 scroll_content_ = new ScrollContentsView(); 357 scroll_content_ = new ScrollContentsView();
338 scroller_ = new FixedSizedScrollView; 358 scroller_ = new FixedSizedScrollView;
339 scroller_->SetContentsView(scroll_content_); 359 scroller_->SetContentsView(scroll_content_);
340 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. 360 // Make the |scroller_| have a layer to clip |scroll_content_|'s children.
341 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). 361 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer().
(...skipping 22 matching lines...) Expand all
364 scroll_content_->AddChildView(new ScrollSeparator); 384 scroll_content_->AddChildView(new ScrollSeparator);
365 } 385 }
366 386
367 void TrayDetailsView::Reset() { 387 void TrayDetailsView::Reset() {
368 RemoveAllChildViews(true); 388 RemoveAllChildViews(true);
369 title_row_ = nullptr; 389 title_row_ = nullptr;
370 scroller_ = nullptr; 390 scroller_ = nullptr;
371 scroll_content_ = nullptr; 391 scroll_content_ = nullptr;
372 progress_bar_ = nullptr; 392 progress_bar_ = nullptr;
373 back_button_ = nullptr; 393 back_button_ = nullptr;
394 label_ = nullptr;
395 tri_view_ = nullptr;
374 } 396 }
375 397
376 void TrayDetailsView::ShowProgress(double value, bool visible) { 398 void TrayDetailsView::ShowProgress(double value, bool visible) {
377 DCHECK(UseMd()); 399 DCHECK(UseMd());
378 DCHECK(title_row_); 400 DCHECK(tri_view_);
379 if (!progress_bar_) { 401 if (!progress_bar_) {
380 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight); 402 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight);
381 progress_bar_->SetVisible(false); 403 progress_bar_->SetVisible(false);
382 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1); 404 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1);
383 } 405 }
384 406
385 progress_bar_->SetValue(value); 407 progress_bar_->SetValue(value);
386 progress_bar_->SetVisible(visible); 408 progress_bar_->SetVisible(visible);
387 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible); 409 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible);
388 } 410 }
389 411
412 views::CustomButton* TrayDetailsView::CreateSettingsButton(LoginStatus status) {
413 DCHECK(UseMd());
414 SystemMenuButton* button = new SystemMenuButton(
415 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon,
416 IDS_ASH_STATUS_TRAY_SETTINGS);
417 if (!TrayPopupUtils::CanOpenWebUISettings(status))
418 button->SetState(views::Button::STATE_DISABLED);
419 return button;
420 }
421
422 views::CustomButton* TrayDetailsView::CreateHelpButton(LoginStatus status) {
423 DCHECK(UseMd());
424 SystemMenuButton* button =
425 new SystemMenuButton(this, SystemMenuButton::InkDropStyle::SQUARE,
426 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
427 if (!TrayPopupUtils::CanOpenWebUISettings(status))
428 button->SetState(views::Button::STATE_DISABLED);
429 return button;
430 }
431
432 void TrayDetailsView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
433 if (UseMd())
434 UpdateStyle();
435 }
436
437 void TrayDetailsView::UpdateStyle() {
438 if (!GetNativeTheme() || !label_)
439 return;
440
441 TrayPopupItemStyle style(GetNativeTheme(),
442 TrayPopupItemStyle::FontStyle::TITLE);
443 style.SetupLabel(label_);
444 }
445
390 void TrayDetailsView::HandleViewClicked(views::View* view) { 446 void TrayDetailsView::HandleViewClicked(views::View* view) {
391 NOTREACHED(); 447 NOTREACHED();
392 } 448 }
393 449
394 void TrayDetailsView::HandleButtonPressed(views::Button* sender, 450 void TrayDetailsView::HandleButtonPressed(views::Button* sender,
395 const ui::Event& event) { 451 const ui::Event& event) {
396 NOTREACHED(); 452 NOTREACHED();
397 } 453 }
398 454
399 void TrayDetailsView::CreateExtraTitleRowButtons() {} 455 void TrayDetailsView::CreateExtraTitleRowButtons() {}
400 456
401 void TrayDetailsView::TransitionToDefaultView() { 457 void TrayDetailsView::TransitionToDefaultView() {
402 // Cache pointer to owner in this function scope. TrayDetailsView will be 458 // Cache pointer to owner in this function scope. TrayDetailsView will be
403 // deleted after called ShowDefaultView. 459 // deleted after called ShowDefaultView.
404 SystemTrayItem* owner = owner_; 460 SystemTrayItem* owner = owner_;
405 if (UseMd()) { 461 if (UseMd()) {
406 if (back_button_ && back_button_->HasFocus()) 462 if (back_button_ && back_button_->HasFocus())
407 owner->set_restore_focus(true); 463 owner->set_restore_focus(true);
408 } else { 464 } else {
409 if (title_row_ && title_row_->content() && 465 if (title_row_ && title_row_->content() &&
410 title_row_->content()->HasFocus()) { 466 title_row_->content()->HasFocus()) {
411 owner->set_restore_focus(true); 467 owner->set_restore_focus(true);
412 } 468 }
413 } 469 }
414 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 470 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
415 owner->set_restore_focus(false); 471 owner->set_restore_focus(false);
416 } 472 }
417 473
474 views::Button* TrayDetailsView::CreateBackButton() {
475 DCHECK(UseMd());
476 SystemMenuButton* button = new SystemMenuButton(
477 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuArrowBackIcon,
478 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU);
479 return button;
480 }
481
418 void TrayDetailsView::Layout() { 482 void TrayDetailsView::Layout() {
419 if (UseMd()) { 483 if (UseMd()) {
420 views::View::Layout(); 484 views::View::Layout();
421 if (scroller_ && !scroller_->is_bounded()) 485 if (scroller_ && !scroller_->is_bounded())
422 scroller_->ClipHeightTo(0, scroller_->height()); 486 scroller_->ClipHeightTo(0, scroller_->height());
423 } 487 }
424 488
425 if (UseMd() || bounds().IsEmpty()) { 489 if (UseMd() || bounds().IsEmpty()) {
426 views::View::Layout(); 490 views::View::Layout();
427 return; 491 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (index < child_count() - 1 && child_at(index + 1) != title_row_) 530 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
467 scroll_border_->set_visible(true); 531 scroll_border_->set_visible(true);
468 else 532 else
469 scroll_border_->set_visible(false); 533 scroll_border_->set_visible(false);
470 } 534 }
471 535
472 views::View::OnPaintBorder(canvas); 536 views::View::OnPaintBorder(canvas);
473 } 537 }
474 538
475 } // namespace ash 539 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_details_view.h ('k') | ash/common/system/tray_accessibility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698