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

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: new approach 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/tray/system_tray.h" 12 #include "ash/common/system/tray/system_tray.h"
13 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_event_filter.h" 14 #include "ash/common/system/tray/tray_event_filter.h"
15 #include "ash/common/system/view_observer.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/base/ui_base_switches_util.h" 22 #include "ui/base/ui_base_switches_util.h"
22 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
23 #include "ui/compositor/layer_animation_element.h" 24 #include "ui/compositor/layer_animation_element.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 25 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/events/event_constants.h" 26 #include "ui/events/event_constants.h"
26 #include "ui/gfx/animation/tween.h" 27 #include "ui/gfx/animation/tween.h"
27 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gfx/image/image_skia.h" 30 #include "ui/gfx/image/image_skia.h"
30 #include "ui/gfx/image/image_skia_operations.h" 31 #include "ui/gfx/image/image_skia_operations.h"
31 #include "ui/gfx/nine_image_painter.h" 32 #include "ui/gfx/nine_image_painter.h"
33 #include "ui/gfx/scoped_canvas.h"
32 #include "ui/gfx/skia_util.h" 34 #include "ui/gfx/skia_util.h"
33 #include "ui/gfx/transform.h" 35 #include "ui/gfx/transform.h"
34 #include "ui/views/background.h" 36 #include "ui/views/background.h"
35 #include "ui/views/layout/box_layout.h" 37 #include "ui/views/layout/box_layout.h"
36 #include "ui/wm/core/window_animations.h" 38 #include "ui/wm/core/window_animations.h"
37 39
38 namespace { 40 namespace {
39 41
40 const int kAnimationDurationForPopupMs = 200; 42 const int kAnimationDurationForPopupMs = 200;
41 43
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { 104 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
103 background_color = SkColorSetA(kShelfBaseColor, 105 background_color = SkColorSetA(kShelfBaseColor,
104 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); 106 GetShelfConstant(SHELF_BACKGROUND_ALPHA));
105 } 107 }
106 108
107 // TODO(bruthig|tdanderson): The background should be changed using a 109 // TODO(bruthig|tdanderson): The background should be changed using a
108 // fade in/out animation. 110 // fade in/out animation.
109 SkPaint background_paint; 111 SkPaint background_paint;
110 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 112 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
111 background_paint.setColor(background_color); 113 background_paint.setColor(background_color);
112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 114 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius,
113 background_paint); 115 background_paint);
114 116
115 if (tray_background_view_->draw_background_as_active()) { 117 if (tray_background_view_->draw_background_as_active()) {
116 SkPaint highlight_paint; 118 SkPaint highlight_paint;
117 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); 119 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
118 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); 120 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
119 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, 121 canvas->DrawRoundRect(view->GetContentsBounds(), kTrayRoundedBorderRadius,
120 highlight_paint); 122 highlight_paint);
121 } 123 }
122 } 124 }
123 125
124 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const { 126 void PaintNonMaterial(gfx::Canvas* canvas, views::View* view) const {
125 const int kGridSizeForPainter = 9; 127 const int kGridSizeForPainter = 9;
126 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = { 128 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = {
127 { 129 {
128 // Horizontal 130 // Horizontal
129 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), 131 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 PreferredSizeChanged(); 203 PreferredSizeChanged();
202 } 204 }
203 205
204 void TrayBackgroundView::TrayContainer::UpdateLayout() { 206 void TrayBackgroundView::TrayContainer::UpdateLayout() {
205 // Adjust the size of status tray dark background by adding additional 207 // Adjust the size of status tray dark background by adding additional
206 // empty border. 208 // empty border.
207 views::BoxLayout::Orientation orientation = 209 views::BoxLayout::Orientation orientation =
208 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal 210 IsHorizontalAlignment(alignment_) ? views::BoxLayout::kHorizontal
209 : views::BoxLayout::kVertical; 211 : views::BoxLayout::kVertical;
210 212
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); 213 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0);
220 layout->SetDefaultFlex(1); 214 layout->SetDefaultFlex(1);
221 views::View::SetLayoutManager(layout); 215 views::View::SetLayoutManager(layout);
222 PreferredSizeChanged(); 216 PreferredSizeChanged();
223 } 217 }
224 218
225 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
226 // TrayBackgroundView 220 // TrayBackgroundView
227 221
228 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) 222 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf,
223 ViewObserver* view_observer)
229 : wm_shelf_(wm_shelf), 224 : wm_shelf_(wm_shelf),
230 tray_container_(NULL), 225 tray_container_(NULL),
231 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), 226 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
232 background_(NULL), 227 background_(NULL),
233 draw_background_as_active_(false), 228 draw_background_as_active_(false),
234 widget_observer_(new TrayWidgetObserver(this)) { 229 widget_observer_(new TrayWidgetObserver(this)) {
235 DCHECK(wm_shelf_); 230 DCHECK(wm_shelf_);
236 set_notify_enter_exit_on_child(true); 231 set_notify_enter_exit_on_child(true);
237 232
238 tray_container_ = new TrayContainer(shelf_alignment_); 233 tray_container_ = new TrayContainer(shelf_alignment_);
239 SetContents(tray_container_); 234 SetContents(tray_container_);
240 tray_event_filter_.reset(new TrayEventFilter); 235 tray_event_filter_.reset(new TrayEventFilter);
236 view_observer_ = view_observer;
237 is_separator_visible_ = false;
241 238
242 SetPaintToLayer(true); 239 SetPaintToLayer(true);
243 layer()->SetFillsBoundsOpaquely(false); 240 layer()->SetFillsBoundsOpaquely(false);
244 // Start the tray items not visible, because visibility changes are animated. 241 // Start the tray items not visible, because visibility changes are animated.
245 views::View::SetVisible(false); 242 views::View::SetVisible(false);
243 CalculateAndSetTrayContainerBorder();
246 } 244 }
247 245
248 TrayBackgroundView::~TrayBackgroundView() { 246 TrayBackgroundView::~TrayBackgroundView() {
249 if (GetWidget()) 247 if (GetWidget())
250 GetWidget()->RemoveObserver(widget_observer_.get()); 248 GetWidget()->RemoveObserver(widget_observer_.get());
251 StopObservingImplicitAnimations(); 249 StopObservingImplicitAnimations();
252 } 250 }
253 251
254 void TrayBackgroundView::Initialize() { 252 void TrayBackgroundView::Initialize() {
255 GetWidget()->AddObserver(widget_observer_.get()); 253 GetWidget()->AddObserver(widget_observer_.get());
256 } 254 }
257 255
258 // static 256 // static
259 void TrayBackgroundView::InitializeBubbleAnimations( 257 void TrayBackgroundView::InitializeBubbleAnimations(
260 views::Widget* bubble_widget) { 258 views::Widget* bubble_widget) {
261 WmWindow* window = WmLookup::Get()->GetWindowForWidget(bubble_widget); 259 WmWindow* window = WmLookup::Get()->GetWindowForWidget(bubble_widget);
262 window->SetVisibilityAnimationType( 260 window->SetVisibilityAnimationType(
263 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 261 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
264 window->SetVisibilityAnimationTransition(::wm::ANIMATE_HIDE); 262 window->SetVisibilityAnimationTransition(::wm::ANIMATE_HIDE);
265 window->SetVisibilityAnimationDuration( 263 window->SetVisibilityAnimationDuration(
266 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs)); 264 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs));
267 } 265 }
268 266
269 void TrayBackgroundView::SetVisible(bool visible) { 267 void TrayBackgroundView::SetVisible(bool visible) {
270 if (visible == layer()->GetTargetVisibility()) 268 if (visible == layer()->GetTargetVisibility())
271 return; 269 return;
270 // OnVisibilityChange will only be called if the visibility of the tray item
271 // is changed.
272 view_observer_->OnVisibilityChange(this);
272 273
273 if (visible) { 274 if (visible) {
274 // The alignment of the shelf can change while the TrayBackgroundView is 275 // The alignment of the shelf can change while the TrayBackgroundView is
275 // hidden. Reset the offscreen transform so that the animation to becoming 276 // hidden. Reset the offscreen transform so that the animation to becoming
276 // visible reflects the current layout. 277 // visible reflects the current layout.
277 HideTransformation(); 278 HideTransformation();
278 // SetVisible(false) is defered until the animation for hiding is done. 279 // SetVisible(false) is defered until the animation for hiding is done.
279 // Otherwise the view is immediately hidden and the animation does not 280 // Otherwise the view is immediately hidden and the animation does not
280 // render. 281 // render.
281 views::View::SetVisible(true); 282 views::View::SetVisible(true);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 371 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
371 AddChildView(contents); 372 AddChildView(contents);
372 } 373 }
373 void TrayBackgroundView::SetContentsBackground() { 374 void TrayBackgroundView::SetContentsBackground() {
374 background_ = new TrayBackground(this); 375 background_ = new TrayBackground(this);
375 tray_container_->set_background(background_); 376 tray_container_->set_background(background_);
376 } 377 }
377 378
378 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { 379 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
379 shelf_alignment_ = alignment; 380 shelf_alignment_ = alignment;
381 CalculateAndSetTrayContainerBorder();
380 tray_container_->SetAlignment(alignment); 382 tray_container_->SetAlignment(alignment);
381 } 383 }
382 384
385 void TrayBackgroundView::CalculateAndSetTrayContainerBorder() {
386 if (!MaterialDesignController::IsShelfMaterial()) {
387 tray_container()->SetBorder(views::Border::NullBorder());
388 return;
389 }
390 if (IsHorizontalAlignment(shelf()->GetAlignment())) {
391 // Extend hit region horizontally when horizontally aligned.
392 tray_container()->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(
393 0, kHitRegionPadding, 0, kHitRegionPadding + kSeparatorWidth)));
394 } else {
395 // Extend hit region vertically when vertically aligned.
396 tray_container()->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(
397 kHitRegionPadding, 0, kHitRegionPadding + kSeparatorWidth, 0)));
398 }
399 }
400
383 void TrayBackgroundView::OnImplicitAnimationsCompleted() { 401 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
384 // If there is another animation in the queue, the reverse animation was 402 // 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 403 // 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 404 // the visibility so that the next animation may render. The value of
387 // layer()->GetTargetVisibility() can be incorrect if the hide animation was 405 // layer()->GetTargetVisibility() can be incorrect if the hide animation was
388 // aborted to schedule an animation to become visible. As the new animation 406 // aborted to schedule an animation to become visible. As the new animation
389 // is not yet added to the queue. crbug.com/374236 407 // is not yet added to the queue. crbug.com/374236
390 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility()) 408 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility())
391 return; 409 return;
392 views::View::SetVisible(false); 410 views::View::SetVisible(false);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 if (!background_) 521 if (!background_)
504 return; 522 return;
505 SchedulePaint(); 523 SchedulePaint();
506 } 524 }
507 525
508 void TrayBackgroundView::UpdateBubbleViewArrow( 526 void TrayBackgroundView::UpdateBubbleViewArrow(
509 views::TrayBubbleView* bubble_view) { 527 views::TrayBubbleView* bubble_view) {
510 // Nothing to do here. 528 // Nothing to do here.
511 } 529 }
512 530
531 void TrayBackgroundView::SetSeparatorVisibility(bool is_show) {
532 if (is_separator_visible_ != is_show)
533 is_separator_visible_ = is_show;
534 }
535
536 void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
537 if (!MaterialDesignController::IsShelfMaterial() ||
538 shelf()->GetBackgroundType() ==
539 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT)
540 return;
541
542 if (is_separator_visible_) {
543 const int height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
544 const int width = kSeparatorWidth;
545 const int x = height + kHitRegionPadding + kHitRegionPadding;
546 const int y = (GetShelfConstant(SHELF_SIZE) - height) / 2;
547 const float scale = canvas->UndoDeviceScaleFactor();
548 SkPaint paint;
549 paint.setColor(kSeparatorColor);
550 paint.setAntiAlias(true);
551 const bool horizontal_shelf =
552 IsHorizontalAlignment(shelf()->GetAlignment());
553 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
554 : gfx::Rect(y, x, height, width);
555 gfx::ScopedCanvas scoped_canvas(canvas);
556 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
557 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
558 rect.bottom_right(), paint);
559 }
560 }
561
513 } // namespace ash 562 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698