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

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: Ben comments 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 }; 264 };
258 265
259 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) 266 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner)
260 : owner_(owner), 267 : owner_(owner),
261 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), 268 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)),
262 title_row_(nullptr), 269 title_row_(nullptr),
263 scroller_(nullptr), 270 scroller_(nullptr),
264 scroll_content_(nullptr), 271 scroll_content_(nullptr),
265 progress_bar_(nullptr), 272 progress_bar_(nullptr),
266 scroll_border_(nullptr), 273 scroll_border_(nullptr),
274 tri_view_(nullptr),
275 label_(nullptr),
267 back_button_(nullptr) { 276 back_button_(nullptr) {
268 SetLayoutManager(box_layout_); 277 SetLayoutManager(box_layout_);
269 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 278 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
270 } 279 }
271 280
272 TrayDetailsView::~TrayDetailsView() {} 281 TrayDetailsView::~TrayDetailsView() {}
273 282
274 void TrayDetailsView::OnViewClicked(views::View* sender) { 283 void TrayDetailsView::OnViewClicked(views::View* sender) {
275 if (!UseMd() && title_row_ && sender == title_row_->content()) { 284 if (!UseMd() && title_row_ && sender == title_row_->content()) {
276 TransitionToDefaultView(); 285 TransitionToDefaultView();
277 return; 286 return;
278 } 287 }
279 288
280 HandleViewClicked(sender); 289 HandleViewClicked(sender);
281 } 290 }
282 291
283 void TrayDetailsView::ButtonPressed(views::Button* sender, 292 void TrayDetailsView::ButtonPressed(views::Button* sender,
284 const ui::Event& event) { 293 const ui::Event& event) {
285 if (UseMd() && sender == back_button_) { 294 if (UseMd() && sender == back_button_) {
286 TransitionToDefaultView(); 295 TransitionToDefaultView();
287 return; 296 return;
288 } 297 }
289 298
290 HandleButtonPressed(sender, event); 299 HandleButtonPressed(sender, event);
291 } 300 }
292 301
293 void TrayDetailsView::CreateTitleRow(int string_id) { 302 void TrayDetailsView::CreateTitleRow(int string_id) {
303 DCHECK(!tri_view_);
294 DCHECK(!title_row_); 304 DCHECK(!title_row_);
295 title_row_ = new SpecialPopupRow(); 305
296 title_row_->SetTextLabel(string_id, this);
297 if (UseMd()) { 306 if (UseMd()) {
298 title_row_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, 307 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
299 kTitleRowPaddingBottom, 0)); 308
300 AddChildViewAt(title_row_, 0); 309 back_button_ = CreateBackButton();
310 tri_view_->AddView(TriView::Container::START, back_button_);
311
312 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
313 label_ = TrayPopupUtils::CreateDefaultLabel();
314 label_->SetText(rb.GetLocalizedString(string_id));
315 UpdateStyle();
316 tri_view_->AddView(TriView::Container::CENTER, label_);
317
318 tri_view_->SetContainerVisible(TriView::Container::END, false);
319
320 tri_view_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0,
321 kTitleRowPaddingBottom, 0));
322 AddChildViewAt(tri_view_, 0);
301 views::Separator* separator = 323 views::Separator* separator =
302 new views::Separator(views::Separator::HORIZONTAL); 324 new views::Separator(views::Separator::HORIZONTAL);
303 separator->SetColor(kHorizontalSeparatorColor); 325 separator->SetColor(kHorizontalSeparatorColor);
304 separator->SetPreferredSize(kTitleRowSeparatorHeight); 326 separator->SetPreferredSize(kTitleRowSeparatorHeight);
305 separator->SetBorder(views::CreateEmptyBorder( 327 separator->SetBorder(views::CreateEmptyBorder(
306 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0)); 328 kTitleRowProgressBarHeight - kTitleRowSeparatorHeight, 0, 0, 0));
307 AddChildViewAt(separator, kTitleRowSeparatorIndex); 329 AddChildViewAt(separator, kTitleRowSeparatorIndex);
308 } else { 330 } else {
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
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) {
398 DCHECK(UseMd());
399 SystemMenuButton* button = new SystemMenuButton(
400 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon,
401 IDS_ASH_STATUS_TRAY_SETTINGS);
402 if (!TrayPopupUtils::CanOpenWebUISettings(status))
403 button->SetState(views::Button::STATE_DISABLED);
404 return button;
405 }
406
407 views::CustomButton* TrayDetailsView::CreateHelpButton(LoginStatus status) {
408 DCHECK(UseMd());
409 SystemMenuButton* button =
410 new SystemMenuButton(this, SystemMenuButton::InkDropStyle::SQUARE,
411 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
412 if (!TrayPopupUtils::CanOpenWebUISettings(status))
413 button->SetState(views::Button::STATE_DISABLED);
414 return button;
415 }
416
417 void TrayDetailsView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
418 UpdateStyle();
419 }
420
421 void TrayDetailsView::UpdateStyle() {
422 if (!GetNativeTheme())
bruthig 2016/11/16 14:58:31 I have to apologize, I was wrong. GetNativeTheme(
423 return;
424
425 TrayPopupItemStyle style(GetNativeTheme(),
426 TrayPopupItemStyle::FontStyle::TITLE);
427 style.SetupLabel(label_);
428 }
429
375 void TrayDetailsView::HandleViewClicked(views::View* view) { 430 void TrayDetailsView::HandleViewClicked(views::View* view) {
376 NOTREACHED(); 431 NOTREACHED();
377 } 432 }
378 433
379 void TrayDetailsView::HandleButtonPressed(views::Button* sender, 434 void TrayDetailsView::HandleButtonPressed(views::Button* sender,
380 const ui::Event& event) { 435 const ui::Event& event) {
381 NOTREACHED(); 436 NOTREACHED();
382 } 437 }
383 438
384 void TrayDetailsView::CreateExtraTitleRowButtons() {} 439 void TrayDetailsView::CreateExtraTitleRowButtons() {}
385 440
386 void TrayDetailsView::TransitionToDefaultView() { 441 void TrayDetailsView::TransitionToDefaultView() {
387 // Cache pointer to owner in this function scope. TrayDetailsView will be 442 // Cache pointer to owner in this function scope. TrayDetailsView will be
388 // deleted after called ShowDefaultView. 443 // deleted after called ShowDefaultView.
389 SystemTrayItem* owner = owner_; 444 SystemTrayItem* owner = owner_;
390 if (UseMd()) { 445 if (UseMd()) {
391 if (back_button_ && back_button_->HasFocus()) 446 if (back_button_ && back_button_->HasFocus())
392 owner->set_restore_focus(true); 447 owner->set_restore_focus(true);
393 } else { 448 } else {
394 if (title_row_ && title_row_->content() && 449 if (title_row_ && title_row_->content() &&
395 title_row_->content()->HasFocus()) { 450 title_row_->content()->HasFocus()) {
396 owner->set_restore_focus(true); 451 owner->set_restore_focus(true);
397 } 452 }
398 } 453 }
399 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 454 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
400 owner->set_restore_focus(false); 455 owner->set_restore_focus(false);
401 } 456 }
402 457
458 views::Button* TrayDetailsView::CreateBackButton() {
459 DCHECK(UseMd());
460 SystemMenuButton* button = new SystemMenuButton(
461 this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuArrowBackIcon,
462 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU);
463 return button;
464 }
465
403 void TrayDetailsView::Layout() { 466 void TrayDetailsView::Layout() {
404 if (UseMd()) { 467 if (UseMd()) {
405 views::View::Layout(); 468 views::View::Layout();
406 if (scroller_ && !scroller_->is_bounded()) 469 if (scroller_ && !scroller_->is_bounded())
407 scroller_->ClipHeightTo(0, scroller_->height()); 470 scroller_->ClipHeightTo(0, scroller_->height());
408 } 471 }
409 472
410 if (UseMd() || bounds().IsEmpty()) { 473 if (UseMd() || bounds().IsEmpty()) {
411 views::View::Layout(); 474 views::View::Layout();
412 return; 475 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (index < child_count() - 1 && child_at(index + 1) != title_row_) 514 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
452 scroll_border_->set_visible(true); 515 scroll_border_->set_visible(true);
453 else 516 else
454 scroll_border_->set_visible(false); 517 scroll_border_->set_visible(false);
455 } 518 }
456 519
457 views::View::OnPaintBorder(canvas); 520 views::View::OnPaintBorder(canvas);
458 } 521 }
459 522
460 } // namespace ash 523 } // 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