Chromium Code Reviews| 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..afd779b94cf880b009eb09251c7a6763818c4c3f 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, |
|
James Cook
2016/08/19 00:55:50
nit: cache the result of view->GetLocalBounds() in
yiyix
2016/08/19 19:07:56
Thanks! After i finally get it working after many
|
| + 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); |
| } |
| } |
| @@ -207,15 +226,23 @@ void TrayBackgroundView::TrayContainer::UpdateLayout() { |
| IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal |
| : views::BoxLayout::kVertical; |
| + gfx::Insets insets; |
| if (!ash::MaterialDesignController::IsShelfMaterial()) { |
| // Additional padding used to adjust the user-visible size of status tray |
| // dark background. |
| const int padding = 3; |
|
varkha
2016/08/19 16:33:39
nit: can you declare the constant in anonymous nam
yiyix
2016/08/19 19:07:56
Done.
|
| - SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_)); |
| + insets = gfx::Insets(padding); |
| } else { |
| - SetBorder(views::Border::CreateEmptyBorder(margin_)); |
| + // Extend hit region horizontally or vertically depending on shelf |
| + // alignment. |
| + insets = |
| + gfx::Insets(IsHorizontalAlignment(alignment_) |
| + ? gfx::Insets(0, kHitRegionPadding, 0, |
| + kHitRegionPadding + kSeparatorWidth) |
| + : gfx::Insets(kHitRegionPadding, 0, |
| + kHitRegionPadding + kSeparatorWidth, 0)); |
| } |
| - |
| + SetBorder(views::Border::CreateEmptyBorder(insets + margin_)); |
| views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
| layout->SetDefaultFlex(1); |
| views::View::SetLayoutManager(layout); |
| @@ -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,7 @@ void TrayBackgroundView::SetVisible(bool visible) { |
| layer()->SetVisible(false); |
| HideTransformation(); |
| } |
| + wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this); |
| } |
| const char* TrayBackgroundView::GetClassName() const { |
| @@ -508,4 +537,37 @@ void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { |
| } |
| } |
| +void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) { |
| + is_separator_visible_ = is_shown; |
| + SchedulePaint(); |
| +} |
| + |
| +void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| + if (!MaterialDesignController::IsShelfMaterial() || |
| + shelf()->GetBackgroundType() == |
| + ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT || |
| + !is_separator_visible_) { |
| + return; |
| + } |
| + // In the given |canvas|, draws a 1x32px separator line 4 pixel to the right |
| + // of the TrayBackgroundView. |
| + const bool horizontal_shelf = IsHorizontalAlignment(shelf()->GetAlignment()); |
|
James Cook
2016/08/19 00:55:50
I would use IsHorizontalAlignment(shelf_alignment_
yiyix
2016/08/19 19:07:56
Done.
|
| + const int height = kTrayItemSize; |
| + const int width = kSeparatorWidth; |
| + const int x = horizontal_shelf ? GetLocalBounds().width() - kSeparatorWidth |
| + : GetLocalBounds().height() - kSeparatorWidth; |
|
varkha
2016/08/19 16:33:39
nit: can you shorten code to (pseudocode):
const i
yiyix
2016/08/19 19:07:56
Done.
|
| + 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 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 |