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

Side by Side Diff: ash/system/tray/tray_background_view.cc

Issue 2961313003: Touch gestures for System Tray/ IME/ Stylus/ Notifications (Closed)
Patch Set: Fixed msw's comments. Created 3 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/system/tray/tray_background_view.h" 5 #include "ash/system/tray/tray_background_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "ash/shelf/shelf.h" 11 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_constants.h" 12 #include "ash/shelf/shelf_constants.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/system/status_area_widget_delegate.h" 14 #include "ash/system/status_area_widget_delegate.h"
15 #include "ash/system/tray/system_tray_notifier.h" 15 #include "ash/system/tray/system_tray_notifier.h"
16 #include "ash/system/tray/tray_constants.h" 16 #include "ash/system/tray/tray_constants.h"
17 #include "ash/system/tray/tray_container.h" 17 #include "ash/system/tray/tray_container.h"
18 #include "ash/system/tray/tray_event_filter.h" 18 #include "ash/system/tray/tray_event_filter.h"
19 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
19 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
20 #include "ui/accessibility/ax_node_data.h" 21 #include "ui/accessibility/ax_node_data.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/gfx/animation/tween.h" 25 #include "ui/gfx/animation/tween.h"
25 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
27 #include "ui/gfx/geometry/size.h" 28 #include "ui/gfx/geometry/size.h"
28 #include "ui/gfx/transform.h" 29 #include "ui/gfx/transform.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 124 }
124 125
125 // Reference to the TrayBackgroundView for which this is a background. 126 // Reference to the TrayBackgroundView for which this is a background.
126 TrayBackgroundView* tray_background_view_; 127 TrayBackgroundView* tray_background_view_;
127 128
128 SkColor color_; 129 SkColor color_;
129 130
130 DISALLOW_COPY_AND_ASSIGN(TrayBackground); 131 DISALLOW_COPY_AND_ASSIGN(TrayBackground);
131 }; 132 };
132 133
134 // CloseBubbleObserver is used to delay closing the tray bubbles until the
135 // animation completes.
136 class CloseBubbleObserver : public ui::ImplicitAnimationObserver {
137 public:
138 explicit CloseBubbleObserver(TrayBackgroundView* tray_background_view)
139 : tray_background_view_(tray_background_view) {}
140
141 ~CloseBubbleObserver() override {}
142
143 void OnImplicitAnimationsCompleted() override {
144 tray_background_view_->CloseBubble();
145 delete this;
146 }
147
148 private:
149 TrayBackgroundView* tray_background_view_ = nullptr;
150
151 DISALLOW_COPY_AND_ASSIGN(CloseBubbleObserver);
152 };
153
133 //////////////////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////////////////
134 // TrayBackgroundView 155 // TrayBackgroundView
135 156
136 TrayBackgroundView::TrayBackgroundView(Shelf* shelf) 157 TrayBackgroundView::TrayBackgroundView(Shelf* shelf)
137 // Note the ink drop style is ignored. 158 // Note the ink drop style is ignored.
138 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), 159 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
139 shelf_(shelf), 160 shelf_(shelf),
140 tray_container_(new TrayContainer(shelf)), 161 tray_container_(new TrayContainer(shelf)),
141 background_(new TrayBackground(this)), 162 background_(new TrayBackground(this)),
142 is_active_(false), 163 is_active_(false),
143 separator_visible_(true), 164 separator_visible_(true),
144 widget_observer_(new TrayWidgetObserver(this)) { 165 widget_observer_(new TrayWidgetObserver(this)) {
145 DCHECK(shelf_); 166 DCHECK(shelf_);
146 set_notify_enter_exit_on_child(true); 167 set_notify_enter_exit_on_child(true);
147 set_ink_drop_base_color(kShelfInkDropBaseColor); 168 set_ink_drop_base_color(kShelfInkDropBaseColor);
148 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); 169 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
149 170
150 SetLayoutManager(new views::FillLayout); 171 SetLayoutManager(new views::FillLayout);
151 172
152 tray_container_->SetBackground( 173 tray_container_->SetBackground(
153 std::unique_ptr<views::Background>(background_)); 174 std::unique_ptr<views::Background>(background_));
154 AddChildView(tray_container_); 175 AddChildView(tray_container_);
155 176
156 tray_event_filter_.reset(new TrayEventFilter); 177 tray_event_filter_.reset(new TrayEventFilter);
157 178
158 SetPaintToLayer(); 179 SetPaintToLayer();
159 layer()->SetFillsBoundsOpaquely(false); 180 layer()->SetFillsBoundsOpaquely(false);
160 // Start the tray items not visible, because visibility changes are animated. 181 // Start the tray items not visible, because visibility changes are animated.
161 views::View::SetVisible(false); 182 views::View::SetVisible(false);
183
184 drag_controller_ = base::MakeUnique<TrayDragController>(shelf);
162 } 185 }
163 186
164 TrayBackgroundView::~TrayBackgroundView() { 187 TrayBackgroundView::~TrayBackgroundView() {
165 if (GetWidget()) 188 if (GetWidget())
166 GetWidget()->RemoveObserver(widget_observer_.get()); 189 GetWidget()->RemoveObserver(widget_observer_.get());
167 StopObservingImplicitAnimations(); 190 StopObservingImplicitAnimations();
168 } 191 }
169 192
170 void TrayBackgroundView::Initialize() { 193 void TrayBackgroundView::Initialize() {
171 GetWidget()->AddObserver(widget_observer_.get()); 194 GetWidget()->AddObserver(widget_observer_.get());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const gfx::Vector2dF vector(0, kTrayItemSize); 322 const gfx::Vector2dF vector(0, kTrayItemSize);
300 canvas->Draw1pxLine(point, point + vector, color); 323 canvas->Draw1pxLine(point, point + vector, color);
301 } else { 324 } else {
302 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, 325 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2,
303 local_bounds.height() - kSeparatorWidth); 326 local_bounds.height() - kSeparatorWidth);
304 const gfx::Vector2dF vector(kTrayItemSize, 0); 327 const gfx::Vector2dF vector(kTrayItemSize, 0);
305 canvas->Draw1pxLine(point, point + vector, color); 328 canvas->Draw1pxLine(point, point + vector, color);
306 } 329 }
307 } 330 }
308 331
332 TrayBubbleView* TrayBackgroundView::GetBubbleView() {
333 return nullptr;
334 }
335
309 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { 336 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() {
310 tray_container_->UpdateAfterShelfAlignmentChange(); 337 tray_container_->UpdateAfterShelfAlignmentChange();
311 338
312 // The tray itself expands to the right and bottom edge of the screen to make 339 // The tray itself expands to the right and bottom edge of the screen to make
313 // sure clicking on the edges brings up the popup. However, the focus border 340 // sure clicking on the edges brings up the popup. However, the focus border
314 // should be only around the container. 341 // should be only around the container.
315 gfx::Rect paint_bounds(GetBackgroundBounds()); 342 gfx::Rect paint_bounds(GetBackgroundBounds());
316 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); 343 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
317 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 344 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
318 kFocusBorderColor, kFocusBorderThickness, 345 kFocusBorderColor, kFocusBorderThickness,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 gfx::Insets tray_bg_insets = GetInsets(); 412 gfx::Insets tray_bg_insets = GetInsets();
386 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { 413 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
387 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), 414 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(),
388 -tray_bg_insets.bottom(), anchor_insets.right()); 415 -tray_bg_insets.bottom(), anchor_insets.right());
389 } else { 416 } else {
390 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), 417 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(),
391 anchor_insets.bottom(), -tray_bg_insets.right()); 418 anchor_insets.bottom(), -tray_bg_insets.right());
392 } 419 }
393 } 420 }
394 421
395 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { 422 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() {
396 return Shell::GetContainer( 423 aura::Window* container = Shell::GetContainer(
397 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), 424 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
398 kShellWindowId_SettingBubbleContainer); 425 kShellWindowId_SettingBubbleContainer);
426
427 // Place the bubble in |container|, or in a window clipped to the work area
428 // in maximize mode, in order to make sure that the tray bubble during
msw 2017/07/14 21:00:30 nit: "in maximize mode, to avoid tray bubble and s
minch1 2017/07/15 02:46:29 Done.
429 // dragging will no overlap with shelf.
430 if (Shell::Get()
431 ->maximize_mode_controller()
432 ->IsMaximizeModeWindowManagerEnabled()) {
433 if (!clipping_window_.get()) {
434 clipping_window_ = base::MakeUnique<aura::Window>(nullptr);
435 clipping_window_->Init(ui::LAYER_NOT_DRAWN);
436 clipping_window_->layer()->SetMasksToBounds(true);
437 container->AddChild(clipping_window_.get());
438 clipping_window_->Show();
439 }
440 clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds());
441 return clipping_window_.get();
442 }
443 return container;
444 }
445
446 void TrayBackgroundView::AnimateToTargetBounds(const gfx::Rect& target_bounds,
447 bool close_bubble) {
448 const int kAnimationDurationMS = 200;
449
450 ui::ScopedLayerAnimationSettings settings(
451 GetBubbleView()->GetWidget()->GetNativeView()->layer()->GetAnimator());
452 settings.SetTransitionDuration(
453 base::TimeDelta::FromMilliseconds(kAnimationDurationMS));
454 settings.SetTweenType(gfx::Tween::EASE_OUT);
455 settings.SetPreemptionStrategy(
456 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
457 if (close_bubble)
458 settings.AddObserver(new CloseBubbleObserver(this));
459 GetBubbleView()->GetWidget()->SetBounds(target_bounds);
399 } 460 }
400 461
401 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() 462 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask()
402 const { 463 const {
403 return base::MakeUnique<views::RoundRectInkDropMask>( 464 return base::MakeUnique<views::RoundRectInkDropMask>(
404 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); 465 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius);
405 } 466 }
406 467
407 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { 468 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) {
408 if (is_active_) 469 if (is_active_)
(...skipping 29 matching lines...) Expand all
438 } 499 }
439 500
440 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { 501 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const {
441 gfx::Insets insets = GetBackgroundInsets(); 502 gfx::Insets insets = GetBackgroundInsets();
442 gfx::Rect bounds = GetLocalBounds(); 503 gfx::Rect bounds = GetLocalBounds();
443 bounds.Inset(insets); 504 bounds.Inset(insets);
444 return bounds; 505 return bounds;
445 } 506 }
446 507
447 } // namespace ash 508 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698