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

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 nits. 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
« no previous file with comments | « ash/system/tray/tray_background_view.h ('k') | ash/system/tray_drag_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 layer()->SetOpacity(0.0f); 250 layer()->SetOpacity(0.0f);
230 layer()->SetVisible(false); 251 layer()->SetVisible(false);
231 HideTransformation(); 252 HideTransformation();
232 } 253 }
233 } 254 }
234 255
235 const char* TrayBackgroundView::GetClassName() const { 256 const char* TrayBackgroundView::GetClassName() const {
236 return kViewClassName; 257 return kViewClassName;
237 } 258 }
238 259
239 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { 260 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
240 PreferredSizeChanged(); 261 if (drag_controller())
241 } 262 drag_controller_->ProcessGestureEvent(event, this);
242 263
243 void TrayBackgroundView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 264 if (!event->handled())
244 ActionableView::GetAccessibleNodeData(node_data); 265 ActionableView::OnGestureEvent(event);
245 node_data->SetName(GetAccessibleNameForTray());
246 } 266 }
247 267
248 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { 268 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
249 StatusAreaWidgetDelegate* delegate = 269 StatusAreaWidgetDelegate* delegate =
250 StatusAreaWidgetDelegate::GetPrimaryInstance(); 270 StatusAreaWidgetDelegate::GetPrimaryInstance();
251 if (delegate && delegate->ShouldFocusOut(reverse)) 271 if (delegate && delegate->ShouldFocusOut(reverse))
252 Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse); 272 Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse);
253 } 273 }
254 274
275 void TrayBackgroundView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
276 ActionableView::GetAccessibleNodeData(node_data);
277 node_data->SetName(GetAccessibleNameForTray());
278 }
279
280 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
281 PreferredSizeChanged();
282 }
283
255 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() 284 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple()
256 const { 285 const {
257 return base::MakeUnique<views::FloodFillInkDropRipple>( 286 return base::MakeUnique<views::FloodFillInkDropRipple>(
258 size(), GetBackgroundInsets(), GetInkDropCenterBasedOnLastEvent(), 287 size(), GetBackgroundInsets(), GetInkDropCenterBasedOnLastEvent(),
259 GetInkDropBaseColor(), ink_drop_visible_opacity()); 288 GetInkDropBaseColor(), ink_drop_visible_opacity());
260 } 289 }
261 290
262 std::unique_ptr<views::InkDropHighlight> 291 std::unique_ptr<views::InkDropHighlight>
263 TrayBackgroundView::CreateInkDropHighlight() const { 292 TrayBackgroundView::CreateInkDropHighlight() const {
264 gfx::Rect bounds = GetBackgroundBounds(); 293 gfx::Rect bounds = GetBackgroundBounds();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const gfx::Vector2dF vector(0, kTrayItemSize); 328 const gfx::Vector2dF vector(0, kTrayItemSize);
300 canvas->Draw1pxLine(point, point + vector, color); 329 canvas->Draw1pxLine(point, point + vector, color);
301 } else { 330 } else {
302 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2, 331 const gfx::PointF point((kShelfSize - kTrayItemSize) / 2,
303 local_bounds.height() - kSeparatorWidth); 332 local_bounds.height() - kSeparatorWidth);
304 const gfx::Vector2dF vector(kTrayItemSize, 0); 333 const gfx::Vector2dF vector(kTrayItemSize, 0);
305 canvas->Draw1pxLine(point, point + vector, color); 334 canvas->Draw1pxLine(point, point + vector, color);
306 } 335 }
307 } 336 }
308 337
338 void TrayBackgroundView::ProcessGestureEventForBubble(ui::GestureEvent* event) {
339 if (drag_controller())
340 drag_controller_->ProcessGestureEvent(event, this);
341 }
342
343 TrayBubbleView* TrayBackgroundView::GetBubbleView() {
344 return nullptr;
345 }
346
347 void TrayBackgroundView::CloseBubble() {}
348
349 void TrayBackgroundView::ShowBubble() {}
350
309 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() { 351 void TrayBackgroundView::UpdateAfterShelfAlignmentChange() {
310 tray_container_->UpdateAfterShelfAlignmentChange(); 352 tray_container_->UpdateAfterShelfAlignmentChange();
311 353
312 // The tray itself expands to the right and bottom edge of the screen to make 354 // 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 355 // sure clicking on the edges brings up the popup. However, the focus border
314 // should be only around the container. 356 // should be only around the container.
315 gfx::Rect paint_bounds(GetBackgroundBounds()); 357 gfx::Rect paint_bounds(GetBackgroundBounds());
316 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness)); 358 paint_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
317 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 359 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
318 kFocusBorderColor, kFocusBorderThickness, 360 kFocusBorderColor, kFocusBorderThickness,
319 GetLocalBounds().InsetsFrom(paint_bounds))); 361 GetLocalBounds().InsetsFrom(paint_bounds)));
320 } 362 }
321 363
364 void TrayBackgroundView::AnchorUpdated() {}
365
366 void TrayBackgroundView::BubbleResized(
367 const views::TrayBubbleView* bubble_view) {}
368
322 void TrayBackgroundView::OnImplicitAnimationsCompleted() { 369 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
323 // If there is another animation in the queue, the reverse animation was 370 // If there is another animation in the queue, the reverse animation was
324 // triggered before the completion of animating to invisible. Do not turn off 371 // triggered before the completion of animating to invisible. Do not turn off
325 // the visibility so that the next animation may render. The value of 372 // the visibility so that the next animation may render. The value of
326 // layer()->GetTargetVisibility() can be incorrect if the hide animation was 373 // layer()->GetTargetVisibility() can be incorrect if the hide animation was
327 // aborted to schedule an animation to become visible. As the new animation 374 // aborted to schedule an animation to become visible. As the new animation
328 // is not yet added to the queue. crbug.com/374236 375 // is not yet added to the queue. crbug.com/374236
329 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility()) 376 if (layer()->GetAnimator()->is_animating() || layer()->GetTargetVisibility())
330 return; 377 return;
331 views::View::SetVisible(false); 378 views::View::SetVisible(false);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 gfx::Insets tray_bg_insets = GetInsets(); 432 gfx::Insets tray_bg_insets = GetInsets();
386 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { 433 if (GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
387 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(), 434 return gfx::Insets(-tray_bg_insets.top(), anchor_insets.left(),
388 -tray_bg_insets.bottom(), anchor_insets.right()); 435 -tray_bg_insets.bottom(), anchor_insets.right());
389 } else { 436 } else {
390 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(), 437 return gfx::Insets(anchor_insets.top(), -tray_bg_insets.left(),
391 anchor_insets.bottom(), -tray_bg_insets.right()); 438 anchor_insets.bottom(), -tray_bg_insets.right());
392 } 439 }
393 } 440 }
394 441
395 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { 442 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() {
396 return Shell::GetContainer( 443 aura::Window* container = Shell::GetContainer(
397 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), 444 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
398 kShellWindowId_SettingBubbleContainer); 445 kShellWindowId_SettingBubbleContainer);
446
447 // Place the bubble in |container|, or in a window clipped to the work area
448 // in maximize mode, to avoid tray bubble and shelf overlap.
449 if (Shell::Get()
450 ->maximize_mode_controller()
451 ->IsMaximizeModeWindowManagerEnabled()) {
452 if (!clipping_window_.get()) {
453 clipping_window_ = base::MakeUnique<aura::Window>(nullptr);
454 clipping_window_->Init(ui::LAYER_NOT_DRAWN);
455 clipping_window_->layer()->SetMasksToBounds(true);
456 container->AddChild(clipping_window_.get());
457 clipping_window_->Show();
458 }
459 clipping_window_->SetBounds(shelf_->GetUserWorkAreaBounds());
460 return clipping_window_.get();
461 }
462 return container;
463 }
464
465 void TrayBackgroundView::AnimateToTargetBounds(const gfx::Rect& target_bounds,
466 bool close_bubble) {
467 const int kAnimationDurationMS = 200;
468
469 ui::ScopedLayerAnimationSettings settings(
470 GetBubbleView()->GetWidget()->GetNativeView()->layer()->GetAnimator());
471 settings.SetTransitionDuration(
472 base::TimeDelta::FromMilliseconds(kAnimationDurationMS));
473 settings.SetTweenType(gfx::Tween::EASE_OUT);
474 settings.SetPreemptionStrategy(
475 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
476 if (close_bubble)
477 settings.AddObserver(new CloseBubbleObserver(this));
478 GetBubbleView()->GetWidget()->SetBounds(target_bounds);
399 } 479 }
400 480
401 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() 481 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask()
402 const { 482 const {
403 return base::MakeUnique<views::RoundRectInkDropMask>( 483 return base::MakeUnique<views::RoundRectInkDropMask>(
404 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); 484 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius);
405 } 485 }
406 486
407 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { 487 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) {
408 if (is_active_) 488 if (is_active_)
(...skipping 29 matching lines...) Expand all
438 } 518 }
439 519
440 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { 520 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const {
441 gfx::Insets insets = GetBackgroundInsets(); 521 gfx::Insets insets = GetBackgroundInsets();
442 gfx::Rect bounds = GetLocalBounds(); 522 gfx::Rect bounds = GetLocalBounds();
443 bounds.Inset(insets); 523 bounds.Inset(insets);
444 return bounds; 524 return bounds;
445 } 525 }
446 526
447 } // namespace ash 527 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_background_view.h ('k') | ash/system/tray_drag_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698