File: frame_size_button.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (582 lines) | stat: -rw-r--r-- 21,327 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ui/frame/caption_buttons/frame_size_button.h"

#include <memory>

#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/user_metrics.h"
#include "chromeos/ui/base/window_properties.h"
#include "chromeos/ui/frame/caption_buttons/snap_controller.h"
#include "chromeos/ui/frame/frame_utils.h"
#include "chromeos/ui/frame/multitask_menu/multitask_menu.h"
#include "chromeos/ui/frame/multitask_menu/multitask_menu_nudge_controller.h"
#include "chromeos/utils/haptics_util.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/hit_test.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/screen.h"
#include "ui/display/tablet_state.h"
#include "ui/events/devices/haptic_touchpad_effects.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/animation/compositor_animation_runner.h"
#include "ui/views/widget/widget.h"

namespace chromeos {

namespace {

// The default delay between the user pressing the size button and the buttons
// adjacent to the size button morphing into buttons for snapping left and
// right.
constexpr base::TimeDelta kSetButtonsToSnapModeDelay = base::Milliseconds(150);

// The amount that a user can overshoot one of the caption buttons while in
// "snap mode" and keep the button hovered/pressed.
constexpr int kMaxOvershootX = 200;
constexpr int kMaxOvershootY = 50;

// TODO(b/277770052): Adjust the press duration to reflect the shorter overall
// time to activate the multitask menu.
constexpr base::TimeDelta kPieAnimationPressDuration = base::Milliseconds(150);
constexpr base::TimeDelta kPieAnimationHoverDuration = base::Milliseconds(500);

// Returns true if a mouse drag while in "snap mode" at |location_in_screen|
// would hover/press |button| or keep it hovered/pressed.
bool HitTestButton(const views::FrameCaptionButton* button,
                   const gfx::Point& location_in_screen) {
  gfx::Rect expanded_bounds_in_screen = button->GetBoundsInScreen();
  if (button->GetState() == views::Button::STATE_HOVERED ||
      button->GetState() == views::Button::STATE_PRESSED) {
    expanded_bounds_in_screen.Inset(
        gfx::Insets::VH(-kMaxOvershootY, -kMaxOvershootX));
  }
  return expanded_bounds_in_screen.Contains(location_in_screen);
}

SnapDirection GetSnapDirection(const views::FrameCaptionButton* to_hover) {
  if (!to_hover)
    return SnapDirection::kNone;

  aura::Window* window = to_hover->GetWidget()->GetNativeWindow();
  switch (to_hover->GetIcon()) {
    case views::CAPTION_BUTTON_ICON_LEFT_TOP_SNAPPED:
      return GetSnapDirectionForWindow(window, /*left_top=*/true);
    case views::CAPTION_BUTTON_ICON_RIGHT_BOTTOM_SNAPPED:
      return GetSnapDirectionForWindow(window, /*left_top=*/false);
    case views::CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE:
    case views::CAPTION_BUTTON_ICON_MINIMIZE:
    case views::CAPTION_BUTTON_ICON_CLOSE:
    case views::CAPTION_BUTTON_ICON_BACK:
    case views::CAPTION_BUTTON_ICON_LOCATION:
    case views::CAPTION_BUTTON_ICON_MENU:
    case views::CAPTION_BUTTON_ICON_ZOOM:
    case views::CAPTION_BUTTON_ICON_CENTER:
    case views::CAPTION_BUTTON_ICON_FLOAT:
    case views::CAPTION_BUTTON_ICON_CUSTOM:
    case views::CAPTION_BUTTON_ICON_COUNT:
      NOTREACHED();
  }
}

}  // namespace

// This view controls animating a pie on a parent button which indicates when
// long press or long hover will end.
class FrameSizeButton::PieAnimationView : public views::View,
                                          public views::AnimationDelegateViews {
  METADATA_HEADER(PieAnimationView, views::View)

 public:
  explicit PieAnimationView(FrameSizeButton* button)
      : views::AnimationDelegateViews(this), button_(button) {
    SetCanProcessEventsWithinSubtree(false);
    animation_.SetTweenType(gfx::Tween::LINEAR);
  }
  PieAnimationView(const PieAnimationView&) = delete;
  PieAnimationView& operator=(const PieAnimationView&) = delete;
  ~PieAnimationView() override = default;

  void Start(base::TimeDelta duration, MultitaskMenuEntryType entry_type) {
    entry_type_ = entry_type;

    const double animation_value =
        entry_type_ == MultitaskMenuEntryType::kFrameSizeButtonLongPress
            ? animation_.GetCurrentValue()
            : 0.0;

    animation_.Reset(animation_value);
    // `SlideAnimation` is unaffected by debug tools such as
    // "--ui-slow-animations" flag, so manually multiply the duration here. Note
    // that this will also cause `AnimationEnded` to run immediately if the test
    // is using zero duration. If we are partially through the animation when
    // the button is pressed, then we want the duration to be relative to the
    // percentage of the animation that still needs to be completed. For
    // example, if we are 1/4 through the animation when pressed, then we want
    // the remaining animation to only take 3/4 of the full long press duration.
    animation_.SetSlideDuration(
        ui::ScopedAnimationDurationScaleMode::duration_multiplier() * duration *
        (1 - animation_value));
    animation_.Show();
  }

  void Stop() {
    animation_.Reset(0.0);
    SchedulePaint();
  }

  // views::View:
  void OnPaint(gfx::Canvas* canvas) override {
    if (!GetWidget()) {
      return;
    }

    const double animation_value = animation_.GetCurrentValue();
    if (animation_value == 0.0) {
      return;
    }

    // The pie is a filled arc which starts at the top and sweeps around
    // clockwise.
    const SkScalar start_angle = -90.f;
    const SkScalar sweep_angle = 360.f * animation_value;

    SkPath path;
    const gfx::Rect bounds = GetLocalBounds();
    path.moveTo(bounds.CenterPoint().x(), bounds.CenterPoint().y());
    path.arcTo(gfx::RectToSkRect(bounds), start_angle, sweep_angle,
               /*forceMoveTo=*/false);
    path.close();

    cc::PaintFlags flags;
    flags.setColor(
        GetWidget()->GetColorProvider()->GetColor(ui::kColorSysStateHover));
    flags.setAntiAlias(true);
    flags.setStyle(cc::PaintFlags::kFill_Style);
    canvas->DrawPath(path, flags);
  }

  // views::AnimationDelegateViews:
  void AnimationEnded(const gfx::Animation* animation) override {
    SchedulePaint();
    button_->ShowMultitaskMenu(entry_type_);
  }

  void AnimationProgressed(const gfx::Animation* animation) override {
    SchedulePaint();
  }

 private:
  gfx::SlideAnimation animation_{this};

  // Tracks the entry type that triggered the latests pie animation. Used for
  // recording metrics once the menu is shown.
  MultitaskMenuEntryType entry_type_ =
      MultitaskMenuEntryType::kFrameSizeButtonHover;

  // The button `this` is associated with. Unowned.
  const raw_ptr<FrameSizeButton> button_;
};

BEGIN_METADATA(FrameSizeButton, PieAnimationView)
END_METADATA

// The class to observe the to-be-snapped window during the waiting-for-snap
// mode. If the window's window state is changed or the window is put in
// overview during the waiting mode, cancel the snap.
class FrameSizeButton::SnappingWindowObserver : public aura::WindowObserver {
 public:
  SnappingWindowObserver(aura::Window* window, FrameSizeButton* size_button)
      : window_(window), size_button_(size_button) {
    window_->AddObserver(this);
  }

  SnappingWindowObserver(const SnappingWindowObserver&) = delete;
  SnappingWindowObserver& operator=(const SnappingWindowObserver&) = delete;

  ~SnappingWindowObserver() override {
    if (window_) {
      window_->RemoveObserver(this);
      window_ = nullptr;
    }
  }

  // aura::WindowObserver:
  void OnWindowPropertyChanged(aura::Window* window,
                               const void* key,
                               intptr_t old) override {
    DCHECK_EQ(window_, window);
    if ((key == chromeos::kIsShowingInOverviewKey &&
         window_->GetProperty(chromeos::kIsShowingInOverviewKey)) ||
        key == chromeos::kWindowStateTypeKey) {
      // If the window is put in overview while we're in waiting-for-snapping
      // mode, or the window's window state has changed, cancel the snap.
      size_button_->CancelSnap();
    }
  }

  void OnWindowDestroying(aura::Window* window) override {
    DCHECK_EQ(window_, window);
    window_->RemoveObserver(this);
    window_ = nullptr;
    size_button_->CancelSnap();
  }

 private:
  raw_ptr<aura::Window> window_;
  raw_ptr<FrameSizeButton> size_button_;
};

FrameSizeButton::FrameSizeButton(PressedCallback callback,
                                 FrameSizeButtonDelegate* delegate)
    : views::FrameCaptionButton(std::move(callback),
                                views::CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
                                HTMAXBUTTON),
      delegate_(delegate),
      long_tap_delay_(kSetButtonsToSnapModeDelay) {
  display_observer_.emplace(this);

  pie_animation_view_ = AddChildView(std::make_unique<PieAnimationView>(this));
}

FrameSizeButton::~FrameSizeButton() = default;

bool FrameSizeButton::IsMultitaskMenuShown() const {
  return multitask_menu_widget_ && !multitask_menu_widget_->IsClosed();
}

void FrameSizeButton::ShowMultitaskMenu(MultitaskMenuEntryType entry_type) {
  CHECK(!display::Screen::GetScreen()->InTabletMode());
  RecordMultitaskMenuEntryType(entry_type);
  // Owned by the bubble which contains this view. If there is an existing
  // bubble, it will be deactivated and then close and destroy itself.
  auto menu_delegate = std::make_unique<MultitaskMenu>(
      /*anchor=*/this, GetWidget(),
      /*close_on_move_out=*/entry_type ==
          MultitaskMenuEntryType::kFrameSizeButtonHover);
  multitask_menu_ = menu_delegate->GetWeakPtr();
  multitask_menu_widget_ = base::WrapUnique(
      views::BubbleDialogDelegateView::CreateBubble(std::move(menu_delegate)));
  multitask_menu_widget_->Show();
  delegate_->GetMultitaskMenuNudgeController()->OnMenuOpened(
      /*tablet_mode=*/false);

  haptics_util::PlayHapticTouchpadEffect(
      ui::HapticTouchpadEffect::kSnap,
      ui::HapticTouchpadEffectStrength::kMedium);
}

void FrameSizeButton::ToggleMultitaskMenu() {
  CHECK(!display::Screen::GetScreen()->InTabletMode());
  if (!multitask_menu_widget_) {
    ShowMultitaskMenu(MultitaskMenuEntryType::kAccel);
  } else {
    multitask_menu_widget_->Close();
  }
}

bool FrameSizeButton::OnMousePressed(const ui::MouseEvent& event) {
  if (IsTriggerableEvent(event)) {
    StartLongTapDelayTimer(event);
  }

  return views::FrameCaptionButton::OnMousePressed(event);
}

bool FrameSizeButton::OnMouseDragged(const ui::MouseEvent& event) {
  UpdateSnapPreview(event);
  // By default a FrameCaptionButton reverts to STATE_NORMAL once the mouse
  // leaves its bounds. Skip FrameCaptionButton's handling when
  // |in_snap_mode_| == true because we want different behavior.
  if (!in_snap_mode_)
    views::FrameCaptionButton::OnMouseDragged(event);

  if (multitask_menu_) {
    multitask_menu_->multitask_menu_view()->OnSizeButtonDrag(
        views::View::ConvertPointToScreen(this, event.location()));
  }

  return true;
}

void FrameSizeButton::OnMouseReleased(const ui::MouseEvent& event) {
  if (IsTriggerableEvent(event)) {
    CommitSnap(event);

    if (multitask_menu_) {
      multitask_menu_->multitask_menu_view()->OnSizeButtonRelease(
          views::View::ConvertPointToScreen(this, event.location()));
    }
  }

  pie_animation_view_->Stop();

  views::FrameCaptionButton::OnMouseReleased(event);
}

void FrameSizeButton::OnMouseCaptureLost() {
  SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate::kYes);
  views::FrameCaptionButton::OnMouseCaptureLost();
}

void FrameSizeButton::OnMouseMoved(const ui::MouseEvent& event) {
  // Ignore any synthetic mouse moves during a drag.
  if (!in_snap_mode_)
    views::FrameCaptionButton::OnMouseMoved(event);
}

void FrameSizeButton::OnGestureEvent(ui::GestureEvent* event) {
  if (event->details().touch_points() > 1) {
    SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate::kYes);
    return;
  }
  if (event->type() == ui::EventType::kGestureTapDown && delegate_->CanSnap() &&
      !display::Screen::GetScreen()->InTabletMode()) {
    StartLongTapDelayTimer(*event);

    // Go through FrameCaptionButton's handling so that the button gets pressed.
    views::FrameCaptionButton::OnGestureEvent(event);
    return;
  }

  if (event->type() == ui::EventType::kGestureScrollBegin ||
      event->type() == ui::EventType::kGestureScrollUpdate) {
    UpdateSnapPreview(*event);

    if (multitask_menu_) {
      multitask_menu_->multitask_menu_view()->OnSizeButtonDrag(
          views::View::ConvertPointToScreen(this, event->location()));
    }

    event->SetHandled();
    return;
  }

  if (event->type() == ui::EventType::kGestureTap ||
      event->type() == ui::EventType::kGestureScrollEnd ||
      event->type() == ui::EventType::kScrollFlingStart ||
      event->type() == ui::EventType::kGestureEnd) {
    if (multitask_menu_ && !multitask_menu_->GetWidget()->IsClosed() &&
        multitask_menu_->multitask_menu_view()->OnSizeButtonRelease(
            views::View::ConvertPointToScreen(this, event->location()))) {
      event->SetHandled();
      return;
    }

    if (CommitSnap(*event)) {
      event->SetHandled();
      return;
    }
  }

  views::FrameCaptionButton::OnGestureEvent(event);
}

void FrameSizeButton::StateChanged(views::Button::ButtonState old_state) {
  views::FrameCaptionButton::StateChanged(old_state);

  // Ignore if there is no native window, which can happen during widget
  // shutdown.
  if (!GetWidget()->GetNativeWindow()) {
    return;
  }

  // Pie animation will start on both active/inactive window.
  if (aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(
          GetWidget()->GetNativeWindow()->GetRootWindow());
      cursor_client && cursor_client->IsCursorVisible() &&
      GetState() == views::Button::STATE_HOVERED) {
    // On animation end we should show the multitask menu.
    // Note that if the window is not active, after the pie animation this will
    // activate the window.
    StartPieAnimation(kPieAnimationHoverDuration,
                      MultitaskMenuEntryType::kFrameSizeButtonHover);
  } else if (old_state == views::Button::STATE_HOVERED &&
             GetState() != views::Button::STATE_PRESSED) {
    // We want to continue the animation if the button was pressed while it was
    // already hovered, so only stop in other instances.
    pie_animation_view_->Stop();
  }
}

void FrameSizeButton::Layout(PassKey) {
  // Use the bounds of the inkdrop for the pie animation.
  gfx::Rect bounds = GetLocalBounds();
  bounds.Inset(GetInkdropInsets(bounds.size()));
  pie_animation_view_->SetBoundsRect(bounds);

  LayoutSuperclass<views::FrameCaptionButton>(this);
}

void FrameSizeButton::OnDisplayTabletStateChanged(display::TabletState state) {
  if (state == display::TabletState::kEnteringTabletMode) {
    pie_animation_view_->Stop();
    long_tap_delay_timer_.Stop();
  }
}

void FrameSizeButton::StartLongTapDelayTimer(const ui::LocatedEvent& event) {
  const bool is_mouse = event.IsMouseEvent();
  if (long_tap_delay_.is_zero()) {
    OnLongTapDelayTimerEnded(is_mouse, event.location());
  } else {
    long_tap_delay_timer_.Start(
        FROM_HERE, long_tap_delay_,
        base::BindOnce(&FrameSizeButton::OnLongTapDelayTimerEnded,
                       base::Unretained(this), is_mouse, event.location()));
  }
}

void FrameSizeButton::StartPieAnimation(base::TimeDelta duration,
                                        MultitaskMenuEntryType entry_type) {
  if (display::Screen::GetScreen()->InTabletMode() || IsMultitaskMenuShown()) {
    return;
  }

  pie_animation_view_->Start(duration, entry_type);
}

void FrameSizeButton::AnimateButtonsToSnapMode() {
  SetButtonsToSnapMode(FrameSizeButtonDelegate::Animate::kYes);

  // Start observing the to-be-snapped window.
  snapping_window_observer_ = std::make_unique<SnappingWindowObserver>(
      GetWidget()->GetNativeWindow(), this);
}

void FrameSizeButton::SetButtonsToSnapMode(
    FrameSizeButtonDelegate::Animate animate) {
  DCHECK(!display::Screen::GetScreen()->InTabletMode());
  in_snap_mode_ = true;

  // When using a right-to-left layout the close button is left of the size
  // button and the minimize button is right of the size button.
  if (base::i18n::IsRTL()) {
    delegate_->SetButtonIcons(views::CAPTION_BUTTON_ICON_RIGHT_BOTTOM_SNAPPED,
                              views::CAPTION_BUTTON_ICON_LEFT_TOP_SNAPPED,
                              animate);
  } else {
    delegate_->SetButtonIcons(views::CAPTION_BUTTON_ICON_LEFT_TOP_SNAPPED,
                              views::CAPTION_BUTTON_ICON_RIGHT_BOTTOM_SNAPPED,
                              animate);
  }
}

void FrameSizeButton::UpdateSnapPreview(const ui::LocatedEvent& event) {
  if (!in_snap_mode_) {
    // Set the buttons adjacent to the size button to snap left and right early
    // if the user drags past the drag threshold.
    // |set_buttons_to_snap_mode_timer_| is checked to avoid entering the snap
    // mode as a result of an unsupported drag type (e.g. only the right mouse
    // button is pressed).
    gfx::Vector2d delta(event.location() -
                        set_buttons_to_snap_mode_timer_event_location_);
    if (!long_tap_delay_timer_.IsRunning() ||
        !views::View::ExceededDragThreshold(delta)) {
      return;
    }
    AnimateButtonsToSnapMode();
  }

  const views::FrameCaptionButton* to_hover = GetButtonToHover(event);
  SnapDirection snap = GetSnapDirection(to_hover);

  gfx::Point event_location_in_screen(event.location());
  views::View::ConvertPointToScreen(this, &event_location_in_screen);
  bool press_size_button =
      to_hover || HitTestButton(this, event_location_in_screen);

  if (to_hover) {
    // Progress the minimize and close icon morph animations to the end if they
    // are in progress.
    SetButtonsToSnapMode(FrameSizeButtonDelegate::Animate::kNo);
  }

  delegate_->SetHoveredAndPressedButtons(to_hover,
                                         press_size_button ? this : nullptr);
  delegate_->ShowSnapPreview(snap,
                             /*allow_haptic_feedback=*/event.IsMouseEvent());
}

const views::FrameCaptionButton* FrameSizeButton::GetButtonToHover(
    const ui::LocatedEvent& event) const {
  gfx::Point event_location_in_screen(event.location());
  views::View::ConvertPointToScreen(this, &event_location_in_screen);
  const views::FrameCaptionButton* closest_button =
      delegate_->GetButtonClosestTo(event_location_in_screen);
  if ((closest_button->GetIcon() ==
           views::CAPTION_BUTTON_ICON_LEFT_TOP_SNAPPED ||
       closest_button->GetIcon() ==
           views::CAPTION_BUTTON_ICON_RIGHT_BOTTOM_SNAPPED) &&
      HitTestButton(closest_button, event_location_in_screen)) {
    return closest_button;
  }
  return nullptr;
}

bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) {
  snapping_window_observer_.reset();
  SnapDirection snap = GetSnapDirection(GetButtonToHover(event));
  delegate_->CommitSnap(snap);
  delegate_->SetHoveredAndPressedButtons(nullptr, nullptr);

  if (snap == SnapDirection::kPrimary) {
    base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
  } else if (snap == SnapDirection::kSecondary) {
    base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
  } else {
    SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate::kYes);
    return false;
  }

  SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate::kNo);
  return true;
}

void FrameSizeButton::CancelSnap() {
  snapping_window_observer_.reset();
  delegate_->CommitSnap(SnapDirection::kNone);
  delegate_->SetHoveredAndPressedButtons(nullptr, nullptr);
  SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate::kYes);
}

void FrameSizeButton::SetButtonsToNormalMode(
    FrameSizeButtonDelegate::Animate animate) {
  in_snap_mode_ = false;
  pie_animation_view_->Stop();
  long_tap_delay_timer_.Stop();
  delegate_->SetButtonsToNormal(animate);
}

void FrameSizeButton::OnLongTapDelayTimerEnded(bool is_mouse,
                                               const gfx::Point& location) {
  StartPieAnimation(kPieAnimationPressDuration,
                    is_mouse
                        ? MultitaskMenuEntryType::kFrameSizeButtonLongPress
                        : MultitaskMenuEntryType::kFrameSizeButtonLongTouch);

  // The minimize and close buttons are set to snap left and right when
  // snapping is enabled. Do not enable snapping if the minimize button is not
  // visible. The close button is always visible.
  if (!in_snap_mode_ && delegate_->CanSnap() &&
      delegate_->IsMinimizeButtonVisible()) {
    set_buttons_to_snap_mode_timer_event_location_ = location;
    AnimateButtonsToSnapMode();
  }
}

BEGIN_METADATA(FrameSizeButton)
END_METADATA

}  // namespace chromeos