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

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

Issue 2717973004: Improve painting of cros tray separators. (Closed)
Patch Set: restore include Created 3 years, 9 months 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 | « no previous file | ash/common/system/tray/tray_constants.h » ('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_background_view.h" 5 #include "ash/common/system/tray/tray_background_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/ash_constants.h" 9 #include "ash/common/ash_constants.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 if (action_performed) 560 if (action_performed)
561 return; 561 return;
562 ActionableView::HandlePerformActionResult(action_performed, event); 562 ActionableView::HandlePerformActionResult(action_performed, event);
563 } 563 }
564 564
565 void TrayBackgroundView::OnPaintFocus(gfx::Canvas* canvas) { 565 void TrayBackgroundView::OnPaintFocus(gfx::Canvas* canvas) {
566 // The tray itself expands to the right and bottom edge of the screen to make 566 // The tray itself expands to the right and bottom edge of the screen to make
567 // sure clicking on the edges brings up the popup. However, the focus border 567 // sure clicking on the edges brings up the popup. However, the focus border
568 // should be only around the container. 568 // should be only around the container.
569 gfx::RectF paint_bounds; 569 gfx::RectF paint_bounds;
570 if (MaterialDesignController::IsShelfMaterial()) { 570 paint_bounds = gfx::RectF(GetBackgroundBounds());
571 paint_bounds = gfx::RectF(GetBackgroundBounds()); 571 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
572 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
573 } else {
574 paint_bounds = gfx::RectF(GetContentsBounds());
575 paint_bounds.Inset(gfx::Insets(1));
576 }
577 canvas->DrawSolidFocusRect(paint_bounds, kFocusBorderColor, 572 canvas->DrawSolidFocusRect(paint_bounds, kFocusBorderColor,
578 kFocusBorderThickness); 573 kFocusBorderThickness);
579 } 574 }
580 575
581 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { 576 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
582 ActionableView::OnPaint(canvas); 577 ActionableView::OnPaint(canvas);
583 if (!MaterialDesignController::IsShelfMaterial() || 578 if (shelf()->GetBackgroundType() ==
584 shelf()->GetBackgroundType() ==
585 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || 579 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT ||
586 !separator_visible_) { 580 !separator_visible_) {
587 return; 581 return;
588 } 582 }
589 // In the given |canvas|, for a horizontal shelf draw a separator line to the 583 // In the given |canvas|, for a horizontal shelf draw a separator line to the
590 // right or left of the TrayBackgroundView when the system is LTR or RTL 584 // right or left of the TrayBackgroundView when the system is LTR or RTL
591 // aligned, respectively. For a vertical shelf draw the separator line 585 // aligned, respectively. For a vertical shelf draw the separator line
592 // underneath the items instead. 586 // underneath the items instead.
593 const bool horizontal_shelf = IsHorizontalAlignment(shelf_alignment_);
594 const gfx::Rect local_bounds = GetLocalBounds(); 587 const gfx::Rect local_bounds = GetLocalBounds();
595 const int height = kTrayItemSize; 588 const SkColor color = SkColorSetA(SK_ColorWHITE, 0x4D);
596 const int x =
597 horizontal_shelf
598 ? (base::i18n::IsRTL() ? 0 : (local_bounds.width() - kSeparatorWidth))
599 : (local_bounds.height() - kSeparatorWidth);
600 const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2;
601 gfx::ScopedCanvas scoped_canvas(canvas);
602 const float scale = canvas->UndoDeviceScaleFactor();
603 cc::PaintFlags flags;
604 flags.setColor(kTraySeparatorColor);
605 flags.setAntiAlias(true);
606 589
607 const gfx::Rect bounds = horizontal_shelf 590 if (IsHorizontalAlignment(shelf_alignment_)) {
608 ? gfx::Rect(x, y, kSeparatorWidth, height) 591 const gfx::PointF point(
609 : gfx::Rect(y, x, height, kSeparatorWidth); 592 base::i18n::IsRTL() ? 0 : (local_bounds.width() - kSeparatorWidth),
610 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); 593 (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2);
611 gfx::PointF line_start = 594 const gfx::Vector2dF vector(0, kTrayItemSize);
612 horizontal_shelf 595 canvas->Draw1pxLine(point, point + vector, color);
613 ? (base::i18n::IsRTL() ? rect.origin() : rect.top_right()) 596 } else {
614 : rect.bottom_left(); 597 const gfx::PointF point((GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2,
615 gfx::PointF line_end = 598 local_bounds.height() - kSeparatorWidth);
616 (horizontal_shelf && base::i18n::IsRTL() ? rect.bottom_left() 599 const gfx::Vector2dF vector(kTrayItemSize, 0);
617 : rect.bottom_right()); 600 canvas->Draw1pxLine(point, point + vector, color);
618 601 }
619 canvas->DrawLine(line_start, line_end, flags);
620 } 602 }
621 603
622 gfx::Insets TrayBackgroundView::GetBackgroundInsets() const { 604 gfx::Insets TrayBackgroundView::GetBackgroundInsets() const {
623 gfx::Insets insets = GetMirroredBackgroundInsets(shelf_alignment_); 605 gfx::Insets insets = GetMirroredBackgroundInsets(shelf_alignment_);
624 606
625 // |insets| are relative to contents bounds. Change them to be relative to 607 // |insets| are relative to contents bounds. Change them to be relative to
626 // local bounds. 608 // local bounds.
627 gfx::Insets local_contents_insets = 609 gfx::Insets local_contents_insets =
628 GetLocalBounds().InsetsFrom(GetContentsBounds()); 610 GetLocalBounds().InsetsFrom(GetContentsBounds());
629 MirrorInsetsIfNecessary(&local_contents_insets); 611 MirrorInsetsIfNecessary(&local_contents_insets);
630 insets += local_contents_insets; 612 insets += local_contents_insets;
631 613
632 return insets; 614 return insets;
633 } 615 }
634 616
635 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { 617 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const {
636 gfx::Insets insets = GetBackgroundInsets(); 618 gfx::Insets insets = GetBackgroundInsets();
637 gfx::Rect bounds = GetLocalBounds(); 619 gfx::Rect bounds = GetLocalBounds();
638 bounds.Inset(insets); 620 bounds.Inset(insets);
639 return bounds; 621 return bounds;
640 } 622 }
641 623
642 } // namespace ash 624 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698