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

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 Created 4 years, 5 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"
(...skipping 11 matching lines...) Expand all
22 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
23 #include "ui/compositor/layer_animation_element.h" 23 #include "ui/compositor/layer_animation_element.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/events/event_constants.h" 25 #include "ui/events/event_constants.h"
26 #include "ui/gfx/animation/tween.h" 26 #include "ui/gfx/animation/tween.h"
27 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
30 #include "ui/gfx/image/image_skia_operations.h" 30 #include "ui/gfx/image/image_skia_operations.h"
31 #include "ui/gfx/nine_image_painter.h" 31 #include "ui/gfx/nine_image_painter.h"
32 #include "ui/gfx/scoped_canvas.h"
32 #include "ui/gfx/skia_util.h" 33 #include "ui/gfx/skia_util.h"
33 #include "ui/gfx/transform.h" 34 #include "ui/gfx/transform.h"
34 #include "ui/views/background.h" 35 #include "ui/views/background.h"
35 #include "ui/views/layout/box_layout.h" 36 #include "ui/views/layout/box_layout.h"
36 #include "ui/wm/core/window_animations.h" 37 #include "ui/wm/core/window_animations.h"
37 38
38 namespace { 39 namespace {
39 40
40 const int kAnimationDurationForPopupMs = 200; 41 const int kAnimationDurationForPopupMs = 200;
41 42
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { 103 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
103 background_color = SkColorSetA(kShelfBaseColor, 104 background_color = SkColorSetA(kShelfBaseColor,
104 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); 105 GetShelfConstant(SHELF_BACKGROUND_ALPHA));
105 } 106 }
106 107
107 // TODO(bruthig|tdanderson): The background should be changed using a 108 // TODO(bruthig|tdanderson): The background should be changed using a
108 // fade in/out animation. 109 // fade in/out animation.
109 SkPaint background_paint; 110 SkPaint background_paint;
110 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 111 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
111 background_paint.setColor(background_color); 112 background_paint.setColor(background_color);
112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 113 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius,
113 background_paint); 114 background_paint);
114 115
115 if (tray_background_view_->draw_background_as_active()) { 116 if (tray_background_view_->draw_background_as_active()) {
116 SkPaint highlight_paint; 117 SkPaint highlight_paint;
117 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); 118 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
118 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); 119 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
119 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 120 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius,
120 highlight_paint); 121 highlight_paint);
121 } 122 }
122 } 123 }
123 124
124 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { 125 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const {
125 const int kGridSizeForPainter = 9; 126 const int kGridSizeForPainter = 9;
126 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { 127 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = {
127 { 128 {
128 // Horizontal 129 // Horizontal
129 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), 130 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 PreferredSizeChanged(); 202 PreferredSizeChanged();
202 } 203 }
203 204
204 void TrayBackgroundView::TrayContainer::UpdateLayout() { 205 void TrayBackgroundView::TrayContainer::UpdateLayout() {
205 // Adjust the size of status tray dark background by adding additional 206 // Adjust the size of status tray dark background by adding additional
206 // empty border. 207 // empty border.
207 views::BoxLayout::Orientation orientation = 208 views::BoxLayout::Orientation orientation =
208 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal 209 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal
209 : views::BoxLayout::kVertical; 210 : views::BoxLayout::kVertical;
210 211
211 if (!ash::MaterialDesignController::IsShelfMaterial()) {
212 // Additional padding used to adjust the user-visible size of status tray
213 // dark background.
214 const int padding = 3;
215 SetBorder(
216 views::Border::CreateEmptyBorder(padding, padding, padding, padding));
217 }
218
219 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); 212 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0);
220 layout->SetDefaultFlex(1); 213 layout->SetDefaultFlex(1);
221 views::View::SetLayoutManager(layout); 214 views::View::SetLayoutManager(layout);
222 PreferredSizeChanged(); 215 PreferredSizeChanged();
223 } 216 }
224 217
225 //////////////////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////////////////
226 // TrayBackgroundView 219 // TrayBackgroundView
227 220
228 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) 221 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf)
229 : wm_shelf_(wm_shelf), 222 : wm_shelf_(wm_shelf),
230 tray_container_(NULL), 223 tray_container_(NULL),
231 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), 224 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
232 background_(NULL), 225 background_(NULL),
233 draw_background_as_active_(false), 226 draw_background_as_active_(false),
234 widget_observer_(new TrayWidgetObserver(this)) { 227 widget_observer_(new TrayWidgetObserver(this)) {
235 DCHECK(wm_shelf_); 228 DCHECK(wm_shelf_);
236 set_notify_enter_exit_on_child(true); 229 set_notify_enter_exit_on_child(true);
237 230
238 tray_container_ = new TrayContainer(shelf_alignment_); 231 tray_container_ = new TrayContainer(shelf_alignment_);
239 SetContents(tray_container_); 232 SetContents(tray_container_);
240 tray_event_filter_.reset(new TrayEventFilter); 233 tray_event_filter_.reset(new TrayEventFilter);
241 234
242 SetPaintToLayer(true); 235 SetPaintToLayer(true);
243 layer()->SetFillsBoundsOpaquely(false); 236 layer()->SetFillsBoundsOpaquely(false);
244 // Start the tray items not visible, because visibility changes are animated. 237 // Start the tray items not visible, because visibility changes are animated.
245 views::View::SetVisible(false); 238 views::View::SetVisible(false);
239 CalculateAndSetTrayContainerBorder();
246 } 240 }
247 241
248 TrayBackgroundView::~TrayBackgroundView() { 242 TrayBackgroundView::~TrayBackgroundView() {
249 if (GetWidget()) 243 if (GetWidget())
250 GetWidget()->RemoveObserver(widget_observer_.get()); 244 GetWidget()->RemoveObserver(widget_observer_.get());
251 StopObservingImplicitAnimations(); 245 StopObservingImplicitAnimations();
252 } 246 }
253 247
254 void TrayBackgroundView::Initialize() { 248 void TrayBackgroundView::Initialize() {
255 GetWidget()->AddObserver(widget_observer_.get()); 249 GetWidget()->AddObserver(widget_observer_.get());
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 364 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
371 AddChildView(contents); 365 AddChildView(contents);
372 } 366 }
373 void TrayBackgroundView::SetContentsBackground() { 367 void TrayBackgroundView::SetContentsBackground() {
374 background_ = new TrayBackground(this); 368 background_ = new TrayBackground(this);
375 tray_container_->set_background(background_); 369 tray_container_->set_background(background_);
376 } 370 }
377 371
378 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { 372 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
379 shelf_alignment_ = alignment; 373 shelf_alignment_ = alignment;
374 CalculateAndSetTrayContainerBorder();
380 tray_container_->SetAlignment(alignment); 375 tray_container_->SetAlignment(alignment);
381 } 376 }
382 377
378 void TrayBackgroundView::CalculateAndSetTrayContainerBorder() {
379 if (!MaterialDesignController::IsShelfMaterial()) {
380 tray_container()->SetBorder(views::Border::NullBorder());
381 return;
382 } else {
varkha 2016/07/14 21:34:48 nit: no need for 'else' with early return above.
yiyix 2016/07/26 20:27:31 Done.
383 if (IsHorizontalAlignment(shelf()->GetAlignment())) {
384 // Extend hit region horizontally when horizontally aligned.
385 tray_container()->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(
386 0, kHitRegionPadding, 0, kHitRegionPadding + kSeparatorWidth)));
387 } else {
388 // Extend hit region vertically when vertically aligned.
389 tray_container()->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(
390 kHitRegionPadding, 0, kHitRegionPadding + kSeparatorWidth, 0)));
391 }
392 }
393 }
394
383 void TrayBackgroundView::OnImplicitAnimationsCompleted() { 395 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
384 // If there is another animation in the queue, the reverse animation was 396 // If there is another animation in the queue, the reverse animation was
385 // triggered before the completion of animating to invisible. Do not turn off 397 // triggered before the completion of animating to invisible. Do not turn off
386 // the visibility so that the next animation may render. The value of 398 // the visibility so that the next animation may render. The value of
387 // layer()->GetTargetVisibility() can be incorrect if the hide animation was 399 // layer()->GetTargetVisibility() can be incorrect if the hide animation was
388 // aborted to schedule an animation to become visible. As the new animation 400 // aborted to schedule an animation to become visible. As the new animation
389 // is not yet added to the queue. crbug.com/374236 401 // is not yet added to the queue. crbug.com/374236
390 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility()) 402 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility())
391 return; 403 return;
392 views::View::SetVisible(false); 404 views::View::SetVisible(false);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 if (!background_) 515 if (!background_)
504 return; 516 return;
505 SchedulePaint(); 517 SchedulePaint();
506 } 518 }
507 519
508 void TrayBackgroundView::UpdateBubbleViewArrow( 520 void TrayBackgroundView::UpdateBubbleViewArrow(
509 views::TrayBubbleView* bubble_view) { 521 views::TrayBubbleView* bubble_view) {
510 // Nothing to do here. 522 // Nothing to do here.
511 } 523 }
512 524
525 void TrayBackgroundView::DrawSeparator(gfx::Canvas* canvas) {
526 if (!(shelf()->GetBackgroundType() ==
527 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) &&
528 MaterialDesignController::IsShelfMaterial()) {
varkha 2016/07/14 21:34:47 How about if (!MaterialDesignController::IsShelfM
yiyix 2016/07/26 20:27:31 It is better for readers to follow
529 const int x = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY) + kHitRegionPadding +
530 kHitRegionPadding;
531 const int y = (GetShelfConstant(SHELF_SIZE) -
532 GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY)) /
533 2;
534 const int width = kSeparatorWidth;
535 const int height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
varkha 2016/07/14 21:34:47 If you move this up you can use |height| instead o
yiyix 2016/07/26 20:27:31 Done.
536 const float scale = canvas->UndoDeviceScaleFactor();
537 SkPaint paint;
538 paint.setColor(kSeparatorColor);
539 paint.setAntiAlias(true);
540 const bool horizontal_shelf =
541 IsHorizontalAlignment(shelf()->GetAlignment());
542 gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
varkha 2016/07/14 21:34:47 nit: const.
yiyix 2016/07/26 20:27:31 Done.
543 : gfx::Rect(y, x, height, width);
544 gfx::ScopedCanvas scoped_canvas(canvas);
545 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
546 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
547 rect.bottom_right(), paint);
548 }
549 }
550
513 } // namespace ash 551 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698