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

Unified Diff: ash/common/system/tray/tray_background_view.cc

Issue 2147143002: [Chrome OS MD] Draw a 1px separator between 2 tray items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge conflicts + comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/tray/tray_background_view.cc
diff --git a/ash/common/system/tray/tray_background_view.cc b/ash/common/system/tray/tray_background_view.cc
index e6393764d72dda2bf251ca1f66e52c3359dffb96..6fb2bafbb4d6837f07dc47d1a7899e356c24415a 100644
--- a/ash/common/system/tray/tray_background_view.cc
+++ b/ash/common/system/tray/tray_background_view.cc
@@ -9,6 +9,7 @@
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shelf/wm_shelf_util.h"
#include "ash/common/shell_window_ids.h"
+#include "ash/common/system/status_area_widget.h"
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_event_filter.h"
@@ -25,9 +26,11 @@
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/nine_image_painter.h"
+#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h"
#include "ui/views/background.h"
@@ -101,15 +104,31 @@ class TrayBackground : public views::Background {
SkPaint background_paint;
background_paint.setFlags(SkPaint::kAntiAlias_Flag);
background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_));
- canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius,
- background_paint);
+ gfx::Rect bounds;
+
+ // The hit region are padded to the |view| as insets, so they are included
+ // in the local bounds. Remove these regions from view because hit region is
+ // invisible.
+ if (IsHorizontalAlignment(GetShelf()->GetAlignment())) {
+ bounds = gfx::Rect(view->GetLocalBounds().x() + kHitRegionPadding,
+ view->GetLocalBounds().y(),
+ view->GetLocalBounds().width() - kHitRegionPadding -
+ kHitRegionPadding - kSeparatorWidth,
+ view->GetLocalBounds().height());
+ } else {
+ bounds = gfx::Rect(view->GetLocalBounds().x(),
+ view->GetLocalBounds().y() + kHitRegionPadding,
+ view->GetLocalBounds().width(),
+ view->GetLocalBounds().height() - kHitRegionPadding -
+ kHitRegionPadding - kSeparatorWidth);
+ }
+ canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint);
if (tray_background_view_->draw_background_as_active()) {
SkPaint highlight_paint;
highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
- canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius,
- highlight_paint);
+ canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint);
}
}
@@ -206,17 +225,25 @@ void TrayBackgroundView::TrayContainer::UpdateLayout() {
views::BoxLayout::Orientation orientation =
IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal
: views::BoxLayout::kVertical;
-
+ views::BoxLayout* layout;
yoshiki 2016/08/18 08:39:08 nit: I think we don't need to move it to here.
yiyix 2016/08/18 20:01:43 Done.
if (!ash::MaterialDesignController::IsShelfMaterial()) {
// Additional padding used to adjust the user-visible size of status tray
// dark background.
const int padding = 3;
SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_));
} else {
- SetBorder(views::Border::CreateEmptyBorder(margin_));
+ // Extend hit region horizontally or vertically depending on shelf
+ // alignment.
+ const gfx::Insets insets(
+ IsHorizontalAlignment(alignment_)
+ ? margin_ + gfx::Insets(0, kHitRegionPadding, 0,
+ kHitRegionPadding + kSeparatorWidth)
+ : margin_ + gfx::Insets(kHitRegionPadding, 0,
+ kHitRegionPadding + kSeparatorWidth, 0));
+ SetBorder(views::Border::CreateEmptyBorder(insets));
yoshiki 2016/08/18 08:39:08 nit: I think adding |margin_| at last is simpler.
varkha 2016/08/18 16:33:24 I think you can conditionally calculate insets and
yiyix 2016/08/18 20:01:43 Done.
}
- views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0);
+ layout = new views::BoxLayout(orientation, 0, 0, 0);
layout->SetDefaultFlex(1);
views::View::SetLayoutManager(layout);
PreferredSizeChanged();
@@ -231,6 +258,7 @@ TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf)
shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
background_(NULL),
draw_background_as_active_(false),
+ is_separator_visible_(false),
widget_observer_(new TrayWidgetObserver(this)) {
DCHECK(wm_shelf_);
set_notify_enter_exit_on_child(true);
@@ -314,6 +342,8 @@ void TrayBackgroundView::SetVisible(bool visible) {
layer()->SetVisible(false);
HideTransformation();
}
+ // Update the separator visibility accordingly.
varkha 2016/08/18 16:33:24 nit: Please consider dropping this comment.
yiyix 2016/08/18 20:01:43 Done.
+ wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this);
}
const char* TrayBackgroundView::GetClassName() const {
@@ -508,4 +538,33 @@ void TrayBackgroundView::UpdateShelfItemBackground(int alpha) {
}
}
+void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) {
+ is_separator_visible_ = is_shown;
yoshiki 2016/08/18 08:39:08 Shouldn't we call SchedulePaint() after setting th
yiyix 2016/08/18 20:01:43 Done.
+}
+
+void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
+ if (!MaterialDesignController::IsShelfMaterial() ||
+ shelf()->GetBackgroundType() ==
+ ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT ||
+ !is_separator_visible_) {
+ return;
+ }
+
+ const int height = kTrayItemSize;
+ const int width = kSeparatorWidth;
+ const int x = kTrayItemSize + kHitRegionPadding + kHitRegionPadding;
yoshiki 2016/08/18 08:39:08 Using kTrayItemSize is wrong. The width (or heigh
yiyix 2016/08/18 20:01:43 In material design the tray has a fixed size is 32
+ const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2;
+ gfx::ScopedCanvas scoped_canvas(canvas);
+ const float scale = canvas->UndoDeviceScaleFactor();
+ SkPaint paint;
+ paint.setColor(kSeparatorColor);
+ paint.setAntiAlias(true);
+ const bool horizontal_shelf = IsHorizontalAlignment(shelf()->GetAlignment());
+ const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
+ : gfx::Rect(y, x, height, width);
+ gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
+ canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
+ rect.bottom_right(), paint);
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698