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

Side by Side 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 unified diff | Download patch
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 "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_constants.h" 8 #include "ash/common/shelf/shelf_constants.h"
9 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/common/system/status_area_widget.h"
12 #include "ash/common/system/tray/system_tray.h" 13 #include "ash/common/system/tray/system_tray.h"
13 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_event_filter.h" 15 #include "ash/common/system/tray/tray_event_filter.h"
15 #include "ash/common/wm_lookup.h" 16 #include "ash/common/wm_lookup.h"
16 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
17 #include "ash/common/wm_window.h" 18 #include "ash/common/wm_window.h"
18 #include "grit/ash_resources.h" 19 #include "grit/ash_resources.h"
19 #include "ui/accessibility/ax_view_state.h" 20 #include "ui/accessibility/ax_view_state.h"
20 #include "ui/base/nine_image_painter_factory.h" 21 #include "ui/base/nine_image_painter_factory.h"
21 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
22 #include "ui/compositor/layer_animation_element.h" 23 #include "ui/compositor/layer_animation_element.h"
23 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
24 #include "ui/events/event_constants.h" 25 #include "ui/events/event_constants.h"
25 #include "ui/gfx/animation/tween.h" 26 #include "ui/gfx/animation/tween.h"
26 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gfx/geometry/size.h"
28 #include "ui/gfx/image/image_skia.h" 30 #include "ui/gfx/image/image_skia.h"
29 #include "ui/gfx/image/image_skia_operations.h" 31 #include "ui/gfx/image/image_skia_operations.h"
30 #include "ui/gfx/nine_image_painter.h" 32 #include "ui/gfx/nine_image_painter.h"
33 #include "ui/gfx/scoped_canvas.h"
31 #include "ui/gfx/skia_util.h" 34 #include "ui/gfx/skia_util.h"
32 #include "ui/gfx/transform.h" 35 #include "ui/gfx/transform.h"
33 #include "ui/views/background.h" 36 #include "ui/views/background.h"
34 #include "ui/views/layout/box_layout.h" 37 #include "ui/views/layout/box_layout.h"
35 #include "ui/wm/core/window_animations.h" 38 #include "ui/wm/core/window_animations.h"
36 39
37 namespace { 40 namespace {
38 41
39 const int kAnimationDurationForPopupMs = 200; 42 const int kAnimationDurationForPopupMs = 200;
40 43
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 97
95 void set_alpha(int alpha) { alpha_ = alpha; } 98 void set_alpha(int alpha) { alpha_ = alpha; }
96 99
97 private: 100 private:
98 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } 101 WmShelf* GetShelf() const { return tray_background_view_->shelf(); }
99 102
100 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { 103 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const {
101 SkPaint background_paint; 104 SkPaint background_paint;
102 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 105 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
103 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); 106 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_));
104 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 107 gfx::Rect bounds;
105 background_paint); 108
109 // The hit region are padded to the |view| as insets, so they are included
110 // in the local bounds. Remove these regions from view because hit region is
111 // invisible.
112 if (IsHorizontalAlignment(GetShelf()->GetAlignment())) {
113 bounds = gfx::Rect(view->GetLocalBounds().x() + kHitRegionPadding,
114 view->GetLocalBounds().y(),
115 view->GetLocalBounds().width() - kHitRegionPadding -
116 kHitRegionPadding - kSeparatorWidth,
117 view->GetLocalBounds().height());
118 } else {
119 bounds = gfx::Rect(view->GetLocalBounds().x(),
120 view->GetLocalBounds().y() + kHitRegionPadding,
121 view->GetLocalBounds().width(),
122 view->GetLocalBounds().height() - kHitRegionPadding -
123 kHitRegionPadding - kSeparatorWidth);
124 }
125 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint);
106 126
107 if (tray_background_view_->draw_background_as_active()) { 127 if (tray_background_view_->draw_background_as_active()) {
108 SkPaint highlight_paint; 128 SkPaint highlight_paint;
109 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); 129 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
110 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); 130 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
111 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 131 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint);
112 highlight_paint);
113 } 132 }
114 } 133 }
115 134
116 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { 135 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const {
117 const int kGridSizeForPainter = 9; 136 const int kGridSizeForPainter = 9;
118 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { 137 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = {
119 { 138 {
120 // Horizontal 139 // Horizontal
121 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), 140 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ),
122 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), 141 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (details.parent == this) 218 if (details.parent == this)
200 PreferredSizeChanged(); 219 PreferredSizeChanged();
201 } 220 }
202 221
203 void TrayBackgroundView::TrayContainer::UpdateLayout() { 222 void TrayBackgroundView::TrayContainer::UpdateLayout() {
204 // Adjust the size of status tray dark background by adding additional 223 // Adjust the size of status tray dark background by adding additional
205 // empty border. 224 // empty border.
206 views::BoxLayout::Orientation orientation = 225 views::BoxLayout::Orientation orientation =
207 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal 226 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal
208 : views::BoxLayout::kVertical; 227 : views::BoxLayout::kVertical;
209 228 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.
210 if (!ash::MaterialDesignController::IsShelfMaterial()) { 229 if (!ash::MaterialDesignController::IsShelfMaterial()) {
211 // Additional padding used to adjust the user-visible size of status tray 230 // Additional padding used to adjust the user-visible size of status tray
212 // dark background. 231 // dark background.
213 const int padding = 3; 232 const int padding = 3;
214 SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_)); 233 SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(padding) + margin_));
215 } else { 234 } else {
216 SetBorder(views::Border::CreateEmptyBorder(margin_)); 235 // Extend hit region horizontally or vertically depending on shelf
236 // alignment.
237 const gfx::Insets insets(
238 IsHorizontalAlignment(alignment_)
239 ? margin_ + gfx::Insets(0, kHitRegionPadding, 0,
240 kHitRegionPadding + kSeparatorWidth)
241 : margin_ + gfx::Insets(kHitRegionPadding, 0,
242 kHitRegionPadding + kSeparatorWidth, 0));
243 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.
217 } 244 }
218 245
219 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); 246 layout = new views::BoxLayout(orientation, 0, 0, 0);
220 layout->SetDefaultFlex(1); 247 layout->SetDefaultFlex(1);
221 views::View::SetLayoutManager(layout); 248 views::View::SetLayoutManager(layout);
222 PreferredSizeChanged(); 249 PreferredSizeChanged();
223 } 250 }
224 251
225 //////////////////////////////////////////////////////////////////////////////// 252 ////////////////////////////////////////////////////////////////////////////////
226 // TrayBackgroundView 253 // TrayBackgroundView
227 254
228 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) 255 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf)
229 : wm_shelf_(wm_shelf), 256 : wm_shelf_(wm_shelf),
230 tray_container_(NULL), 257 tray_container_(NULL),
231 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), 258 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
232 background_(NULL), 259 background_(NULL),
233 draw_background_as_active_(false), 260 draw_background_as_active_(false),
261 is_separator_visible_(false),
234 widget_observer_(new TrayWidgetObserver(this)) { 262 widget_observer_(new TrayWidgetObserver(this)) {
235 DCHECK(wm_shelf_); 263 DCHECK(wm_shelf_);
236 set_notify_enter_exit_on_child(true); 264 set_notify_enter_exit_on_child(true);
237 265
238 tray_container_ = new TrayContainer(shelf_alignment_); 266 tray_container_ = new TrayContainer(shelf_alignment_);
239 SetContents(tray_container_); 267 SetContents(tray_container_);
240 tray_event_filter_.reset(new TrayEventFilter); 268 tray_event_filter_.reset(new TrayEventFilter);
241 269
242 SetPaintToLayer(true); 270 SetPaintToLayer(true);
243 layer()->SetFillsBoundsOpaquely(false); 271 layer()->SetFillsBoundsOpaquely(false);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 layer()->SetTransform(transform); 335 layer()->SetTransform(transform);
308 } else { 336 } else {
309 // Listen only to the hide animation. As we cannot turn off visibility 337 // Listen only to the hide animation. As we cannot turn off visibility
310 // until the animation is over. 338 // until the animation is over.
311 animation.AddObserver(this); 339 animation.AddObserver(this);
312 animation.SetTweenType(gfx::Tween::EASE_IN); 340 animation.SetTweenType(gfx::Tween::EASE_IN);
313 layer()->SetOpacity(0.0f); 341 layer()->SetOpacity(0.0f);
314 layer()->SetVisible(false); 342 layer()->SetVisible(false);
315 HideTransformation(); 343 HideTransformation();
316 } 344 }
345 // 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.
346 wm_shelf_->GetStatusAreaWidget()->OnTrayVisibilityChanged(this);
317 } 347 }
318 348
319 const char* TrayBackgroundView::GetClassName() const { 349 const char* TrayBackgroundView::GetClassName() const {
320 return kViewClassName; 350 return kViewClassName;
321 } 351 }
322 352
323 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { 353 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
324 PreferredSizeChanged(); 354 PreferredSizeChanged();
325 } 355 }
326 356
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Nothing to do here. 531 // Nothing to do here.
502 } 532 }
503 533
504 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { 534 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) {
505 if (background_) { 535 if (background_) {
506 background_->set_alpha(alpha); 536 background_->set_alpha(alpha);
507 SchedulePaint(); 537 SchedulePaint();
508 } 538 }
509 } 539 }
510 540
541 void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) {
542 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.
543 }
544
545 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
546 if (!MaterialDesignController::IsShelfMaterial() ||
547 shelf()->GetBackgroundType() ==
548 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT ||
549 !is_separator_visible_) {
550 return;
551 }
552
553 const int height = kTrayItemSize;
554 const int width = kSeparatorWidth;
555 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
556 const int y = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2;
557 gfx::ScopedCanvas scoped_canvas(canvas);
558 const float scale = canvas->UndoDeviceScaleFactor();
559 SkPaint paint;
560 paint.setColor(kSeparatorColor);
561 paint.setAntiAlias(true);
562 const bool horizontal_shelf = IsHorizontalAlignment(shelf()->GetAlignment());
563 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
564 : gfx::Rect(y, x, height, width);
565 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
566 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
567 rect.bottom_right(), paint);
568 }
569
511 } // namespace ash 570 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698